Skip to content

ragged text is not hyphenated, because an infinite background makes every line good - #772

Merged
tannevaled merged 2 commits into
mainfrom
raggedright-first-pass
Nov 13, 2026
Merged

tannevaled merged 2 commits into
mainfrom
raggedright-first-pass

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

ragged text is not hyphenated, because an infinite background makes every line good

\raggedright broke its lines as if the paragraph were justified, and
hyphenated them.

Why ragged text is not hyphenated

tex.web §852 gives badness 0 and fitness decent to ANY line carrying infinite
stretch. \raggedright's \rightskip is 0pt plus 1fil, so TeX's FIRST pass —
no hyphenation, at \pretolerance — succeeds on every ragged paragraph it meets
and the hyphenating pass is never reached.

That is the whole mechanism. It is not a rule about hyphens; it is what an
infinite background does to badness.

go-typeset/linebreak carries one float of stretch and flattens a fil to a
large finite number (its issue #12, item 1), so the lines came back with a large
but FINITE badness, the first pass failed, and the paragraph was hyphenated
exactly as if it were justified. Our ragged and justified paragraphs were
character for character the same, which is "ragged text breaks as if justified
and gets its glue afterwards" seen rather than argued.

Measured

tectonic 0.17.0, \hsize=100pt, lmroman10 on both sides:

reference before after
\raggedright 6 lines, 0 hyphens, no warning … and a mea-sure …, 2 overfull 0 hyphens, 0 overfull
justified 6 lines, 2 hyphens, one Overfull \hbox (1.172pt) 1 hyphen pa-per unchanged

⚠ The justified column is the control, and it does not move. Swept at eleven
measures from 80pt to 200pt against a worktree at the merge-base, the justified
output is byte for byte identical before and after. Ragged improves at 80, 90,
100 and 180pt — the hyphen goes AND the overfull lines go, 1, 1, 2, 1 → 0, 0, 0,
0 — and is unchanged everywhere else.

⚠ 110pt and 130pt still set ragged text with overfull lines. Identical before
and after, so that is older than this change; it belongs to #768 and stays open.

It is NOT "do not hyphenate when ragged"

TeX still hyphenates ragged text when a word would otherwise not fit: the first
pass fails because the line is not good, whatever the \rightskip. Measured at
\hsize=60pt, the reference breaks incomprehen- / sibilities under
\raggedright, and so do we. There is a test for it.

⛔ A claim this branch first made and could not support

The overfull test in the new branch was written asking Ratio < -1, then
rewritten to measure the width, with the reasoning that the ratio is blind to a
line with no shrinkable glue — #771's defect, one file away, an hour earlier.

The mutation does not support that. Swapping the width back for the ratio,
or deleting the test altogether, leaves the whole suite green: at any measure
narrow enough to overfull a line, the first pass fails before the question is
ever asked. I could not build a document that distinguishes them.

The width is kept, for a reason that IS demonstrable: greedyLines never sets
Ratio at all, so a Line it built carries 0 — that, not the absence of glue,
is what made Ratio < -1 count nothing in #771. One lineOverflowSP now
answers the question for both callers. The comments say the test has no witness
rather than implying it caught something.

Mutations run

mutation expected observed
disable the ragged branch entirely ragged test red, justified green ✅ exactly that
width test → Ratio < -1 ? survives — no witness
delete the overfull test ? survives — no witness
inserted helpers above noteBadLines' body caught ✅ TestDocCommentNamesItsOwnFunction

⚠ DRAFT until the corpus A/B lands

\raggedright is in 871 of 2935 corpus papers — 29.7%, the most common of
the line-breaking commands — so this changes what a large fraction of real
documents get. The A/B is running now and will be posted here. I argued on #769
that a behaviour change should not merge before its A/B; this one is in no
hurry, so it waits.

Refs #768.

🤖 Generated with Claude Code

…very line good

\raggedright broke its lines as if the paragraph were justified, and
hyphenated them. tex.web §852 gives badness 0 and fitness `decent` to ANY line
carrying infinite stretch; \raggedright's \rightskip is 0pt plus 1fil, so TeX's
FIRST pass — no hyphenation, at \pretolerance — succeeds on every ragged
paragraph it meets and the hyphenating pass is never reached.

That is why ragged text is not hyphenated. It is not a rule about hyphens, it
is what an infinite background does to badness.

go-typeset/linebreak carries one float of stretch and flattens a fil to a large
finite number (its issue #12, item 1), so the lines came back with a large but
FINITE badness, the first pass failed, and the paragraph was hyphenated exactly
as if it were justified.

MEASURED, tectonic 0.17.0, \hsize=100pt, lmroman10 on both sides:

	reference  ragged     6 lines, 0 hyphens, no warning
	reference  justified  6 lines, 2 hyphens, one Overfull \hbox (1.172pt)
	before     ragged     `… and a mea-sure …`, 2 overfull lines of our own
	after      ragged     0 hyphens, 0 overfull

⚠ THE JUSTIFIED COLUMN IS THE CONTROL AND IT DOES NOT MOVE. Swept at eleven
measures from 80pt to 200pt, the justified output is byte for byte identical
before and after. The ragged output improves at 80, 90, 100 and 180pt — the
hyphen goes AND the overfull lines go (1, 1, 2, 1 → 0, 0, 0, 0) — and is
unchanged everywhere else. 110pt and 130pt still set ragged text with overfull
lines; that is older than this change and stays open.

⚠ AND IT IS NOT "DO NOT HYPHENATE WHEN RAGGED". TeX still hyphenates ragged
text when a word would otherwise not fit: the first pass fails because the line
is not good, whatever the \rightskip. Measured at \hsize=60pt, the reference
breaks `incomprehen-` / `sibilities` under \raggedright and so do we.

⛔ A CLAIM THIS COMMIT FIRST MADE AND COULD NOT SUPPORT. The overfull test in
the new branch was written asking `Ratio < -1`, then rewritten to measure the
width with the reasoning that the ratio is blind to a line with no shrinkable
glue — #771's defect, one file away, an hour earlier. The mutation does not
support it: swapping the width back for the ratio, or deleting the test
altogether, leaves the whole suite green, because at any measure narrow enough
to overfull a line the first pass fails before the question is asked.

The width is kept, for a reason that IS demonstrable: greedyLines never sets
Ratio at all, so a Line it built carries 0 — that, not the absence of glue, is
what made `Ratio < -1` count nothing in #771. One lineOverflowSP now answers
the question for both callers. The comments say the test has no witness rather
than implying it caught something.

Refs #768.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

⛔ THE CORPUS A/B IS IN, AND IT GOES THE WRONG WAY. Two papers moved and BOTH
MOVED DOWN.

base rows=60 scored=37   head rows=60 scored=37
   2607.14549   96.5% -> 96.4%  (-0.1, revtex4-2)
   2607.14914   92.6% -> 92.4%  (-0.2, revtex4-2)

moved=2 status_flips=0 only_base=0 only_head=0

Same corpus slice, same seed, same machine, base = the merge-base commit.

⚠ AND THEY ARE NOT NOISE. The scorer is deterministic: base reads 96.5% for
2607.14549 here, which is exactly where #771's A/B left that paper an hour ago.
The same binary gives the same number, so −0.1 and −0.2 are real movements,
small as they are.

⛔ NEITHER PAPER USES \raggedright. Nothing in either source says
\raggedright, \RaggedRight, \raggedleft or loads ragged2e. The change
reaches them through raggedBackground(), which asks whether EITHER skip
carries infinite stretch — and \centering sets both. So every centred title,
heading, caption and author block in a revtex paper now takes the first-pass
path too.

That is not obviously wrong: §852 is about the background being infinite, not
about which command set it, and TeX does not hyphenate centred text either. But
it means this PR's measured gain is about \raggedright while its measured
LOSS is about \centering, and the two were not separated before the A/B ran.

WHAT I AM DOING ABOUT IT

Building a variant whose raggedBackground() is true only for a RIGHT-ragged
background with a finite left skip — strict \raggedright, excluding
\centering — and re-running those two papers through the same harness. If
their score returns to base, the regression is attributable to centred
material and the condition is what has to be argued about. If it does not, the
attribution above is wrong and I will say so.

⚠ WHAT THE SCORE IS. Word recall against the reference PDF, not a verdict on
typesetting. A move of −0.1 means some words on some page are no longer found
where the reference has them; it does not say the page is worse to read. It is
still a move AWAY from the oracle, which is what this project is closing, so it
counts against the change until it is explained.

This stays a draft.

@tannevaled

Copy link
Copy Markdown
Contributor Author

⭐ THE ATTRIBUTION IS IN, AND IT REVERSES THE READING OF THE SCORE.

1. The regression is entirely \centering, not \raggedright

A variant whose raggedBackground() is true only for a strict right-ragged
background — right skip infinite, left skip FINITE, which excludes \centering
and \raggedleft — scored against the same two papers:

paper base head strict-\raggedright variant
2607.14549 96.5% (1004/1040) 96.4% (1003/1040) 96.5% (1004/1040)
2607.14914 92.6% (1270/1372) 92.4% (1268/1372) 92.6% (1270/1372)

The variant returns to base exactly, word for word. So the whole movement is
three words, and all of it comes from centred material.

2. ⛔ BUT THE BROAD CONDITION IS THE FAITHFUL ONE — MEASURED

tectonic 0.17.0, the same paragraph inside \begin{center} at \hsize=100pt:

6 lines, 0 hyphens, no warning
… is wrong on / every line it sets.

identical to its \raggedright setting of the same text. The reference does not
hyphenate centred text, which is what §852 predicts — it is about the background
being infinite, not about which command set it. The variant that scores better
is the one that is wrong.

3. ⭐ AND THE PAGE THAT "LOST" A WORD IS VISIBLY BETTER

Word-multiset diff of the two PDFs for 2607.14549. What base has and head does
not:

CenterforTheoretical    ElectronicEngineering
QiluNormalUniversity    Jinan250200

Those are the affiliation lines WITH NO SPACES BETWEEN THE WORDS — the
signature of a centred line that was overfull and had its glue shrunk to
nothing to make it fit. Head sets the same lines as

Center for Theoretical    Electronic Engineering
Qilu Normal University    Jinan 250200

Head also replaces eight spurious hyphenations in centred material with whole
words: char-/acterized, follow-/ing, in-/dicated, repre-/sent,
respec-/tively, sys-/tems, transfor-/mations, con/trary become
characterized, following, indicated, represent, respectively,
systems, transformations, contrary — which is what the reference sets.

The net −1 word comes from token boundaries around a stray 0.5 fragment
(0.5This + case + siperiodic on one side, 0.5siperiodic.case + This on
the other), not from text that stopped appearing.

What I conclude, so it can be disagreed with

The corpus score is a proxy: word recall against the reference's extracted text.
Here it moved −0.1 while the direct comparison with the reference improved and a
visible defect — words touching each other in a centred block — was removed. I
am treating the oracle and the page as the authority over the proxy, and
marking this ready.

⚠ If that is the wrong call, the fix is one line (&& and == 0 in
raggedBackground), it buys back 3 words of recall, and it makes the engine
hyphenate centred text, which the reference does not.

…s about the BACKGROUND

The corpus A/B of this branch moved two revtex papers DOWN, and neither of them
uses \raggedright: the change reaches them through \centering, which sets both
skips to 0pt plus 1fil. So the condition had to be argued rather than assumed.

MEASURED, tectonic 0.17.0, the same paragraph inside \begin{center} at
\hsize=100pt: 6 lines, 0 hyphens, no warning — character for character what it
sets the same text \raggedright. The reference does not hyphenate centred text,
which is what §852 predicts: it is about the background being infinite, not
about which command set it.

A variant narrowed to a strictly right-ragged background scores BETTER — it
returns both papers to their base word recall exactly — and is wrong, because it
makes the engine hyphenate centred text. The test added here refuses it, and the
mutation was run: with `&&` and `== 0` the centred paragraph comes out
`Typogra-phy … a mea-sure …` and the test goes red while the \raggedright one
stays green.

⭐ AND THE PAGE THAT LOST A WORD OF RECALL IS VISIBLY BETTER. A word-multiset
diff of the two PDFs for 2607.14549 shows what base set in the affiliation
block:

	CenterforTheoretical    ElectronicEngineering
	QiluNormalUniversity    Jinan250200

with no spaces between the words — a centred line that was overfull and had its
glue shrunk to nothing. After, those are four ordinary lines of separate words.
Eight spurious hyphenations go with them (char-/acterized, follow-/ing,
in-/dicated, repre-/sent, respec-/tively, sys-/tems, transfor-/mations,
con/trary). The net -1 word is token boundaries around a stray `0.5` fragment,
not text that stopped appearing.

The corpus score is a proxy for the reference; here the proxy and the reference
disagree, and this follows the reference.

Refs #768.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

⛔⛔ CORRECTION: THE AFFILIATION FINDING ABOVE IS AN EXTRACTION ARTEFACT, NOT
SOMETHING THIS BRANCH FIXED. I published it; it is wrong; here is what is
actually there.

I wrote that base set the affiliation block as CenterforTheoretical,
ElectronicEngineering, QiluNormalUniversity, Jinan250200 — words with no
spaces — and that this PR repaired them. That came from a scratch word-diff
that read the PDFs with pdfops text. The scoring harness reads them with
poppler's pdftotext, and through pdftotext those words do not differ at all.

The engine's own line dump settles it. Both PDFs, page 1:

base   y=120.19  x0= 72.56  x1=561.63  | …@gmail.com; Center for Theoretical Physics of Complex …
head   y=120.19  x0= 72.56  x1=561.63  | …@gmail.com; Center for Theoretical Physics of Complex …

The spaces are in both. Nothing ran together, and this PR did not fix it.

⛔ A PROBE THROUGH A DIFFERENT EXTRACTOR MEASURES THE EXTRACTOR. That is a
lesson this repository already holds (#716 is about the metric not seeing what
is on the page) and I walked into it anyway, then published the result twice.

What IS true, re-measured through the harness's own extractor

  1. The hyphenations are real. Through pdftotext, base holds char-,
    acterized, repre-, sent, exponen-, tial, transfor-…, and head
    holds characterized, represent, exponential, transformations. Both
    extractors agree on these, and it is what tectonic sets. That part of the
    earlier comment stands.

  2. What actually moved in the front matter is the MEASURE of those lines,
    not their spaces.
    Base sets the affiliation lines full width
    (x0=72.00, x1=562.18); head sets them narrower and indented
    (x0=87.46, x1=546.72) — i.e. centred, which is what an \author block asks
    for. That is a real difference and it is this change's doing, but it is a
    difference in line width, not in whether words touch.

  3. The −0.1 / −0.2 of word recall is still unexplained, and I am no longer
    claiming it is outweighed by a defect this branch removed. What I can still
    say is that the hyphenation change follows the reference (measured, in the
    PR body and in the comment above) and that the strict-\raggedright variant
    that scores better hyphenates centred text, which the reference does not.

The verdict I asked for is unchanged in direction but weaker in evidence than I
stated: follow the oracle on the hyphenation, and treat the recall movement as
open rather than as explained.

tannevaled added a commit that referenced this pull request Nov 13, 2026
…egression

#772 lost 0.1 and 0.2 points of word recall on two revtex papers and I could
not say why. The new tool says why, and most of it is not the engine.

⛔ pdftotext WITHOUT -layout READS A TWO-COLUMN PAGE AS ONE STREAM and fuses the
end of one column's line onto the start of another's. These are real tokens
from 2607.14549:

	disFigure   distribhe   participaentire   quaThe   respecIn
	transforlution   matTo   quag   quasiof   reperiodic

WHICH boundaries fuse depends on where the lines break, so a line-breaking
change moves them. On that paper the plain extraction reports 36 and 37 words
differing between the two builds; with -layout it reports 23 and 18, and every
fused token above is gone. What is left is the change itself: char-/acterized →
characterized, follow-/ing → following, in-/dicated, repre-/sent,
respec-/tively, sys-/tems, transfor-/mations.

⭐ AND THE SCORE MOVES WITH IT. Re-scoring #772's two papers with -layout
extraction (a throwaway build of gotex-refdiff, not this commit):

	2607.14914   plain -0.2  ->  -layout  1327 vs 1327 words, NO difference
	2607.14549   plain -0.1  ->  -layout  1020 vs 1019 words, ONE word

So one of the two regressions was the extractor fusing columns, and the other
is a single word.

⚠⚠ THIS IS NOT A PROPOSAL TO SWITCH THE SCORER. -layout moves the ABSOLUTE
scores by nine points on BOTH sides (2607.14549: 96.5% -> 87.6%), because the
padding it inserts changes tokenisation everywhere, including the reference's.
Every historical number would move. It is a diagnostic for reading a delta, and
gotex-refdiff is untouched here.

The flag is on gotex-worddiff; internal/pdftext.CaptureRunner takes opts and
places them BEFORE the file, where pdftotext takes its options. The mutation
was run: with the opts appended after the path instead, the test goes red
(`cat -u` becomes `cat f - -u`, which reads a file that is not there).

Refs #716, #772.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

⭐ THE REGRESSION IS EXPLAINED, AND MOST OF IT IS NOT THIS BRANCH.

I left the −0.1 / −0.2 open above. gotex-worddiff (#773) answers it.

pdftotext reads a two-column page as ONE stream

Without -layout it fuses the end of one column's line onto the start of
another's. Real tokens from 2607.14549's two builds:

disFigure   distribhe   participaentire   quaThe   respecIn
transforlution   matTo   quag   quasiof   reperiodic

WHICH boundaries fuse depends on where the lines break — so a line-breaking
change moves them, and they arrive at the scorer as words that appeared or
vanished.

On that paper the plain extraction reports 36 and 37 words differing between
base and head. With -layout it reports 23 and 18, and every fused token above
is gone. What is left is this branch's actual work:

char-/acterized -> characterized      follow-/ing  -> following
in-/dicated     -> indicated          repre-/sent  -> represent
respec-/tively  -> respectively       sys-/tems    -> systems
transfor-/mations -> transformations

And the score moves with the extraction

Re-scoring both papers with -layout extraction (a throwaway build of
gotex-refdiff, nothing committed):

paper plain with -layout
2607.14914 −0.2 1327 vs 1327 — no difference at all
2607.14549 −0.1 1020 vs 1019 — one word

So one of the two regressions was the extractor fusing columns. The other is a
single word.

⚠⚠ This is NOT a proposal to switch the scorer

-layout moves the ABSOLUTE scores by nine points on BOTH sides (2607.14549:
96.5% → 87.6%), because the padding it inserts changes tokenisation everywhere,
the reference's included. Every historical number in this tracker would move.
It is a diagnostic for reading a delta, not a better metric, and
gotex-refdiff is untouched.

Where that leaves this PR

  • The hyphenation change follows the reference — measured against tectonic at
    three measures, with the justified control byte-identical.
  • The corpus cost is one word on one paper, not two regressions.
  • The variant that avoids even that word hyphenates centred text, which the
    reference does not.

I am no longer claiming a visible improvement outweighs a loss — that claim was
the extraction artefact I corrected above. The claim now is narrower and
measured: this follows the oracle, and it costs one word of a proxy whose
sensitivity to column fusion is larger than the effect being measured.

tannevaled added a commit that referenced this pull request Nov 13, 2026
…re uses (#773)

* gotex-worddiff: which words moved, read through the extractor the score uses

gotex-refdiff says a paper fell 0.1 points of word recall. It does not say
which words, so there is no way to tell a regression from an improvement the
metric mis-counts — which is #716's subject, and which #772 ran into head-on.

gotex-worddiff reports the multiset difference between two of OUR PDFs: the
words one holds that the other lacks, and the reverse. No reference; measuring
against the oracle is gotex-refdiff's job. Exit 0 same words, 1 different, 2 an
error.

⛔⛔ AND ITS FIRST ACT WAS TO CATCH ITS OWN AUTHOR, WHICH IS WHY THE EXTRACTOR
IS SHARED

The scratch probe this replaces read the PDFs with `pdfops text` and reported
that a revtex affiliation block had set as `CenterforTheoretical`,
`QiluNormalUniversity` — words with no spaces between them — and that #772 had
repaired it. That was published on #772 and on #716 before it was checked.

Reading the same two files through poppler's pdftotext, which is what
gotex-refdiff SCORES with, there is no such difference; and the engine's own
line dump shows the spaces present in both files, at identical coordinates. The
finding was two extractors disagreeing, dressed as an engine defect. Both
comments are corrected.

So the extraction itself — which binary, how it is found on PATH or through
pkgx, the poppler project pin that stops `pkgx pdftotext` failing with
MultipleProjects — moves into internal/pdftext, and gotex-refdiff is rewired
onto it. What does NOT move is what refdiff makes of the text: word recall, and
its genuine-empty versus tool-error distinction. Those are scoring semantics,
not extraction.

WHAT IS TESTED

 - the shapes a line-breaking change makes: a word split across a hyphen on one
   side and whole on the other, a fused token
 - a word both files hold is not a difference, and the same words in a
   different order exit 0
 - it is a MULTISET: three occurrences against two IS a difference
 - ⛔ a failed extraction is an error, never an empty page — otherwise a missing
   poppler reports every word of the other file as a difference, a maximal and
   confident meaningless answer
 - an absent or zero-byte file, likewise
 - internal/pdftext: the poppler pin, a tool found on PATH, and a missing tool
   that must error rather than return no text

The repository's own gate caught the missing .gitignore row
(TestEveryCommandIsIgnoredAtTheRoot).

Refs #716, #772.

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

* gotex-worddiff -layout, and the column fusion it found under #772's regression

#772 lost 0.1 and 0.2 points of word recall on two revtex papers and I could
not say why. The new tool says why, and most of it is not the engine.

⛔ pdftotext WITHOUT -layout READS A TWO-COLUMN PAGE AS ONE STREAM and fuses the
end of one column's line onto the start of another's. These are real tokens
from 2607.14549:

	disFigure   distribhe   participaentire   quaThe   respecIn
	transforlution   matTo   quag   quasiof   reperiodic

WHICH boundaries fuse depends on where the lines break, so a line-breaking
change moves them. On that paper the plain extraction reports 36 and 37 words
differing between the two builds; with -layout it reports 23 and 18, and every
fused token above is gone. What is left is the change itself: char-/acterized →
characterized, follow-/ing → following, in-/dicated, repre-/sent,
respec-/tively, sys-/tems, transfor-/mations.

⭐ AND THE SCORE MOVES WITH IT. Re-scoring #772's two papers with -layout
extraction (a throwaway build of gotex-refdiff, not this commit):

	2607.14914   plain -0.2  ->  -layout  1327 vs 1327 words, NO difference
	2607.14549   plain -0.1  ->  -layout  1020 vs 1019 words, ONE word

So one of the two regressions was the extractor fusing columns, and the other
is a single word.

⚠⚠ THIS IS NOT A PROPOSAL TO SWITCH THE SCORER. -layout moves the ABSOLUTE
scores by nine points on BOTH sides (2607.14549: 96.5% -> 87.6%), because the
padding it inserts changes tokenisation everywhere, including the reference's.
Every historical number would move. It is a diagnostic for reading a delta, and
gotex-refdiff is untouched here.

The flag is on gotex-worddiff; internal/pdftext.CaptureRunner takes opts and
places them BEFORE the file, where pdftotext takes its options. The mutation
was run: with the opts appended after the path instead, the test goes red
(`cat -u` becomes `cat f - -u`, which reads a file that is not there).

Refs #716, #772.

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

---------

Co-authored-by: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled marked this pull request as ready for review November 13, 2026 13:46
@tannevaled
tannevaled merged commit 16878d5 into main Nov 13, 2026
18 checks passed
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