跳到主要内容
知仓学习社ZHICANG

extract-tikz

Extract TikZ diagrams from Beamer `.tex` source, compile each to a standalone PDF, and convert to SVG with 0-based indexing. Use when user says "ext…

不碰外部(只输出文字)无严重或高危命中pedrohcgs/claude-code-my-workflow

它会碰到什么

扫了多少1 个文本文件,5 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Extract TikZ Diagrams to SVG

Extract TikZ diagrams from the Beamer source, compile to multi-page PDF, and convert each page to SVG for use in Quarto slides.

> Creating a brand-new diagram instead of extracting? Use [/new-diagram](../new-diagram/SKILL.md) — it scaffolds from templates/tikz-snippets/ with the prevention rules pre-applied.

Steps

Step 0: Freshness Check (MANDATORY)

Before compiling, verify that extract_tikz.tex matches the current Beamer source.

  1. Find the Beamer source: ls Slides/$ARGUMENTS*.tex
  2. Extract all \begin{tikzpicture} blocks from Beamer
  3. Compare with Figures/$ARGUMENTS/extract_tikz.tex
  4. If ANY difference exists: update extract_tikz.tex from the Beamer source
  5. If extract_tikz.tex doesn't exist: create it from scratch

Step 1: Prevention pre-check (MANDATORY — halt on violation)

Before compiling, verify every \begin{tikzpicture} block in Figures/$ARGUMENTS/extract_tikz.tex satisfies the prevention rules in [.claude/rules/tikz-prevention.md](../../rules/tikz-prevention.md). The pre-check is a small Python script shared with /new-diagram so both skills enforce identical behavior:

python3 scripts/check-tikz-prevention.py "Figures/$ARGUMENTS/extract_tikz.tex"

What it checks:

  • P3 — scale=X without node scaling. Bare scale= shrinks coordinates but not text. Allowed forms: scale=X, every node/.style={scale=X} or scale=X, transform shape. The checker parses the full \begin{tikzpicture}[...] options block even when it spans multiple lines.
  • P4 — Directional keyword on edge labels. Every edge label (node inside a \draw) must carry above, below, left, right, or a compound (e.g. above left). midway alone is a path position, not a direction. The checker scans the full \draw ...; statement so \draw on one line and node[...]{...} on the next line are still linked.

Note what the pre-check does NOT enforce: P1 (boxed-node explicit dimensions) and P2 (coordinate-map comment) are structural and get flagged by tikz-reviewer in Step 8, not here.

Exit codes: 0 = all files pass, 1 = one or more P3/P4 violations (stderr lists file, line, snippet, rule), 2 = usage error.

If exit is non-zero: halt, report the offending lines, and ask the user to fix the Beamer source (single source of truth). Do NOT compile.

Step 2: Navigate to the lecture's Figures directory

cd Figures/$ARGUMENTS

Step 3: Compile the extract_tikz.tex file

TEXINPUTS=../../Preambles:$TEXINPUTS xelatex -interaction=nonstopmode extract_tikz.tex

Step 4: Count the number of pages

pdfinfo extract_tikz.pdf | grep "Pages:"

Step 5: Convert each page to SVG using 0-BASED INDEXING

CRITICAL: PDF pages are 1-indexed, but output SVG files are 0-indexed!

PAGES=$(pdfinfo extract_tikz.pdf | grep "Pages:" | awk '{print $2}')
for i in $(seq 1 $PAGES); do
  idx=$(printf "%02d" $((i-1)))
  pdf2svg extract_tikz.pdf tikz_exact_$idx.svg $i
done

Step 6: Sync to docs/ for deployment

cd ../..
./scripts/sync_to_docs.sh $ARGUMENTS

Step 7: Verify SVG files

  • Read 2-3 SVG files to confirm they contain valid SVG markup
  • Confirm file sizes are reasonable (not 0 bytes)

Step 8: Visual Quality Review (tikz-reviewer)

Spawn the tikz-reviewer agent (via the Agent tool with subagent_type=tikz-reviewer) on the TikZ source blocks to catch label overlaps, geometric errors, and visual inconsistencies. The reviewer cites specific passes and formulas from [.claude/rules/tikz-measurement.md](../../rules/tikz-measurement.md). If it returns NEEDS REVISION or REJECTED, loop:

  1. Apply the recommended fixes to the Beamer .tex source (single source of truth).
  2. Re-copy the updated block to extract_tikz.tex.
  3. Re-run the prevention pre-check (Step 1) and compile.
  4. Regenerate SVGs, re-sync.
  5. Re-invoke tikz-reviewer.

Stop when tikz-reviewer returns APPROVED (max 5 rounds).

Step 9: Report results

Source of Truth Reminder

TikZ diagrams MUST be edited in the Beamer .tex file first, then copied verbatim to extract_tikz.tex. See .claude/rules/single-source-of-truth.md.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 1,585
本站分层T1
该仓技能数60
原文件路径.claude/skills/extract-tikz/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 60 个技能