Skip to content

a break position counts LETTERS, and half of Points counted bytes - #8

Merged
tannevaled merged 1 commit into
mainfrom
points-counts-letters
Nov 13, 2026
Merged

tannevaled merged 1 commit into
mainfrom
points-counts-letters

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

a break position counts LETTERS, and half of Points counted bytes

Points built its value array over the augmented word by byte index
(n := len(w), w[i:j], val[i+k]) and read it back by rune index
(L := len([]rune(word)), and val[t+1] for a break after t letters).

Those agree for exactly as long as every letter is one byte — which is every
English word and no French, German, Czech, Polish or Vietnamese one.

⛔ And nothing failed loudly

val[t+1] simply read a different slot, so an accented word broke in the wrong
place or not at all. The caller sees a plausible number and has no way to know
it is the wrong one.

Measured, with its control

Two words of the SAME letter structure, differing only in whether one letter
takes two bytes, under the single pattern a1b:

Points("xaby") = [2]      the control: all ASCII, one byte per letter
Points("éaby") = [3]      one letter along — the same word, shifted

and a word that is all multi-byte letters, where the mismatch is largest:

Points("ééèè") = [3]      want [2]

⚠ The control is asserted first and fails the test outright if it does not
give [2]: a comparison against a broken control measures nothing.

The fix

Everything counts letters — the augmented word becomes a []rune, the pattern
lookup slices it by rune, and the value array is indexed the way it is read.

⚠ ASCII behaviour is unchanged, which is the thing to check rather than
assume: TestPointsFollowsLiangsRule still gives hyphenation -> [2 6], and
the existing suite passes untouched. For a one-byte-per-letter word the two
indexings were already the same number.

Found during a bibliography pass over tex.web §§891–966 from a consumer
(go-tex/engine), which reads this package for every paragraph it sets.

🤖 Generated with Claude Code

Points built its value array over the augmented word by BYTE index
(n := len(w), w[i:j], val[i+k]) and read it back by RUNE index
(L := len([]rune(word)), and val[t+1] for a break after t letters).

Those agree for exactly as long as every letter is one byte — which is every
English word and no French, German, Czech, Polish or Vietnamese one.

⛔ AND NOTHING FAILED LOUDLY. val[t+1] simply read a different slot, so an
accented word broke in the wrong place or not at all. The caller sees a
plausible number and has no way to know it is the wrong one.

MEASURED, WITH ITS CONTROL

Two words of the SAME letter structure, differing only in whether one letter
takes two bytes, under the single pattern a1b:

	Points("xaby") = [2]      the control: all ASCII, one byte per letter
	Points("éaby") = [3]      one letter along — the same word, shifted

and a word that is all multi-byte letters, where the mismatch is largest:

	Points("ééèè") = [3]      want [2]

The control is asserted FIRST and fails the test outright if it does not give
[2], because a comparison against a broken control measures nothing.

THE FIX

Everything counts letters: the augmented word becomes a []rune, the pattern
lookup slices it by rune, and the value array is indexed the same way it is
read.

⚠ ASCII BEHAVIOUR IS UNCHANGED, which is the thing to check rather than to
assume: TestPointsFollowsLiangsRule still gives hyphenation -> [2 6], and the
whole existing suite passes untouched. For a one-byte-per-letter word the two
indexings were already the same number.

Found during a bibliography pass over tex.web §§891-966 from a consumer
(go-tex/engine), which reads this package for every paragraph it sets.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit d9d3c0c into main Nov 13, 2026
11 checks passed
@tannevaled
tannevaled deleted the points-counts-letters branch November 13, 2026 13:49
tannevaled added a commit to go-tex/engine that referenced this pull request Nov 13, 2026
…ghout (#774)

go-typeset/hyphenation v1.0.1 (its #8) fixes an indexing mismatch: the value
array was built over the augmented word by BYTE index and read back by RUNE
index. The two agree for exactly as long as every letter is one byte — every
English word and no French, German, Czech, Polish or Vietnamese one.

⛔ SO EVERY TEST HERE WENT ON PASSING while a whole class of input was set
wrong. Nothing in this engine's suite used a multi-byte letter in a word long
enough to hyphenate.

MEASURED against tectonic 0.17.0, one paragraph at \hsize=72pt, the SAME
English patterns on both sides (no babel, no language option):

	reference   Une présenta-/tion … représentations élé-/mentaires …
	v1.0.0      Une présent-/ation … des représentat-/ions éléme-/ntaires …
	v1.0.1      Une présenta-/tion … représentations élémentaires …

`éléme-ntaires` is the shape of the defect: a break between the m and the n of
a syllable, where no pattern in hyphen.tex can put one, and displaced by
exactly as many positions as the word has multi-byte letters before it.
`présenta-tion` is the one word both engines break in the same place, and
v1.0.1 matches the reference there.

THE GATE, AND ITS MUTATION

accenthyphen_test.go asserts the reference's break and the ABSENCE of the four
offset breaks. Its mutation is the dependency itself — pinning go.mod back to
v1.0.0 reddens it, which is how the two outputs above were produced, from two
builds of this engine differing only in that line:

	accenthyphen_test.go:48: `présentation` is not broken where the reference
	  breaks it (`présenta-` / `tion`)
	accenthyphen_test.go:57: the byte/rune offset is back: "éléme-" is in the page

⚠ WHAT THIS DOES NOT CLAIM. The corpus is English-language physics, so the
papers that score here barely exercise it; this is not expected to move the
fidelity number and no claim is made that it does. It is a defect fixed on its
own witness, in a class the metric does not reach — the same shape as #716.

Refs go-typeset/hyphenation#8.

Co-authored-by: Claude Opus 5 <[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