extract-tikz

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Extract TikZ Diagrams to SVG

提取TikZ图表为SVG

Extract TikZ diagrams from the Beamer source, compile to multi-page PDF, and convert each page to SVG for use in Quarto slides.
从Beamer源文件中提取TikZ图表,编译为多页PDF,再将每页转换为SVG,用于Quarto幻灯片。

Steps

步骤

Step 0: Freshness Check (MANDATORY)

步骤0:新鲜度检查(必填)

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
编译前,请确认
extract_tikz.tex
与当前Beamer源文件一致。
  1. 查找Beamer源文件:
    ls Slides/$ARGUMENTS*.tex
  2. 从Beamer中提取所有
    \begin{tikzpicture}
  3. Figures/$ARGUMENTS/extract_tikz.tex
    进行对比
  4. 若存在任何差异:从Beamer源文件更新extract_tikz.tex
  5. 若extract_tikz.tex不存在:从头创建该文件

Step 1: Navigate to the lecture's Figures directory

步骤1:导航至课程的Figures目录

bash
cd Figures/$ARGUMENTS
bash
cd Figures/$ARGUMENTS

Step 2: Compile the extract_tikz.tex file

步骤2:编译extract_tikz.tex文件

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

Step 3: Count the number of pages

步骤3:统计页数

bash
pdfinfo extract_tikz.pdf | grep "Pages:"
bash
pdfinfo extract_tikz.pdf | grep "Pages:"

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

步骤4:以0为起始索引将每页转换为SVG

CRITICAL: PDF pages are 1-indexed, but output SVG files are 0-indexed!
bash
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
重要提示:PDF页面是1为起始索引,但输出的SVG文件是0为起始索引!
bash
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 5: Sync to docs/ for deployment

步骤5:同步至docs/目录以部署

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

Step 6: Verify SVG files

步骤6:验证SVG文件

  • Read 2-3 SVG files to confirm they contain valid SVG markup
  • Confirm file sizes are reasonable (not 0 bytes)
  • 查看2-3个SVG文件,确认其包含有效的SVG标记
  • 确认文件大小合理(不为0字节)

Step 7: Report results

步骤7:报告结果

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
.
TikZ图表必须先在Beamer的
.tex
文件中编辑,再完整复制到
extract_tikz.tex
中。详见
.claude/rules/single-source-of-truth.md