⚡ LightningTeX
Genuine LuaHBLaTeX in the Browser — Millisecond Incremental Live Preview, Zero Backend.
Try LightningTeX online →
English · 简体中文 · Standalone Engine SDK · Renderer Docs · Source Build Recipe · Deployment · QA & Benchmarks
Why LightningTeX?
Modern LaTeX tools have long forced writers into a compromise:
- Cloud or Traditional Full-Compile Editors run real TeX, delivering authentic typography, macro expansion, and PDF output—but every edit waits seconds for a full-document compilation pass and server round-trip.
- Browser HTML / MathJax / KaTeX Previewers respond in milliseconds—but they are approximations, not TeX. They rely on browser text layout rather than Knuth–Plass line breaking, substitute fonts, and cannot execute real LaTeX counters, preamble macros, or package hooks.
LightningTeX eliminates this trade-off. It brings realtime-tex's Lua-side incremental typesetting architecture directly into the browser via a custom-trimmed LuaHBTeX 1.24.0 (TeX Live 2026) WebAssembly runtime, paired with a dependency-free modern writing workspace.
Core Product Philosophy
- Real TeX, Never Approximated: Every paragraph, inline or display formula (
equation, align, gather, multline), list, heading, and theorem environment is typeset by actual LuaHBLaTeX. Glyphs are placed at integer scaled-point (sp, $1\text{ pt} = 65536\text{ sp}$) coordinates and drawn directly from engine font outlines (OpenType/TrueType glyph indices and original Type 1 PFB charstrings).
- Two-Speed Hybrid Pipeline (Instant Local Reflow + Quiet Background Convergence):
- Fast Path (
Live / Reflow, ~5–20 ms warm): A persistent LuaHBTeX worker stays alive inside TeX's outer loop (\loop\rtexstep...\repeat), replays the exact captured state of the edited unit, typesets only the affected unit in a \vbox, and updates the page canvas in place—stretching or slicing horizontal page bands when line counts or formula heights change (pagination pending).
- Slow Path (
Full): After a provisional Reflow, ~500 ms of inactivity triggers background compilation to update pagination, page numbers, TOC/bookmarks, and bibliography. Preamble, cross-reference, or unsupported changes route directly to Full. Fixed-geometry Live updates keep the preview current without scheduling an idle full compile; PDF export compiles the latest source when needed.
- Fail-Closed Correctness & Transparent Observability: Before any unit is edited live, LightningTeX compiles its original captured source in the live worker and proves that every row box, glue setting, font descriptor, glyph index, and relative
sp coordinate matches the full-compile baseline. Incomplete math delimiters or unbalanced braces never trigger noisy broken builds—the previous valid preview is calmly held while the caret math popover auto-repairs open groups. The top-bar Live Inspector shows the exact routing path, latency timeline, and PDF sync state for every keystroke.
- 100% Client-Side & Zero Backend: All TeX compilation, BibTeX
.bst interpretation, font outline parsing, and project persistence happen locally inside the browser. Your document content never leaves your machine.
 Integer scaled points. Glyphs are drawn from their own Bézier outlines at integer sp positions. |
 Band reflow. A taller formula opens its band and slides the page below it, while exact pagination settles in the background. |
 Never a broken frame. An unclosed \( holds the page while the caret popover sets the repaired formula. |
Every animation here is rendered frame by frame from recorded engine output (display lists, glyph outlines and measured latencies). Nothing is mocked up.
Quick Start
1. Run a Prebuilt Release Bundle
If you downloaded the ready-to-run release archive, no npm install or local TeX Live installation is required. Using Node.js 22.12+:
node server.mjs
Then open http://127.0.0.1:4173 in a desktop browser (use PORT=8080 node server.mjs to customize the port).
[!IMPORTANT]
Do not open index.html via file://. Web Workers, streaming WASM assembly, and the SharedArrayBuffer incremental channel require a secure HTTP context (http://127.0.0.1 or https://) with Cross-Origin Isolation headers (COOP: same-origin, COEP: require-corp). server.mjs configures these headers automatically on 127.0.0.1. For production static hosting, see docs/DEPLOYMENT.md.
2. Run from Source
Building and testing require Node.js 22.22.2+ (22.x), 24.15.0+ (24.x), or 26+. This does not change the Node.js requirement for the zero-dependency prebuilt server above.
npm ci
npm run dev # Start Vite dev server
npm run build # Build production web app into dist/
npm run preview # Serve dist/ on http://127.0.0.1:4173 with COOP/COEP headers
To publish on Vercel, install its CLI, run vercel login, then vercel --prod from the repository root. The included configuration supplies the required routes and headers; see the Vercel deployment steps.
On first launch, LightningTeX streams ~42.4 MiB of gzip-compressed engine and TeX Live basic assets (~54.4 MiB unpacked; internal TeX files remain stored in 16 KiB LZ4 blocks) with staged progress so you can start editing immediately. Additional packages (microtype, booktabs, enumitem, etc.) are fetched on demand when used in a document and persisted in browser Cache Storage.
To use a custom font in the PDF and live preview, upload its .otf or .ttf file to the project, then load fontspec and point it at the file, for example \setmainfont[Path=fonts/]{MyFont-Regular.otf}. The browser engine does not read fonts installed on your computer.
Technical Architecture
LightningTeX separates the writing workspace from two browser-based LuaHBTeX workers: one keeps local edits responsive, while the other produces the complete PDF and document layout.
flowchart TB
subgraph UI["Main Thread"]
Editor["Editor & Project Files"]
Coordinator["Update Coordinator"]
Preview["Page Preview & Source Sync"]
end
Live["Live Worker<br/>Incremental LuaHBTeX Typesetting"]
Full["Background Worker<br/>Full LuaHBTeX Compilation"]
Editor --> Coordinator
Coordinator -->|"Eligible local edits"| Live
Live -->|"Updated display lists"| Coordinator
Coordinator -->|"Structural changes or pagination settlement"| Full
Full -->|"PDF & captured document context"| Coordinator
Coordinator -->|"Validated updates"| Preview
Two Complementary Compilation Paths
The live worker keeps the TeX runtime, preamble, and fonts loaded between edits. A shared-memory request channel lets it receive work while TeX remains inside its synchronous processing loop. The background worker handles full-document compilation, including cross-references and bibliography. Both workers reuse the compiled WebAssembly module but keep their memory and filesystems isolated.
Capture, Replay & Verification
Full compilation captures the layout and typesetting context of each supported document unit. Local edits replay that context to preserve counters, fonts, paragraph geometry, and resolved references. Local template settings, linked citations, and scoped gray/RGB text color can coexist with incremental prose and equation edits. Before a unit's first live edit, its original source is re-typeset and checked against the full-compile baseline. Unsupported edits or failed checks fall back to full compilation; multi-file updates are applied together only when the whole batch is valid and current.
Preview from TeX Output
The renderer draws glyph outlines at the positions supplied by TeX, combining local updates with PDF.js page rendering rather than using browser text layout. Fixed-geometry edits repaint only the affected region (Live). Changes in height resize page bands and shift the content below (Reflow), with exact pagination restored by a background compile after typing pauses. Incomplete input keeps the last valid preview visible.
Reuse Across Compilations
A trimmed WebAssembly build and on-demand TeX packages keep the initial runtime focused. Browser caching reduces repeated resource downloads, while auxiliary-file reuse avoids unnecessary compilation passes. A JavaScript BibTeX interpreter processes bibliography styles within the browser, keeping document compilation entirely client-side.
For implementation details, see the engine SDK, renderer, and source build recipe. Performance measurements are collected in QA & Benchmarks.
Writing Workspace Highlights
LightningTeX's UI (ui/) is built from scratch with zero frontend framework dependencies, designed around typographic clarity, keyboard speed, and immediate visual feedback:
| Category |
Capabilities |
| Live Inspector & Status Capsule |
Top-bar status capsule displays real-time update latency (Live 6.1 ms) and a 12-bar sparkline. Clicking opens the Live Inspector: a 24-bar timeline (Live, Reflow, Full, Waiting), localized routing explanation, live worker status & restart count, median latency, and PDF sync state (in sync, behind by a number of edits, or updating). |
| Bidirectional Source ⇄ Preview Sync |
Source → Preview: Moving the caret highlights the corresponding paragraph/formula/heading on the page margin and shows an edge chip when scrolled out of view. Preview → Source: Clicking a rendered line uses alignGlyph to match NFKC-normalized glyph codepoints, ligatures, and math italics to source text. It jumps to the matched word, or an approximate row position when no match is found. |
| Caret Math Popover & Hover Cards |
Math Popover: Live-typesets the formula under the caret using the document's preamble macros and fonts, automatically closing unfinished braces/delimiters/environments. Hover Cards (400 ms dwell): Preview typeset target equations on \ref/\eqref, image thumbnails & dimensions on \includegraphics, macro definitions, and .bib entry titles, authors, years, and metadata. Ctrl/Cmd + Click or F12 jumps to definition. |