19.5 \spacefactor



Influence LaTeX’s stretching and shrinking of glue. Few user-level documents need to use this.

While LaTeX is laying out the material, it may stretch or shrink the gaps between words. (This space is not a character; it is called the interword glue; see \hspace). The \spacefactor parameter (a TeX primitive) allows you to, for instance, have the space after a period stretch more than the space after a word-ending letter.

After LaTeX places each character, or rule or other box, it sets a parameter called the space factor. If the next thing in the input is a space then this parameter affects how much stretching or shrinking can happen. A space factor that is larger than the normal value means that the glue can stretch more and shrink less. Normally, the space factor is 1000. This value is in effect following most characters, and any non-character box or math formula. But it is 3000 after a period, exclamation mark, or question mark, 2000 after a colon, 1500 after a semicolon, 1250 after a comma, and 0 after a right parenthesis or bracket, or closing double quote or single quote. Finally, it is 999 after a capital letter.

If the space factor f is 1000 then the glue gap will be the font’s normal space value (for Computer Modern Roman 10 point this is 3.3333pt). Otherwise, if the space factor f is greater than 2000 then TeX adds the font’s extra space value (for Computer Modern Roman 10 point this is 1.11111pt), and then the font’s normal stretch value is multiplied by f /1000 and the normal shrink value is multiplied by 1000/f (for Computer Modern Roman 10 point these are 1.66666 and 1.11111pt).

For example, consider the period ending ‘A man's best friend is his dog.’. After it, TeX puts in a fixed extra space, and also allows the glue to stretch 3 times as much and shrink 1/3 as much, as the glue after friend or any of the other words, since they are not followed by punctuation.

The rules for space factors are even more complex because they play additional roles. In practice, there are two consequences. First, if a period or other punctuation is followed by a right parenthesis or bracket, or right single or double quote then the spacing effect of that period carries through those characters (that is, the following glue will have increased stretch and shrink). Second, if punctuation comes after a capital letter then the normal effect of the period is does not happen, so you get an ordinary space. This second case also affects abbreviations that do not end in a capital letter (see \@).

You can only use \spacefactor in paragraph mode or LR mode (see Modes). You can see the current value with \the\spacefactor or \showthe\spacefactor.

Finally, not especially related to \spacefactor itself: if you get errors like ‘You can't use `\spacefactor' in vertical mode’, or ‘You can't use `\spacefactor' in math mode.’, or ‘Improper \spacefactor’ then you have probably tried to redefine an internal command. See \makeatletter & \makeatother.

Unofficial LaTeX2e reference manual