202 lines
9.7 KiB
Markdown
202 lines
9.7 KiB
Markdown
# 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:
|
||
|
||
1. 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.
|
||
2. 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.
|
||
3. 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 `geometry` document 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 uses Times Roman/bold/italic metrics (`ptmr8t`, `ptmb8t`,
|
||
`ptmri8t`, `ptmbi8t`) with Liberation Serif TrueType;
|
||
- the arXiv class's top/bottom rules, "A Preprint" undertitle and uppercase
|
||
Times title are drawn, and two author groups are laid out side by side as a
|
||
centred two-column halign. ORCID icons are replaced by an `iD` text
|
||
marker, not the vector logo;
|
||
- project `.bib` entries now produce author-year labels and natbib-style
|
||
parenthetical citations; inline `thebibliography` without labels remains
|
||
numeric, and the full natbib option surface is not implemented;
|
||
- display math is approximate;
|
||
- PNG/JPEG/BMP floats now reserve their image height, embed the raster with
|
||
its real pixel dimensions, centre the image within the float, and emit it
|
||
into the SVG preview as a PNG data URI. Table floats are centred with their
|
||
booktabs rules, and the sample's figure/table order now follows TeX. Vector/
|
||
PDF images are still missing, and general float placement remains
|
||
approximate.
|
||
- Incremental foundation exists:
|
||
- `Engine::edit` + page hashes;
|
||
- project-scoped sessions and changed-page reporting;
|
||
- web `applyPages` skips 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=1` with 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;
|
||
- the preview response can be filtered to `changedPages` with `?patch=1`;
|
||
- the web client applies sparse page patches by their `index`;
|
||
- `changedPages` already identifies the pages that need repainting.
|
||
- Incremental bottlenecks:
|
||
- release-mode measurements after the paragraph-unit cache: article-basic
|
||
**47 ms**, arXiv late edit **p50 47.6 ms / p95 53.3 ms** (one page changed),
|
||
With the real lipsum text and Times metrics, arXiv previews measured
|
||
17.5–22 ms warm and 168 ms cold (590 KB JSON); the Times TFM parse is lazy
|
||
and cached.
|
||
a 10-page simple document **p50 13 ms / p95 14.7 ms**; the measured
|
||
3-page and 10-page cases now meet the <100 ms target, while the cold
|
||
first build is still 150–370 ms and a heading/front-matter edit still
|
||
reflows multiple pages;
|
||
- patch responses are serialised only for changed pages, and display lists
|
||
are skipped for unchanged pages; the arXiv late edit still carried one page
|
||
at 175 KB, and a heading edit carried two at 315 KB of a 396 KB full
|
||
response; cache hits return ~170 bytes and 10–40 ms;
|
||
- the `scripts/bench-preview.py` harness reproduces these numbers: initial
|
||
full, then repeated small buffer edits with HTTP/server latency, bytes and
|
||
changedPages;
|
||
- there is no WebSocket/SSE stream yet, only request/response patches;
|
||
- release profiling showed the real bottleneck was **build_document**, not
|
||
page layout. A bounded paragraph-unit cache keyed by text/font/style (and
|
||
cleared when the paragraph-shaping geometry changes) now reuses unchanged
|
||
units; build_document drops from ~196 ms to ~30–40 ms for the arXiv late
|
||
edit. Float/table/math units are still rebuilt, and the first cold build
|
||
does not benefit.
|
||
- Developer profiling: `TEXRRA_PROFILE=1` prints geometry/paragraph/before-render
|
||
timings from the project preview path. Earlier notes in this document used a
|
||
debug binary (430 ms/2.1 s) and overstate the release latency.
|
||
|
||
## 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,
|
||
`.bib` field 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 the rule body; the surrounding fbox frame
|
||
is still missing.
|
||
|
||
### M4 — Incremental protocol
|
||
|
||
Acceptance:
|
||
|
||
- WebSocket/SSE revision stream with page patches;
|
||
- warm p95 edit-to-preview <100 ms for a 10-page document (currently met on a
|
||
simple 10-page stress document at p95 14.7 ms, and on the 3-page arXiv
|
||
sample at p95 70.3 ms);
|
||
- 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
|
||
|
||
1. Finish M1: title/author block and a coordinate regression harness. The page
|
||
frame fix is already in the working tree.
|
||
2. Add Times TFM metrics (M2) before touching math, because line breaking and
|
||
page breaks depend on the correct font metrics.
|
||
3. Build the patch protocol (M4) in parallel with fidelity work; it is mostly
|
||
server/web plumbing and does not depend on the math engine.
|
||
4. 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.
|