9.6 fontspec - Font selection for Unicode engines

In pdfTEX, fonts can be specified simply through calls to or through support packages that do those calls on behalf of the user. In Unicode engines this interface does not work because fonts in Unicode encoding (TU) usually do not have any supporting .fd files and so would not know how to load font shape declarations and alter the internal NFSS tables to access the requested fonts.

This is the price of the fact that with Unicode engines it is essentially possible to use any OpenType or TrueType font available on your computer without the need to first provide font metric files (.tfm) for TEX.

At the same time, directly using the low-level font loading facilities of the Unicode engines is not practical either, and so Will Robertson with contributions by Khaled Hosny, Philipp Gesang, and others developed the fontspec package that abstracts this loading process and provides a fairly simple and flexible interface to combine it with the powers of NFSS.

9.6.1 Setting up the main document font families

At its core, fontspec provides three declarations to set up three font families needed in most documents: a serif family, a sans serif family, and a typewriter family that then can be accessed through the usual NFSS commands, i.e., and r the corresponding declarative forms.

9.6.2 Setting up additional font families

Most of the time it is enough to set up the fonts for , , and with the declarations discussed above. However, sometimes one needs additional fonts for special cases. For example, you might want to use a specially condensed font for marginal notes or you want to define heading commands that use a different font family from the document body font and not just a bolder version of that. For such purposes you can define named font commands that work just like but select the desired family instead.

9.6.3 Setting up a single font face

Sometimes access to a single font face is wanted and there is no need to set up the whole family with all its different faces. In that case you might prefer over because that saves processing time and resources.

9.6.4 Interfacing with core NFSS commands

As mentioned before, the interface to NFSS is by default partly hidden, and all necessary setups are done behind the scenes by the fontspec declarations. As a result, it is possible to use the high-level NFSS commands such as

There are, however, ways to provide the necessary information as part of the feature-list argument in the fontspec declarations discussed thus far.

To explicitly name the font family, use the key NFSSFamily. A possible use case for this is shown in the next example, where we explicitly set the NFSS family name and then pass it to fancyvrb. Usually the high-level commands or newly defined ones, like , for changing the family are enough, so this is seldom needed.

9.6.5 Altering the look and feel of fonts

The interfaces of the fontspec package allow loading fonts with specific features enabled by specifying those in the form of key/value pairs. This can be done in the optional feature-list argument of any of the declarations. These features are then applied when loading and setting up the font family, e.g., the declaration

9.6.6 General configuration options

The interfaces of the fontspec package allow loading fonts with specific features enabled by specifying those in the form of key/value pairs. This can be done in the optional feature-list argument of any of the declarations. These features are then applied when loading and setting up the font family, e.g., the declaration

9.6.7 unicodefonttable - Displaying font tables for larger fonts

The nfssfont.tex file described in Section 9.5.9 does not help you if you are interested in looking for fonts to use with fontspec in Unicode engines, because it can only produce font tables displaying the first 256 glyphs of such a font and Opentype or TrueType fonts often contain several thousand glyphs.

To tabulate such fonts use the unicodefonttable package developed by the author. It offers you a flexible command to generate glyph tables for any font that can be used with Unicode TEX engines, either listing the full glyph set or any portion thereof.