Match TeX hyphenation and justification semantics
This commit is contained in:
1 parent
ac134b3c4e
commit
4fbc43f5ff
6 files changed
+5074
-56
No files matched your search
+14
-16
@@ -48,7 +48,7 @@ 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`). 285 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 286 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
@@ -154,21 +154,19 @@ Acceptance: 30 fixtures covering widths, indents, hyphenation, overfull and
|
||||
underfull lines; line break positions and overfull boxes identical to
|
||||
pdfLaTeX.
|
||||
|
||||
Status (P0 committed, P1 in progress): the oracle harness found and fixed two
|
||||
real defects — the TFM lig/kern reader kept the last instruction for a shared
|
||||
key instead of the first (`k` + `a` picked up `w`'s kern), and justification
|
||||
squeezed overfull lines past their declared shrink. Both are fixed and the
|
||||
150pt fixture now matches pdfLaTeX word for word.
|
||||
|
||||
Status (continued): the breaker now reproduces TeX's passes and demerits.
|
||||
Pass 0 uses `\pretolerance` without hyphenation, pass 1 `\tolerance` with it,
|
||||
and a third pass with `\tolerance=10000` plus `\emergencystretch` runs only when
|
||||
that register is positive. With zero emergencystretch TeX gives up and fills
|
||||
each line to the first break at or past the measure, which is exactly the
|
||||
overfull fallback implemented here. Demerits combine line penalty, badness,
|
||||
break penalties and adjacent fitness changes, and the final line keeps its
|
||||
natural width. Both oracle fixtures now pass, so TeX's emergency choices are
|
||||
reproduced rather than approximated.
|
||||
Status (P0 committed, P1 in progress): the oracle harness found and fixed
|
||||
four real defects: the TFM lig/kern reader kept the last instruction for a
|
||||
shared key (`k` + `a` picked up `w`'s kern), justification squeezed overfull
|
||||
lines past their declared shrink while clamping legal stretch, the vendored
|
||||
plain-TeX hyphenation patterns disagreed with pdfLaTeX (`kappa`, `lambda`),
|
||||
and the final-pass fallback did not model TeX's artificial demerits. The
|
||||
breaker now uses TeX Live's `hyph-en-us` patterns and exceptions with
|
||||
`\lefthyphenmin=2`/`\righthyphenmin=3`, stretches normal glue past its
|
||||
nominal stretch while clamping shrink at the declared limit, and falls back to
|
||||
the longest prefix within `\tolerance` or the first overflowing prefix. The
|
||||
oracle compares 100, 120, 150, 180, 200 and 240pt and all six match pdfLaTeX
|
||||
word for word within 0.05pt; the narrow measures exercise hyphenated and
|
||||
overfull breaks.
|
||||
|
||||
Still open: explicit `\tolerance`/`\pretolerance` overrides, flagged
|
||||
(hyphenated) demerits, `\parfillskip` variants, `\hangindent`/`\parshape`,
|
||||
|
||||
+26
-18
@@ -61,19 +61,23 @@ class execution are still ahead.
|
||||
|
||||
M1 reads real CMR10 TFM metrics at runtime (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 reproduces
|
||||
TeX's paragraph breaker: pass 0 uses `\pretolerance` without hyphenation,
|
||||
pass 1 uses `\tolerance`, and a third pass with `\tolerance=10000` runs only
|
||||
when `\emergencystretch` is positive. With zero emergencystretch TeX gives up
|
||||
and fills each line to the first break at or past the measure, which leaves
|
||||
the familiar overfull boxes; the same fallback runs here. Justification 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.
|
||||
parameters), hyphenates with TeX Live's `hyph-en-us` patterns and exceptions
|
||||
(`\lefthyphenmin=2`, `\righthyphenmin=3`), and reproduces TeX's paragraph
|
||||
breaker: pass 0 uses `\pretolerance` without hyphenation, pass 1 uses
|
||||
`\tolerance`, and a third pass with `\tolerance=10000` runs only when
|
||||
`\emergencystretch` is positive. With zero emergencystretch TeX's final pass
|
||||
keeps `\tolerance` and forces overfull breaks through artificial demerits;
|
||||
the fallback here mirrors that choice by taking the longest prefix within
|
||||
tolerance and otherwise the first prefix that overflows. Justification
|
||||
stretches normal glue past its nominal stretch (badness simply exceeds 100)
|
||||
and clamps shrink at the declared limit, so overfull lines stay overfull
|
||||
exactly as in TeX.
|
||||
|
||||
`tests/oracle.rs` checks the 150pt and 180pt fixtures against pdfLaTeX: both
|
||||
match the oracle word for word and within 0.05pt horizontally. The 150pt
|
||||
fixture exercises the overfull fallback, the 180pt fixture the ordinary
|
||||
pass-1 solution. `route_d_multiline_bands_track_pdftex` rasterizes the same
|
||||
`tests/oracle.rs` compares a matrix of measures (100, 120, 150, 180, 200 and
|
||||
240pt) against pdfLaTeX: every fixture matches word for word and within 0.05pt
|
||||
horizontally. The narrow measures exercise hyphenated and overfull breaks,
|
||||
150pt the final-pass overfull box, and 180-240pt ordinary tolerance
|
||||
solutions. `route_d_multiline_bands_track_pdftex` rasterizes the same
|
||||
paragraph in both engines and compares ink bands, covering baseline placement
|
||||
and justification.
|
||||
|
||||
@@ -92,7 +96,7 @@ and justification.
|
||||
| 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, hyphenation, TeX demerits and tolerance passes, pdfLaTeX oracles at 150pt and 180pt; explicit tolerance registers 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, pdfLaTeX oracle matrix 100-240pt; explicit tolerance registers, `\looseness`, `\parshape` and more fixtures 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 |
|
||||
| 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 |
|
||||
@@ -103,10 +107,14 @@ and justification.
|
||||
## Current limits
|
||||
|
||||
- The M1 paragraph builder parses CMR10 TFM metrics (widths, height/depth,
|
||||
italic correction, kern pairs, ligatures), applies plain-TeX hyphenation and
|
||||
runs TeX's tolerance passes with demerits. Remaining gaps are explicit
|
||||
`\tolerance`/`\pretolerance` overrides, hyphenated-break penalties and
|
||||
`\parfillskip` variants.
|
||||
italic correction, kern pairs, ligatures), applies TeX Live's en-US
|
||||
hyphenation patterns and runs TeX's tolerance passes with demerits. Remaining
|
||||
gaps are explicit `\tolerance`/`\pretolerance` overrides (the defaults and
|
||||
`\emergencystretch` are modelled), `\hyphenpenalty`/`\exhyphenpenalty`,
|
||||
`\looseness`, `\parshape` and `\parfillskip` variants.
|
||||
|
||||
The pdfLaTeX oracle pins six measures (100-240pt) and all match; no oracle
|
||||
fixture is ignored.
|
||||
|
||||
The pdfLaTeX oracle currently pins two measures (150pt and 180pt). The earlier
|
||||
multi-width table was produced by the old single-cost breaker and is no longer
|
||||
@@ -237,7 +245,7 @@ for a later overlaid slash.
|
||||
| Milestone | State | Notes |
|
||||
| --- | --- | --- |
|
||||
| M0 checkpoint engine | done | page list, page hashes, snapshot/restore, edit replay |
|
||||
| M1 horizontal/paragraphs | partial | boxes/glue/penalties, CMR10 metrics, hyphenation, TeX demerits and tolerance passes, pdfTeX 150pt/180pt oracles |
|
||||
| M1 horizontal/paragraphs | partial | boxes/glue/penalties, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, pdfTeX oracle matrix 100-240pt |
|
||||
| M2 vertical/page builder | partial | vsize, topskip, insertions, marks, Rust output hook, top/bottom floats, float-page/text fractions, rules, vskip, penalties; interpreted `\output` absent |
|
||||
| M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter |
|
||||
| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping |
|
||||
|
||||
Reference in new issue
Block a user