Skip to content

The hyphenation pass against tex.web §§891-966: nine divergences, starting with a paragraph's first word #765

Open

Description

@tannevaled

A read of the hyphenation pass against tex.web §§891-966. Nine divergences, each with its tex.web place and the Go line. Hyphenation decides where lines break, and lines decide pages, so this is on the same channel the corpus deviation is measured through.

⚠ Provenance. This came out of a bibliography pass. I verified (1) myself — hyphenation.go:136-150 starts a word at any charNode with no test of what precedes it. The other eight I am relaying with their citations rather than having re-derived each; treat them as leads with addresses.

⚠ Where the code is. go-typeset/hyphenation is 97 lines and is Liang's algorithm alone. Everything TeX-specific — word gathering, \patterns, \language, the min-lengths — lives in this repository's own hyphenation.go. Eight of the nine below are therefore ours to fix, not upstream's.

(1) The glue precondition — verified

§891 and §894 are explicit: hyphenation is attempted only where cur_p points to a glue node, and §899 lists what may follow a word (glue, penalty, ins, adjust, mark, whatsit, explicit kern). hyphenateList (hyphenation.go:129-191) gathers every maximal run of charNode and hyphenates it, whatever sits on either side.

Two consequences, both of which change line counts:

  • TeX never hyphenates a paragraph's first word, because it is preceded by the \parindent box and not by glue. We always do.
  • TeX never hyphenates next to a box, math, or a user discretionary (§891:17476). We do.

(2) \hyphenchar does not exist

§896 is if hyf_char<0 then goto done1 — a font whose \hyphenchar is −1 is not hyphenated at all. There is no such primitive here; only an unused defaulthyphenchar in texparams.go, and the hyphen is hard-coded as pre: "-" (hyphenation.go:185).

plain.tex's \hyphenchar\tentt=-1 is therefore inexpressible, so \texttt and code are hyphenated where TeX refuses. That is visible damage in a corpus full of listings and identifiers.

(3) \lccode does not classify letters

§891:17480-17483 and §897:17601 (if lc_code(c)=0 then goto done3) make \lccode the definition of "letter". The library lowercases with strings.ToLower and the engine treats any charNode as a letter (hyphenation.go:147-150), so punctuation, digits and apostrophes stay inside the word and change the pattern match.

(4) No exception list

§925-§933, consulted before patterns (§923:18147). \hyphenation{...} is stubbed out entirely (amssubstrate.go:505-506: \def\hyphenation#1{}). A document that corrects a word's break points is silently ignored.

(5) \uchyph has no concept

§236 and §896:17585: \uchyph=0 forbids hyphenating a word that begins with a capital. We always hyphenate.

(6) The 63-letter rule is inverted

§897:17602 is if hn=63 then goto done3 — TeX truncates at 63 letters and still hyphenates the first 63. We skip the word entirely (hyphenation.go:174).

⚠ And capacity_test.go:82-85 pins that behaviour citing "tex.web §891". The line it quotes (if l > max_hyphenatable_length) is not in tex.web — it is a LuaTeX/XeTeX spelling. TeX's own limit is §894:17548, if l_hyf+r_hyf>63.

(7) Points mixes byte and rune indices

hyphenation.go:56-66 indexes w[i:j] and val[i+k] by byte while L and the result are by rune (71-77). Any accented letter — every French, German, Czech or Polish word in the bibliography — yields wrong break positions, silently. This one is in the library.

(8) \language mapping

§934:18261-18263 maps \language ≤ 0 or > 255 to 0; we return nil for any non-zero (hyphenation.go:63), so a document setting \language to anything we do not know loses hyphenation rather than falling back to the default.

(9) No reconstitution

§§904-918 rebuild ligatures and kerns around an inserted hyphen, with hyf_bchar, the init_list punctuation context and the exponential-growth guard of §918. We insert a bare discNode between charNodes and keep the pre-hyphen ligatures — §904's "difficult" case, unhandled.

PRESENT, so that this reads as a census and not a complaint

Liang matching with max-wins and odd-means-break (hyphenation.go:52-79 ≡ §919, §923); \lefthyphenmin/\righthyphenmin as the exact l_hyf … hn-r_hyf range (:73 ≡ §902); second-pass-only gating (paragraph.go:201-209 ≡ §891, §894); \patterns (:77-109 ≡ §951); \language selection (:60-73).

⚠ Not claimed

That any of these accounts for a particular part of the corpus deviation. Each has an address; none has a measured cost. (1) is the one I would measure first, because "never hyphenate the first word of a paragraph" is a rule that fires on every paragraph of every document and is cheap to implement.

Possibly related and worth re-measuring now: #381 ("our lines hold 69 characters where the reference holds 66, with the font and the measure controlled"). The font is no longer controlled the way it was — #764 replaced one scaled face with the reference's eight optical sizes — so that count may have moved for a reason unrelated to hyphenation.

Refs #754.

🤖 Generated with Claude Code

Prior art: priorart "hyphenation glue precondition hyphenchar lccode uchyph exception list" at 2026-11-12 20:51 CET reported prior art; checked: 460 entries. #754 (open) is my earlier audit of the delegated layers and names no hyphenation rule. #381 (open, lines hold 69 chars vs 66) is adjacent and flagged in the body as worth re-measuring after #764. #583/#441 are line-breaker and interline-glue issues, not the hyphenation pass. None states any of the nine.

Activity

  1. tannevaled commented on Nov 15, 2026

    @tannevaled
    ContributorAuthor

    Item (3) has a witness now, with the reference controlled: a trailing period creates an extra hyphenation point that \righthyphenmin would forbid, and we take it where the reference declines.

    I arrived at this from the other end — looking for a \sloppy witness for #768 whose badness is not saturated — and priorart landed me here, so this is a measurement for an item already filed rather than a new finding.

    The extra point

    Asked of the hyphenator this engine actually uses, with \lefthyphenmin=2 and \righthyphenmin=3:

    "completely"    points=[3]      com-pletely
    "completely."   points=[3 8]    com-plete-ly.
    "paragraph"     points=[4]      para-graph
    "paragraph."    points=[4]      para-graph.
    

    ⛔ complete-ly is not a legal break and the hyphenator knows it — without the period it offers only com-pletely, because two letters after the hyphen is under \righthyphenmin. With the period the fragment counts three characters, the limit is satisfied arithmetically, and the break appears. paragraph. is the control: a word whose points do not sit near the end is unaffected, so this is the min-affix arithmetic and not the pattern match.

    And the period really is inside the word the engine passes. Read off the node list for \hbox{ completely. }:

    list: _completely._
    

    one run of charNodes, period included — which is hyphenation.go:147-150 treating any charNode as a letter, exactly as this issue's item (3) says. §891:17480-17483 is the rule it departs from: "Each character c is now classified as either a nonletter (if lc_code(c)=0)… TeX looks ahead for as many consecutive letters as possible", with §897:17601's if lc_code(c)=0 then goto done3 ending the word at the period.

    What it costs, against tectonic 0.17.0

    Typographical incomprehensibilities overwhelm every paragraph completely. at \hsize=100pt, \parindent=0pt:

    lines hyphens overfull
    reference 3 incompre- 2 — 8.68pt and 20.93pt
    this engine 3 incompre-, complete-ly 3 — worst 13.14pt

    So the illegal break is not cosmetic: the reference accepts a 20.93pt overfull line rather than take it, and we take it and come out with a third bad box. ⚠ Note the direction — our worst overflow is smaller. A metric that rewards narrower overflow would score this engine better for making a break TeX forbids.

    ⭐ And the control, which is the half worth having

    The same paragraph at \hsize=120pt, where no illegal point arises:

    reference     Typographical incomprehen- / sibilities overwhelm every para- / graph completely.
    this engine   Typographical incomprehen- / sibilities overwhelm every para- / graph completely.
    

    Three lines, the same two hyphens, and both engines report the same two overfull boxes with the same worst overflow, 14.63pt — to the hundredth of a point. I nearly published that agreement as a divergence, having read our overfull=2 without first reading the reference's log.

    So in this regime the two agree exactly, and the defect shows only where a word with punctuation sits near a break. That is a far smaller population than "every hyphenated word", which is worth knowing before anyone prices item (3).

    ⚠ Not claimed: that this is the whole of item (3). Digits and apostrophes are in its text too and I measured neither; and the pattern-match half — a period changing which patterns apply — is not exercised by this witness, where the arithmetic alone explains the extra point.

    🤖 Generated with Claude Code

  2. tannevaled commented on Nov 15, 2026

    @tannevaled
    ContributorAuthor

    Item (7) is already fixed in the version this engine requires. Measured, not read off a comment.

    The item says Points mixes byte and rune indices, that any accented letter yields wrong break positions silently, and that it is in the library. go-typeset/hyphenation v1.0.1 — which go.mod requires today — works in runes throughout (w := []rune("." + strings.ToLower(word) + ".")), and its own comment cites the old symptom: Points("éaby") returning [3] where "xaby" returned [2].

    A measurement printed in a comment is not a check, so I re-ran that witness against v1.0.1:

    "xaby"   points=[2] runes=4 bytes=4
    "éaby"   points=[2] runes=4 bytes=5
    

    Identical, as they must be — a break position is a count of LETTERS — despite four bytes against five. The defect is gone.

    ⚠ And my first attempt measured the wrong thing, which is worth a line because it would mislead anyone repeating this: with the default mins (left 2, right 3) a four-letter word cannot break at all, 2+3 being more than 4, so both words answered [] and the indexing was invisible. The probe needs SetMins(1, 1) before it measures anything.

    So (7) can be struck from the nine. Nothing else in the census is touched by this — I measured item (3) separately (the comment above) and none of the other seven.

    🤖 Generated with Claude Code

  3. tannevaled commented on Nov 15, 2026

    @tannevaled
    ContributorAuthor

    Three more of the nine, read against main at b20d14a: (4) is fixed, (5) stands, and (6) stands with a test pinning it — citing the reference for the behaviour the reference does not have.

    (4) No exception list — fixed, strike it

    The item says \hyphenation{…} is \def\hyphenation#1{} in amssubstrate.go. On main it is a real primitive:

    primitives.go:1850   e.prim("hyphenation", func(e *Engine) { e.doHyphenation() })
    

    with hyphexception_test.go beside it, whose own comment refers back to the old stub. #775 did it. The only remaining mentions of the stub are in that test's prose.

    (5) \uchyph has no concept — stands

    One occurrence in the whole tree:

    texparams.go:29   "uchyph": 1, "time": 0, "day": 0, …
    

    Accepted as a named count with TeX's default, and read by nothing. So \uchyph=0 is silently ignored, as the item says. (For scale: \uchyph appeared in 9 of 2935 corpus papers, 0.3%, in the census on #769 — the smallest population of the five commands measured there.)

    (6) The 63-letter rule — stands, and a test pins it

    Confirmed against the source, and the item's reading is right:

    17602:    if hn=63 then goto done3;
    

    done3 is the EXIT of the letter-collecting loop, not an abandonment of the word: the hn letters already collected are what gets hyphenated. §891:17491-17492 says it in prose — "however, n must be less than 64, so a character that would otherwise be c_64 is effectively not a letter" — a nonletter ends the word, and the first 63 letters are hyphenated.

    ⛔ And the new part: a test asserts our behaviour and cites the reference for it. capacity_test.go:91-94:

    long := strings.Repeat("hyphenation", 10) // 110 letters, over it
    if got := count(long); got != 0 {
        t.Errorf("a %d-letter word got %d hyphenation points, want 0 (tex.web §891)", len(long), got)
    }

    want 0 (tex.web §891) — and §891 says the opposite. The citation makes the divergence look verified, which is worse than an uncited assertion: the next reader has no reason to check it. It is the shape of a-test-that-pinned-our-own-divergence, with a reference attached.

    ⚠ Said fairly, because that test has a real job: it lives in capacity_test.go among the expansion-bomb guards, and bounding the work a pathological word can cause is correct. The point is that TeX's own behaviour is equally bounded — 63 letters, then stop collecting — so the ceiling can be kept exactly as it is while matching the reference. What has to change is the branch at the ceiling and that test's expectation, not the ceiling.

    Where that leaves the nine

    (1) glue precondition verified in the issue, and #766 merged
    (2) \hyphenchar not measured by me
    (3) \lccode stands — witness in my comment above (completely. → an extra illegal point)
    (4) exception list fixed by #775 — strike
    (5) \uchyph stands — accepted, never read
    (6) 63 letters stands — plus a test citing §891 for the wrong behaviour
    (7) byte/rune fixed in hyphenation v1.0.1 — strike, measured in my comment above
    (8) \language not measured by me
    (9) reconstitution not measured by me

    ⚠ Not claimed: anything about (2), (8) or (9). I read the source for the four I report and ran the two that have witnesses; the rest are the issue's own text, unverified by me.

    🤖 Generated with Claude Code

  4. tannevaled commented on Nov 15, 2026

    @tannevaled
    ContributorAuthor

    (2) is fixed as well, and (8) is narrower than filed — the divergence is the OUT-OF-RANGE mapping, not \language in general. That leaves (9) as the only one of the nine I have not measured.

    (2) \hyphenchar does not exist — fixed, strike it

    It does. \hyphenchar\font is assignable since #767 and readable now (fontquery_test.go:117-127 reads \the\hyphenchar\font as 45 and as −1 after assignment), e.hyphenCharOf exists, and hyphenchar_test.go pins the rule the item cites — a font whose \hyphenchar is negative is never hyphenated, §896 — with tulmtt.fd:51's \hyphenchar\font\m@ne for the typewriter family as its witness.

    (8) \language mapping — stands, but say which half

    Measured, four values, one engine each:

    \language=0    -> a hyphenator offering paragraph→para-graph
    \language=-1   -> nil (no hyphenation at all)
    \language=300  -> nil (no hyphenation at all)
    \language=5    -> nil (no hyphenation at all)
    

    against tex.web:18261-18263:

    @d set_cur_lang==if language<=0 then cur_lang:=0
      else if language>255 then cur_lang:=0
      else cur_lang:=language
    

    ⭐ So the defect is the out-of-range cases, and only those. \language=-1 and \language=300 are mapped by TeX to 0 — English — and we hyphenate them not at all. That is a two-line fix at hyphenation.go:98: clamp before comparing.

    ⚠ And \language=5 is NOT the same thing, which the item's wording runs together. There TeX would use language 5's patterns, which this engine does not embed; returning nil is then a deliberate choice and arguably the right one, since hyphenating French with English patterns breaks words in places no reader would accept. Worth keeping as a documented choice rather than fixing into a wrong answer — which is why I am reporting (8) as half a defect rather than one.

    Where the nine stand now

    (1) glue precondition verified in the issue; #766 merged
    (2) \hyphenchar fixed by #767 — strike
    (3) \lccode stands — witness: completely. gains a point \righthyphenmin forbids
    (4) exception list fixed by #775 — strike
    (5) \uchyph stands — accepted, read by nothing
    (6) 63 letters stands — and capacity_test.go:91-94 pins it citing §891 for the opposite
    (7) byte/rune fixed in hyphenation v1.0.1 — strike
    (8) \language half — out-of-range should fall back to 0; in-range is a choice
    (9) reconstitution not measured by me

    Four of the nine were already closed by work that landed after the census (#766, #767, #775, and hyphenation v1.0.1), which is the main thing this adds: the issue reads as nine open divergences and four of them are done.

    ⚠ Not claimed: anything about (9). §§904-918's ligature reconstitution is the largest of the nine and I did not look at it.

    🤖 Generated with Claude Code

  5. tannevaled commented on Nov 15, 2026

    @tannevaled
    ContributorAuthor

    Item (9)'s root cause sits one step UPSTREAM of reconstitution, and it is much larger than "§904's difficult case is unhandled": a ligature is formed before the paragraph is broken, so the word this engine hyphenates is not the word the author wrote. Nineteen of twenty ordinary technical words are hyphenated wrongly or not at all.

    Found doing the bibliography the issue asks for, reading §§904-918 as filed.

    What the reference does

    tex.web:17478-17479, describing what the hyphenation pass is handed:

    The ligature nodes among $p_1\ldots p_{m-1}$ are effectively expanded into the original non-ligature characters; the kern nodes and whatsits are ignored.

    So TeX hyphenates letters, having undone the ligatures, and only then does reconstitute (:17747-17758) rebuild them around the break it chose — setting hyphen_passed for exactly the break whose translation "would have been different if $x_{k+1}$ had been hchar" (:17769-17772).

    What this engine does

    The ligature is already one charNode when the paragraph pass runs:

    \setbox0=\hbox{ shelfful }   ->  _shelfful_        8 letters, 7 runes
    \setbox0=\hbox{ baffling }   ->  _baffling_         8 letters, 6 runes
    

    and the hyphenator is then asked about that. Twenty words an arXiv paper cannot avoid, each carrying fi, fl, ff, ffi or ffl, comparing the points for the word as written against the word as held:

    difficult       difficult        plain=[3 5]      held=[]        HYPHENATION LOST
    final           final           plain=[2]        held=[]        HYPHENATION LOST
    finite          finite          plain=[2]        held=[]        HYPHENATION LOST
    profile         profile         plain=[3]        held=[]        HYPHENATION LOST
    overflow        overflow        plain=[4]        held=[]        HYPHENATION LOST
    offline         offline          plain=[2]        held=[]        HYPHENATION LOST
    classification  classification  plain=[4 6 8 10] held=[4 7 9]   BREAKS DIFFER
    identification  identification  plain=[4 6 8 10] held=[4 7 9]   BREAKS DIFFER
    different       different       plain=[3 6]      held=[5]       BREAKS DIFFER
    definition      definition      plain=[3 4 6]    held=[3 5]     BREAKS DIFFER
    configuration   configuration   plain=[3 6 7 9]  held=[6 8]     BREAKS DIFFER
    reflection      reflection      plain=[2 6]      held=[5]       BREAKS DIFFER
    coefficient     coefficient      plain=[2 4 6]    held=[2 4]     BREAKS DIFFER
    … 6 more differing
    
    of 20 words: 6 lost hyphenation, 13 moved a break, 1 unaffected
    

    The one "unaffected" is affine, which has no points either way — so it is untestable rather than correct.

    ⭐ The control, because the table above is a proxy

    Those rows compare Points(collapsed) with Points(written). Asking the engine itself, through hyphenateList, gives the same answer:

    hyphenateList(shelfful)        -> _shelfful_                  no discretionary at all
    hyphenateList(different)       -> _differ[-]ent_              where the patterns say dif-fer-ent
    hyphenateList(classification)  -> _clas[-]sifi[-]ca[-]tion_   where they say clas-si-fi-ca-tion
    

    So clas-sifi-ca-tion is what this engine sets, and dif-fer-ent is set differ-ent — one break instead of two, in a place the patterns do not name.

    ⚠ And my own instrument had the same class of bug

    The first run of that table reported "6 lost, 9 moved, 5 unaffected". Its classifier compared len(asSet) != len(w) in bytes, and "efficient" (9 bytes) against "efficient" (7 runes, 9 bytes) compares equal — so four words that had lost a break point were counted as unaffected. Corrected to compare the point lists directly, it is 6 and 13 and 1. The same byte/rune confusion as item (7), in the measuring tool this time, an hour after I measured that one fixed.

    Why this is worth more than its place in the list

    These are not edge-case words: definition, different, classification, coefficient, final, difficult are the vocabulary of the corpus. A systematically wrong hyphenation changes how much text a line holds, which is the channel #381 reads (our lines holding 69 characters where the reference holds 66) and the kind of defect #716 showed the fidelity metric is blind to.

    ⚠ Not claimed: a corpus figure. The population over the 2935 papers needs a run, and the host's 1-minute load average has been 8.9 to 133 all day, never under the ~8 threshold this repository measures under. Twenty hand-picked words are a demonstration, not a measurement of the corpus.

    ⚠ Also not claimed: that fixing it is only "expand before hyphenating". That half is small; the other half is §§904-918 — rebuilding the three lists around the chosen break — which is item (9) as filed and is not small.

    🤖 Generated with Claude Code

  6. tannevaled commented on Nov 17, 2026

    @tannevaled
    ContributorAuthor

    Where the nine stand, 2026-11-17

    Eight are closed. This census has been read as an open list of nine since it was
    filed, and tonight that nearly cost a rebuild: I opened it to pick the next item,
    took (1) — the one the body itself names as "the one I would measure first" —
    and only priorart stopped me, by printing #766 merged. The body is the thing
    a reader believes, so it is the thing that has to carry the state.

    # divergence where it landed
    (1) the glue precondition — a paragraph's first word #766 merged
    (2) \hyphenchar does not exist #767 merged (and #770 for reading it back)
    (3) \lccode does not classify letters #824 merged
    (4) no exception list #809 merged
    (5) \uchyph has no concept #828, open tonight
    (6) the 63-letter rule is inverted merged; hyphenation.go:404 truncates, and the citation that was not in tex.web is gone
    (7) Points mixes byte and rune indices go-typeset/hyphenation#8 merged — the one that was upstream
    (8) \language mapping merged; hyphenation.go:91-110
    (9) no reconstitution (§§904-918) ⚠ open, and the only one left

    What remains

    (9) alone. It is also the largest by a long way: reconstitute (§§904-918)
    rebuilds ligatures and kerns around each inserted hyphen, with hyf_bchar, the
    init_list punctuation context, and §918's guard against exponential growth. We
    insert a bare discNode between charNodes and keep the pre-hyphen ligatures —
    §904's "difficult" case, unhandled.

    ⚠ Its cost is unmeasured, and I am not asserting it is small. It fires only
    where a hyphen lands inside a ligature or a kern pair, which in English is rarer
    than the other eight but not negligible (off-ice, shelf-ful). The witness it
    wants is a word list crossed with break positions, not a page.

    ⚠ What this comment is not

    It is not a claim that the hyphenation pass now matches tex.web. Eight items
    from one read of §§891-966 are closed; a second read would find more, and two
    things this very body already flags are still open and unquantified: #381 (69
    characters to the reference's 66) and the \lccode-lowered letters that
    lcCodeOf's own header says are not fed to the hyphenator — the library still
    lowercases with strings.ToLower, so a document that remaps \lccode to make
    one character hyphenate as another is still unobeyed.

    Refs #828, Refs #381, Refs #766, Refs #767, Refs #770, Refs #809, Refs #824.
    Refs go-typeset/hyphenation#8.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions