Skill Overview
This skill generates geometry SVG figures suitable for exam papers, presentations, and teaching materials, and outputs them as PNG image files, which can be inserted directly into Word documents or PowerPoint slides.
Core Script Location(please confirm before any use):
GEOM_DIR=""
for d in /mnt/skills/user/jh-math-geometry/scripts \
/tmp/jh-math-geometry/scripts; do
[ -f "$d/geometry_renderer.py" ] && GEOM_DIR="$d" && break
done
echo "腳本目錄:$GEOM_DIR"
Processing Flow
Step 1: Understand the Requirements
Based on the user's description, determine which figures are needed. If unsure, quickly confirm:
- Which unit (triangle/quadrilateral/circle/solid...)?
- Which letters/numbers need to be labeled?
- Are there special markings (right-angle symbols, equal-side tick marks, angle arcs)?
- Output target: Word, PPTX, or pure image download?
Step 2: Create the Figure Specification JSON
Create the spec according to the requirements, save it to /home/claude/geometry_spec.json:
{
"figures": [
{
"id": "fig1",
"type": "triangle",
"config": {
"subtype": "right",
"vertex_labels": ["A", "B", "C"],
"right_angle_at": "C",
"side_labels": {"AB": "5", "BC": "3", "CA": "4"}
},
"canvas": {"width": 280, "height": 220}
}
],
"options": {"format": "png", "dpi": 150}
}
For detailed parameters, see
references/figure-catalog.md(read using the view tool).
Step 3: Install Dependencies and Run Rendering
pip install cairosvg python-docx python-pptx --break-system-packages -q
mkdir -p /home/claude/geometry_output
python3 "$GEOM_DIR/geometry_renderer.py" \
/home/claude/geometry_spec.json \
/home/claude/geometry_output/
ls /home/claude/geometry_output/
Step 4: Visual Confirmation
# 用 view 工具看 SVG(快速確認)
Use the view tool to view the generated .svg file to confirm whether the figure is correct.
If there are errors (label offset, poor proportions), adjust config and run again.
Step 5: Output
Pure image download
cp /home/claude/geometry_output/fig1.png /mnt/user-data/outputs/
Insert into Word
python3 - <<'EOF'
from docx import Document
from docx.shared import Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
import sys; sys.path.insert(0, "$GEOM_DIR")
from insert_to_docx import insert_figure, figures_from_manifest
doc = Document() # 或 Document('existing.docx')
figures_from_manifest('/home/claude/geometry_output/manifest.json', doc, width_cm=7.0)
doc.save('/home/claude/geometry_output/geometry.docx')
print("✅")
EOF
cp /home/claude/geometry_output/geometry.docx /mnt/user-data/outputs/
Insert into PowerPoint
python3 - <<'EOF'
from pptx import Presentation
import sys; sys.path.insert(0, "$GEOM_DIR")
from insert_to_pptx import figures_from_manifest
prs = Presentation() # 或 Presentation('existing.pptx')
figures_from_manifest('/home/claude/geometry_output/manifest.json', prs,
mode='individual', title_prefix='幾何圖形')
prs.save('/home/claude/geometry_output/geometry.pptx')
print("✅")
EOF
cp /home/claude/geometry_output/geometry.pptx /mnt/user-data/outputs/
Finally use present_files to provide the download.
Standard Flow for Being Called by Other Skills
When jh-math-exam or soil-teaching-deck and other skills need geometry figures,
insert the following steps directly into that skill's flow:
# 1. 找到腳本目錄
GEOM_DIR=""
for d in /mnt/skills/user/jh-math-geometry/scripts \
/tmp/jh-math-geometry/scripts; do
[ -f "$d/geometry_renderer.py" ] && GEOM_DIR="$d" && break
done
pip install cairosvg --break-system-packages -q
# 2. 建立圖形 spec(Claude 根據題目需求自行決定內容)
cat > /home/claude/geometry_spec.json << 'SPEC'
{
"figures": [
{"id": "q3_fig", "type": "triangle", "config": {...}, "canvas": {"width":250,"height":200}}
],
"options": {"format": "png", "dpi": 150}
}
SPEC
# 3. 渲染
mkdir -p /home/claude/geometry_output
python3 "$GEOM_DIR/geometry_renderer.py" /home/claude/geometry_spec.json /home/claude/geometry_output/
# 4. 取得 PNG 路徑供插入
FIGURE_PNG="/home/claude/geometry_output/q3_fig.png"
Figure Type Quick Reference Table
| type value | Description | Common subtypes |
|---|---|---|
triangle |
Triangle | general right isosceles equilateral |
quadrilateral |
Quadrilateral | parallelogram rectangle rhombus square trapezoid right_trapezoid |
circle |
Circle | (no subtype, controlled using elements) |
coordinate_plane |
Coordinate plane | (including lines, parabolas, points, line segments) |
solid_3d |
Solid figures | rectangular_prism cylinder cone triangular_prism square_pyramid triangular_pyramid |
parallel_lines |
Parallel lines cut by a transversal | (n_parallel controls the number of lines) |
triangle_center |
Triangle centers | centroid circumcenter incenter |
similar_triangles |
Similar triangles | (triangle1 + triangle2 configured separately) |
Marking System
| Function | Parameter | Description |
|---|---|---|
| Vertex labels | vertex_labels |
Default ["A","B","C"] |
| Right-angle symbol | right_angle_at |
Specify vertex |
| Angle arc | angle_arcs |
{"A":1} = one arc,{"A":2} = two arcs (congruent angles) |
| Equal-side tick marks | equal_marks |
{"AB":1,"CD":1} = same group,{"EF":2} = another group |
| Side length/side name | side_labels |
{"AB":"5"} or {"AB":"a"} |
| Dashed edges | dashed_sides |
["AB"] |
| Height | altitude_from |
Draw the height from the specified vertex |
| Median | median_from |
Draw median from the specified vertex |
Reference location
| What is needed | Which file to read |
|---|---|
| Complete parameters for all shape types + quick copy examples | references/figure-catalog.md |
| SVG generation engine source code | scripts/geometry_renderer.py |
| SVG → PNG conversion | scripts/svg_to_image.py |
| Function for inserting into Word | scripts/insert_to_docx.py |
| Function for inserting into PPTX | scripts/insert_to_pptx.py |
Notes
- cairosvg installation: must be redone before each new conversation
pip install - Coordinate confirmation: use
viewtool to view.svgconfirm before inserting into the document - Canvas size: recommended for exam paper figures
280×220; recommended for presentation figures360×280 - Font: SVG uses serif; after exporting to PNG, the appearance is consistent in Word/PPTX
- Multi-figure batch: the figures array can hold multiple figures at once; manifest.json records all output paths