Skip to content

linebreak v1.8.0: a hyphen on the last line but one stops being free - #784

Merged
tannevaled merged 4 commits into
mainfrom
bump/linebreak-v1.6.0
Nov 15, 2026
Merged

tannevaled merged 4 commits into
mainfrom
bump/linebreak-v1.6.0

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

linebreak v1.6.0: a hyphen on the last line but one stops being free

go-typeset/linebreak v1.6.0 fixes the demerits charged at the break that ENDS a
paragraph. tex.web:17197-17198 makes that break a distinguished call:

@<Try the final line break at the end of the paragraph...@>=
begin try_break(eject_penalty,hyphenated);

so break_type is hyphenated there whatever item sits at the end, and
:16906-16908's test reduces to "was the PREVIOUS break a hyphen", with
cur_p=null selecting \finalhyphendemerits over \doublehyphendemerits.

The library had atEnd = b == n (a paragraph's last line ends at the forced
penalty, not at n) and flagged taken from the item at that break (a
\penalty-10000, never flagged), so NEITHER parameter was charged: a hyphen on
the last line but one cost nothing where TeX charges \finalhyphendemerits.

This engine already reads both parameters from the document
(paragraph.go:209-210, \doublehyphendemerits and \finalhyphendemerits through
namedInt), so the fix takes effect here with no change on this side.

⚠⚠ THE CORPUS A/B IS OWED AND HAS NOT RUN. This changes paragraph breaking
wherever a penultimate break is a hyphen and the alternative's is not, which is
a large share of justified prose, and the honest measurement is a before/after
against the reference. It has not run because the machine's 1-minute load
average is 14.6, over the ~8 threshold this repository measures under; a run
taken now would be worthless and would starve the other sessions on this host.
Deferred on purpose and said out loud. ⛔ This should not merge until it has run.

⚠ AND IT IS NEUTRAL ON #768's WITNESS, measured before this branch existed with
the fixed library replaced in: both candidate solutions there end … para- / graph., so \finalhyphendemerits is charged to both and cancels. ev-ery is
still declined, overfull stays at 2, and the lead for that issue has moved to
go-typeset/linebreak#12 item (2) — the hyphen's width is not charged to the line
that breaks at it, so that line is measured about 2.5pt short.

Refs #768, go-typeset/linebreak#12.

(#768 stays OPEN and is NOT addressed here: this is neutral on its
witness, as measured above. go-typeset/linebreak#12 stays OPEN too — its item
(3) is what v1.6.0 closed, and eight of its nine items stand.)

Co-Authored-By: Claude Opus 5 [email protected]

🤖 Generated with Claude Code

go-typeset/linebreak v1.6.0 fixes the demerits charged at the break that ENDS a
paragraph. tex.web:17197-17198 makes that break a distinguished call:

	@<Try the final line break at the end of the paragraph...@>=
	begin try_break(eject_penalty,hyphenated);

so `break_type` is hyphenated there whatever item sits at the end, and
:16906-16908's test reduces to "was the PREVIOUS break a hyphen", with
`cur_p=null` selecting \finalhyphendemerits over \doublehyphendemerits.

The library had `atEnd = b == n` (a paragraph's last line ends at the forced
penalty, not at n) and `flagged` taken from the item at that break (a
\penalty-10000, never flagged), so NEITHER parameter was charged: a hyphen on
the last line but one cost nothing where TeX charges \finalhyphendemerits.

This engine already reads both parameters from the document
(paragraph.go:209-210, \doublehyphendemerits and \finalhyphendemerits through
namedInt), so the fix takes effect here with no change on this side.

⚠⚠ THE CORPUS A/B IS OWED AND HAS NOT RUN. This changes paragraph breaking
wherever a penultimate break is a hyphen and the alternative's is not, which is
a large share of justified prose, and the honest measurement is a before/after
against the reference. It has not run because the machine's 1-minute load
average is 14.6, over the ~8 threshold this repository measures under; a run
taken now would be worthless and would starve the other sessions on this host.
Deferred on purpose and said out loud. ⛔ This should not merge until it has run.

⚠ AND IT IS NEUTRAL ON #768's WITNESS, measured before this branch existed with
the fixed library replaced in: both candidate solutions there end `… para- /
graph.`, so \finalhyphendemerits is charged to both and cancels. `ev-ery` is
still declined, overfull stays at 2, and the lead for that issue has moved to
go-typeset/linebreak#12 item (2) — the hyphen's width is not charged to the line
that breaks at it, so that line is measured about 2.5pt short.

Refs #768, go-typeset/linebreak#12.

(#768 stays OPEN and is NOT addressed here: this is neutral on its
witness, as measured above. go-typeset/linebreak#12 stays OPEN too — its item
(3) is what v1.6.0 closed, and eight of its nine items stand.)

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled and others added 2 commits November 15, 2026 14:19
…ur change

Rebased onto main (which now carries #785) and re-pointed at v1.8.0, so this
one pull request is the whole linebreak catch-up. What matters for the A/B it
owes is that the scope has NOT widened:

  v1.6.0  \finalhyphendemerits reaches the paragraph-ending break.
          CHANGES BREAKING wherever a penultimate break is a hyphen and the
          alternative's is not. This is the change this PR has owed an A/B for
          since it was opened, and it still is.

  v1.7.0  \tracingparagraphs, Params.Trace. A NO-OP here: Trace is nil unless a
          caller sets it, and nothing in this engine sets it yet (the wiring
          design, Options.Trace, is on #768 and is not in this PR).

  v1.8.0  A penalty's width is charged to the line that breaks there and to no
          other, tex.web:17128-17137. A NO-OP here TOO, and that is checked
          rather than assumed: paragraph.go:579 and :588 both pass
          Penalty(0, …), so no width exists to be charged either way.

So the measurement this PR owes is unchanged — one behaviour change, not three —
and splitting it would buy nothing while making three A/B runs out of one.

⚠⚠ STILL HELD, AND THE A/B STILL HAS NOT RUN. The host's 1-minute load average
has been 14.6, 22.3, 61, 133 and 10.8 over the day, never once under the ~8
threshold this repository measures under. ⛔ Do not merge this without it.

⭐ AND v1.8.0 IS WHAT MAKES THE REAL FIX POSSIBLE, which is the reason to take
it now rather than later. The engine passes Penalty(0, …) for every
discretionary with a comment explaining why a real width "would inflate every
line holding an unbroken hyphenation point" — true of the library until
v1.8.0. The price was the other half: the line that DOES break at a hyphen was
measured without the hyphen it will carry, about 2.5pt at 10pt. That workaround
can now be removed, in its own pull request, with its own A/B. On #768's witness
31 of 35 scored breaks sit at both the badness and demerits ceilings, so a
systematic 2.5pt error in what badness is computed FROM is the live lead there.

Suite green, gofmt silent.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled tannevaled changed the title linebreak v1.6.0: a hyphen on the last line but one stops being free linebreak v1.8.0: a hyphen on the last line but one stops being free Nov 15, 2026
@tannevaled

Copy link
Copy Markdown
Contributor Author

linebreak v1.8.0 instead of v1.6.0: three versions, still ONE behaviour change

Rebased onto main (which now carries #785) and re-pointed at v1.8.0, so this
one pull request is the whole linebreak catch-up. What matters for the A/B it
owes is that the scope has NOT widened:

v1.6.0 \finalhyphendemerits reaches the paragraph-ending break.
CHANGES BREAKING wherever a penultimate break is a hyphen and the
alternative's is not. This is the change this PR has owed an A/B for
since it was opened, and it still is.

v1.7.0 \tracingparagraphs, Params.Trace. A NO-OP here: Trace is nil unless a
caller sets it, and nothing in this engine sets it yet (the wiring
design, Options.Trace, is on #768 and is not in this PR).

v1.8.0 A penalty's width is charged to the line that breaks there and to no
other, tex.web:17128-17137. A NO-OP here TOO, and that is checked
rather than assumed: paragraph.go:579 and :588 both pass
Penalty(0, …), so no width exists to be charged either way.

So the measurement this PR owes is unchanged — one behaviour change, not three —
and splitting it would buy nothing while making three A/B runs out of one.

⚠⚠ STILL HELD, AND THE A/B STILL HAS NOT RUN. The host's 1-minute load average
has been 14.6, 22.3, 61, 133 and 10.8 over the day, never once under the ~8
threshold this repository measures under. ⛔ Do not merge this without it.

⭐ AND v1.8.0 IS WHAT MAKES THE REAL FIX POSSIBLE, which is the reason to take
it now rather than later. The engine passes Penalty(0, …) for every
discretionary with a comment explaining why a real width "would inflate every
line holding an unbroken hyphenation point" — true of the library until
v1.8.0. The price was the other half: the line that DOES break at a hyphen was
measured without the hyphen it will carry, about 2.5pt at 10pt. That workaround
can now be removed, in its own pull request, with its own A/B. On #768's witness
31 of 35 scored breaks sit at both the badness and demerits ceilings, so a
systematic 2.5pt error in what badness is computed FROM is the live lead there.

Suite green, gofmt silent.

Co-Authored-By: Claude Opus 5 [email protected]

🤖 Generated with Claude Code

@tannevaled

Copy link
Copy Markdown
Contributor Author

CI green at 4e04a4d with linebreak v1.8.0 — 20 checks, 0 statuses. The corpus A/B is now the ONLY outstanding item on this PR.

Recording it so whoever picks this up does not have to re-establish where it stands:

  • the three linebreak versions it carries amount to one behaviour change (v1.6.0's \\finalhyphendemerits); v1.7.0's trace is nil-by-default and v1.8.0's disc_width is a no-op while paragraph.go:579 and :588 pass Penalty(0, …)
  • the suite is green, gofmt -l . silent, and \sloppy is a no-op, and we refuse the overfull lines the reference accepts #768's witness is unchanged (neutral by cancellation, measured with the library replaced in)
  • ⛔ do not merge without the A/B. The host's 1-minute load average today: 14.6, 22.3, 61, 133, 10.8, 23.6, 16.8 — never once under the ~8 threshold this repository measures under. Page counts are deterministic under load, but 120 compiles while ~25 sessions share this machine is a cost paid by everyone else, so this is deferred rather than taken badly.

🤖 Generated with Claude Code

@tannevaled

Copy link
Copy Markdown
Contributor Author

The corpus A/B this PR has owed all day is measured, and so is the claim about which of its three versions does anything. The bump costs Σ|page deviation| +1 on ONE paper and buys nothing measurable; the whole cost is v1.6.0's, and v1.7.0 + v1.8.0 are free.

The A/B

base origin/main  7ce5e760      head 636cc4cc  (this branch, merged onto main)
154 papers  (GOTEX_PDFRENDER unset)

scored            154 paper(s)
Σ|page deviation| 310 -> 311   (+1)
exact pagination  27 -> 27   (+0)
papers moved      1   (0 toward the reference, 1 away, 0 sideways)
  2209.13768      23 ->  24   (reference  22)

⭐ One mover, moving away. There is no net figure hiding an offsetting pair here — the single label is the regression. 2209.13768 was one page over the reference and is now two.

⭐ Which version does it? v1.6.0, alone. The other two are free.

This PR carries three library versions, and the note on it said only v1.6.0 changes behaviour — v1.7.0's trace being nil-by-default and v1.8.0's disc_width a no-op while paragraph.go:579/:588 pass Penalty(0, …). That was read, not measured, so I measured it: a control branch off the same base with linebreak v1.6.0 alone.

head a16297ff  (main + linebreak v1.6.0, nothing else)

scored            154 paper(s)
Σ|page deviation| 310 -> 311   (+1)
exact pagination  27 -> 27   (+0)
papers moved      1   (0 toward the reference, 1 away, 0 sideways)
  2209.13768      23 ->  24   (reference  22)

Identical, down to the paper and the page count. So:

Why the measurement is citable despite the machine

Both runs were taken under load, which this repository's rule normally forbids. The reason it is sound here is that gotex-abdiff names what load would do to it: compileAndCount returns timed out after …, and the report refuses to score at all when a paper fails on one side unless -keep-going. Neither run was given that flag, and both scored 154 of 154 — so no paper's count was decided by the clock.

⭐ And the two runs are each other's control on exactly that point: they launched at 1-minute load 7.4 and 20.0 and returned byte-identical verdicts. Page counts are deterministic under load; only durations and timeouts are not.

⚠ The head was merged onto current main first, deliberately. Measured as it stood, this branch predated #789 and #790 — both of which touch hyphenation.go — and the A/B would have attributed their effects to the linebreak bump. After the merge the isolated diff against the base is go.mod + go.sum alone, and abdiff independently checks that the head descends from the base.

What I think this means, and the decision is not mine

The change makes the engine charge a demerit TeX charges (tex.web §859's final_hyphen_demerits), and the corpus answers with +1 on 310 across one paper of 154. That is this repository's recurring shape — correct on its witness, and the corpus says no — and five PRs are already held in it.

Three options, in the order I would take them:

  1. Land it. 153 of 154 papers do not move, exact pagination is unchanged, and the one that moves was already wrong. 0.3% of Σ against implementing a documented TeX demerit, plus v1.7.0's trace arriving free, looks like a good trade — and without the bump, \tracingparagraphs cannot reach the engine at all, which blocks the diagnosis of several open breaks.
  2. Diagnose 2209.13768 first. One paper, one page: gotex-linediff on the page where they diverge would say whether the extra page is a genuinely worse break or a near-tie flipping, which changes how much the +1 should weigh. I have not run it.
  3. Hold for an opt-in. If \finalhyphendemerits were a Params field defaulting to off, v1.7.0's trace could land at zero corpus cost. That is a go-typeset/linebreak design change and arguably the wrong direction — the demerit is not optional in TeX.

⚠ Not claimed

  • That the +1 is a defect in v1.6.0. It is faithful to tex.web; it is simply not what this corpus metric rewards.
  • Anything about 2209.13768's cause. I measured that it grew a page, not why.
  • That figures are rendered. GOTEX_PDFRENDER is unset — abdiff prints so — and 83 of the 154 papers have a PDF figure that is therefore an empty box. It cancels between the two sides, so the difference is valid, but the layout measured is not the real document's. Setting it is not the fix: 993 figures are empty boxes, 951 for want of GOTEX_PDFRENDER — and with it four papers never finish #416 records four papers never finishing with it, which would make abdiff refuse to score.
  • Word displacement. This is page counts (gotex-abdiff). The -layout word-displacement metric (gotex-refdiff) is a different question and was not run.

🤖 Generated with Claude Code

@tannevaled
tannevaled merged commit f841176 into main Nov 15, 2026
18 checks passed
@tannevaled
tannevaled deleted the bump/linebreak-v1.6.0 branch November 15, 2026 18:20
tannevaled added a commit that referenced this pull request Nov 15, 2026
#793)

tex.web §863, on entering the second pass:

    second_pass:=true; final_pass:=(emergency_stretch<=0);

So the second pass is the final one ONLY when \emergencystretch is zero. A
positive one buys a THIRD pass, and it is that pass which carries the stretch in
the background. paragraph.go hard-coded `final_pass` true and said why: the
parameter was accept-and-ignore here, so it was "always zero as far as breaking
is concerned". The third pass could not exist.

go-typeset/linebreak v1.9.0 grew the Params.EmergencyStretch it needs. This
reads the dimen and runs §863's structure: two passes when it is zero, three
when it is not.

⭐ IT IS NOT A RARE PARAMETER. latex.go:1376 is LaTeX's own \sloppy:

    \def\sloppy{\tolerance 9999\emergencystretch 3em\hfuzz .5pt\vfuzz\hfuzz}

so every \sloppy paragraph asks for 3em of emergency stretch, and only the
\tolerance half of that request was being honoured — sloppy_test.go said so in
its own words, and this corrects that comment.

Population, measured with gotex-paramcensus over the 154-paper list rather than
estimated: 4 papers set \emergencystretch literally and 8 more use \sloppy,
with no overlap — 12 of 154. Counting only the literal name, as an earlier
census of mine did, said 4 and missed two thirds of it. sloppy_test.go records
\sloppy in 775 of the 2935 papers, 26.4%.

⚠ And one of the eight is 2209.13768 — the single paper whose pagination moved
in #784's A/B (23 -> 24 pages, reference 22). A paper whose \emergencystretch
should be 3em and was ignored.

The witness, on a 72pt measure with the shape #768 uses:

    \fussy  (emergencystretch 0pt)   3 overfull line(s), worst 10.92pt
    \sloppy (emergencystretch 3em)   0 overfull lines

Verified by mutation: with the dimen read replaced by a constant zero, \sloppy
returns identical numbers to \fussy (3 overfull, worst 10.92pt) and the test
names the reason. The second test pins the zero case — \fussy and the default
must reach identical code, since neither can enter the third pass, which is what
makes this bit-identical for the other 142 papers by construction.

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