Typesetting glue (source code)

= Typesetting glue
{title2=$(g,s,t)$}

\b[Typesetting glue] represents adjustable space between pieces of typeset material. In a finite, single-order model, describe a glue item by a nominal width $g_i$, stretch coefficient $s_i\geq0$ and shrink coefficient $t_i\geq0$. A shared <line adjustment ratio> $r$ gives
$$
\boxed{g_i'=\begin{cases}g_i+r s_i,&r\geq0,\\g_i+r t_i,&r<0.\end{cases}}
$$
Thus a negative $r$ reduces the gap. The coefficients describe relative flexibility; they need not be identical for all spaces. This model is a useful part of <text justification>.<Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass>[pp.1123–1127: glue widths, stretch, shrink and adjustment ratios]{ref}

For example, two nominal gaps of width 3 with stretch coefficients 1 and 3 become $3.5$ and $4.5$ when $r=1/2$. Their total extra width is 2. With shrink coefficients 1 and 1, $r=-1$ makes both gaps width 2. The same natural line can therefore reach different targets by using the appropriate coefficients.

\Image[/typesetting-glue-adjustment.png]
{title=Proportional stretching and shrinking of <typesetting glue>}
{description=Original finite-glue example: boxes of widths 8,6,10; two gaps with nominal width 3, stretch coefficients 1 and 3, and shrink coefficients 1 each. The generator computes the adjustment ratios and resulting widths.}

<TeX> also distinguishes <typesetting glue orders>, so the finite model above does not describe every glue setting. In a horizontal line, <typesetting glue> changes gaps rather than stretching the outlines of the <glyphs>.