Support TeX looseness on paragraph final lines

This commit is contained in:
gloamxun committed 2026-10-23 01:26:54 +08:00
1 parent 295c934438
commit 8cb09ea5a8
2 files changed
+27 -20

No files matched your search

+12 -8
View File
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and `\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the 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 route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
PDF opt-in with `?engine=route-d`). 299 workspace tests are green and no oracle PDF opt-in with `?engine=route-d`). 305 workspace tests are green and no oracle
fixture is ignored. fixture is ignored.
Known gaps, in dependency order: Known gaps, in dependency order:
@@ -56,10 +56,10 @@ Known gaps, in dependency order:
1. paragraph breaking reproduces TeX's passes and demerits (including 1. paragraph breaking reproduces TeX's passes and demerits (including
`\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`, `\adjdemerits`, `\doublehyphendemerits`, `\finalhyphendemerits`,
`\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions, `\hyphenpenalty`, `\exhyphenpenalty`, `\hyphenation` exceptions,
`\hangindent`/`\hangafter`/`\parshape` line geometry and `\parfillskip` `\hangindent`/`\hangafter`/`\parshape` line geometry, `\parfillskip`
with or without `fil` and default `\sfcode` sentence spacing), but not yet with or without `fil`, default `\sfcode` sentence spacing and
`\looseness`, custom `\sfcode` overrides or generic `fil`/`fill` glue `\looseness`), but not yet custom `\sfcode` overrides or generic
orders; `fil`/`fill` glue orders;
2. the page builder is a scrolling builder with fraction policies, not a TeX 2. the page builder is a scrolling builder with fraction policies, not a TeX
page builder with badness and an interpreted `\output`; page builder with badness and an interpreted `\output`;
3. `\insert` classes are data structures, not TeX registers and an output 3. `\insert` classes are data structures, not TeX registers and an output
@@ -196,9 +196,13 @@ stretch is multiplied and shrink divided by the space factor, `\fontdimen7`
is added from 2000, and `\frenchspacing` switches it off; a 150pt punctuated is added from 2000, and `\frenchspacing` switches it off; a 150pt punctuated
oracle fixture matches pdfLaTeX's line breaks and word positions. oracle fixture matches pdfLaTeX's line breaks and word positions.
Still open: generic `fil`/`fill` glue orders, `\looseness`, custom `\sfcode` `\looseness` adjusts the final line count inside TeX's `[1,9]` window and is
overrides, vertical-list skips (`\baselineskip`, `\lineskip`, `\parskip`), reverted when no feasible layout exists; 120pt and 200pt fixtures require one
double/final hyphen demerit oracle fixtures, and more width fixtures. extra line and match pdfLaTeX exactly.
Still open: generic `fil`/`fill` glue orders, custom `\sfcode` overrides,
vertical-list skips (`\baselineskip`, `\lineskip`, `\parskip`), double/final
hyphen demerit oracle fixtures, and more width fixtures.
### P2 — Vertical list, page builder, `\output` (L2) ### P2 — Vertical list, page builder, `\output` (L2)
+15 -12
View File
@@ -109,7 +109,7 @@ and justification.
| Milestone | Content | Acceptance | | Milestone | Content | Acceptance |
| --- | --- | --- | | --- | --- | --- |
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 | | 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, TeX Live en-US hyphenation, TeX demerits and tolerance passes, pdfLaTeX oracle matrix 100-240pt plus register fixtures; `\looseness`, `\parshape` and more fixtures next | | M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing, `\looseness`, pdfLaTeX oracle matrix 100-240pt plus four register fixtures; custom `\sfcode`, generic fil and vertical skips 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 | | 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**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; no booktabs/longtable parity yet | | M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; no booktabs/longtable parity yet |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with CMR10 metrics, delimiter scaling, accents and a display-list painter; no CMEX size variants or TeX math spacing classes yet | | M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with CMR10 metrics, delimiter scaling, accents and a display-list painter; no CMEX size variants or TeX math spacing classes yet |
@@ -129,13 +129,16 @@ and justification.
line is justified. Sentence spacing follows TeX's default `\sfcode` values: line is justified. Sentence spacing follows TeX's default `\sfcode` values:
interword glue stretch is multiplied by the space factor, shrink is divided interword glue stretch is multiplied by the space factor, shrink is divided
by it, `\fontdimen7` is added from factor 2000, and `\frenchspacing` by it, `\fontdimen7` is added from factor 2000, and `\frenchspacing`
disables the effect. Remaining gaps are `\looseness`, custom `\sfcode` disables the effect. `\looseness` shifts the paragraph by whole lines when
overrides, generic `fil`/`fill` glue orders outside `\parfillskip`, and the the requested count lies between one and nine lines away from the natural
vertical-list skips (`\baselineskip`, `\lineskip`, `\parskip`). count (the adjustment is reverted when no feasible layout exists).
Remaining gaps are custom `\sfcode` overrides, generic `fil`/`fill` glue
orders outside `\parfillskip`, and the vertical-list skips
(`\baselineskip`, `\lineskip`, `\parskip`).
The pdfLaTeX oracle pins the 100-240pt measure matrix plus `\hangindent`, The pdfLaTeX oracle pins the 100-240pt measure matrix plus `\hangindent`,
`\parfillskip` and sentence-spacing fixtures; all match and no oracle fixture `\parfillskip`, sentence-spacing and `\looseness` fixtures; all match and no
is ignored. oracle fixture is ignored.
- `\middle|` inside `\left...\right` is accepted as a delimiter symbol (not yet stretched). - `\middle|` inside `\left...\right` is accepted as a delimiter symbol (not yet stretched).
- `\sqrt[n]{x}` carries an optional degree atom; `\left.` is an empty - `\sqrt[n]{x}` carries an optional degree atom; `\left.` is an empty
@@ -300,7 +303,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. 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 188 unit tests plus six route-D integration tests and eight oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 299 tests (188 route-D unit, 6 route-D integration, 8 oracle, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path. The crate currently has 192 unit tests plus six route-D integration tests and ten oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 305 tests (192 route-D unit, 6 route-D integration, 10 oracle, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
### M0 incremental demo ### M0 incremental demo
@@ -328,11 +331,11 @@ The staged program that closes these milestones is described in
Route D currently covers M0-M4/M6 as a working subset. The remaining milestones are Route D currently covers M0-M4/M6 as a working subset. The remaining milestones are
deliberately open rather than approximated: deliberately open rather than approximated:
- **M1**: `\looseness`, custom `\sfcode` overrides, generic `fil`/`fill` - **M1**: custom `\sfcode` overrides, generic `fil`/`fill` glue orders and
glue orders and the vertical-list skips are still open; the tolerance, penalty the vertical-list skips are still open; the tolerance, penalty and demerit
and demerit registers, `\hyphenation` exceptions, registers, `\hyphenation` exceptions, `\hangindent`/`\parshape`,
`\hangindent`/`\parshape`, `\parfillskip` with or without `fil`, and the `\parfillskip` with or without `fil`, `\looseness`, and the default
default `\sfcode`/`\frenchspacing` sentence spacing are modelled. `\sfcode`/`\frenchspacing` sentence spacing are modelled.
- **M5**: `cmr10.tfm` is parsed at runtime with widths, glyph heights/depths and kern pairs. only used text faces embed Liberation Serif/Mono as Type0/Identity-H; each face is subset to the glyphs actually used (composite components included, glyph IDs retained); FontFile2 and ToUnicode streams use Flate compression; the ToUnicode CMap follows the used characters; ff/fi/fl/ffi/ffl ligatures come from TFM, and CMR10 italic corrections are applied at line ends; full NFSS family switching is not implemented. - **M5**: `cmr10.tfm` is parsed at runtime with widths, glyph heights/depths and kern pairs. only used text faces embed Liberation Serif/Mono as Type0/Identity-H; each face is subset to the glyphs actually used (composite components included, glyph IDs retained); FontFile2 and ToUnicode streams use Flate compression; the ToUnicode CMap follows the used characters; ff/fi/fl/ffi/ffl ligatures come from TFM, and CMR10 italic corrections are applied at line ends; full NFSS family switching is not implemented.
- **M6**: `\output`, `\insert`, mark/float output policies, class-file execution and - **M6**: `\output`, `\insert`, mark/float output policies, class-file execution and
math limit policies are only partially modeled; `OutputRoutine::wants_break` can force a page break between units, and insertion material is stacked by class from the page bottom; `\output` is still Rust code rather than interpreted tokens. math limit policies are only partially modeled; `OutputRoutine::wants_break` can force a page break between units, and insertion material is stacked by class from the page bottom; `\output` is still Rust code rather than interpreted tokens.