Start route D incremental TeX core with M0 checkpoint spike

This commit is contained in:
gloamxun committed 2026-10-20 12:06:39 +08:00
1 parent b41a2a9a97
commit 99dbb5ebb0
8 files changed
+447 -3

No files matched your search

+8
View File
@@ -155,3 +155,11 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- Lines whose justification ratio exceeds 3 fall back to natural spacing instead of stretching inter-word gaps across the measure.
- Numeric bibliographies format author names as Surname, I. for standard journal styles.
## Route D core (experimental)
is an isolated M0 spike for a TeX-compatible
incremental engine. It has vertical boxes/glue/penalties, page-boundary
checkpoints, page hashes and a page-local edit test. It is not yet wired into
the server; the v1 engine remains the production path.
+77
View File
@@ -0,0 +1,77 @@
# TeX-compatible incremental core (route D)
Status: **M0 architecture spike implemented** in `crates/texrra-tex-core`.
The production v1 engine in `src/rust_typeset` remains the default and is kept as
a fallback while the TeX-compatible core grows.
## Why route D
The v1 engine parses LaTeX into `DocumentModel` and lays it out with
hand-written algorithms. That gives true incremental preview, but it cannot be
page-identical for arbitrary `.cls`/`.sty` files: class files are TeX programs,
and their layout primitives (`\vbox`, `\halign`, `\output`, `\twocolumn`,
insertions, math lists, font metrics) are not executed.
Route D is a TeX-compatible execution/layout core designed for incremental
operation from the start. It does **not** embed pdfTeX, XeTeX or Tectonic.
## M0 scope (this spike)
`crates/texrra-tex-core` currently provides:
- `VerticalItem::{Box, Glue, Penalty}` and `VerticalBox` as the first vertical
list model;
- `Unit::paragraph` as a placeholder for the future TeX paragraph builder;
- `Engine::layout` that builds pages with a simple page goal;
- `Checkpoint` before every top-level unit, containing the completed-page count,
used vertical space and current page items;
- `Page` hashes derived from both vertical items and the contributing unit
sources;
- `Engine::edit` which restores the checkpoint before the edited unit,
re-executes only the suffix, compares page hashes, and reports
`recomputed_pages`;
- serde round-trip for checkpoints.
M0 proves the incremental contract, not TeX compatibility. The paragraph
builder, page builder, math, fonts and class execution are still ahead.
## Target architecture
- Persistent TeX VM state: macros, registers, fonts, counters, output queue.
- Stable IDs for top-level units.
- Checkpoint at page boundaries plus unit boundaries.
- Dependency graph for labels, references, counters, TOC and citations.
- Dirty propagation: after a local edit, replay from the nearest checkpoint and
stop at the first unchanged page hash.
- Float/footnote queues restored with the checkpoint.
## Milestones
| Milestone | Content | Acceptance |
| --- | --- | --- |
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | line breaks match pdfTeX for test paragraphs |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | one-column article matches reference pages |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap |
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
| M6 | class/package execution (`article`, `sn-jnl`) | Overleaf page-count parity |
| M7 | `\special`, PDF XObjects, hyperref annotations | PDF structure parity |
## Current limits
- The M0 paragraph model is a character-count placeholder; it does not run the
TeX paragraph algorithm yet.
- Page breaking only handles vertical boxes/glue; penalties are recorded but not
interpreted.
- No macro state, output routine, math, fonts or PDF output in the new core yet.
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
## Verification
```sh
cargo test -p texrra-tex-core --offline
```
The four M0 tests cover page splitting, checkpoint serialization and
page-local editing.