Skip to content

About

Realtime TeX: re-typesets only the paragraph you edit in ~1 ms with an unmodified LuaTeX. Exact, embeddable.

Topics

Resources

Stars

176 stars

Watchers

1 watching

Forks

Repository files navigation

realtime-tex (rtex)

English | 简体中文

See your LaTeX document update as you type, in about a millisecond, without leaving LuaLaTeX.

rtex in VS Code: the paragraph being edited updates in the preview as you type

rtex is a library for editors. When you type, it re-typesets only the paragraph you are editing, using a LuaLaTeX process that has already loaded your preamble, and hands the editor the new lines to draw. A full compile runs in the background and takes care of what really is global: page breaks, floats, the table of contents, references and bibliographies.

The result is exactly what LuaLaTeX produces: the same line breaks, the same glyphs, at the same positions to 1/65536 pt. rtex uses an unmodified LuaTeX from TeX Live, and exported PDFs are identical to a normal LuaLaTeX build.

                         ┌─▶ live engine ──────▶ new lines of that paragraph   (≈ 1 ms)
 keystroke ─▶ rtex ──────┤
                         └─▶ background pass ──▶ whole pages, references, TOC   (seconds, after you pause)

The approach follows Clemens Lode, Real-Time LuaTeX: Recompiling Large Documents in 1 ms (TUG 2026).

Use it in VS Code

The quickest way to use rtex is the Realtime TeX Live Preview extension for VS Code. It shows a live preview next to your editor and installs rtex (and, if needed, a minimal TeX Live) for you on first use. Open a .tex file, click the preview icon in the editor title bar (or press Ctrl+Alt+V, Cmd+Alt+V on a Mac), and start typing. It runs rtex natively on Linux, macOS and Windows, and downloads the prebuilt engine for your platform.

The rest of this page is about rtex itself: the library the extension is built on.

How fast

Time from keystroke to the updated paragraph in the editor's hands (median of 300 edits, on a 4-vCPU cloud VM; a laptop is usually faster). Full benchmarks.

Paragraph 10-page document 100 pages 300 pages
one line 0.50 ms 0.48 ms 0.61 ms
four lines 1.04 ms 1.10 ms 1.18 ms
ten lines — 2.39 ms 1.94 ms
a list, a figure, a table, display math 1.4–1.9 ms 1.5–1.7 ms

Document length does not matter, only the paragraph does. The font setup matters too. With fontspec's default OpenType shaping, a long paragraph takes up to 4–5× longer than with TFM fonts or Renderer=Basic (why).

Typed into the same document, a paragraph updates in 1.3–1.6 ms with rtex, 18 ms (10 pages) to 414 ms (300 pages) with Typst 0.15.1, and a full LuaLaTeX run takes 0.5–1.7 s. That full run is what Overleaf repeats on every recompile (comparison).

What updates live

Text, math (inline and display, align and friends), references and citations, lists, theorems, figures and tables, headings, footnote marks, your own macros and environments, and most packages. When rtex cannot prove that a live result would be exact, it says why, and the paragraph appears with the next background pass instead. That covers preamble edits, the table of contents, margin notes, and text whose output depends on page state. Full list.

Install

Prebuilt binaries for Linux (x86_64, arm64), macOS (Apple silicon, Intel) and Windows (x86_64) are attached to every release. Each archive holds the rtex command, the C library and header, and rtex's TeX support files. Unpack it anywhere and run bin/rtex doctor to check that rtex finds its files and your LuaLaTeX. You still need a TeX Live with LuaLaTeX; see below for a minimal one.

# Linux x86_64; the other archives are rtex-aarch64-unknown-linux-gnu.tar.gz,
# rtex-aarch64-apple-darwin.tar.gz, rtex-x86_64-apple-darwin.tar.gz, rtex-x86_64-pc-windows-msvc.zip
curl -L https://github.com/HenryXiaoYang/realtime-tex/releases/latest/download/rtex-x86_64-unknown-linux-gnu.tar.gz | tar -xz
rtex-*/bin/rtex doctor

Try it from source

You need Rust and a TeX Live with LuaLaTeX. The script installs a minimal TeX Live into build/texlive (about 15 minutes; on Windows, run it from Git Bash). An existing TeX Live or MacTeX works too: set RTEX_TEXLIVE_BIN to its bin directory.

git clone https://github.com/HenryXiaoYang/realtime-tex && cd realtime-tex
scripts/install-texlive.sh && source build/texlive.env
cargo build --release

# make a 10-page test book, apply one live edit, and print what came back
target/release/rtex gen-book --pages 10 --out build/fx/book-10
target/release/rtex edit --project build/fx/book-10 --find "Baseline export" --text " (edited)"

# check that live output matches the real PDF, then export
target/release/rtex verify --project build/fx/book-10
target/release/rtex export --project build/fx/book-10 --out build/book-10.pdf --check

To edit your own document live, use the VS Code extension, or drive a session yourself with rtex serve --project path/to/your/project (JSON lines on stdin/stdout).

Build it into your own editor

rtex can be used as a Rust crate, as a C library (include/rtex.h), or as a subprocess speaking JSON lines. The editor sends edits and gets events: this paragraph now looks like this and here are the new pages. Each comes with display lists: glyphs from font files at exact positions, ready to draw. Pages that contain something a display list cannot describe, such as TikZ drawings, come with a PDF to draw them from. See the embedding guide; the VS Code extension is a complete example of a host.

Platforms

Linux, macOS and Windows. CI runs the test suite on all three against a real TeX Live. Only LuaLaTeX is supported (not pdfLaTeX or XeLaTeX), with a LaTeX kernel from 2021 or later.

Documentation

Live editing what updates as you type, what waits, how to make it faster
How it works the live engine, background passes, how rtex decides what can go live
Embedding Rust, C and JSON-lines APIs, events, configuration, drawing
Display lists the drawing format, binary and JSON
Correctness how output is checked against LuaTeX and its PDF, current results
Benchmarks latency, background passes, fonts, comparison with the paper
Engine protocol how rtex talks to the live LuaTeX process (for contributors)
Development building, testing, CI, debugging engine failures
Changelog

Status

Version 0.0.4. It works and is tested, but the API, the C ABI and the display-list format may still change before 0.1.

License

MIT, see LICENSE. The paper's benchmark, vendored in bench/upstream/, keeps its own MIT license.

Thanks

About

Realtime TeX: re-typesets only the paragraph you edit in ~1 ms with an unmodified LuaTeX. Exact, embeddable.

Topics

Resources

Stars

176 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages