Skip to content

render-pipeline: a hyphenated word's fragments are measured in their own units, not the whole word's - #421

Merged
GoKubar merged 1 commit into
mainfrom
lane/nixos-offpage-glyphs/hyphen-fragment-units
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
lane/nixos-offpage-glyphs/hyphen-fragment-units

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

render-pipeline: a hyphenated word's fragments are measured in their own units, not the whole word's

typeset::word_items cuts a hyphenatable word at its Liang points, shapes
each fragment on its own, and keeps the font kern the whole-word shaping had
across the point as an explicit kern after the discretionary, so an unbroken
word keeps exactly its width (TeX's reconstitution, §903-918). That kern is
whole minus parts:

let upem = shaped.units_per_em as f64;          // the WHOLE word's
let pt = |units: i64| size * units as f64 / upem;
let width = |t: &str| shaper.shape(&face, t).width_units;
...
let kern = pt(width(whole) - width(head) - width(tail));

but width_units is only meaningful next to the units_per_em of the
shaping that produced it, and shape picks the shaping per string:
shape_tfm runs the TFM ligature/kern program and reports 2^20 units per em,
and it bails out to shape_otf — the face's own units per em, 1000 for Latin
Modern — the moment one character of the string has no T1 slot. Two fragments
of the same word can therefore come back in units that differ by a factor of
1048.

fixtures/real-world/unicode-accents has ellipsis\dots;, which reaches the
shaper as ellipsis…;. U+2026 has no T1 slot, so the whole word and the tail
sis…; were measured by the font program and the head lip by the TFM
program, and all three were then divided by the whole word's 1000:

HYPH word="ellipsis…;" upem=1000 size=10.95
  full="lipsis…;"/3126u/upem1000
  pre="lip"/1158757u/upem1048576
  post="sis…;"/2014u/upem1000
  kern=-12676.21275

set_line moves the line's x cursor by every kern, so the last five glyphs
of ellipsis and every word after them on that line were painted at
x = -12321.25 bp: 12300 points off the left edge of a 612 bp page, where a
reader of that document sees the \dots material and the rest of the line
simply vanish. It is byte-identical on every run.

The fix measures in points, the one scale the two shapings share, and keeps
the exact integer subtraction for the ordinary case where all three
measurements do agree on their units, so no same-units word moves by a
rounding bit. The pre-break hyphen's own advance had the same defect (a head
that is pure T1 under a word that is not), and is converted the same way.

This is not a \dots bug and not a \dots boundary. Any character with no
T1 slot does it, in any hyphenatable word, whenever one fragment is pure T1;
the size of the jump is the head fragment's TFM width, so it differs per word
(typesetting\dots gave -13954 bp, transliteration\dots -5682 bp).
Measured, before -> after, on the paragraph that caught it:

\dots, \ldots, \textellipsis after a word   -12628.85 ->  0.08 bp
\dag after a word                          -12628.85 ->  0.08
Greek / Cyrillic / CJK after a word        -12628.85 ->  0.00
typesetting\dots                           -13953.69 ->  0.07
transliteration\dots                        -5681.61 ->  0.03
\dots after a space, three literal periods,
`é`, all-T1 words (controls)                    0.00 ->  0.00
\cdots \vdots \ddots \dotsc \dotsb \dotsm
in math, \dots in math (controls)               0.00 ->  0.00

Corpus effect, both sides measured with PR #415's rank.py (geometry only,
no raster stage; #415 is still open, so these are not comparable with numbers
taken from main's grouping). On unicode-accents page 1 the six aligned
words after the discretionary go from dx -12635.94 / -12640.53 bp to -7.01 /
-11.60, which removes the corpus's top-ranked item; the page's worst
remaining dx is the pre-existing -39.86 bp CJK line. Fixture accuracy
82.28% -> 82.39% dx (one more word aligns); corpus-wide dx 85.59, dy 75.08,
both 69.02 over 15040 aligned words, unchanged to two decimals either side —
six words out of fifteen thousand is not a percentage, it is a visible hole
in one page.

The residual -7.01 bp is a second, independent defect that this change does
not touch and does not claim to: \dots reaches the pipeline as the single
character U+2026 and is painted as one 7.31 bp glyph, where pdflatex expands
\textellipsis to .\kern\fontdimen3\font three times and sets 14.3 bp of
dots (crates/tex-text-encoding/src/typeset.rs:908 already implements that
expansion; the adapter does not use it). Fixing that would also keep such
words on the TFM path, but it is a different cause and belongs in its own PR.

Gates: cargo test --release --no-fail-fast on crates/render-pipeline,
60 test binaries, 0 failed (one new, hyphenated_fragment_units, which fails
on today's main with dots: glyph 5 of run "ellipsis…;" is painted at x = -12321.25 bp, off a 612.00 bp page); amsmath 59/59 within 0.5 bp,
tabular 106/106 (words 0.5 bp, rules 0.1 bp), HW1 and HW2 3 pages / 0 errors
/ 0 font-FAILURE diagnostics.

No vendor file is touched and no re-pin is required.

Implementation-Agent: Claude Opus 5 (lane nixos-offpage-glyphs, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)

…own units, not the whole word's

`typeset::word_items` cuts a hyphenatable word at its Liang points, shapes
each fragment on its own, and keeps the font kern the whole-word shaping had
across the point as an explicit kern after the discretionary, so an unbroken
word keeps exactly its width (TeX's reconstitution, §903-918). That kern is
whole minus parts:

    let upem = shaped.units_per_em as f64;          // the WHOLE word's
    let pt = |units: i64| size * units as f64 / upem;
    let width = |t: &str| shaper.shape(&face, t).width_units;
    ...
    let kern = pt(width(whole) - width(head) - width(tail));

but `width_units` is only meaningful next to the `units_per_em` of the
shaping that produced it, and `shape` picks the shaping per string:
`shape_tfm` runs the TFM ligature/kern program and reports 2^20 units per em,
and it bails out to `shape_otf` — the face's own units per em, 1000 for Latin
Modern — the moment one character of the string has no T1 slot. Two fragments
of the same word can therefore come back in units that differ by a factor of
1048.

`fixtures/real-world/unicode-accents` has `ellipsis\dots;`, which reaches the
shaper as `ellipsis…;`. U+2026 has no T1 slot, so the whole word and the tail
`sis…;` were measured by the font program and the head `lip` by the TFM
program, and all three were then divided by the whole word's 1000:

    HYPH word="ellipsis…;" upem=1000 size=10.95
      full="lipsis…;"/3126u/upem1000
      pre="lip"/1158757u/upem1048576
      post="sis…;"/2014u/upem1000
      kern=-12676.21275

`set_line` moves the line's x cursor by every kern, so the last five glyphs
of `ellipsis` and every word after them on that line were painted at
x = -12321.25 bp: 12300 points off the left edge of a 612 bp page, where a
reader of that document sees the `\dots` material and the rest of the line
simply vanish. It is byte-identical on every run.

The fix measures in points, the one scale the two shapings share, and keeps
the exact integer subtraction for the ordinary case where all three
measurements do agree on their units, so no same-units word moves by a
rounding bit. The pre-break hyphen's own advance had the same defect (a head
that is pure T1 under a word that is not), and is converted the same way.

This is not a `\dots` bug and not a `\dots` boundary. Any character with no
T1 slot does it, in any hyphenatable word, whenever one fragment is pure T1;
the size of the jump is the head fragment's TFM width, so it differs per word
(`typesetting\dots` gave -13954 bp, `transliteration\dots` -5682 bp).
Measured, before -> after, on the paragraph that caught it:

    \dots, \ldots, \textellipsis after a word   -12628.85 ->  0.08 bp
    \dag after a word                          -12628.85 ->  0.08
    Greek / Cyrillic / CJK after a word        -12628.85 ->  0.00
    typesetting\dots                           -13953.69 ->  0.07
    transliteration\dots                        -5681.61 ->  0.03
    \dots after a space, three literal periods,
    `é`, all-T1 words (controls)                    0.00 ->  0.00
    \cdots \vdots \ddots \dotsc \dotsb \dotsm
    in math, \dots in math (controls)               0.00 ->  0.00

Corpus effect, both sides measured with PR #415's `rank.py` (geometry only,
no raster stage; #415 is still open, so these are not comparable with numbers
taken from `main`'s grouping). On `unicode-accents` page 1 the six aligned
words after the discretionary go from dx -12635.94 / -12640.53 bp to -7.01 /
-11.60, which removes the corpus's top-ranked item; the page's worst
remaining dx is the pre-existing -39.86 bp CJK line. Fixture accuracy
82.28% -> 82.39% dx (one more word aligns); corpus-wide dx 85.59, dy 75.08,
both 69.02 over 15040 aligned words, unchanged to two decimals either side —
six words out of fifteen thousand is not a percentage, it is a visible hole
in one page.

The residual -7.01 bp is a second, independent defect that this change does
not touch and does not claim to: `\dots` reaches the pipeline as the single
character U+2026 and is painted as one 7.31 bp glyph, where pdflatex expands
`\textellipsis` to `.\kern\fontdimen3\font` three times and sets 14.3 bp of
dots (`crates/tex-text-encoding/src/typeset.rs:908` already implements that
expansion; the adapter does not use it). Fixing that would also keep such
words on the TFM path, but it is a different cause and belongs in its own PR.

Gates: `cargo test --release --no-fail-fast` on `crates/render-pipeline`,
60 test binaries, 0 failed (one new, `hyphenated_fragment_units`, which fails
on today's main with `dots: glyph 5 of run "ellipsis…;" is painted at
x = -12321.25 bp, off a 612.00 bp page`); amsmath 59/59 within 0.5 bp,
tabular 106/106 (words 0.5 bp, rules 0.1 bp), HW1 and HW2 3 pages / 0 errors
/ 0 font-FAILURE diagnostics.

No vendor file is touched and no re-pin is required.

Implementation-Agent: Claude Opus 5 (lane nixos-offpage-glyphs, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar merged commit 3691880 into main Sep 14, 2026
21 checks passed
@GoKubar
GoKubar deleted the lane/nixos-offpage-glyphs/hyphen-fragment-units branch September 14, 2026 17:53
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged #419 (⌥⇧↓/⌥⇧↑ duplicate) plus #420/#421/#415. Conflicts in
AccessibilityCommands and CommandPalette kept this lane's
Move/Delete/Join/Sort/Trim (and the current ⌘D duplicate table entry)
alongside main's EditorKeyHandling.duplicateLinesEdit and
CompletingTextView.duplicateLines(below:). Two duplicate implementations
are still present.

Ran: git fetch origin main && git merge origin/main. Conflicts resolved;
tests not run on this merge-only checkpoint.

Next: delete this lane's duplicate plan, hook, ⌘D table/palette/menu
entry; Editor menu Duplicate Line / Duplicate Line Up call main's
duplicateLines(below:); port review tests; hosted one-copy test.

Open questions: whether main's unterminated-last-line caret (same column,
which is EOF when the caret was at EOF) satisfies the review test that
wanted the copy start.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged origin/main with ort; no conflicts. Incoming pipeline tests
displaystyle_switch and hyphenated_fragment_units did not touch adapter.rs
preamble scan.

CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-prelen

compiler --lib:
test result: ok. 327 passed; 0 failed; 0 ignored
compiler --test preamble_lengths:
test result: ok. 10 passed; 0 failed; 0 ignored
compiler --test supported_latex:
test result: ok. 8 passed; 0 failed; 0 ignored
compiler full crate: all binaries green; 4 ignored
(hw2_gate, pinned_fixtures, recovery, unsupported_inventory)

render-pipeline --lib:
test result: ok. 121 passed; 0 failed; 2 ignored
(the 110 vs 119 report mismatch: 110 was 245fc95 before this branch's
adapter tests; 119 was a610cba; 121 is 119 plus the two new scan tests.
Ignored: \input preambles; \@setlength)
render-pipeline --test preamble_lengths_oracle:
test result: ok. 5 passed; 0 failed; 0 ignored
render-pipeline full crate: all binaries green; 2 further ignored
(incremental, math_symbols)

Next: push this lane branch. Lane owner splits PRs.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant