# Qwen Mm Plugins Edu Agent

> Generate step-by-step math problem-solving tutorial videos in Chinese (Mandarin). Use when: (1) a user provides a math problem and wants an explanation video, (2) someone says "make a math tutorial", "explain this equation", "create a teaching video for this problem", "讲解这道题", "生成解题视频", (3) the user wants a Chinese-language math lesson covering formulas, equations, or geometric figures, (4) the user shares a math problem in text or LaTeX and asks for a video walkthrough, (5) the input is an image_assets/ folder containing problem images — the skill will extract the problem via visual recognition, solve it, and generate a tutorial video. Teaching components are rendered as realistic objects (solid opaque panels, 3D cards, SVG figures) with a modern aurora mesh aesthetic.

- Skill: `theheavenlyd3mon/qwen-mm-plugins-edu-agent` (Agent Skill, multi-file: 213 files)
- Install (CLI): `npx skillmds add theheavenlyd3mon/qwen-mm-plugins-edu-agent`
- Raw SKILL.md: https://api.skillmd.com/api/skills/theheavenlyd3mon/qwen-mm-plugins-edu-agent/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: theheavenlyd3mon (https://skillmd.com/u/theheavenlyd3mon)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/theheavenlyd3mon/qwen-mm-plugins-edu-agent

---


# Math Tutorial Video Generator

Transforms a math problem into a step-by-step Chinese-language video tutorial. Teaching components — equations, geometric figures, solution steps — are rendered as realistic objects: solid opaque panels (glass-look via borders + layered shadow, NO `backdrop-filter`, NO translucency), 3D metallic cards, animated SVG constructions, on themed backgrounds with animated gradient orbs and smooth ambient effects. The default theme is "Aurora Scholar" (blue wave texture + indigo/violet/cyan orbs); 4 alternative light themes are available (清雅湖蓝, 柔紫轻盈, 薄荷清新, 暖黄纸感) for visual variety across different problem types — see the Background Theme Catalog in design-system.md.

## Prerequisites (环境准备 — 开工前必查)

This is a **skill-only** capability (no MCP server), so its runtime dependencies are **NOT** auto-installed by `uvx`. Verify ALL of the following before Step 0 — a missing one silently breaks a later step:

| Dependency | Needed for | Install / check |
|------------|-----------|-----------------|
| **Node.js + npm/npx** | scaffold + render (`npx hyperframes`) | `node -v` (≥18) |
| **hyperframes CLI** | `init` / `lint` / `validate` / `render` | pulled on demand via `npx hyperframes` (needs npm-registry access at scaffold time; the project then pins a version in `dist/package.json`) |
| **Headless Chromium + OS libs** | `npx hyperframes render` (puppeteer) + post-render QA gates (`postcheck.py` / `precheck.py` drive headless Chrome) | the browser itself is auto-downloaded by puppeteer on first `npx hyperframes`; on **minimal Linux** you must also `apt install libnss3 libatk-bridge2.0-0 libgbm1 libasound2 libxkbcommon0 libgtk-3-0 fonts-noto-cjk` (else Chrome fails to launch, or CJK/formulas render as tofu boxes). Reuse a system Chrome via `export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium`. |
| **Python 3 + pip** | TTS script | `python3 -m pip --version` |
| **`dashscope` `soundfile` `numpy` `requests`** | Step 3 TTS synthesis + assembly | `python3 -m pip install dashscope soundfile numpy requests` |
| **ffmpeg** | loudness normalization (`loudnorm`) + frame extraction for self-check | `brew install ffmpeg` / `apt install ffmpeg` |
| **`DASHSCOPE_API_KEY`** | Qwen-TTS (`qwen3-tts-flash`) | `export DASHSCOPE_API_KEY="sk-xxx"`, **or** put `DASHSCOPE_API_KEY=sk-xxx` in `~/.qwen-mm-plugins/config` for GUI-launched setups that don't inherit shell exports. `$EDU_SKILL_ROOT/scripts/generate_voice.py` reads it at runtime — **never `cat`/paste the key into the conversation.** |

> **Network boundary:** `npx hyperframes init` and the TTS calls need internet. The *render* itself is air-gapped — that is why fonts / KaTeX / GSAP must be self-hosted into `dist/` (see Step 5 Prerequisites). DashScope TTS may rate-limit under high concurrency; if you hit `Throttling.RateQuota`, lower the thread-pool worker count and add backoff (see step-3).

Before Step 0, resolve `EDU_SKILL_ROOT` to the **absolute directory containing this `SKILL.md`**. All
shipped scripts and assets must be addressed through that root; they are not in the user's project.
Shell tool calls do not necessarily share state, so set it in every command block that uses it (or
substitute the resolved absolute path directly); never rely on an earlier shell invocation:

```bash
EDU_SKILL_ROOT="<absolute directory containing qwen-mm-plugins-edu-agent/SKILL.md>"
test -f "$EDU_SKILL_ROOT/scripts/precheck.py" || { echo "invalid EDU_SKILL_ROOT"; exit 1; }
```

## Pipeline Overview

| Step | Name | Artifact | Reference |
|------|------|----------|-----------|
| 0 | Image Input & Problem Extraction | `PROBLEM.md` | [step-0-image-input.md](references/step-0-image-input.md) |
| 1 | Problem Analysis | `ANALYSIS.md` | [step-1-problem-analysis.md](references/step-1-problem-analysis.md) |
| 2 | Teaching Script | `SCRIPT.md` | [step-2-teaching-script.md](references/step-2-teaching-script.md) |
| 3 | Voice Generation | `narration.wav` + `transcript.json` + `captions.json` (sentence-by-sentence TTS, no Whisper) | [step-3-voice-generation.md](references/step-3-voice-generation.md) |
| 4 | Storyboard | `STORYBOARD.md` | [step-4-storyboard.md](references/step-4-storyboard.md) |
| 5 | Build Components | `compositions/*.html` | [step-5-build-components.md](references/step-5-build-components.md) |
| 6 | Compose & Render | `index.html` + MP4 | [step-6-compose-render.md](references/step-6-compose-render.md) |

## Step 0: Image Input & Problem Extraction

Read [references/step-0-image-input.md](references/step-0-image-input.md).

Read all images from the `image_assets/` folder using the `Read` tool (Claude's multimodal vision directly interprets image content). Extract the complete problem text, convert all math expressions to LaTeX, and describe any figures or diagrams. If JSONL metadata is available (subject, sub_subject, question_type, stepwise_explanation), use it as context hints but treat the image as ground truth.

<HARD-GATE>
`PROBLEM.md` must exist with: complete problem text in Chinese, all math expressions in LaTeX, and figure descriptions (if applicable). All images in `image_assets/` must have been read.
</HARD-GATE>

## Step 1: Problem Analysis

Read [references/step-1-problem-analysis.md](references/step-1-problem-analysis.md).

Parse the input math problem, classify its type, extract knowledge points, and produce a complete solution outline with numbered steps. When `PROBLEM.md` exists from Step 0, use it as the primary input source.

<HARD-GATE>
`ANALYSIS.md` must exist with: problem statement, type classification, solution steps, and final answer — all verified for correctness.
</HARD-GATE>

## Step 2: Teaching Script

Read [references/step-2-teaching-script.md](references/step-2-teaching-script.md).

Write the Chinese narration script with scene markers. Apply math symbol pronunciation rules. Target pacing: 3.5-4.0 Chinese characters per second.

<HARD-GATE>
`SCRIPT.md` must exist with scene-separated narration text in Chinese. All math symbols converted to spoken Chinese.
</HARD-GATE>

## Step 3: Voice Generation

Read [references/step-3-voice-generation.md](references/step-3-voice-generation.md). TTS strategy: **DashScope Qwen-TTS via the official SDK** (`dashscope.MultiModalConversation`, model `qwen3-tts-flash`, HTTP — returns a WAV URL) — no self-hosted TTS node, no URL wiring. **Speed + accuracy:** synthesize every sentence **concurrently** through a thread pool (wall-clock ≈ the slowest single sentence, not the sum), then measure each returned clip's real duration for exact per-sentence timestamps. No Whisper dependency.

Generate standard Mandarin TTS audio. Each sentence's exact duration is measured from its returned audio clip, producing both `narration.wav` and `transcript.json` in one pass with 100% accurate timestamps. No Whisper transcription needed.

<HARD-GATE>
`narration.wav`, `transcript.json`, and `captions.json` must exist. Audio must be loudness-normalized with `ffmpeg loudnorm` (EBU R128, -16 LUFS). Audio is generated with DashScope Qwen-TTS (`dashscope.MultiModalConversation`, model `qwen3-tts-flash`) — `DASHSCOPE_API_KEY` required. Timestamps are measured from TTS output (not estimated). Text in transcript/captions comes from the original script. Timestamps mapped to scene boundaries.
</HARD-GATE>

## Step 4: Storyboard

Read [references/step-4-storyboard.md](references/step-4-storyboard.md). Read [design-system.md](design-system.md) for visual tokens.

Design per-scene visual layout, assign component templates from [math-components.md](references/math-components.md), and plan transitions. Check [assets/ASSET_CATALOG.md](assets/ASSET_CATALOG.md) to identify which pre-built visual components can be reused in each scene. **Select a background theme** from the Background Theme Catalog in design-system.md — set it in the Global Direction block (default: `aurora-scholar`).

<HARD-GATE>
`STORYBOARD.md` must exist with per-scene direction: component type, layout, animation choreography, and transition choice.
</HARD-GATE>

## Step 5: Build Components

Read the `hyperframes` skill — every composition authoring rule applies. Read the `gsap` skill for animation patterns. Read [references/step-5-build-components.md](references/step-5-build-components.md). Read [references/math-components.md](references/math-components.md) for component templates. Read [assets/ASSET_CATALOG.md](assets/ASSET_CATALOG.md) for pre-built visual components. **For geometry diagrams (几何图形)**, read [references/geometry-construction-guide.md](references/geometry-construction-guide.md) for coordinate computation patterns, angle arc construction, and complete worked examples (triangles, quadrilaterals, circles, rotations, reflections); also read [references/golden-example-geometry.md](references/golden-example-geometry.md) for a complete golden pipeline (PROBLEM → HTML compositions) showing the proven split layout, draw-on animation choreography, and narration-synced note blocks from a top-quality geometry proof video. **For circuit schematic diagrams (电路图)**, read [references/circuit-schematic-guide.md](references/circuit-schematic-guide.md) for physics rules and SVG symbol templates. **For any scene that must ANIMATE A PROCESS with real motion (生物过程/受力矢量/波动/滴定/运动演示 — things that split, move, get pulled, or a quantity that changes across stages), read [references/example-process-animation.md](references/example-process-animation.md)** — a top-scoring few-shot (洋葱有丝分裂) with two complete reference scenes and copy-me techniques: staged phase reveal, split-and-move, **connectors that track a moving object and shorten (纺锤丝/绳/矢量牵引)**, live count-up, and a stepped quantity-vs-stage chart (plus the no-360°-spin rule). **🧬 MANDATORY for ANY 染色体/细胞分裂题目 (有丝分裂/减数分裂/染色单体/着丝点/纺锤丝/移向两极): you MUST open and copy [references/examples/mitosis-anaphase.scene.html](references/examples/mitosis-anaphase.scene.html)** — the spindle fibers must be animated `<line>`s that TRACK the moving chromatids and SHORTEN (pull them to the poles), with a live 染色体数 count-up, and NO 360° spin on chromosomes. This is enforced at render time by `scripts/check_chromosome_example.py` (a chromosome cell-division scene without the fiber-shorten tween, or with a 360° spin, FAILS precheck).

Scaffold the project with `npx hyperframes init dist --non-interactive --example blank` (the `--example blank` flag is required — hyperframes ≥0.7.77 rejects a bare `--non-interactive`). **The project root is the current workspace and the scaffold dir MUST be exactly `dist/` at that root — never nest it inside another folder (e.g. NOT `math-tutorial-output/dist`); the renderer and all gates assume `./dist`.** **Build ONE composition per scene listed in `STORYBOARD.md` — one special ray / one solution step / one concept per scene; NEVER cram several planned scenes into a single composition (that is the #1 cause of under-rendered, blank, or half-empty scenes and of run-to-run instability).** **Before writing custom HTML for any visual object**, check the [assets/](assets/) directory — it contains 83 pre-built K12 components (motion, optics, circuit, mechanics, fluid, chemistry, wave, indicators, math), including 6 circuit schematic symbols (`sch-battery`, `sch-ammeter`, `sch-voltmeter`, `sch-switch`, `sch-bulb`, `sch-resistor`). If a matching component exists, copy its CSS + HTML + JS hooks verbatim into the composition instead of building from scratch.

<HARD-GATE>
**>>> MANDATORY: run precheck and loop until it passes <<<**

```bash
EDU_SKILL_ROOT="<absolute directory containing qwen-mm-plugins-edu-agent/SKILL.md>"
python3 "$EDU_SKILL_ROOT/scripts/precheck.py" dist
```

This script auto-fixes LaTeX escaping, then runs all validation checks. **You MUST see `ALL CHECKS PASSED` in the output before proceeding to Step 6.** If any check shows `FAIL`:

1. Read the FAIL message — it prints the exact file, line, and fix instruction
2. Apply the fix to the offending file(s)
3. Re-run `python3 "$EDU_SKILL_ROOT/scripts/precheck.py" dist`
4. **Repeat steps 1-3 until the output contains `ALL CHECKS PASSED`**

**Do NOT proceed to Step 6 with failing checks. Do NOT skip precheck. Do NOT treat precheck failures as warnings.**

---

The precheck validates all of the following (each is also a standalone script in `scripts/`):

- **Asset mirror** — GSAP/KaTeX/fonts mirrored into `compositions/` (sub-compositions resolve `./` relative to their own directory; without the mirror, GSAP/KaTeX/fonts silently fail → blank scenes)
- **Composition format** — sub-compositions are HTML fragments, not full `<!doctype>` documents (full docs → blank panels)
- **No CDN URLs** — no `cdn.jsdelivr.net` or external `src`/`href` (render sandbox is air-gapped → all external loads fail silently)
- **KaTeX CJK** — no Chinese inside `katex.render()` or `data-tex` (KaTeX fonts lack CJK → tofu)
- **CJK font on Chinese text (中文必须用中文字体)** — any SVG `<text>`/`<tspan>` or inline-styled element whose text contains Chinese MUST use a stack including `Noto Sans SC` (e.g. `font-family="Noto Sans SC, Inter, sans-serif"`); `Inter`/`sans-serif` alone has no CJK glyphs so Chinese renders as **NO GLYPH / 豆腐块**. Don't mix scripts in one `<text>` — split Latin (Inter) and Chinese (Noto Sans SC) into separate `<tspan>`/`<text>`. Gate: `scripts/check_cjk_font.py`
- **KaTeX escaping** — LaTeX in JS strings double-escaped (`\\\\dfrac`, not `\\dfrac`; JS eats single `\\d` → "dfrac12" instead of fraction)
- **Unrendered fractions** — no literal "dfrac"/"frac{" leaked into visible HTML text
- **Caption size** — font-size 36–40px (not 64px giant subtitles)
- **Caption pinned to bottom (字幕固定在视频下方)** — every caption bar lives ONLY in `index.html`'s root track and is styled `position:absolute; bottom:48px; left:50%; transform:translateX(-50%)`; NEVER use `top:`, and NEVER put a caption inside a scene composition (it would drift to the top/middle). Gate: `scripts/check_caption_position.py`
- **Caption safe zone** — every scene reserves the bottom ~180px (content in the top ~900px) so the subtitle never covers content (字幕遮挡)
- **Caption overflow** — the caption bar is width-bounded (`max-width:1600px`, never `white-space:nowrap`), uses `width:max-content` (so it uses the full width before wrapping instead of shrinking to the ~960px half-frame), and each cue is short (split long sentences into sequential one-line cues); the subtitle never runs off the frame edge (字幕超出边界). Gate: `scripts/check_caption_overflow.py`
- **Caption always on top (字幕必须在最顶层)** — the caption bar has an unbeatable `z-index` (`2147483647`) so it is ALWAYS above every scene layer/panel and can never be covered (字幕被遮挡); scenes must keep their z-index small (<100). Gate: `scripts/check_caption_overflow.py`
- **Scene layout** — `.scene-content` is a centering box that fills the frame (`position:absolute;inset:0;display:flex;align-items:center;justify-content:center`); filling alone (no flex-center trio) piles a single panel at the TOP with the bottom half empty (排版问题). Gate: `scripts/check_scene_layout.py`
- **No oversize/overflow (排版过大)** — every element fits within 1920×1080 (content within the 1920×900 safe area with edge margins); no CSS `width`>1920px / `height`>1080px, keep `scale()` ≤ ~1.5; size by container (%/max-width/flex/grid), scale SVG via viewBox. Hero text ≤ ~96px is guidance (decorative watermarks may be larger). Gate: `scripts/check_scene_overflow.py`
- **SVG height must be bounded (SVG高度必须有界 — 防止场景突然变大)** — never size a content `<svg>` as `width:100%; height:auto` with a tall/near-square viewBox: `height:auto` ties the rendered height to the viewBox aspect ratio, so at full panel width a `1000×760` viewBox becomes ~1050px tall and overflows the ~860px usable height — the scene appears to "suddenly get big" (场景突然变大). Bound the height: give the SVG `max-height:<usable>px` (e.g. `max-height:760px`), or size it by height inside a bounded flex/grid box with `preserveAspectRatio="xMidYMid meet"`, or choose a viewBox whose aspect ratio matches the available box. Deterministic gate: `scripts/check_svg_height_bound.py`; the headless-measured `scripts/check_scene_fit.py` is the runtime backstop.
- **No overlapping SVG labels (SVG标签禁止重叠)** — inside a single `<svg>`, no two `<text>` labels may collide. Don't stack a fulcrum/center label and its arm/segment labels on one shared line; put the center label above and arm labels below (anchored `end`/`start`, pushed outward past the shape edge) with a gap of ≥ ~1 label-height; stagger point labels that share an axis and never let a point label bury an axis tick number (see Rule #28). Gate: `scripts/check_svg_label_overlap.py`
- **Node-graph diagrams clean (关系图/流程图)** — in a boxes+arrows+in-shape-label diagram: every in-shape label is in the same `<g>` as its shape (else it slides off → white字消失), white SVG text only ever sits inside a dark shape, arrow endpoints stop before the 方框 (no arrowhead poking into a box), edge labels stay in the gaps (see Rule #31). Gate: `scripts/check_svg_node_graph.py`
- **No CSS-hidden content** — no `opacity:0` / `visibility:hidden` in CSS; GSAP handles via `autoAlpha:0` in JS
- **No frosted glass** — no `backdrop-filter`, panels are opaque `#ffffff`
- **Scene coverage** — one composition per storyboard scene, all wired with `data-composition-src` and `window.__timelines[...]`
- **Root refs** — `index.html` uses `data-composition-src` (not `data-src` or `src`) for all scenes
- **Geometry verification** — every geometry scene (SVG with 3+ labeled points) has a `<!-- GEOMETRY VERIFICATION -->` block; all `ASSERT` lines verified mathematically (coordinates satisfy parallel/perpendicular/midpoint/intersection/ratio constraints)

Additional requirements NOT checked by precheck (manual verification):
- Self-hosted fonts + KaTeX + GSAP copied into `dist/` AND mirrored into `dist/compositions/`
- Chinese font NOT subsetted — one full `NotoSansSC-Bold.woff2` per weight
- KaTeX CSS inlined with local font URLs
- No gradient text on KaTeX formulas (use solid `color`, not `background-clip:text`)
- Grid/lattice figures generated programmatically with deduped edges (not hand-typed coordinates)
</HARD-GATE>

## Step 6: Compose & Render

Read [references/step-6-compose-render.md](references/step-6-compose-render.md). Invoke the `hyperframes-cli` skill for CLI commands.

Assemble root `dist/index.html`, run lint + validate + inspect, preview, and render. **All CLI commands (lint, validate, render) must run from inside `dist/`.**

**🔎 MANDATORY after rendering — visual overlap self-check loop (渲染后抽帧自查，看到重叠必须改坐标重渲，直到不重叠):** `precheck.py` now includes `check_render_overlap.py`, a headless render-truth gate that measures REAL bounding boxes and FAILs when a `<text>` is painted under/over a box it doesn't belong to (文字被方框覆盖/压框 — e.g. 取食→取, 捕食→捕; static coordinate gates miss this because scaling + CJK glyph width + SVG paint order make a "clear on paper" label collide in the render). That gate must pass. **In addition, you MUST look at the pixels:** for every scene with boxes/connectors/labels/charts, extract a settled frame (`ffmpeg -ss <scene_midpoint> -i output.mp4 -frames:v 1 /tmp/ov.png`), open it with the Read tool, and check by eye for **文字被框压/裁切、框和线重叠、框对不齐，以及方向/朝向/语义错误**（figure 画反/朝向错：燃着木条火焰须在瓶内而非瓶口外、斜面朝向、箭头矢量方向、仪器插入端、倾倒口朝向、电池极性/电流方向、图表是否真的体现所述趋势）. If you see ANY overlap/misalignment/wrong-orientation, **edit the offending coordinates (move labels into the gap with clearance / shorten connectors / align boxes / draw highlight rings inside the box / flip the reversed figure), re-render, and look again — repeat until every frame is visually clean and physically correct.** Never claim "visually verified" without having actually extracted and read the frames. Full loop in [references/step-6-compose-render.md](references/step-6-compose-render.md) → "Post-Render Visual Overlap Self-Check".

**🚫 MANDATORY after rendering — line/curve render-truth gate (线/曲线漏画检测):** run `python3 "$EDU_SKILL_ROOT/scripts/postcheck.py" dist` and loop until it prints `ALL POST-RENDER CHECKS PASSED`. Its `check_curves_rendered.py` is renderer-agnostic: it renders a KNOWN-GOOD reference of each scene (GSAP + fonts injected by absolute path), then checks that every solid line/curve that scene should draw is **actually painted in `output.mp4`**. This catches the most deceptive render bug — a graph that shows its dots/axes/labels but drops the connecting curves (**"有点、没线"**) because JS-generated path `d` never ran (typically a hand-rolled renderer that stripped GSAP without re-injecting it by absolute `file://`). Pre-render gates cannot catch this — the composition is correct; only the rendered pixels reveal the loss. **Prevention: render with `npx hyperframes render`; do NOT hand-roll a CDP/puppeteer renderer — and if you must, re-inject GSAP/KaTeX/fonts via absolute `file://` paths (as you already do for bg-texture), never strip `./gsap/gsap.min.js` and leave it.** Full section in [references/step-6-compose-render.md](references/step-6-compose-render.md) → "Post-Render Line/Curve Render-Truth Gate".

**🌊 MANDATORY after rendering — smooth-curve render-truth gate (曲线不能用折线逼近，看到折线必须改代码重渲，直到通过):** the same `postcheck.py` now also runs `check_smooth_curve_render.py`. It loads each continuous-curve scene (抛物线/双曲线/正弦/指数/反比例衰减 …), seeks the animation to its settled state, then **walks the ACTUAL rendered curve geometry** (`getPointAtLength`) and FAILs when a curve is drawn as a handful of straight chords — a jagged zig-zag with sharp kinks and long dead-straight runs between them (`<path d="M488,585 L500,540 L530,480 …">` 这类 ~7 段直线拼出来的"曲线"). This is a **visual/render-truth** check: it sees the rendered shape, so it also catches curves whose `d` is generated by JS (which the static pre-render `check_smooth_curve.py` cannot see). **When it FAILs, you MUST rewrite that curve's code and re-render, looping until it passes** — do NOT ship a jagged curve. **Fix:** build the path `d` with the Catmull-Rom `smoothPath()` helper (sparse control points → cubic Béziers), OR emit a densely-sampled point list (~1 pt per ≤10 px, ~120+ pts across a wide axis). Genuinely piecewise-linear graphs (`y=|x|`, 分段函数, 折线统计图, 匀速距离-时间) are exempt. See references/step-5-build-components.md → "Smooth curves (顺滑曲线)".

<HARD-GATE>
**>>> Pre-render gate: precheck must have passed <<<**

Before rendering, confirm that `python3 "$EDU_SKILL_ROOT/scripts/precheck.py" dist` was already run in Step 5 and printed `ALL CHECKS PASSED`. If you skipped it or are unsure, run it now — it takes seconds. Do NOT render with failing prechecks.

`npx hyperframes lint` and `npx hyperframes validate` pass with zero errors (run from `dist/`). Video rendered to MP4 via `npx hyperframes render` inside `dist/`. The output `.mp4` file must exist inside `dist/` and be reported to the user. Preview-only is NOT sufficient — rendering is mandatory. **After rendering: `check_render_overlap.py` passes AND you have extracted+viewed a frame from every box/connector/label/chart scene and confirmed no clipped/covered text, no line-into-box, no misaligned boxes — fixing coordinates and re-rendering until clean. AND `python3 "$EDU_SKILL_ROOT/scripts/postcheck.py" dist` prints `ALL POST-RENDER CHECKS PASSED` (every line/curve the scene should draw is actually painted in output.mp4 — 线/曲线没漏画).**
</HARD-GATE>

## Design System

Read [design-system.md](design-system.md) before writing ANY HTML. It defines the "Aurora Scholar" light-themed visual identity. Use its exact color tokens, font specs, and component styles. Do not invent colors.

## Problem Type Reference

| Problem Type | Typical Duration | Scenes | Key Components |
|---|---|---|---|
| Single equation | 30-60s | 4-5 | Problem Card + 2-3 Formula Panels + Conclusion |
| Multi-step algebra | 60-120s | 6-8 | Problem Card + Analysis + Steps + Summary |
| Geometry proof | 90-150s | 7-10 | Problem Card + Geometry Canvas + Proof Steps |
| Word problem | 60-90s | 5-7 | Problem Card + Modeling + Solve + Verify |

## Non-Negotiable Rules

1. **Caption text from original script (字幕必须用原始脚本文本).** Video captions/subtitles MUST use text from `captions.json` (which contains the original narration script text with timestamps measured from TTS output). The timestamps are 100% accurate because they are measured from each sentence's actual TTS audio duration during sentence-by-sentence synthesis. The OpenCC `t2s` conversion is no longer needed — transcript text comes directly from the original script.
2. **KaTeX for layout-dependent math; plain HTML/Chinese for simple symbols (复杂公式用KaTeX，简单符号用HTML或中文).** Use KaTeX only when the expression needs math layout features (fractions, roots, summations, matrices). For simple comparisons and standalone symbols (≤, ≥, °, ×), prefer HTML entities or Chinese text directly — e.g., write `<span>OP' ≤ 1</span>` not `katex.render("OP' \\leq 1", ...)` — this avoids the fragile JS backslash-escaping pipeline entirely (see Rule #25). Never display raw LaTeX source code. **When you DO use KaTeX in JS strings, ALWAYS double-escape LaTeX backslashes** — write `"\\\\dfrac{1}{2}"` not `"\\dfrac{1}{2}"`. The `\\d` escape is silent: JS turns `\\d` → `d`, so `\\dfrac` becomes `dfrac` and KaTeX renders italic text "dfrac12" instead of a fraction. This is the single most common rendering bug. After building all compositions, run `python3 "$EDU_SKILL_ROOT/scripts/check_katex_escaping.py" dist` and fix every reported line BEFORE proceeding to Step 6.
3. **Chinese pacing.** Narration at 3.5-4.0 characters/second. Leave 0.5-1.0s pauses between steps.
4. **Three layers per scene.** Background treatment (wave texture + aurora mesh orbs) + content layer + accent elements. No flat single-layer scenes. See design-system.md "Background Treatment" for the exact CSS pattern and aurora palette guide.
5. **Solid opaque panels — frosted glass is FORBIDDEN (禁止毛玻璃，完全避免遮挡).** All content panels use the solid panel style from design-system.md — OPAQUE `background:#ffffff` (or white alpha ≥ 0.92), depth from borders + layered box-shadow + inset top highlight. **NEVER** use `backdrop-filter` / `-webkit-backdrop-filter`, and **NEVER** a see-through translucent panel background — a blurred/see-through panel washes out and OCCLUDES the problem text / diagram / formulas behind it (this is a hard defect). Enforced by `scripts/check_no_glass.py` (in `precheck.py`): render is blocked if any glass/translucent panel is found.
6. **SVG geometry.** Geometric figures use SVG path drawing animation, never static images.
7. **Deterministic.** No `Math.random()`, `Date.now()`, or async timeline construction.
8. **Delegate.** Use the `hyperframes` skill for composition rules, `hyperframes-cli` for CLI commands. TTS uses **DashScope Qwen-TTS via the official SDK** (`dashscope.MultiModalConversation`, model `qwen3-tts-flash`, HTTP) — no self-hosted node, no URL wiring; needs `DASHSCOPE_API_KEY`. Synthesize sentences **concurrently** (thread pool) for speed, and take per-sentence timestamps from each returned clip's measured duration (see step-3-voice-generation.md). This skill defines the math-tutorial domain logic only.
9. **Dark text on light backgrounds (浅色背景深色文字).** This is a light-theme design system. All text — KaTeX equations, SVG labels, Chinese body text, HTML table cells — MUST use dark colors (`#0f172a` or darker). Every composition MUST include the full "Mandatory Global Color Reset" block from design-system.md: root selector with `color: #0f172a`, `.katex, .katex * { color: #0f172a; }`, `.katex-mathml { display: none !important; }`, and `table, th, td { color: #0f172a; }`. Never use `#fff`, `#f8fafc`, `#e8ecf4`, or any light color for text on the light background.
10. **Pre-built assets first.** Before writing custom HTML/CSS for any visual object (car, train, candle, battery, lens, etc.), check [assets/ASSET_CATALOG.md](assets/ASSET_CATALOG.md). If a matching component exists, copy its CSS and HTML verbatim. If NO match exists, follow the "Quality Fallback Template" in ASSET_CATALOG.md — every custom object must have ≥3 gradient layers, inset shadows, ground shadow, glow halo, and no CSS @keyframes. Compare against the candle component for quality level.
11. **No emoji.** Never use emoji characters (🔧⚙️🔵🔴🟢⭕📐✅❌⚡💡 etc.) anywhere in visible text — titles, labels, captions, formula notes, phase titles, badge text, or any string rendered in the video. Headless Chromium has no emoji font installed; all emoji render as □ (tofu boxes) in the final video. Use plain Chinese text or SVG/CSS shapes instead.
12. **Math symbols: simple via HTML entities, complex via KaTeX — NO Chinese inside KaTeX (简单符号用HTML实体，复杂公式用KaTeX，KaTeX禁止包含中文).** Common math comparison and operator symbols are safe as HTML entities in Noto Sans SC / Inter: ≤ (`&le;`), ≥ (`&ge;`), ≠ (`&ne;`), ° (`&deg;`), × (`&times;`), ÷ (`&divide;`), ± (`&plusmn;`), ² (`&sup2;`), ³ (`&sup3;`) — use these directly in HTML text instead of KaTeX when no layout structure is needed (see Rule #25). **Greek letters (α, β, γ, δ, ε, θ, λ, μ, π, φ, ω) are safe as Unicode characters in HTML text** — Inter-Variable.woff2 contains all Greek glyphs (Noto Sans SC does NOT). The font-family stack `"Noto Sans SC", Inter, sans-serif` will fall back to Inter for Greek. **NEVER write the English word** ("alpha", "beta", "theta") **— always use the Unicode character** (α, β, θ). Do NOT insert other specialized Unicode math symbols (∠, △, ⊥, ∥, √, ∞, ₁, ₂, etc.) directly into HTML text — use KaTeX for these in formulas, or Chinese equivalents in non-formula context ("角ABC" not "∠ABC", "三角形" not "△"). For inline subscripts/superscripts in labels, use HTML `<sub>`/`<sup>` tags (e.g., `F<sub>1</sub>` not `F₁`). The only safe non-ASCII characters in plain text are standard CJK Unified Ideographs (U+4E00–U+9FFF), common CJK punctuation, the HTML-entity math symbols listed above, and Greek letters (U+0370–U+03FF). **CRITICAL: Never put Chinese text inside KaTeX `\text{...}` or any KaTeX command.** KaTeX's math fonts (KaTeX_Main, KaTeX_Math, etc.) do NOT contain CJK glyphs — any Chinese character inside `\text{}` renders as □ tofu boxes. When a formula needs to be mixed with Chinese text, break it into separate HTML elements:
    ```html
    <!-- WRONG — Chinese in \text{} renders as □□□ -->
    <span id="eq" data-tex="n \text{ 还是 } V"></span>

    <!-- CORRECT — Chinese in HTML, math in KaTeX -->
    <span>判断操作对 </span><span id="eq-n" data-tex="n"></span><span> 或 </span><span id="eq-v" data-tex="V"></span><span> 的影响</span>
    ```
13. **KaTeX CSS must be inlined, fonts self-hosted (字幕和公式的CSS必须内联，字体离线).** The HyperFrames compiler processes CDN `<link rel="stylesheet">` tags by extracting ONLY `@font-face` rules and discarding all other CSS. This silently breaks KaTeX layout (fractions, subscripts, spacing render as flat plain text). **Never** use `<link rel="stylesheet" href="...katex.min.css">`. Instead: copy the shipped `assets/katex/katex.min.css` into `dist/katex/`, rewrite its font URLs to the **local** self-hosted path (`url(./katex/fonts/`), and paste the full CSS as `<style id="katex-inline-css">` in every composition and in `index.html`. Load `katex.min.js` from the local `dist/katex/` copy, **not** a CDN. See step-5 for the exact procedure.
14. **Circuit schematic physics accuracy (电路原理图物理正确性).** When drawing circuit schematic diagrams (电路图) in SVG: (a) battery symbol — **长线 = 正极(+), 短线 = 负极(-)**, never reverse the labels; (b) current direction — conventional current flows from battery `+` terminal through external circuit to `-` terminal, all arrows must form a consistent closed loop; (c) ammeter — must be wired in **series**, current enters `+` terminal; (d) voltmeter — must be wired in **parallel** with dashed branch wires (`stroke-dasharray`), `+` terminal toward higher potential; (e) **wire segmentation (导线分段)** — wires must STOP at component terminals, never draw a continuous wire that passes through components (components are NOT decorative overlays on wires); (f) **switch must break the circuit (开关必须断路)** — incoming wire ends at switch pivot, outgoing wire starts at contact terminal, switch orientation must match wire direction (vertical wire → vertical switch), no zero-length line segments; (g) **layout distribution (布局分布)** — distribute series components across multiple sides of the rectangular loop, do NOT stack all components on one side; **an empty side of the loop may be JUST a wire (导线) — never add/duplicate a component only to "fill" or "balance" a side**; (h) **no duplicate wires** — each wire gap between components is drawn exactly once; (h2) **component inventory correctness (元件清单正确性) — 每个真实元件恰好出现一次** — the set of components must match the problem's actual circuit; single-instance instruments (**变阻器/滑动变阻器, 电流表, 电压表, 开关, 电源**) must each appear EXACTLY ONCE — never invent or duplicate a component (drawing two 变阻器 in series is a physics error). Only true multiples in the problem (e.g. 两个灯泡 L₁/L₂, 两个电阻 R₁/R₂) may repeat. `check_circuit_inventory.py` gates this; (h3) **circuit loop MUST be closed / 电源两端必须都接线 (回路闭合)** — the main series loop is a single closed path: trace it from the 电源 `+` terminal through every component back to the 电源 `-` terminal — **every gap must have a wire, and the power source's BOTH terminals must each connect to a wire**. No unwired component terminal, no **dangling wire stub** (悬空导线端点 — a wire end that lands in empty space instead of on a component terminal or another wire at a corner). In physical wiring diagrams whose wire coordinates live in a JS array (`var wires=[["w1",x1,y1,x2,y2],…]`), it is easy to forget the segment that closes the left side back up to the source — **do not**. `check_circuit_closed.py` gates this; (i) **physical wiring diagram layout (实物连接图布局)** — "连接电表" and "连接主回路" operation scenes must use a **rectangular loop** layout (NOT a flat horizontal line) with ammeter IN the series loop (on the bottom return wire) and voltmeter on a visually separate dashed parallel branch; wire routing stays compact (≤100px margin beyond components); use Circuit Wiring Operation (C12) template from math-components.md, NOT Chemistry Operation Flow (C9); see circuit-schematic-guide.md Section 12; (j) **voltmeter connection wires must not protrude (电压表连接导线禁止突出)** — the `sch-voltmeter` template has NO built-in wire stubs; terminal endpoints are at the circle edge (±30 from center, not ±50); all dashed connection wires must be drawn as separate `<line>` elements from the main circuit T-junction point to the voltmeter circle edge — wires must start at the junction and end at the circle edge, never extending past either point; (k) **voltmeter branch junctions must have dots and clean routing (电压表分支点必须有圆点且路由干净)** — every T-junction where a voltmeter dashed wire meets the main circuit wire must have a filled junction dot (`<circle r="4-5">`); the dashed wire endpoint coordinates must be exactly ON the main wire (no offset); position the voltmeter so its terminals align with junction points to allow straight dashed lines; if L-shaped routing is unavoidable, use a single `<path>` with `stroke-linejoin="round"` — NEVER two separate `<line>` elements (they create gaps/protrusions at corners). Use `sch-*` templates from [assets/ASSET_CATALOG.md](assets/ASSET_CATALOG.md) and read [references/circuit-schematic-guide.md](references/circuit-schematic-guide.md) for the full pre-flight checklist.
15. **Caption formulas use KaTeX inline rendering (字幕公式必须用KaTeX渲染).** Video captions must display proper math notation — never show spoken-form Chinese like "G M m除以R的平方". When assembling caption `<div>` elements in `index.html`, replace all spoken-form math expressions from `captions.json` with `<span class="cm">LaTeX code</span>` elements. The root `index.html` must load KaTeX JS and include a script that renders all `.cm` spans with `katex.render()` in inline mode. Use `\tfrac` for fractions (compact, fits single-line captions). **KaTeX angle pitfall:** for degrees use `^\circ`, for arcminutes use a plain ASCII `'` (prime), for arcseconds use `''`. **NEVER** use `'` or `\"` in KaTeX math — these are text-mode accent commands that cause the entire formula to render as red error text. See step-6 for the full template, common replacements table, KaTeX pitfalls, and examples.
16. **Self-hosted offline fonts — Chinese MUST NOT be tofu (中文字体必须离线内嵌).** The font files are shipped with this skill under `assets/fonts/` and MUST be copied into `dist/assets/fonts/` (see step-5 Prerequisites). Every sub-composition file AND the root `index.html` MUST embed them via an inline `@font-face` `<style>` block (the exact block is in step-6 for the root and `assets/k12-scholar-font-template.css` for compositions). **Do NOT use a Google Fonts / CDN `<link>`** and do NOT rely on the compiler's built-in embedding or system fonts (PingFang SC): the render sandbox is air-gapped, so a CDN font that fails to load makes ALL Chinese render as garbled boxes (乱码). Use a **CJK-first** stack everywhere — `font-family: "Noto Sans SC", Inter, sans-serif` — and never `Inter, sans-serif` alone. **This applies no matter HOW font-family is set** — SVG `<text>` attr, inline `style=`, AND CSS **class rules**. The #1 miss is a small label/eyebrow/badge class (e.g. `.block-number{font-family:Inter,sans-serif}`) that the design intends for a Latin number like "01" but the model fills with Chinese (对称性/题目所给) → those 3–4 characters render as 豆腐块 while the rest of the card is fine. Any class that could ever hold Chinese must include `"Noto Sans SC"`. Enforced by `scripts/check_cjk_font.py` (now also scans class-based font-family, not just SVG/inline).
17. **No CDN/external URLs at render time (渲染时禁止任何CDN/外部URL).** Every `<script src>`, `<link href>`, and CSS `url()` in compositions and `index.html` MUST use local relative paths. The AP render sandbox is **air-gapped** with no internet access — CDN URLs that load successfully on a local machine will **silently fail** on AP, breaking GSAP timelines (no animations), KaTeX rendering (raw LaTeX in captions), and font loading (tofu boxes). Specifically: (a) GSAP — load from `./gsap/gsap.min.js` (shipped in `assets/gsap/`, copied to `dist/gsap/` AND `dist/compositions/gsap/` in step-5); (b) KaTeX JS — load from `./katex/katex.min.js`; (c) KaTeX CSS — inline as `<style>`, fonts from `./katex/fonts/`; (d) body fonts — inline `@font-face` from `./assets/fonts/`. **Never** use `cdn.jsdelivr.net`, `cdnjs.cloudflare.com`, `unpkg.com`, or any other external host in a `src` or `href` attribute. **CRITICAL: sub-compositions in `dist/compositions/` resolve `./` relative to their own directory — the assets MUST be mirrored into `dist/compositions/` (gsap/, katex/, assets/) or all `./` paths silently 404 and GSAP/KaTeX/fonts fail to load (blank scenes, no animations, tofu).** Enforced by `scripts/check_asset_mirror.py` in `precheck.py`.
18. **Defensive rendering — no CSS-hidden content (防御性渲染 — CSS禁止隐藏内容).** The #1 cause of blank videos is CSS `opacity: 0` on `.scene-content` or content elements, combined with a JS error that prevents GSAP from revealing them. **Rules:** (a) **Never** set `opacity: 0`, `visibility: hidden`, or `display: none` on any content element in CSS — GSAP handles the initial hidden state dynamically via `autoAlpha: 0` in `fromTo()`; (b) Wrap the **entire** GSAP timeline construction in a `try-catch` block — if any tween fails, the timeline still registers and content stays visible; (c) Each `katex.render()` call must have its **own** `try-catch` — one bad LaTeX string must not crash the entire composition; (d) Always pass `throwOnError: false` to `katex.render()`. See step-5 "Defensive Script Pattern" for the complete code template.
19. **Reproducibility — stable structure every run (稳定复现 — 结构固定).** The same problem must yield the same well-formed video every time; the biggest source of r

…(truncated)
