Introduction
The world of digital typesetting is notorious for its speed bottlenecks. For decades, compiling a large LaTeX document—especially one with complex graphics, bibliographies, and cross-references—could take tens of seconds or even minutes. This delay interrupts the iterative writing process, forcing authors to wait before seeing their changes rendered. A groundbreaking preprint presented at TUG 2026, titled Real-Time LuaTeX: Recompiling Large Documents in 1ms, introduces a paradigm shift that promises to eliminate this latency entirely.
The authors, researchers and TeX developers, describe a novel approach that leverages the LuaTeX engine's scripting capabilities to achieve recompilation speeds of under one millisecond for large documents. This is not an incremental improvement; it is a fundamental redesign of how TeX processes document changes. Instead of recompiling the entire document from scratch, the system tracks dependencies at the token and node level, enabling surgical updates to the output PDF without reprocessing unchanged content. This article provides a detailed technical breakdown of the methodology, practical implementation steps, and the implications for the LaTeX community.
The Core Problem: Traditional TeX Compilation
Traditional TeX compilation is a batch process. When a user runs pdflatex or lualatex, the engine reads the entire source file, parses macros, expands tokens, builds horizontal and vertical lists, and then outputs a DVI or PDF file. Any change—even a single character—triggers a full recompilation. For a large document with hundreds of pages, figures, and cross-references, this can take 10-30 seconds or more. This is especially painful during the editing phase, where authors need to see changes quickly.
Key bottlenecks in traditional compilation:
- Full tokenization: Every run re-reads and tokenizes the entire source.
- Macro expansion: All macros are re-expanded even if unchanged.
- Hyphenation and ligature processing: These operations are repeated globally.
- Output flushing: The entire PDF is regenerated, even for minor tweaks.
The TUG 2026 preprint addresses these issues by introducing a real-time incremental compilation system built on top of LuaTeX.
How Real-Time LuaTeX Achieves 1ms Recompilation
The system described in the preprint is not a separate tool but a set of Lua scripts and patches to the LuaTeX engine that enable incremental compilation. The key insight is that most edits are local—a user typically changes a single paragraph, a figure caption, or a section heading. The system exploits this locality by maintaining a persistent internal state of the document and only reprocessing the modified parts.
1. Incremental Tokenization and Macro Expansion
Traditional TeX re-reads the entire input file each run. In the real-time system, the LuaTeX engine maintains a global token store in memory. When a file is loaded, its tokens are cached. On subsequent runs, the system compares file timestamps and checksums to detect which source files have changed. Only the modified files are re-tokenized and re-expanded. The unchanged parts are restored from the cache.
This approach reduces overhead dramatically. For a document with 50 input files, if only one file changes, the system processes only that file. The authors report that tokenization time drops from ~200ms to under 50µs for unchanged sections.
2. Node-Level Dependency Tracking
The heart of the system is a node-level dependency graph. In LuaTeX's internal representation, a document is a tree of nodes (characters, glue, kerns, hboxes, vboxes, etc.). Each node is tagged with metadata indicating which source tokens produced it. When a change is made, the system identifies the affected nodes using a reverse dependency lookup. It then removes only those nodes from the output list and re-processes the affected region.
For example, if a user edits a single paragraph, the system deletes the nodes corresponding to that paragraph and re-typesets only that paragraph. The rest of the document remains untouched. This is possible because LuaTeX's node list is mutable and supports surgical deletion and insertion.
3. Persistent PDF Page Cache
One of the most innovative aspects is the page-level PDF cache. Instead of regenerating the entire PDF, the system maintains a cache of rendered PDF pages. When nodes are updated, the system determines which pages are affected. Only those pages are re-rendered and re-inserted into the PDF file. The PDF's internal cross-references and object numbers are updated incrementally, avoiding a full rewrite.
The preprint demonstrates that for a 200-page document, changing a single character on page 50 results in regenerating only that page (~1ms), while the other 199 pages are copied from the cache.
4. Non-Destructive Output
The system does not overwrite the existing PDF file but instead patches it in-place. It uses LuaTeX's pdfextension primitives to manipulate the PDF structure directly. This avoids the overhead of writing a temporary file and renaming it.
Practical Implementation: Setting Up Real-Time LuaTeX
To use the real-time compilation system, authors need to install a modified version of LuaTeX and load the incremental compilation package. The preprint provides detailed instructions, summarized here.
Step 1: Install the Modified LuaTeX
The system requires a patched version of LuaTeX (version 1.20 or later). The patch adds hooks for incremental tokenization and node tracking. The preprint recommends downloading the binary from the TUG 2026 distribution. The package is called luatex-realtime.
# Example installation on Linux
wget https://tug.org/tug2026/luatex-realtime.tar.gz
tar -xzf luatex-realtime.tar.gz
cd luatex-realtime
./configure --prefix=/usr/local/texlive/2026
make && make install
Step 2: Load the Package in Your Document
Add the following line to the preamble of your LaTeX document:
\usepackage{luatexrealtime}
This package activates the incremental compilation engine. It provides options for cache size, debug output, and dependency tracking depth.
Step 3: Use the Real-Time Compiler
Instead of running lualatex directly, use the provided script realtime-lualatex:
realtime-lualatex mydocument.tex
This script starts a persistent LuaTeX process that watches source files for changes. It compiles the document once fully, then enters a watch mode. On the first run, compilation time is normal (~5-10 seconds for a large document). On subsequent runs after a change, compilation time drops to 1ms or less.
Step 4: Integrate with an Editor
The preprint demonstrates integration with Vim and Emacs using a simple plugin that triggers recompilation on file save. For example, the Vim plugin adds an autocommand:
au BufWritePost *.tex silent !realtime-lualatex %
This provides near-instant preview updates without leaving the editor.
Example Workflow
Consider a 150-page technical report with 50 figures and 200 cross-references. The author edits a single sentence on page 72. With traditional LuaTeX, recompilation takes 12 seconds. With luatexrealtime, the recompilation takes 0.8ms. The PDF viewer updates within 10ms.
Technical Challenges and Solutions
The authors encountered several challenges during development.
Challenge 1: Floating Figures and Page Breaks
Floating figures and automatic page breaks are dynamic—changing one paragraph can shift subsequent content across pages. The system handles this by treating page breaks as nodes with dependencies. When a change affects page breaking, the system re-typesets all pages from the first affected break onward. This is still much faster than full recompilation because only a few pages are affected.
Challenge 2: Cross-References and Labels
Cross-references (\ref, \cite) depend on the entire document. If a label is added or removed, the system must update the auxiliary files and re-resolve all references. The preprint describes a two-pass approach: the first pass updates the .aux file incrementally, the second pass resolves references for affected pages only.
Challenge 3: Macro Packages
Complex macro packages like pgfplots or tikz generate large node lists. The system tracks dependencies at the macro level. If a TikZ picture is changed, the entire picture is re-typeset, but the surrounding text remains cached.
Performance Benchmarks
The preprint includes benchmarks comparing traditional LuaTeX with the real-time system. The tests were performed on a standard laptop (2025 MacBook Pro, M4 chip).
| Document Type | Pages | Traditional Compilation | Real-Time Compilation (full) | Real-Time (single edit) |
|---|---|---|---|---|
| Simple article | 10 | 0.8s | 0.9s | 0.2ms |
| Technical report | 150 | 12.3s | 12.5s | 0.8ms |
| PhD thesis with figures | 300 | 45.1s | 46.0s | 1.2ms |
| Book with index | 500 | 120.0s | 122.0s | 2.5ms |
Note: Full compilation for the real-time system is slightly slower due to dependency tracking overhead.
The key result is that single-edit recompilation time is consistently under 3ms, regardless of document size. This is a reduction of three to four orders of magnitude.
Implications for the LaTeX Community
This development has profound implications for LaTeX authors, editors, and publishers.
- Improved productivity: Authors can edit and preview changes in real time, similar to word processors. This reduces context-switching and frustration.
- Collaborative editing: Multiple authors can work on the same document with near-instant preview, enabling faster iteration.
- Integration with web platforms: The system could power online LaTeX editors (like Overleaf) to provide instant preview without server-side compilation delays. ASI Biont supports integration with web-based LaTeX tools through its API—details at asibiont.com/courses.
- Accessibility for beginners: New users often find the compile-wait cycle discouraging. Real-time feedback lowers the barrier to entry.
Limitations and Future Work
The preprint acknowledges several limitations:
- Memory usage: The persistent token and node cache consumes RAM proportional to document size. A 500-page document may require 2-4 GB of memory.
- Compatibility: Some low-level TeX primitives and packages may not support incremental compilation. The system falls back to full compilation for incompatible code.
- Security: The persistent process must be sandboxed to prevent malicious code from leaking state between documents.
The authors plan to address these in future releases. They also hint at integrating the system with the LuaTeX JIT compiler for further speed gains.
Conclusion
The Real-Time LuaTeX system represents a major leap forward in digital typesetting. By recompiling large documents in 1ms, it eliminates the most significant pain point of LaTeX workflows. The preprint provides a clear technical roadmap for implementation, and the system is already available for testing. For authors who work with large documents—whether technical reports, theses, or books—this technology promises to make LaTeX as responsive as any modern WYSIWYG editor while retaining its unparalleled typesetting quality.
The full details are available in the preprint at TUG 2026: Source.
References
- Lode, P. et al. (2026). Real-Time LuaTeX: Recompiling Large Documents in 1ms. TUG 2026 Preprints. Source.
- LuaTeX development team. (2025). LuaTeX Reference Manual, version 1.20.
- TeX Users Group. (2026). TUG 2026 Conference Proceedings.
Comments