Convert figure screenshots and sketches into publication-quality TikZ code using Claude.
Input PNG → Plan → Generate TikZ → Compile → Evaluate → Refine → Output .tex + .png
↑ │
└──── targeted edits ─┘
Schedule diagram — passes on the first try
| Input | Output |
|---|---|
![]() |
![]() |
Pipeline with curves and shading — 5 refinement iterations
| Input | Iteration 1 | Final |
|---|---|---|
![]() |
![]() |
![]() |
Requirements: Python 3.12+, uv, TeX Live with pdflatex, poppler, Anthropic API key.
# macOS
brew install --cask basictex && brew install poppler
# Ubuntu/Debian
apt-get install texlive-pictures texlive-latex-extra poppler-utilsgit clone https://github.com/yourname/sketch2fig
cd sketch2fig
uv sync
echo "ANTHROPIC_API_KEY=sk-..." > .env
uv run sketch2fig convert your_figure.pngOutput lands in output/<name>/final.tex and final.png.
Try it on a bundled example:
uv run sketch2fig convert tests/fixtures/real_examples/4_schedule.png --verbose| Flag | Description |
|---|---|
--clean |
Aesthetic cleanup — improve alignment even if input is rough |
--max-iters N |
Max refinement iterations (default: 5) |
--output-dir PATH |
Custom output directory |
--verbose |
Show plan summary, per-iteration scores, and evaluator critique |
- Plan — Claude analyzes the figure: element types, layout, connections, color semantics
- Generate — Claude writes a
tikzpicturefrom the plan, using the original image for detail - Compile —
pdflatexcompiles the code; on failure Claude auto-fixes errors (up to 3 retries) - Evaluate — The rendered PNG is scored against the input on completeness, structure, text, and aesthetics
- Refine — Below threshold, Claude makes targeted edits and re-compiles (up to 5 iterations)
All figure understanding and code generation use Claude's vision capabilities via the Anthropic API.




