← Back to articles

Why I Built TeXres: Modernizing TeX While Waiting for Typst

I love Typst. Its syntax is clean, its compiler is written in modern Rust, and its incremental rendering is a breath of fresh air. Typst is unequivocally the future of scientific and technical document preparation.

And yet, you cannot submit Typst to most journals or repositories today.

Virtually all major academic journals across mathematics, physics, economics, and computer science, as well as preprint servers like arXiv, do not accept Typst source files. They mandate LaTeX. They provide 40-page .cls and .sty templates written twenty or thirty years ago that depend on obscure macro expansions and legacy packages. Until scientific publishing overhauls its entire submission and typesetting infrastructure—which could take a decade or more—dealing with TeX remains completely inevitable for researchers and engineers.

So the pragmatic question became: How to alleviate the daily agony of TeX right now, without waiting for the world to catch up?

That frustration led me to build TeXres. Not as a new language, but as a modern, pure-Rust reconstruction of the entire TeX engine and toolchain that compiles unchanged, legacy LaTeX manuscripts at 2020s software speeds.

1. The Four Daily Agonies of TeX

Anyone who writes research in LaTeX knows the friction points by heart:

  • Too many fragmented tools to choose from: Are you using pdflatex? xelatex? lualatex? Do you run bibtex or biber? Why do you need an external Perl script (latexmk) just to figure out how many times to recompile your file? Why can't there be one clean binary that just builds the document?
  • Pollution of near-useless auxiliary files: A simple 5-page draft litters your folder with .aux, .log, .out, .toc, .bbl, .blg, .fls, .fdb_latexmk, and .synctex.gz. If a single byte goes corrupt in an auxiliary file, the entire compiler crashes until you manually wipe the directory.
  • Counter-intuitive, cryptic error messages: When something breaks, TeX halts at a terrifying interactive ? prompt or dumps 800 lines of inscrutable macro tracebacks deep inside package code you didn't write, without telling you the actual typo in your source text.
  • Painfully slow compilation: A standard build spawns 3 to 4 sequential subprocesses, searches across 100,000 files using kpathsea, and re-reads everything from disk. An incremental sentence edit takes 5 to 15 seconds.

2. The 40-Year Bottleneck: Why Legacy TeX is Slow

Standard TeX implementations (such as Web2C / pdfTeX / XeTeX) date back decades. While Donald Knuth's typesetting algorithms are legendary for mathematical beauty, the surrounding runtime model suffers from four major architectural bottlenecks:

  1. Filesystem Thrashing (kpathsea): Whenever you invoke \usepackage{amsmath}, TeX Live searches through massive directory trees containing over 100,000 files using the kpathsea library. On modern operating systems, thousands of stat() and open() syscalls burn hundreds of milliseconds before a single letter is typeset.
  2. The Subprocess Carousel: A standard build does not just run TeX. To resolve citations, cross-references, and table of contents, a Perl script (latexmk) orchestrates multiple subprocess invocations: running pdflatex, spawning bibtex, re-running pdflatex, and repeating until convergence. Each invocation pays the full initialization and process creation penalty.
  3. No Incremental State Validation: If you edit a typo in section 3, legacy engines discard everything and re-parse the entire document, packages, macros, and fonts from disk.
  4. Memory Unsoundness and Segfaults: Classic TeX engines use fixed static arrays in C with manual memory pointers. When memory limits are exceeded or tricky macro packages clash, you get confusing error dumps or hard crashes.

3. How I Rebuilt TeX from Scratch in Rust

To eliminate these bottlenecks without sacrificing Knuth's exact mathematical typesetting rules, TeXres was engineered around three principles:

A. 100% In-Memory Package Resolution

Instead of requiring a multi-gigabyte TeX Live installation and traversing disk hierarchies, texres embeds pre-compressed format assets and over 24,000 standard TeX packages directly into the binary. When a document loads a package, it resolves from an in-memory index in less than 50 microseconds. Zero disk lookups, zero missing package dialogs.

B. Unified Single-Pass Convergence

Rather than executing external Perl wrappers and separate command-line binaries, texres embeds the TeX engine, package resolver, native BibTeX interpreter, and dependency-tracking driver in one process. It analyzes auxiliary citations and references in-memory, converging multi-pass dependencies in a single lifecycle.

C. Cryptographic Artifact Caching

TeXres maintains a lightweight dependency graph with BLAKE3/xxHash state hashing. If only a single paragraph changes, font metrics, macro definitions, and unchanged auxiliary streams are reused immediately, reducing warm incremental rebuilds to under 10 milliseconds.

4. Real-World Performance: 3,000 arXiv Papers

I verified texres against 3,000 real-world arXiv research papers spanning mathematics, physics, and computer science. The benchmarks speak for themselves:

Workload TeXres TeX Live (pdflatex + latexmk) Speedup
Incremental Rebuild (Warm) 0.8 – 8.2 ms 40 – 60 ms 10× – 70× faster
Short Papers (1–3 pages) 12 – 45 ms 450 – 900 ms 20× – 35× faster
Long Manuscripts (15–40 pages) 180 – 650 ms 3,200 – 7,800 ms 10× – 18× faster
Heavy Math & Citations 240 – 780 ms 4,500 – 11,200 ms 14× – 19× faster
"Clean compiles across arXiv: TeXres cleanly compiled 2,620 papers vs 2,613 for TeX Live, with a 96.39% mean visual pixel parity score."

5. Compiler-Grade Diagnostics (No More Cryptic `?` Prompts)

Every LaTeX user has experienced the dread of Knuth's infamous ? prompt halting a build with a cryptic message buried 800 lines deep in a .log file:

! Undefined control sequence.
l.14 \textbld
             {Empirical Results}
? 

If you don't know what to press, typing the wrong character can dump 50 cascading phantom errors or hang your editor and automated CI pipeline indefinitely.

Because texres is engineered like a modern language compiler, it replaces this 1980s terminal prompt with beautiful, rustc-quality visual diagnostics:

error[E0042]: undefined command `\textbld`
  --> document.tex:14:5
   |
14 |     \textbld{Empirical Results}
   |     ^^^^^^^^ help: did you mean `\textbf`?
   = note: macro `\textbld` is not defined in any loaded package

Key diagnostic upgrades in texres:

  • Exact Source Code Spans: Shows the physical file, line, and column with source code context and squiggly underlines.
  • Fuzzy Spelling Suggestions: Analyzes Levenshtein distance against all loaded macros to suggest typos (e.g. \centr → \center).
  • Unclosed Environment Tracking: When you forget an \end{equation}, it points to the exact opening tag rather than failing at the end of the file.
  • Zero Interactive Hangs: Never pauses with a modal ? prompt in non-interactive terminals or CI pipelines.

6. Installing and Getting Started

TeXres is fully open source under the MIT and Apache 2.0 licenses. Standalone native packages are available for Linux, macOS, and Windows.

# macOS (Homebrew)
brew install leoliu0/texres/texres

# Arch Linux (AUR)
yay -S texres-bin

# Windows, Debian/Ubuntu, Fedora and other Linux:
# download from https://github.com/leoliu0/texres/releases/latest

To compile any paper with automatic BibTeX convergence:

texres paper.tex

You can drop it directly into VS Code (LaTeX Workshop) by setting "latex-workshop.latex.tools": [{"name": "texres", "command": "texres", "args": ["-pdf", "%DOC%"]}].

Help Test Your Papers & File Issues

Have a tricky paper, custom style file, or obscure macro package that doesn't compile? Please open an issue on GitHub! Minimal reproduction snippets and bug reports are warmly welcome at github.com/leoliu0/texres/issues.


Check out the project on GitHub: github.com/leoliu0/texres. If you find it useful for your own writing, starring the repo helps others discover it!