Abstract
Creating high-quality scientific figures can be time-consuming and challenging, even though sketching ideas on paper is relatively easy. Furthermore, recreating existing figures that are not stored in formats preserving semantic information is equally complex. To tackle this problem, we introduce DeTikZify, a novel multimodal language model that automatically synthesizes scientific figures as semantics-preserving TikZ graphics programs based on sketches and existing figures. To achieve this, we create three new datasets: DaTikZv2, the largest TikZ dataset to date, containing over 360k human-created TikZ graphics; SketchFig, a dataset that pairs hand-drawn sketches with their corresponding scientific figures; and SciCap++, a collection of diverse scientific figures and associated metadata. We train DeTikZify on SciCap++ and DaTikZv2, along with synthetically generated sketches learned from SketchFig. We also introduce an MCTS-based inference algorithm that enables DeTikZify to iteratively refine its outputs without the need for additional training. Through both automatic and human evaluation, we demonstrate that DeTikZify outperforms commercial Claude 3 and GPT-4V in synthesizing TikZ programs, with the MCTS algorithm effectively boosting its performance. We make our code, models, and datasets publicly available.
Introduction
Professional scientific figures are essential for clear communication in research, yet they represent a significant bottleneck in the publication process. While a researcher can quickly sketch a concept on a napkin or whiteboard, translating that sketch into a high-quality, editable, and publication-ready format like TikZ—a LaTeX-native graphics language—is notoriously difficult. TikZ offers unparalleled precision and integration with scientific documents, but its steep learning curve and complex syntax often deter users.
Existing image-to-vector tools typically produce low-level SVG files that lack semantic structure, making them nearly impossible to edit. Large Language Models (LLMs) have shown promise in code generation, but they frequently struggle with the spatial reasoning and specific syntactic requirements of graphics programming. DeTikZify addresses this "usability gap" by automatically synthesizing semantics-preserving TikZ programs from either hand-drawn sketches or existing raster images.
Methodology
DeTikZify utilizes a multimodal architecture that integrates a vision encoder with a code-specialized language model. Specifically, it employs SigLIP for visual processing and variants of LLaMA (such as DeepSeek-Coder) for generating the TikZ code.
MCTS-based Refinement
A key technical innovation of DeTikZify is its inference strategy. Rather than relying on a single "one-shot" generation, the model employs a Monte Carlo Tree Search (MCTS) algorithm to iteratively refine its output. This process is guided by a dual reward system:
- Compiler Diagnostics: The system checks if the generated code compiles successfully in a LaTeX environment.
- Self-Assessed Perceptual Similarity (SelfSim): The model uses its own vision encoder to compare the rendered output of the generated code against the original input image, allowing it to "debug" visual discrepancies.
Datasets
The effectiveness of DeTikZify is rooted in three large-scale datasets developed for this work:
- DaTikZv2: The largest TikZ dataset currently available, containing over 360,000 human-created TikZ programs sourced from arXiv and TeX.StackExchange.
- SketchFig: A specialized dataset of 549 pairs of real human sketches and their corresponding professional figures.
- SciCap++: A collection of 734,000 scientific figures paired with rich metadata, including captions and OCR text, used for multimodal pretraining.
To improve the model's robustness to messy input, the authors used Instruct-Pix2Pix to synthetically transform professional TikZ figures into "hand-drawn" versions, creating a large-scale training set for sketch-to-code synthesis.
Results and Discussion
DeTikZify demonstrates superior performance compared to leading commercial models. In human evaluations using Best-Worst Scaling (BWS), the 7-billion parameter version (DeTikZify-DS7b) significantly outperformed both GPT-4V and Claude 3.
The MCTS refinement algorithm proved to be a critical component. In human evaluations, the MCTS-refined model achieved a score of 0.39, whereas the one-shot version of the same model scored significantly lower, and GPT-4V trailed at 0.09. Furthermore, the models exhibit high compilation rates, with a "Mean Token Efficiency" of 82–91%, indicating that they often produce valid code within just one or two attempts.
Conclusion
DeTikZify represents a significant step toward automating the creation of scientific graphics. By treating code as a semantic bridge, it ensures that outputs are not just visually accurate but also fully editable and accessible. While challenges remain—such as improving the rendering of text from handwriting and reducing the computational cost of MCTS—the model's ability to outperform general-purpose LLMs highlights the value of domain-specific multimodal training and iterative refinement. Future work will focus on expanding support to other graphics languages like MetaPost and PSTricks.
Summary updated