diff --git a/README.md b/README.md index 5de007d..acb630b 100644 --- a/README.md +++ b/README.md @@ -606,8 +606,8 @@ Letter) set the MediaBox and the preview page box; the route-D endpoints read leading `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight` dimension assignments from the submitted source. Page marks collected by `\mark` are exposed through `Engine::top_mark`, `first_mark` and `bot_mark` with TeX's carry-forward rules. -`Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page (the paged builder applies the same limits and carries overflow onto dedicated pages), and `InsertionClass::multiplier` applies TeX's `\count` reserve factor; `Document::insertion_skip` models `\skip\footins` once per page before the first insertion class, and `InsertionClass::skip` overrides it for one class. `Engine::layout_paged` feeds the same material through `page::PageBuilder`, which places top floats at the head of a page, defers a late float, reserves `Document::text_float_sep` above the body and applies the insertion class limits; bottom floats sit at the page bottom with `Document::float_sep` between them and a `Document::bottom_fraction_percent` cap, while in-text floats flow inline with their `Document::in_text_sep` gaps counted as body height. Vertical glue is set after the break: `Document::ragged_bottom` defaults to TeX's `\raggedbottom`, and setting it false applies `\flushbottom`, stretching `StretchGlue` so the page body reaches the goal; glue of the highest order with stretch absorbs the whole setting, so `\vfil` makes short pages free. The v1 `/preview` and project APIs are unchanged and remain the default. +`Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page (the paged builder applies the same limits and carries overflow onto dedicated pages), and `InsertionClass::multiplier` applies TeX's `\count` reserve factor; `Document::insertion_skip` models `\skip\footins` once per page before the first insertion class, and `InsertionClass::skip` overrides it for one class. `Engine::layout_paged` feeds the same material through `page::PageBuilder`, which places top floats at the head of a page, defers a late float, reserves `Document::text_float_sep` above the body and applies the insertion class limits; bottom floats sit at the page bottom with `Document::float_sep` between them and a `Document::bottom_fraction_percent` cap, while in-text floats flow inline with their `Document::in_text_sep` gaps counted as body height. Vertical glue is set after the break: `Document::ragged_bottom` defaults to TeX's `\raggedbottom`, and setting it false applies `\flushbottom`, stretching `StretchGlue` so the page body reaches the goal; glue of the highest order with stretch absorbs the whole setting, so `\vfil` makes short pages free. `POST /preview` and the project APIs now default to route-D with a v1 fallback; `?engine=v1` (or `TEXRRA_ENGINE=v1`) forces the old pipeline. -Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline unless the server is started with `TEXRRA_ENGINE=route-d`, which makes route-D the default. An explicit `?engine=` always overrides `TEXRRA_ENGINE` for both previews and PDFs, so `?engine=v1` forces the old pipeline while `?engine=route-d` opts in even when the server defaults to v1. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and switches both the preview request and `POST /api/projects/{id}/pdf`, since the PDF handler honors the same `engine=route-d` query. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages, and route-D PDF exports reuse an eight-entry cache keyed by the expanded source (`X-Texrra-Cache: hit`), and the flat `/api/route-d/preview` and `/api/route-d/pdf` endpoints memoise the last 32 previews and eight PDFs by source hash; text edits and structural edits with an unchanged paragraph prefix rebuild from the first difference through `Engine::relayout_from`, reusing the sealed pages before it, while edits without a reusable prefix fall back to a full layout. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D +Project previews and PDFs default to the new core (`POST /api/projects/{id}/preview` without a query); `?engine=v1` or `TEXRRA_ENGINE=v1` forces the old v1 pipeline. An explicit `?engine=` always wins for both previews and PDFs. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and switches both the preview request and `POST /api/projects/{id}/pdf`, since the PDF handler honors the same `engine=route-d` query. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages, and route-D PDF exports reuse an eight-entry cache keyed by the expanded source (`X-Texrra-Cache: hit`), and the flat `/api/route-d/preview` and `/api/route-d/pdf` endpoints memoise the last 32 previews and eight PDFs by source hash; text edits and structural edits with an unchanged paragraph prefix rebuild from the first difference through `Engine::relayout_from`, reusing the sealed pages before it, while edits without a reusable prefix fall back to a full layout. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D document and returns the same page list plus `changedPages` and `recomputedPages`, exposing the checkpoint/page-hash diff from the core. diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index 5533966..6aab1e4 100644 --- a/docs/ROUTE_D_PLAN.md +++ b/docs/ROUTE_D_PLAN.md @@ -1,6 +1,8 @@ # Route D: complete implementation plan Status: active plan. Baseline commit `4414f27`, 2026-10-23. + +Current status and verification evidence: `docs/ROUTE_D_STATUS.md`. Owner: route-D core (`crates/texrra-tex-core`). ## 1. Objective diff --git a/docs/ROUTE_D_STATUS.md b/docs/ROUTE_D_STATUS.md new file mode 100755 index 0000000..8557443 --- /dev/null +++ b/docs/ROUTE_D_STATUS.md @@ -0,0 +1,95 @@ +# Route-D status (handoff after the round-150 recovery) + +Status: active on `main` in `texrra-engine` (the tree is clean after each push). +This page collects what route-D currently does, how to verify it, and the +limits that remain. It is the short companion to the long implementation log in +`ROUTE_D_PLAN.md` and the model notes in `TEX_CORE.md`. + +## Verification + +Run from the repository root: + +```sh +cargo fmt --all -- --check +cargo test --workspace --offline +``` + +The workspace currently passes **1015 tests**: + +| Suite | Tests | +| --- | --- | +| route-D unit (engine) | 437 | +| engine binary unit | 386 | +| server integration | 63 | +| v1 integration | 71 | +| pdfLaTeX oracle | 42 | +| route-D integration | 10 | +| engine/core unit | 4 + 1 | + +The oracle suite compiles fixtures with `pdflatex`, extracts word boxes with +`pdftotext -bbox`/`pdftoppm`, and compares route-D page geometry; it skips +(saying so) when the TeX tools are absent. The server suite includes +`corpus_documents_preview_without_warnings`, which previews +`examples/hello.tex`, `examples/boxes.tex`, `examples/compat.tex` and +`fixtures/arxiv-template/template.tex` and asserts 200, at least one page and an +empty `warnings` array for each. A manual sweep of the same four documents +reports 0 warnings, 1/1/1/2 pages and under 1.5 s per preview. + +## Service defaults + +- Flat `POST /preview` and the project preview/PDF endpoints try route-D first + and fall back to v1 on error. The flat response carries + `X-Preview-Engine: route-d|v1`. +- `?engine=v1` or `TEXRRA_ENGINE=v1` forces the old pipeline; an explicit + `?engine=` wins over the environment. +- `/api/route-d/preview`, `/api/route-d/pdf` and `/api/route-d/edit/{unit}` + remain the explicit route-D surface. +- Geometry-less documents default to Letter (pdfLaTeX's default), not the old + v1 A4 default. + +## Implemented areas + +- **Paragraphs/pages**: Knuth-Plass breaking with prefix-sum candidates, + hyphenation, justification, `\parindent`/`\parskip`, baselineskip/`\lineskip`, + TeX badness page breaking with glue orders, `\topskip`/`\maxdepth`, insertion + classes, marks, floats, `\output` program, incremental page replay. +- **Macros**: textual expansion with group scopes (`{}`, + `\begingroup`), `\def`/`\gdef`/`\edef`/`\xdef`, delimited and undelimited + parameters, `\let`, `\chardef`, `\newif`, `\csname`, `\expandafter`, + `\futurelet`, `\aftergroup`, `\afterassignment`, `\scantokens`, token + registers, `\string`, `\meaning`, `\expanded`, `\unexpanded`, + `\detokenize`; `@` and `%` catcodes are applied. +- **Boxes**: `\sbox`/`\savebox` measured at definition (width/height/depth, + image bodies use decoded pixels), frozen dimensions, `\wd`/`\ht`/`\dp`, + unbreakable `\mbox`/`\usebox`, `\parbox` content, framed/colour boxes. +- **Tables**: `tabular`/`longtable`, `\multicolumn`, `\multirow`, `p{}` + wrapping, `\tabskip`/`\tabcolsep`, booktabs rules, row splitting, real nested + tabulars, and `\valign` transposed into a tabular. +- **Math**: CM metrics and Type1 faces, fractions/scripts/delimiters, aligned + environments, operators, and inline math scaled proportionally at any + paragraph size. +- **Fonts**: twelve CM text faces and four math faces, Liberation fallback per + glyph, Greek/Cyrillic/accents, Greek math commands, fontspec family aliases. +- **Service**: both preview paths default to route-D with v1 fallback, caches + and sessions, engine-labelled flat responses. + +## Known limits + +- Expansion is textual, not a token stream; the catcode table models only `@` + and `%` (other `\catcode` assignments are consumed but not applied). +- Complex-script shaping (Devanagari, Thai, emoji) has no fallback face; this is + outside pdfLaTeX's own scope and is reported rather than silently mis-set. +- A `\parbox` keeps its content unbreakable; its width argument does not wrap. +- Images inside a nested table are not merged into the outer display list. +- `\valign` cells are left-aligned; its preamble alignments/vertical rules are + ignored. +- `\unexpanded` passes text through; the `\edef` freeze semantics are not + modelled. + +## Continuing + +1. Read `TEX_CORE.md` for the model and `ROUTE_D_PLAN.md` for the phase history. +2. Pick a limit above, add a route-D unit test (and a server/corpus test when + user-visible), update the relevant doc paragraph, and push to `main`. +3. Keep `cargo fmt --all -- --check` and the full workspace suite green before + every push; the oracle suite needs `pdflatex`, `pdftotext` and `pdftoppm`. diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index e96d27b..3214456 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -529,7 +529,8 @@ and the arXiv template reports 0 warnings for all four (guillemets, inline spacing, `\parbox`, `\orcidlink` and bare `\hrule` are handled), and the server test `corpus_documents_preview_without_warnings` keeps that true. -Status by area: service default is done (flat and project endpoints); saveboxes +The current verification snapshot lives in `docs/ROUTE_D_STATUS.md`. Status +by area: service default is done (flat and project endpoints); saveboxes are measured and frozen apart from image-only bodies; tables support real nested tabulars but not `\valign`; fonts expose the twelve CM faces plus fontspec family aliases; the macro engine remains textual (scopes, parameters,