Add a pdfLaTeX oracle and clamp justification glue

This commit is contained in:
gloamxun committed 2026-10-23 00:33:35 +08:00
1 parent 1e2d4afd6b
commit 9726f5f736
6 files changed
+379 -18

No files matched your search

+8 -1
View File
@@ -48,7 +48,8 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
PDF opt-in with `?engine=route-d`). 280 workspace tests are green.
PDF opt-in with `?engine=route-d`). 282 workspace tests exist (281 run, one
`#[ignore]`d until P1 supplies TeX tolerance/demerits).
Known gaps, in dependency order:
@@ -121,6 +122,12 @@ Deliverables:
- skips cleanly when TeX tools are unavailable, and records why;
- a `--regen`-style path for refreshing goldens.
Status: the foundation landed in `crates/texrra-tex-core/tests/oracle.rs`. The
150pt CMR10 fixture matches pdfLaTeX word for word (x tolerance 0.05pt), and the
ink-band test now runs on that same oracle-verified fixture. The 180pt fixture is
`#[ignore]`d with the reason "P1: TeX tolerance and demerits" because pdfLaTeX's
emergency pass accepts a 5/7 word split that the simplified demerit model rejects.
Acceptance: at least 20 paragraph fixtures and 5 page fixtures wired into
`cargo test`, harness green.
+14 -8
View File
@@ -60,12 +60,18 @@ class execution are still ahead.
M1 reads real CMR10 TFM metrics (advances, height/depth, italic correction,
kern pairs, ff/fi/fl/ffi/ffl ligatures and the fontdimen glue parameters),
hyphenates with the plain-TeX en-US patterns, and has pdfTeX fixtures for line
breaking. The demerits/tolerance model is still simplified: the final line keeps
its natural width and the last break can differ from TeX when a hyphenated break
would be slightly cheaper. `route_d_multiline_bands_track_pdftex` compares the
rasterized ink bands of a wrapped paragraph with pdfTeX, so baseline placement
and justification are covered for the lines both engines break the same way.
hyphenates with the plain-TeX en-US patterns, and is checked against pdfLaTeX
by `tests/oracle.rs`: the 150pt fixture matches the oracle word for word and
within 0.05pt horizontally. Justification now clamps the glue set ratio to the
declared stretch and shrink, so an overfull line stays overfull exactly as in
TeX instead of being squeezed into the measure.
The demerits/tolerance model is still simplified: the final line keeps its
natural width and the last break can differ from TeX when the emergency pass
would accept a tighter split (the 180pt fixture is `#[ignore]`d until P1).
`route_d_multiline_bands_track_pdftex` rasterizes the same oracle-verified
150pt paragraph in both engines and compares ink bands, covering baseline
placement and justification.
## Target architecture
@@ -82,7 +88,7 @@ and justification are covered for the lines both engines break the same way.
| 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`) | **partial**: item stream, CMR10 metrics, pdfTeX fixture and minimum line fill; hyphenation next |
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, hyphenation, TeX glue clamps and a pdfLaTeX oracle at 150pt; demerits/tolerance next |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; interpreted `\output`, float pages next |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: `Halign` model with natural column widths, spans and rule rows; no `\omit`/`\span` token parsing or PDF painting yet |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: `MathAtom` symbol/script/fraction boxes with CMR10 widths; no token conversion, radicals, accents or painter |
@@ -278,7 +284,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 168 unit tests plus five route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 265 tests (168 route-D unit, 5 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units). v1 remains the live server path.
The crate currently has 179 unit tests plus six route-D integration tests and two oracle fixtures (one ignored). Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 282 tests (179 route-D unit, 6 route-D integration, 2 oracle, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units), of which one is ignored. v1 remains the live server path.
### M0 incremental demo