Definitioncore
Badness of a line
Also called adjustment ratio, line badness.
A measure of how far a line's glue must stretch or shrink, about 100 times the cube of the adjustment ratio, used in the cost of a line break.
The badness of a line tells how much the spaces of a justified line must change from their natural widths to make the line exactly as long as the column. It is about 100 times the cube of the ratio of the change to the amount the spaces can change, and it is capped at 10000. A line set at its natural width has badness 0, a line whose spaces stretch or shrink by their full allowed amount has badness 100, and a line whose spaces would have to shrink more than allowed has no finite badness. Knuth and Plass defined it for TeX, where it is the main part of the cost of a line in Knuth-Plass line breaking.
Definition
Work in the box, glue and penalty model. A line has a natural width , a total stretchability and a total shrinkability (sums over its glue), and it must be set to the length . Its adjustment ratio is
with when and , and when and . Each glue is then set to width (if ) or (if ).
Real badness. The badness of the line is
If the line stretches or shrinks glue of an infinite order (fil, fill or filll), only that glue moves and .
The integer badness of TeX. TeX computes the badness in integers, from the amount that the line must stretch or shrink and the total of the stretch or shrink, both in scaled points (units of point):
- , and if and ;
- otherwise let (TeX uses another order of operations for very large , to avoid an overflow);
- if the badness is 10000, else it is .
Since , this is rounded, with an error of a few units. The value 10000 means "infinitely bad", and the line breaker gives an overfull line a value above it, so it loses to every line that fits.
A line is feasible for a tolerance when and .
Examples and non-examples
| real badness | TeX badness | note | |
|---|---|---|---|
| 0 | 0 | 0 | natural width |
| 1/3 | 3.70 | 4 | |
| 3/10 | 2.7 | 3 | |
| 1/2 | 12.5 | 12 | |
| 1 | 100 | 100 | full stretch or full shrink |
| 2 | 800 | 800 | ; only for stretch, since shrink stops at 1 |
| 3 | 2700 | 2698 | |
| 9/2 | 9112.5 | 10000 | TeX caps already above |
- Stretch and shrink are symmetric. A line 1 unit too long with shrink 3 and a line 1 unit too short with stretch 3 both have and badness 3.70 (4 in TeX).
- The cap in TeX comes early. The largest finite value of the integer form is 8189, at , that is just under 4.35. From there on TeX gives 10000, while the real form reaches 10000 only at . So the two forms can disagree on which of two very loose lines is worse.
- A line that cannot stretch. A line with one word and no glue, shorter than , has , so and the badness is 10000. In TeX it is an underfull box. It is still allowed if the tolerance is 10000.
- A line that is too long. A line with , and has . It is overfull, and its badness is not 10000 but infinite: no tolerance makes it feasible.
- The last line. The last line of a TeX paragraph holds the glue \parfillskip with stretch 1fil, so its badness is 0 however short it is.
- Not the adjustment ratio. The ratio and the badness are different numbers: gives badness 12.5. The badness is a cubic function of , so it grows slowly near 0 and fast beyond 1.
- Not the slack. The cost of printing neatly is the cube of the empty space at the end of a line, which does not depend on the number of spaces. The badness divides by the stretch first, so the same empty space costs less in a line with more spaces.
Related definitions
- Adjustment ratio. The number above; it gives the widths of the glue.
- Demerits. The cost of a line in the Knuth-Plass algorithm, about for the line penalty and the penalty at the break, with extra terms for hyphens and fitness classes. The square of the badness makes one very bad line cost more than several slightly bad ones.
- Fitness class. Knuth and Plass put a line into one of four classes by : tight (), decent (), loose () and very loose (). The bounds and are the badness values 12.5 and 100, and TeX tests its integer badness against 12 and 99.
- Tolerance. The largest badness of a feasible line; plain TeX uses 100 for its first try without hyphens (\pretolerance) and 200 for the second (\tolerance).
- Page badness. The page builder of TeX uses the same function for the glue of a page, as in best-fit page breaking.
- Line cost in least weight subsequence. With rigid spaces and a cost that is a convex function of the width of the line, line breaking is a least weight subsequence problem with the quadrangle inequality. The badness is not of this form, because it divides by the stretch of the line, which changes from line to line.
References
- Donald E. Knuth and Michael F. Plass, Breaking paragraphs into lines, Software: Practice and Experience 11(11), 1119-1184, 1981, the definition of the adjustment ratio, the badness 100 |r|^3, feasible lines and fitness classes
- Donald E. Knuth, The TeXbook, Computers and Typesetting volume A, Addison-Wesley, Chapter 14, How TeX breaks paragraphs into lines (badness, tolerance and demerits)
- Donald E. Knuth, TeX: The Program, Computers and Typesetting volume B, Addison-Wesley, 1986, the badness function in the part on basic arithmetic, and its use in the line breaker
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 4N5WKK Edit this page History Report an error Markdown