Project preview accepts ?buffer=1 and reads the editor text from the POST body. The source is still expanded with project includes/packages/images, but the file on disk is not touched, so typing can drive layout immediately while the normal 450 ms save timer runs independently. Add a server test that previews buffer text, finds it in the SVG, and verifies hello.tex on disk was not rewritten. Roadmap notes that warm buffer previews are still ~430 ms (article) and ~2.1 s (arXiv), and that dirty-page streaming is the next latency step.
7.3 KiB
7.3 KiB
Route-D fidelity and incremental-preview roadmap
Status: active goal, started 2026-10-27. The target is a route-D that produces TeX-compatible output for the supported article/arXiv subset and keeps a Typst-like edit-to-preview loop. These are separate workstreams that must be measured together: fidelity work can easily make preview latency worse.
Definition of done
For a curated corpus of article/arXiv projects:
- PDF fidelity
- page count matches TeX Live;
- text-block origin, measure, headers/footers and page numbers match within a small tolerance;
- title, author block, section style, citations/references, floats, tables and display math are visually recognisable as the TeX output;
- a per-page image-diff report is checked into the test harness, with known exceptions listed explicitly.
- Incremental preview
- warm edit-to-preview p95 under 100 ms for documents up to 10 pages;
- only changed pages are transferred and re-rendered on the client;
- a full PDF can continue in the background without blocking preview;
- typing does not wait for a 450 ms save timer.
- Honest grading
- every unsupported construct produces a warning or a documented exception;
- no project silently loses a column, citation or figure.
The supported subset is explicit: article/report/arXiv-style papers that use the engine's class, list, table, float, citation and math subset. Arbitrary LaTeX execution is not a goal.
Current baseline (2026-10-27)
- Both engines produce 3 pages for the uploaded arXiv template.
- Route-D content is present: tables, basic BibTeX references, citations, headers and page numbers now render.
- Page frame was just fixed: PDF page origin now honours the document's
horizontal/vertical offsets, so a
geometrydocument gets its centred 6.5in text block and page-2/page-3 headers instead of content at x=0. - Still visibly different from TeX:
- body face is CMR/fallback, not Times from
\rmdefault{ptm}; - title/author block, small caps and rules are simplified;
- reference style is numeric, not natbib author-year;
- display math is approximate;
\fbox/rule figures, vector images and float placement differ.
- body face is CMR/fallback, not Times from
- Incremental foundation exists:
Engine::edit+ page hashes;- project-scoped sessions and changed-page reporting;
- web
applyPagesskips pages whose hash is unchanged; - a 90 ms preview debounce and 450 ms save debounce.
- Incremental progress in the working tree:
- project previews accept
?buffer=1with the editor text as the request body, so preview no longer waits for the 450 ms disk save; - the web editor previews on a 40 ms debounce while saving on the old timer;
changedPagesalready identifies the pages that need repainting.
- project previews accept
- Incremental bottlenecks:
- the server still returns every page's SVG JSON;
- the browser downloads all pages before hash-skipping;
- measured warm buffer previews are still about 430 ms for article-basic and 2.1 s for the arXiv template; the <100 ms target is not met;
- no WebSocket/SSE stream or dirty-page patch protocol.
Architecture
Fidelity layers
- F1 — Page frame: paper size, text-block origin (left/top), headers, footers, page numbers, running marks. The route-D PDF and preview must share the exact same origin.
- F2 — Class styles:
\maketitle, title/author/date blocks, section and caption styles, abstract, keywords. Parse the class's declarations rather than special-casing a single template. - F3 — Fonts and metrics: TeX TFM-compatible widths/kerns/ligatures for
Computer Modern and Times (
ptm), then line breaking uses the correct measures. A font metric provider must be independent of the PDF backend. - F4 — Floats, tables, math: float placement/order, booktabs and multicolumn, real inline math in table cells, display-math layout.
- F5 — Citations and references: natbib author-year and numeric styles,
.bibfield coverage, sorting and labels.
Incremental layers
- I1 — Revisions and stable IDs: each block gets a stable source range/ID; an edit produces a revision with a minimal changed range, not a new string compared by prefix.
- I2 — Incremental parse: reparse only affected blocks, preserving unchanged block IR. Then relayout only pages whose dependency set changed.
- I3 — Patch protocol: a persistent WebSocket/SSE channel sends
{revision, changedPages:[{index, hash, svg}], removedPages, pageCount, durationMs, warnings}. The client patches those pages only. - I4 — Preview without disk round-trip: the editor sends its buffer and revision; the server compiles the buffer, while a background job writes the file and builds the full PDF. Cancellation is keyed by revision.
Milestones
M1 — Page frame and class title/author (fidelity)
Acceptance:
- geometry documents have the same text-block origin as TeX within 1 pt;
- page 2/3 headers and page numbers appear at the TeX positions;
- title/author/date block gets its own line structure and vertical spacing;
- a regression test compares PDF text coordinates and preview coordinates.
M2 — Times metrics and section styles
Acceptance:
\rmdefault{ptm}selects Times-compatible metrics for text and line breaks;- section/subsection sizes and spacing follow the class declarations;
- line-break differences against TeX drop measurably on the article corpus.
M3 — Citations, floats and table math
Acceptance:
- natbib author-year output for the arXiv sample, plus numeric mode;
- floats land on the same page as TeX for the corpus, or a warning explains why they cannot;
- table cells typeset inline math instead of the ASCII fallback;
\fbox/rule figure bodies draw a frame.
M4 — Incremental protocol
Acceptance:
- WebSocket/SSE revision stream with page patches;
- warm p95 edit-to-preview <100 ms for a 10-page document;
- typing does not wait for disk save;
- full PDF compilation continues in the background;
- aborted revisions never paint stale pages.
M5 — Fidelity/latency harness in CI
Acceptance:
- TeX Live compiles the corpus in CI (or a pinned docker image);
- route-D PDFs are rasterised and diffed page-by-page;
- preview latency percentiles are recorded per commit;
- the dashboard reports both fidelity and speed, so one cannot regress silently.
Immediate next steps
- Finish M1: title/author block and a coordinate regression harness. The page frame fix is already in the working tree.
- Add Times TFM metrics (M2) before touching math, because line breaking and page breaks depend on the correct font metrics.
- Build the patch protocol (M4) in parallel with fidelity work; it is mostly server/web plumbing and does not depend on the math engine.
- Keep the TeX Live comparison PDF and the generated reference images as the visual oracle for each milestone.
Risks and non-goals
- Exact TeX parity for arbitrary packages is not feasible without executing TeX. The roadmap targets a documented article/arXiv subset.
- Math typesetting is the largest single risk; a full TeX math engine may be a separate project.
- Incremental layout must not be faked by caching the last response: stale pages and revision races are correctness bugs.
- Do not trade fidelity for latency silently; every shortcut must be visible in warnings and in the fidelity report.