Hyphenation opportunity 2026-11-05
A hyphenation opportunity is a position where the language and chosen hyphenation rules permit a word to be divided across lines. An explicit soft hyphen can supply one; automatic hyphenation can find others using a language-appropriate resource. These permitted positions become choices for line breaking.[ref]
CSS Text Module Level 3 by World Wide Web Consortium. §5.3: explicit and automatic language-appropriate hyphenation opportunities
Two tests must then be applied. First, is the division permitted by the linguistic rules? Second, does the resulting geometry and cost make it a useful choice? If the material before a break has width 20, an inserted hyphen adds 2, and the available typesetting line width is 21, the resulting 22-unit line fails the rigid-width fitting test despite the linguistic permission.
A discretionary break represents the alternative printed material. The Knuth-Plass line-breaking algorithm can compare that option with later or earlier permitted breaks using typesetting badness and typesetting penalties.
Line adjustment ratio 2026-11-05
The line adjustment ratio measures the stretch or shrink required to make a candidate line fit. In the finite-glue model, let be its natural line width, its target typesetting line width, and and the total stretch and shrink coefficients of its typesetting glue. DefineIt is a dimensionless quantity: numerator and denominator are widths measured in the same units. Each glue item uses the same , scaled by its own appropriate coefficient.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1125–1127: adjustment ratio and feasible stretching/shrinking
For , and , targets 32 and 28 give and respectively. If a nonzero width difference requires a coefficient total of zero, this model cannot make the adjustment. With ordinary bounded shrinkage, asks the glue to shrink beyond its total allowance and is infeasible. Positive stretch is usually limited by an acceptable-quality threshold rather than by treating as an absolute geometric limit.
The typesetting badness scores spacing quality from the required adjustment, while a line-breaking fitness class records a coarser category for comparison with neighbouring lines. Neither measure alone incorporates every typesetting penalty.
Line-breaking fitness class 2026-11-05
A line-breaking fitness class is a coarse description of how tightly or loosely a line is spaced. The Knuth-Plass line-breaking algorithm distinguishes tight, normal, loose and very loose lines. A transition between sufficiently different classes adds typesetting demerits, even when each line's own spacing is individually acceptable.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. p.1155: four fitness classes and penalties for contrasting adjacent lines
For example, imagine one feasible line has line adjustment ratio and the next has . One compresses its spaces substantially, while the other expands them. That contrast can be more conspicuous than two lines with similar spacing. A paragraph objective can express this using an added termwhere indexes the classes. The indicator function adds the charge only for a sufficiently large class change.
Consequently, the dynamic programming state needs the previous fitness information. Suppose two routes to the same break cost 10 and 12, but the cheaper route's class would add a transition charge of 5 to the next line while the other adds none. Their relevant totals become 15 and 12: discarding the second route solely because would be premature. The principle of optimality applies to states that retain the information the future cost needs.
TeX computes its categories using integer typesetting badness thresholds and handles special glue cases explicitly. Its implementation should therefore be consulted for exact boundary behaviour rather than inferring it from rounded decimal adjustment ratios.[ref]
TeX source code by Donald E. Knuth. try_break: fit_class, badness thresholds 12 and 99, and adj_demerits
TeX line penalty 2026-11-05
The TeX line penalty, set by
\linepenalty, enters the per-line base used to calculate typesetting demerits. In the ordinary finite calculation, a line with typesetting badness contributes before breakpoint and neighbour-dependent terms, where denotes the chosen line penalty.[ref]TeX source code by Donald E. Knuth. try_break: line_penalty+b is squared before other contributions
The algebra shows how it affects a candidate with lines:Changing therefore changes both the line-count term and the way spacing costs enter the comparison.
For a chosen example, assume two feasible layouts have badness profiles and , with all other costs zero and values below saturation. At ,At ,The preferred candidate changes. These are illustrative profiles and parameter values. Actual line breaking must also account for feasible endpoints, typesetting penalties and possible line-breaking fitness class changes.
Typesetting badness 2026-11-05
Typesetting badness scores the spacing strain needed to fit a line. For ordinary finite stretch or permitted finite shrink, a useful smooth guide iswhere is the line adjustment ratio. Doubling the required ratio multiplies this guide by eight, so it strongly penalizes large adjustments. The convex function on nonnegative ratios rewards more evenly distributed spacing strain.
TeX computes an integer approximation with saturation rather than evaluating that real-valued expression exactly. With stretch coefficient in the routine's internal units, excess widths give ratios and routine outputs . In particular, the first differs from the smooth guide value 12.5.[ref]
TeX source code by Donald E. Knuth. badness(t,s): fixed-point approximation, rounding constants and inf_bad; chosen input values evaluated directly
Cubic spacing cost and integer typesetting badness
. Original calculation comparing the smooth guide with TeX's badness routine at chosen finite stretch coefficients. The right panel enlarges the integer steps near r=0.5. All plotted ratios describe stretching. Details.The sentinel 10000 represents saturated badness in the routine. Excessive shrinking is tested separately in paragraph breaking; higher-order stretch has its own treatment. A paragraph's typesetting demerits also include typesetting penalties and possible neighbour-dependent charges, so choosing solely by badness can miss the best layout.
Typesetting demerit 2026-11-05
A typesetting demerit is a contribution to the paragraph cost minimized by the Knuth-Plass line-breaking algorithm. It combines spacing quality with break preferences and, when applicable, costs involving neighbouring lines. Thus typesetting badness is one input to the cost rather than the entire objective.[ref]
TeX source code by Donald E. Knuth. try_break: line_penalty, badness, break penalties and adjacent/hyphen demerits
Consider the ordinary finite-penalty case in TeX, away from its integer saturation and recovery cases. Let be the TeX line penalty, the typesetting badness and the typesetting penalty, with and . The base contribution isCharges for incompatible line-breaking fitness classes or consecutive hyphenated lines can then be added.
For an illustrative choice , and , the base is . Changing only to gives . If an adjacency charge of 100 applies, those become 1025 and 975. These are chosen example parameters, not asserted defaults.
Dynamic programming compares accumulated costs while retaining the dynamic programming state needed by future charges. The lowest-cost break considered alone need not produce the lowest-cost complete text paragraph.
Typesetting penalty 2026-11-05
A typesetting penalty expresses how desirable a candidate break is. In the Knuth-Plass line-breaking algorithm's paragraph representation, a penalty item can also have a width that is included only if that break is taken. This lets the model account for a hyphen introduced by hyphenation without printing it in the unbroken word.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1123–1125: penalty values, widths and flags
For example, suppose the material before an optional break uses 29 units and taking the break introduces a hyphen of width 2. At a typesetting line width of 30, the broken line needs units before any permitted adjustment of typesetting glue. Testing only the pre-hyphen width would wrongly declare it a fit. A finite penalty can discourage a break while still leaving it available when other choices are worse.
In TeX, values prohibit a penalty break and force it. Intermediate positive values discourage and negative values encourage it. These are control conventions of the implementation, not physical lengths.[ref]
TeX source code by Donald E. Knuth. penalty_node definition: inf_penalty and eject_penalty thresholds
The penalty value is an input to the typesetting demerit calculation. It is not the entire paragraph cost: typesetting badness, line-breaking fitness classes and consecutive hyphenated breaks can contribute too. Comparing two penalties alone therefore cannot choose the best text paragraph layout.
