rtex is a typesetting engine for editors. When you type, it re-typesets only the paragraph being edited through a LuaLaTeX process that has already loaded your preamble, and hands the editor the new lines to draw. A full background compile 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 and the same glyphs at the same positions to 1/65536 pt — because rtex uses an unmodified LuaTeX from TeX Live and exported PDFs are identical to a normal LuaLaTeX build. Time from keystroke to updated paragraph is about a millisecond and does not depend on document length. The archive contains the `rtex` command, the C library and header, and rtex TeX support files.
See your LaTeX document update as you type, in about a millisecond, without leaving LuaLaTeX.
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 quickest way to use rtex is the Realtime TeX
extension for VS Code (source).
Install it from the VS Code Marketplace (or Open VSX for VSCodium, Cursor and other editors), or search for "realtime tex" in the Extensions view:
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.54 ms
0.50 ms
four lines
0.91 ms
1.12 ms
1.11 ms
ten lines
—
1.78 ms
1.78 ms
a list, a figure, a table, display math
1.2–1.7 ms
1.6–1.9 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.4–1.5 ms with rtex, 19 ms (10 pages) to 455 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.