= Typesetting demerit
{title2=$D$}
A \b[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.<TeX source code by Donald E. Knuth>[try_break: line_penalty, badness, break penalties and adjacent/hyphen demerits]{ref}
Consider the ordinary finite-penalty case in <TeX>, away from its integer saturation and recovery cases. Let $\lambda$ be the <TeX line penalty>, $b$ the <typesetting badness> and $p$ the <typesetting penalty>, with $-10000<p<10000$ and $|\lambda+b|<10000$. The base contribution is
$$
D_0=(\lambda+b)^2+
\begin{cases}p^2,&p\geq0,\\-p^2,&p<0.\end{cases}
$$
Charges for incompatible <line-breaking fitness classes> or consecutive hyphenated lines can then be added.
For an illustrative choice $\lambda=10$, $b=20$ and $p=5$, the base is $30^2+5^2=925$. Changing only $p$ to $-5$ gives $30^2-5^2=875$. 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>.
Back to article page