render_json now accepts an optional page whitelist. The new project_preview_patch_json_with_images path passes changedPages before building page SVGs, instead of serialising all pages and filtering afterwards in the server. Cache hits still use the old filter helper. Add scripts/bench-preview.py: repeated buffer edits against a running server, reporting HTTP/server latency, bytes and changedPages. Measure release builds: article-basic 37.5 ms (one page), arXiv late edit p50 199 ms / p95 222 ms with one changed page at 175 KB, arXiv heading edit ~480 ms. This is a solid improvement over the debug numbers previously quoted, but the 10-page <100 ms target remains unmet. TEXRRA_PROFILE=1 now gates the geometry/paragraph/before-render timings. Test count is 1073 (67 server).
181 lines
8.4 KiB
Markdown
181 lines
8.4 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 is CMR/fallback, not Times from `\rmdefault{ptm}`;
|
||
- title now uses small caps and author metadata is split onto class-like
|
||
lines; title rules, two-column affiliations and ORCID icons are still
|
||
missing;
|
||
- reference style is numeric, not natbib author-year;
|
||
- display math is approximate;
|
||
- `\fbox`/rule figures, vector images and float placement differ.
|
||
- 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: article-basic warm buffer edit **37.5 ms**
|
||
(one page), arXiv late edit **p50 199 ms / p95 222 ms** (one to two of
|
||
three pages changed), arXiv early/heading edit about **480 ms**; a
|
||
one-page simple document meets the <100 ms target, the 3-page arXiv
|
||
template and the 10-page target do not;
|
||
- patch responses are now serialised only for changed 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;
|
||
- layout is still full-document after parsing the whole buffer; parsing and
|
||
geometry are only ~10 ms of the release pipeline, so layout is the target.
|
||
- 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 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
|
||
|
||
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.
|