9.7 The low level NFSS interface

While the high-level font commands are intended for use in a document, the low-level commands are mainly for defining new commands in packages or in the preamble of a document; see also Section 9.7.5. To make the best use of such font commands, it is helpful to understand the internal organization of fonts in LaTEX’s font selection scheme (NFSS).

One goal of LaTEX’s font selection scheme is to allow rational font selection, with algorithms guided by the principles of generic markup. For this purpose, it would be desirable to allow independent changes for as many font attributes as possible. On the other hand, font families in real life normally contain only a subset of the myriad imaginable font attribute combinations. Therefore, allowing independent changes in too many attributes results in too many combinations for which no real (external) font is available and a default has to be substituted.

LaTEX internally keeps track of five independent font attributes: the “current encoding”, the “current family”, the “current series”, the “current shape”, and the “current size”. The encoding attribute was introduced in NFSS release 2 after it became clear that real support of multiple languages would be possible only by maintaining the character-encoding scheme independently of the other font attributes.

The values of these attributes determine the font currently in use. LaTEX also maintains a large set of tables used to associate attribute combinations with external fonts (i.e., .tfm files that contain the information necessary for TEX to do its job). Font selection inside LaTEX is then done in two steps:

9.7.1 Setting individual font attributes

Every font attribute has one command to change its current value. All of these commands accept more or less any character string as an argument, but only a few values make sense. These values are not hardwired into LaTEX’s font selection scheme, but rather are conventions set up in the internal tables.

We have already used some of them in the previous sections; this section now covers all of the naming conventions used in the standard setup of LaTEX. Obviously, anybody setting up new fonts for use with LaTEX should try to obey these conventions whenever possible, because only a consistent naming convention can guarantee that appropriate fonts are selected in a generically marked-up document.

If you want to select a specific font using this interface — say, Computer Modern Dunhill bold condensed italic 14pt — a knowledge of the interface conventions alone is not enough, because for many of the combinations of the attributes there is no matching external font. You could try your luck by specifying something like the following set of commands:

9.7.2 Setting several font attributes

When designing page styles (see Section 5.4) or layout-oriented commands, you often want to select a particular font — that is, you need to specify values for all attributes. For this task LaTEX provides the command , which takes four arguments: the encoding, family, series, and shape. The command updates those attributes and then calls . If you also want to specify the size and baseline skip, place a command in front of it. For example,

9.7.3 Automatic substitution of fonts

Whenever a font change request cannot be carried out because the combination is not known to LaTEX, it tries to recover by using a font with similar attributes. Here is what happens: if the combination of encoding scheme, family, series, and shape is not declared (see Section 9.8.1), LaTEX tries to find a known combination by first changing the shape attribute to a default. If the resulting combination is still unknown, it tries changing the series to a default. As a last resort, it changes the family to a default value. Finally, the internal table entry is looked up to find the requested size. For example, if you ask for

The substitution process never changes the encoding scheme, because any alteration could produce wrong characters in the output. Recall that the encoding scheme defines how to interpret the input characters, while the other attributes define how the output should look. It would be catastrophic if, say, a £ sign were changed into a $ sign on an invoice just because the software tried to be clever.

Thus, every encoding scheme must have a default family, series, and shape, and at least the combination consisting of the encoding scheme together with the corresponding defaults must have a definition inside LaTEX, as explained in Section 9.8.3.

9.7.4 Substituting the font family if unavailable in an encoding

Given that pdfTEX can only handle fonts with up to 256 glyphs, a single font encoding can support only a few languages. The T1 encoding, for example, does support many of the Latin-based scripts, but if you want to write in Greek or Russian, you need to switch encodings to LGR or T2A. Given that not every font family offers glyphs in such encodings, you may end up with some default family (e.g., Computer Modern) that does not blend in well. For example, when typesetting in a sans serif font such as Montserrat, the Greek characters look rather out of place.

9.7.5 Using low-level commands in the document

The low-level font commands described in the preceding sections are intended to be used in the definition of higher-level commands, either in class or package files or in the document preamble.

Whenever possible, you should avoid using the low-level commands directly in a document if you can use high-level font commands like nstead. The reason is that the low-level commands are very precise instructions to switch to a particular font, whereas the high-level commands can be customized using packages or declarations in the preamble. Suppose, for example, that you have selected Computer Modern Sans in your document using . If you later decide to typeset the whole document with other fonts by applying some font support package, then this would change only those parts of the document that do not contain explicit commands.