Skip to content

shengjiex98/sketch2fig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sketch2fig

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 ─┘

Demo

Schedule diagram — passes on the first try

Input Output

Pipeline with curves and shading — 5 refinement iterations

Input Iteration 1 Final

Getting Started

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-utils
git clone https://github.com/yourname/sketch2fig
cd sketch2fig
uv sync
echo "ANTHROPIC_API_KEY=sk-..." > .env
uv run sketch2fig convert your_figure.png

Output 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

Options

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

How It Works

  1. Plan — Claude analyzes the figure: element types, layout, connections, color semantics
  2. Generate — Claude writes a tikzpicture from the plan, using the original image for detail
  3. Compilepdflatex compiles the code; on failure Claude auto-fixes errors (up to 3 retries)
  4. Evaluate — The rendered PNG is scored against the input on completeness, structure, text, and aesthetics
  5. 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.

About

Convert diagram images to TikZ code using vision LLMs with iterative refinement.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors