extract-tikz
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExtract 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 matches the current Beamer source.
extract_tikz.tex- Find the Beamer source:
ls Slides/$ARGUMENTS*.tex - Extract all blocks from Beamer
\begin{tikzpicture} - Compare with
Figures/$ARGUMENTS/extract_tikz.tex - If ANY difference exists: update extract_tikz.tex from the Beamer source
- If extract_tikz.tex doesn't exist: create it from scratch
编译前,请确认与当前Beamer源文件一致。
extract_tikz.tex- 查找Beamer源文件:
ls Slides/$ARGUMENTS*.tex - 从Beamer中提取所有块
\begin{tikzpicture} - 与进行对比
Figures/$ARGUMENTS/extract_tikz.tex - 若存在任何差异:从Beamer源文件更新extract_tikz.tex
- 若extract_tikz.tex不存在:从头创建该文件
Step 1: Navigate to the lecture's Figures directory
步骤1:导航至课程的Figures目录
bash
cd Figures/$ARGUMENTSbash
cd Figures/$ARGUMENTSStep 2: Compile the extract_tikz.tex file
步骤2:编译extract_tikz.tex文件
bash
TEXINPUTS=../../Preambles:$TEXINPUTS xelatex -interaction=nonstopmode extract_tikz.texbash
TEXINPUTS=../../Preambles:$TEXINPUTS xelatex -interaction=nonstopmode extract_tikz.texStep 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
doneStep 5: Sync to docs/ for deployment
步骤5:同步至docs/目录以部署
bash
cd ../..
./scripts/sync_to_docs.sh $ARGUMENTSbash
cd ../..
./scripts/sync_to_docs.sh $ARGUMENTSStep 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 file first, then copied verbatim to . See .
.texextract_tikz.tex.claude/rules/single-source-of-truth.mdTikZ图表必须先在Beamer的文件中编辑,再完整复制到中。详见。
.texextract_tikz.tex.claude/rules/single-source-of-truth.md