LLM Rewrites a Typesetting Engine: Limits of an Exploratory Experiment
This article explains why math formulas are hard to share on social platforms and reviews the common workarounds. It then examines a reported experiment in which an LLM agent built a typesetting engine compatible with core TeX syntax, covering what the experiment may show, what it cannot prove, and what teams should consider before adopting similar methods.
1. Why Math Formulas Are Hard to Share on Social Platforms
The line between plain text and rich text is still blurry. Ordinary users are affected only to a limited extent, but researchers and technical writers often run into trouble. The main parts of a formula in a paper, such as fractions, superscripts, subscripts, and Greek letters, are not supported by most social platforms and instant messaging tools. Markdown syntax usually does not include formula rendering, and many blogging platforms also lack this feature.
There are three common workarounds, each with clear drawbacks:
| Approach | Clarity | Dependencies | Maintenance cost |
|---|---|---|---|
| Screenshot of the PDF page | Low, blurry when enlarged | None | Hard to keep formatting consistent; manual cropping every time |
| Online formula-to-image service | Medium, depends on service quality | Third-party service | Slow; the service may shut down |
| Sharing a link only | Not applicable | None | Readers must navigate away, poor reading experience |
2. What Is the “Legendary” Typesetting System?
This refers to TeX. Computer scientist Donald Knuth designed it in the late 1970s to improve the quality of mathematical typesetting in publications. According to the author’s own account, he was dissatisfied with the proofs a publisher had produced with a phototypesetting system, so he decided to develop typesetting software himself. The original plan was about six months, but the project took close to a decade. LaTeX is a package system built on TeX and remains a common format for academic papers.
TeX’s macro language supports conditionals, loops, recursion, and macro expansion, and is theoretically Turing complete. As a result, enthusiasts have used it to draw fractal figures, generate mazes, and even implement simple games. At the same time, it has a steep learning curve, and debugging can be tedious.
Knuth set a versioning rule for TeX: each release adds one digit after the decimal point, so the version number gradually approaches pi. This rule reflects the author’s emphasis on stability and helps keep TeX’s behavior consistent over long periods.
3. An Exploratory Experiment
A technical report describes this experiment. Researchers needed to generate images for nine formulas from a paper so they could distribute them across several channels. The initial approach was to extract formula fragments from the LaTeX source and render them one by one.
After reading TeX’s macro definitions and low-level implementation, the agent reached a conclusion: extracting formulas alone only addresses the surface problem. Stable rendering requires understanding the typesetting engine itself. The model then chose a modern systems programming language and tried to implement a typesetting engine compatible with core TeX syntax.
The original report does not disclose the model version, prompts, code size, test set, or timing method. The “ten minutes” figure should therefore be treated as a description from the report and cannot be verified independently. The discussion below focuses on what this kind of experiment can show, not on treating that number as a conclusion.
4. A Conceptual Breakdown of the Experiment Workflow
The report roughly describes the model’s working steps, which can be grouped into three stages. These steps are a conceptual description and have not been independently reproduced.
- Abstraction and modeling. The model treated macro expansion as operations on a syntax tree and tried to describe the “boxes and glue” model of typesetting with functional data structures. This model determines character spacing and line-break positions.
- Module decomposition. The code was split into four modules: lexical analysis, syntax parsing, layout calculation, and font metrics. The module boundaries were clear, which made separate testing easier.
- Self-testing and correction. The model generated test cases, produced output for typical typesetting samples, compared the results with reference renderings, and adjusted the layout algorithm accordingly. The report says the model compared differences between output images, but it did not specify the comparison method or thresholds.
To reproduce a similar experiment, record at least the following: model version, input documents, lines of code, number of test cases, pass rate, failure cases, and how time was measured.
5. What the Experiment Shows and What It Does Not
This experiment supports a few conclusions. First, the quality of the task description matters. A model that can read the original system’s design documents and source code is more likely to produce a targeted solution. Second, clear module boundaries and automated tests make the model’s output easier to verify. Third, the human engineer’s role leans toward defining requirements, reviewing designs, and judging results.
However, the experiment does not support the following claims: that a large typesetting system can be rewritten in ten minutes, that the generated engine behaves identically to TeX on all documents, or that engineering efficiency has improved by any fixed factor. Supporting these claims would require public benchmarks, reproducible data, and a longer record of maintenance.
6. Issues to Consider in Practice
If a team considers using an LLM to help develop typesetting or rendering components, it should pay attention to the following points:
- Code security: The generated parser processes external input, so it needs input validation, resource usage limits, and fuzz testing.
- Licensing: Reference implementations and font files each have their own license terms. Confirm whether modification, redistribution, or commercial use is permitted before use.
- Reproducibility: Record inputs, software versions, and parameters so that identical inputs produce identical outputs.
- Compatibility: List the differences between the new implementation and the original system item by item, especially the spacing of mathematical symbols and line-breaking rules.
7. Conclusion
Whether LLMs can handle complex systems such as typesetting engines remains an open question. A cautious approach is to treat them as exploration tools and rely on testing and code review to decide which results are fit for production.
