Skip to content

Engineering · 2025

Sketch-to-figure (TikZ MCP)

Independent experiment

A personal project pursued purely for intellectual exploration.

The tool converts sketches and text descriptions into editable TikZ figures through a compile-and-review loop. The original CLI captures the whole loop. It detects whether the input is direct text, a text file, or an image, then asks the model to produce a detailed specification covering title, layout, elements with shapes and colors, connections with styles, logical groupings, and style notes. From that spec it generates a complete LaTeX document, extracts the code from any markdown fences, and compiles it. Compilation is deliberately constrained, run with a timeout and without shell-escape for safety.

The defining mechanism is the vision-in-the-loop critique. After each compile, the rendered figure is shown back to the model, which returns an approval flag, a numeric score out of ten, and written feedback, all saved to a per-iteration critique file. If the figure is approved or the score meets the configured threshold (default eight out of ten), the loop stops and emits the final PDF; otherwise the feedback feeds the next revision, up to a maximum iteration count. This makes quality control self-driving: the model judges its own output by actually looking at the pixels, not by re-reading its own code, which is the right signal for a visual artifact.

The second form is a remote MCP server that exposes the same engine to Claude Desktop. Here the conversation itself becomes the critique loop: the user chats, the model writes TikZ and calls a compile tool that returns the rendered image inline so it can see and self-correct, an export tool that produces publication-ready SVG and PDF for a chosen revision, and a session-listing tool. Work is organized into per-user sessions with zero-padded revision numbers, each saved as paired tex, pdf, and png files, backed by SQLite. Access is gated by OAuth with Google as the provider, the server issuing its own opaque tokens, and usage is bounded by a weekly session quota.

The system requires a working pdflatex toolchain and image-conversion tools. Complex figures can require several revisions or reach the iteration cap without converging. Generated figures still require visual review. The CLI uses an automated scoring loop, while the MCP interface supports an interactive workflow.

← Back to all work