The PDF writer received the raw geometry origin instead of the document's
effective offsets, so PDFs started at x=0 and clipped running headers above the
page even though the preview looked shifted. PDF output now uses the same
h_offset/v_offset as the preview.
For a geometry document with a 6.5in measure this restores the 1in text block;
the arXiv template's page-2/3 headers ("arXiv Template", "A Preprint") now
appear. A regression test checks the centred text block.
Add docs/TEX_FIDELITY_ROADMAP.md: page-frame/class/font/citation/math
fidelity workstreams, incremental revision/patch protocol, milestones and the
<100ms warm preview target. Test count is 1070 (433 engine).
160 lines
6.9 KiB
Markdown
160 lines
6.9 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/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.
|
||
- 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 bottlenecks:
|
||
- the server still returns every page's SVG JSON;
|
||
- the browser downloads all pages before hash-skipping;
|
||
- project edits wait for the save timer before preview;
|
||
- the arxiv project's preview/layout is still in the 1.4–1.5 s range;
|
||
- 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,
|
||
`.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.
|