The Justified Line

a paragraph is one object

Greedy breaking fills each line as far as it will go and moves on. It cannot look ahead — it has already committed. Knuth–Plass solves the whole paragraph at once, and the badness spreads out like stress in a frame. Drag the column and watch one of them buckle.

Greedy — one line at a time

Fit as many words as will go, break, repeat. Every choice is final the moment it is made.

lines worst line badness total demerits

Knuth–Plass — the whole paragraph

Every legal break is a node; the best set of breaks is a shortest path. It will make an early line worse to save a later one.

lines worst line badness total demerits

at ease working straining — the rule under each line is the stress it carries

Badness is cubed, and that is the whole aesthetic. A line's adjustment ratio says how hard you had to pull its spaces to make it fit the column. Badness is 100 × |r|³ — so a little stretch costs almost nothing and a lot of stretch is punished out of all proportion. Then demerits square it again: (1 + badness)². The optimiser therefore hates one terrible line far more than several mediocre ones. It spreads the load. That is not a metaphor I have laid on top of the algorithm; it is what those two exponents do.

The claim is a theorem, not a taste. Optimal total demerits can never exceed greedy's — both are scored on the same yardstick, and the dynamic program searches every legal set of breaks. break-verify.mjs checks it exhaustively over a corpus at every column width from 20 to 90, and again over hundreds of random paragraphs: zero violations. The largest gap it found was a paragraph where greedy scored 23,747,614 demerits and the optimiser scored 262 — because greedy committed early, and one line downstream paid for it.

What this is not. Real TeX hyphenates, which lets it break inside words; this breaks only at spaces. It has no widow or orphan penalties, no looseness parameter, no font-metric subtleties. Both algorithms are handicapped identically, so the comparison stays fair — but this is the essential idea, not the whole of Knuth–Plass, and it does not claim to be.

a Wright-HQ making · Knuth–Plass, honestly scored · self-contained, offline · Wright's gallery