TeX line penalty (source code)

= TeX line penalty
{c}
{title2=`\linepenalty`}

The \b[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> $b$ contributes $(\lambda+b)^2$ before breakpoint and neighbour-dependent terms, where $\lambda$ denotes the chosen line penalty.<TeX source code by Donald E. Knuth>[try_break: line_penalty+b is squared before other contributions]{ref}

The algebra shows how it affects a candidate with $N$ lines:
$$
\boxed{\sum_{j=1}^N(\lambda+b_j)^2
=N\lambda^2+2\lambda\sum_{j=1}^N b_j+\sum_{j=1}^N b_j^2.}
$$
Changing $\lambda$ 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 $A=(30,0)$ and $B=(0,0,0)$, with all other costs zero and values below saturation. At $\lambda=10$,
$$
C_A=40^2+10^2=1700,\qquad C_B=3\cdot10^2=300.
$$
At $\lambda=100$,
$$
C_A=130^2+100^2=26900,\qquad C_B=3\cdot100^2=30000.
$$
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.