TeX provides the commands `\vfil`

and `\vfill`

(and their corresponding horizontal versions `\hfil`

and `\hfill`

).

These commands are actually defined as:

```
\vskip 0cm plus 1fil
\vskip 0cm plus 1fill
```

where 'fil' and 'fill' (and in fact `filll`

) are units of infinite glue with increasing orders of infinity. Here's a quote from the TeXBook (p. 71):

TeX actually recognizes several kinds

of infinity, some of which are “more

infinite” than others. You can say

both`\vfil`

and`\vfill`

; the second is

stronger than the first. In other

words, if no other infinite

stretchability is present,`\vfil`

will

expand to fill the remaining space;

but if both`\vfil`

and`\vfill`

are

present simultaneously, the`\vfill`

effectively prevents`\vfil`

from

stretching. You can think of it as if

`\vfil`

has one mile of stretchability,

while`\vfill`

has a trillion miles.

This much I know, at least in theory, and I also know that I can use the `fil`

and `fill`

versions of the spacing commands with different effects.

What I'm less clear on, is why the commands work the way they do, and what the whole concept of "infinite glue" actually means.

So can someone help to elucidate the Knuth quote a bit?

## Best Answer

Let's look at the simplest case

Among the

`<horizontal material>`

there will be also glue, implicit (that is, space tokens) or explicit (`\hskip`

commands).TeX maintains two four dimensional vectors in order to compute the glue ratio, say

vfor thestretchingandwfor theshrinking. A glue such ascontributes 2pt to the first component of

vand 1pt to the first component ofw. A glue such ascontributes 1 to the second component of

vand 0.5 to the third component ofw. At the end we'll haveand similarly for

w, where the components are the sum of all contributions. TeX also maintains the sum of the natural widths of characters, boxes and glues in the`<horizontal material>`

.When TeX has finished gathering the material for the

`\hbox`

, it compares the natural width to the desired box width (in our example to`\hsize`

) and decides what to do. If the natural width is equal to the desired width, it typesets the box. Otherwise it decides that it has to stretch or shrink the glue. In the former case it looks atvand in the latter tow.Let's look at the stretching case (the other is similar). If

vis zero, there' little to do: there's no glue or the glues all cancel with each other: the box will be underfull.Otherwise one entry in

vwill be different from zero; TeX will choose the rightmost non-zero component. This is the order of infinity thatwins(it may be the "finite" component). The excess space to fill is then distributed proportionally among the glues that contributedthatorder of infinity.Let's look at some examples

The box must stretch by 3cm (it's a convenient syntax for doing experiments of this kind), so we have to compute

v=(2pt,3,0,0). The first-order infinity wins, so the excess space will be divided adding 1cm between B and C, and 2cm between C and D; between A and B there will be a 4pt wide space (no stretching). The result is ( denotes the resulting space)Let's see with

Here

v=(2pt,2,1,0), so the second-order infinity wins and the 3cm wide space will go between B and C:Third order infinities are rarely used, but they are there for emergency cases when one has to cancel second order infinities.

The coefficient before

`fil(ll)`

should be a decimal number less than 16384 in absolute value (there must be one). The minimum non-zero value is`2^(-16)=0.000015`

, so saying`0.000014filll`

is equivalent to say`0filll`

(and useless, of course).TeX has some primitives equivalent to glue specifications:

The same algorithm is used for shrinking, but no glue will be stretched to become less than its natural width, while all glues may be used for stretching (possibly resulting in an underfull box). The same holds for vertical boxes.