Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

Chapter 6: Layouts and fonts

Section 6.2: Using fonts

with LuaLATEX and XƎLATEX

‘Why do we need more fonts?’ asked Bill Gates. ‘We’ve got a serif, a sans, and a monospace font. Why do we need more?’

Berry (2017)

The default typeface in LATEX is Computer Modern (CM). This typeface was created by Knuth for use with TEX. It is based on a Victorian book typeface, Monotype Series 8, because he designed TEX originally for typesetting books. Because it is one of the very few book typefaces with a comprehensive set of mathematical fonts, it has remained the default, rather than the variations on Times that you find in wordprocessors and other DTP systems (until recently the full set of mathematical symbols for Times were an expensive commercial add-on).

The standard distribution of TEX Live comes with about 130 OpenType and 75 TrueType typefaces (see § 6.2.2.1 below). There are also some 300 Postscript Type 1 typefaces (many of these are PS versions of the OT and TT faces), and about 165 legacy METAFONT (Postscript Type 3) typefaces, to preserve compatibility with older documents which use them.

LATEX can use more different types of font than any other system

  • The original LATEX could use any METAFONT font;

  • pdfLATEX could use any METAFONT or Postscript Type 1 font;

  • XƎLATEX and LuaLATEX can use any METAFONT or Postscript Type 1 or TrueType or OpenType font.

6.2.1 First time only: setting up fonts

for XƎLATEX and LuaLATEX

XƎLATEX and LuaLATEX let you use all your system fonts (those that came preinstalled with your computer and your non-TEX software) as well as the ones that came with your TEX distribution. There is one small piece of preparation to do, the very first time you use LATEX: index them (properly speaking, cache them) for fast access. After that, you only need to re-index them if you buy or download a new font.

Without this indexing, you can still use your system fonts in LATEX documents but you would have to type in where to find each font file every time, which is tedious.

There are four places where fonts are usually installed on Linux TEX systems:

  1. the system fonts directory (installed by your operating system, wordprocessor, and other ‘office’ software)

  2. the TEX distribution font directory (where the fonts go that came with TEX)

  3. the shared TEX additional fonts directory (only relevant for multi-user shared systems; traditionally this is where system managers would put extra fonts for everyone to use)

  4. the ‘local’ shared TEX fonts directory (only relevant for multi-user shared systems: traditionally this is where authorised users would put extra fonts for everyone to use)

  5. your Personal TEX Directory fonts subdirectory (where you put fonts you buy or download for your own use)

The last one (your Personal TEX Directory) is automatically searched by LATEX and never needs indexing, so it is not in the examples below.

Each fonts directory will normally have subdirectories for the different types of font, eg truetype, opentype, type1, etc.

6.2.1.1 Indexing your fonts under Linux

This section covers three types of Linux installation:

  1. TEX Live installed from the TUG DVD or download on any type of Linux (see the example ‘Font indexing in TEX Live installed from TUG DVD or download on Linux systems’ below)

  2. Debian and its derivatives like Ubuntu that share the .deb repositories (see the penultimate example ‘Font indexing in TEX Live installed from .deb repositories on Debian-based Linux systems’ below)

  3. Red Hat and its derivatives like CentOS that share the .rpm repositories (see the last example ‘Font indexing in TEX Live installed from .rpm repositories on RedHat-based Linux systems’ below)

Exercise 6.1 — Font indexing in TEX Live installed from TUG DVD or download on Linux systems

https://tug.org/texlive/doc/texlive-en/texlive-en.html#xetexfontconfig contains TUG’s online details which you can check for updates.

  1. Open a Command or Terminal window

  2. Become root by typing sudo su - and giving your password when asked

  3. Determine the location of your TEX Live installation by typing

    $ kpsewhich -var-value TEXMFSYSVAR
  4. Using the value of the location of $TEXMFSYSVAR found in step 3 above, copy the file at TEXMFSYSVAR/fonts/conf/texlive-fontconfig.conf to /etc/fonts/conf.d/09-texlive.conf

  5. Update the font cache:

    $ fc-cache -fsv

    (wait a few minutes while it caches your fonts).

  6. Type exit to leave superuser mode

  7. Close the window if you want

The principles are the same but the names of the directories differ slightly. If you have information on how this works on other types of distribution (eg Arch, SuSE, etc) please contact the author.

Exercise 6.2 — Font indexing in TEX Live installed from .deb repositories on Debian-based Linux systems

  1. Open a Command or Terminal window

  2. Become root by typing sudo su - and giving your password when asked

  3. Open your favourite text editor (eg emacs, vi, kate, gedit, etc)

  4. Create a new, empty file /etc/fonts/09-texlive.conf

  5. Copy and paste this configuration into the file:

    <?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <fontconfig>
      <!-- Fonts installed by Debian's tex* packages -->
      <dir>/usr/share/texlive/texmf-dist/fonts/opentype</dir>
      <dir>/usr/share/texlive/texmf-dist/fonts/truetype</dir>
      <dir>/usr/share/texlive/texmf-dist/fonts/type1</dir>
      <!-- Fonts installed on shared multiuser TeX systems -->
      <dir>/usr/share/texmf/fonts/opentype</dir>
      <dir>/usr/share/texmf/fonts/truetype</dir>
      <dir>/usr/share/texmf/fonts/type1</dir>
      <!-- Fonts pre-installed by the operating system -->
      <dir>/usr/share/fonts/opentype</dir>
      <dir>/usr/share/fonts/truetype</dir>
      <dir>/usr/share/fonts/type1</dir>
      <!-- Fonts added by users on some systems -->
      <dir>/usr/local/share/fonts/opentype</dir>
      <dir>/usr/local/share/fonts/truetype</dir>
      <dir>/usr/local/share/fonts/type1</dir>
    </fontconfig>
  6. Save the file

  7. Update the font cache:

    fc-cache -fsv

    (wait a few minutes while it caches your fonts).

  8. Type exit to leave superuser mode

  9. Close the window if you want

Exercise 6.3 — Font indexing in TEX Live installed from .rpm repositories on RedHat-based Linux systems

  1. Open a Command or Terminal window

  2. Become root by typing sudo su - and giving your password when asked

  3. Open your favourite text editor (eg emacs, vi, kate, gedit, etc)

  4. Create a new, empty file in /etc/fonts/ called 09-texlive.conf

  5. Copy and paste this configuration into the file:

    <?xml version="1.0"?> 
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 
    <fontconfig> 
      <dir>/usr/local/texlive/YYYY/texmf-dist/fonts/opentype</dir> 
      <dir>/usr/local/texlive/YYYY/texmf-dist/fonts/truetype</dir> 
      <dir>/usr/local/texlive/YYYY/texmf-dist/fonts/type1</dir> 
      <dir>/usr/local/texlive/texmf-local/fonts/opentype</dir> 
      <dir>/usr/local/texlive/texmf-local/fonts/truetype</dir> 
      <dir>/usr/local/texlive/texmf-local/fonts/type1</dir> 
      <dir>/usr/share/fonts</dir>
    </fontconfig>
  6. Replace YYYY with the year of your TEX Live distribution

  7. Save the file

  8. Update the font cache:

    fc-cache -fv

    (wait a few minutes while it caches your fonts).

  9. Type exit and close the window

6.2.1.2 Indexing your fonts under Windows

TEX Live installed from the TUG DVD or download on Windows systems needs no separate configuration, as the fc-cache program (included with TEX Live) is run automatically after installation.

If you intend adding new fonts that you have bought or downloaded, you should create a Personal TEX Directory with the appropriate subdirectories (eg fonts/truetype etc) and put the fonts in there. No indexing is then needed.

(Be aware that MiKTEX does require that you update MiKTEX’s File Name Database (FNDB) when you add new fonts or personal (non-CTAN) packages: see the mediaobject ‘…’ below for details.)

6.2.1.3 Indexing your fonts under Apple Mac OS X

The Apple Mac distribution of TEX Live, MacTEX, can already use the Mac systems fonts, but you need to add the TEX Live fonts via the FontBook app.

Exercise 6.4 — Font indexing in MacTEX on Apple Mac OS X systems

  1. Open the Finder

  2. Click on the Macintosh HD entry

  3. Press Shift--\splat--. (shift splat dot together) to reveal system folders

  4. Navigate to /usr/local/texlive/YYYY/texmf-dist (replacing YYYY with the year of your MacTEX distribution)

  5. In the menus, click FileAdd to Sidebar

  6. Open FontBook

  7. In FontBook, click + to add fonts

  8. In the Finder panel that opens, click the texmf-dist folder in the sidebar and navigate to the fonts/truetype subfolder

  9. Click Open

  10. If the system prompts for your password, type it in

  11. Wait. If a window opens saying some fonts fail validation, DO NOT install them

  12. Repeat from step 7 above for fonts/opentype

  13. When done, browse FontBook for fonts available to XƎLATEX and LuaLATEX

6.2.2 Set the default font family for a document

As explained in § 6.2 (this section), Computer Modern is the built-in default typeface, so that’s what you get if you don’t specify anything else. There are three ways to specify other typefaces and individual fonts: a ) by using a package; b ) by font name; or c ) by filename.

Using a package is more convenient, especially for whole typefaces, because the configuration of all the component fonts (eg roman, italic, bold, bold-italic, math, etc) has already been done by the package author, but font names or filenames let you specify your system (non-TEX) fonts, which packages cannot do.

6.2.2.1 OpenType and TrueType typeface packages for XƎLATEX and LuaLATEX

The list below gives packages for about 40 OpenType (OT) and TrueType (TT) typefaces installed with a full distribution of TEX, and below that another 20 or so which can be downloaded from CTAN. Both sets are listed in https://pkks.de/fontpackages.html.

(A few packages are not included here because they are not actually fonts in themselves, but ‘enabling’ packages which make specific combinations available for special purposes, such as the hep-font package for math combinations for the High Energy Physics community.)

Most of these packages support a default option, which sets them as the default font for the document, eg

\usepackage[default]{cabin}

will set the Cabin typeface as the default for the document. The fontspec package, which is required for using OT and TT fonts, is built into these packages and does not need to be specified separately.

  • ‘Sphinx of black quartz, judge my vow’ set with the Alegreya font package

  • ‘Sphinx of black quartz, judge my vow’ set with the almendra font package

  • ‘Sphinx of black quartz, judge my vow’ set with the bitter font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cabin font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cantarell font package

  • ‘Sphinx of black quartz, judge my vow’ set with the Chivo font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cinzel font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cochineal font package

  • ‘Sphinx of black quartz, judge my vow’ set with the coelacanth font package

  • ‘Sphinx of black quartz, judge my vow’ set with the comfortaa font package

  • ‘Sphinx of black quartz, judge my vow’ set with the crimson font package

  • ‘Sphinx of black quartz, judge my vow’ set with the CrimsonPro font package

  • ‘Sphinx of black quartz, judge my vow’ set with the dejavu-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the droidsans font package

  • ‘Sphinx of black quartz, judge my vow’ set with the droidserif font package

  • ‘Sphinx of black quartz, judge my vow’ set with the ebgaramond font package

  • ‘Sphinx of black quartz, judge my vow’ set with the forum font package

  • ‘Sphinx of black quartz, judge my vow’ set with the lato font package

  • ‘Sphinx of black quartz, judge my vow’ set with the libertine font package

  • ‘Sphinx of black quartz, judge my vow’ set with the libertinus-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the LibreBodoni font package

  • ‘Sphinx of black quartz, judge my vow’ set with the librecaslon font package

  • ‘Sphinx of black quartz, judge my vow’ set with the linguisticspro font package

  • ‘Sphinx of black quartz, judge my vow’ set with the marcellus font package

  • ‘Sphinx of black quartz, judge my vow’ set with the merriweather font package

  • ‘Sphinx of black quartz, judge my vow’ set with the newpxtext font package

  • ‘Sphinx of black quartz, judge my vow’ set with the newtxtext font package

  • ‘Sphinx of black quartz, judge my vow’ set with the noto-serif font package

  • ‘Sphinx of black quartz, judge my vow’ set with the OldStandard font package

  • ‘Sphinx of black quartz, judge my vow’ set with the opensans font package

  • ‘Sphinx of black quartz, judge my vow’ set with the quattrocento font package

  • ‘Sphinx of black quartz, judge my vow’ set with the Rosario font package

  • ‘Sphinx of black quartz, judge my vow’ set with the sourceserifpro font package

  • ‘Sphinx of black quartz, judge my vow’ set with the TheanoDidot font package

  • ‘Sphinx of black quartz, judge my vow’ set with the TheanoModern font package

  • ‘Sphinx of black quartz, judge my vow’ set with the TheanoOldStyle font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tinos font package

These packages represent a selection of typefaces from suppliers like Google; donated TEX sources like CTAN; foundries like Impallari, Summer Institute of Linguistics (SIL), Ascender, and many others; and learned societies and individuals. Those in the list above are installed with TEX Live; those in the list below can be downloaded and installed from CTAN.

  • ‘Sphinx of black quartz, judge my vow’ set with the accanthis font package

  • ‘Sphinx of black quartz, judge my vow’ set with the andika font package

  • ‘Sphinx of black quartz, judge my vow’ set with the caladea font package

  • ‘Sphinx of black quartz, judge my vow’ set with the CharisSIL font package

  • ‘Sphinx of black quartz, judge my vow’ set with the CormorantGaramond font package

  • ‘Sphinx of black quartz, judge my vow’ set with the fourier-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the garamondlibre font package

  • ‘Sphinx of black quartz, judge my vow’ set with the gfsneohellenicot font package

  • ‘Sphinx of black quartz, judge my vow’ set with the heros-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the ibarra font package

  • ‘Sphinx of black quartz, judge my vow’ set with the imfellEnglish font package

  • ‘Sphinx of black quartz, judge my vow’ set with the kpfonts-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the lexend font package

  • ‘Sphinx of black quartz, judge my vow’ set with the librebaskerville font package

  • ‘Sphinx of black quartz, judge my vow’ set with the noto font package

  • ‘Sphinx of black quartz, judge my vow’ set with the pagella-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the PlayfairDisplay font package

  • ‘Sphinx of black quartz, judge my vow’ set with the plex-serif font package

  • ‘Sphinx of black quartz, judge my vow’ set with the roboto font package

  • ‘Sphinx of black quartz, judge my vow’ set with the schola-otf font package

  • ‘Sphinx of black quartz, judge my vow’ set with the spectral font package

  • ‘Sphinx of black quartz, judge my vow’ set with the xcharter-otf font package

LATEX includes versions of the popular (some would say overused) Adobe ‘35’ fonts which have been built into PDF readers, laser printers, printer drivers, and most DTP systems since the dawn of desktop publishing shortly after TEX was written. These comprised eight text (Latin-alphabet) typefaces and two fonts of symbols or dingbats (35 fonts in total). They are now provided by non-Adobe versions known as the ‘TEX Gyre’ collection, derived from the URW (Unternehmensberatung Rubow Weber) equivalents shown in the list below.

  • ‘Sphinx of black quartz, judge my vow’ set with the tgadventor font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgbonum font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgchorus font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgcursor font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgheros font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgschola font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgpagella font package

  • ‘Sphinx of black quartz, judge my vow’ set with the tgtermes font package

(If you need the old Microsoft Symbol font, it can be downloaded, but Scott Pakin’s Comprehensive LATEX Symbol List is probably a better place to find symbols. The same applies to the Zapf Dingbats font, for which the bbding and marvosym packages provide alternatives. Jonathan Kew has posted details of how to access the actual Zapf Dingbats individually if required.)

The original Computer Modern typeface family was a METAFONT design by Donald Knuth, and was accompanied by a selection of other fonts, also made using METAFONT, some of which are in the list below

  • ‘Sphinx of black quartz, judge my vow’ set with the cmr font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cmss font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cmtt font package

  • ‘Sphinx of black quartz, judge my vow’ set with the panr font package

  • ‘Sphinx of black quartz, judge my vow’ set with the pss font package

  • ‘Sphinx of black quartz, judge my vow’ set with the pntt font package

  • ‘Sphinx of black quartz, judge my vow’ set with the uni font package

  • ‘Sphinx of black quartz, judge my vow’ set with the ccr font package

  • ‘Sphinx of black quartz, judge my vow’ set with the eiad font package

  • ‘Sphinx of black quartz, judge my vow’ set with the rust font package

  • ‘Sphinx of black quartz, judge my vow’ set with the uncl font package

  • ‘Sphinx of black quartz, judge my vow’ set with the cdr font package

The X Consortium donated a number of Latin-alphabet fonts in Postscript Type 1 format: have a look at Charter, Utopia, URW Antiqua Condensed, and URW Grotesk. There are hundreds of other fonts downloadable from CTAN: see Palle Jørgensen’s comprehensive LATEX Font Catalogue published by the Danish TEX Users Group, categorised by type (serif, sans, monospace, decorative, etc) with samples and links to the packages.

At any given time, TEX expects there to be three typefaces available: rm for Roman (Serif), sf for Sans-Serif, and tt for Typewriter (Monospace).

Font familyCode
Roman (serif, with tails on the uprights), the defaultrm
Sans-serif, with no tails on the uprightssf
Monospace (fixed-width or typewriter)tt

It is common to want to change all three defaults at the same time in order for new fonts to match each other. If a typeface provides Roman, Sans, and Monospace all in its own style, the package will change all three defaults automatically. Packages loading a single font family just load that one, so the others would remain Computer Modern. You can load another package for other fonts to replace them, or specify them individually as shown in the rest of this section.

6.2.2.2 OpenType and TrueType fonts and faces by fontname

The fontname of a font is the name that the designer declares is the name of the font family (like Cabin), or sometimes the name of the individual font (like Almendra-Bold). It is not the filename, although sometimes they happen to be the same. The fontname is the name you see in lists of fonts like the font dialog drop-down menu in editors.

font-dialog

You need the fontspec package to use OT and TT faces and fonts by fontname. This package provides three commands to select font families: \setmainfont (for the roman or main face); \setsansfont (for the sans-serif face); and \setmonofont (for the typewriter or monospace face). These all take one compulsory argument: the fontname of the font family or typeface (we will see in § 6.2.2.3 below how to do this with filenames).

Exercise 6.5 — Try setting up fonts by fontname

  1. Open a new LATEX file in your editor (pick a blank or epty one if your editor offers templates)

  2. Copy and paste this text into the file:

    \documentclass[12pt]{article}
    \usepackage{fontspec}
    \setmainfont{Crimson Pro}
    \setsansfont{Cabin Regular}
    \setmonofont{TeX Gyre Cursor}
    \AtBeginDocument{\LARGE}
    \begin{document}
    This is the main (default) font
    
    \sffamily This is the sans-serif font
    
    \ttfamily This is the monospace font
    \end{document}
  3. Process the document and examine the PDF. You may notice that the sans-serif font (Cabin) and the monospace font (Cursor)looks larger than the main font (Crimson), even though they are all set to the \LARGE size (about 18pt, see Table 6.4 below). This is because fonts are designed with different heights to the lowercase and uppercase characters.

  4. Compensate for this by adding the option Scale=MatchLowercase to the sans and mono commands:

    \setsansfont{Cabin Regular}[Scale=MatchLowercase]
    \setmonofont{TeX Gyre Cursor}[Scale=MatchLowercase]
  5. Reprocess and see that the sans and mono fonts have now been loaded at a size which matches the main font

There are packages for the TEX Gyre fonts, like tgcursor (they all start with tg), have a matchlowercase package option which does this scaling.

Most of the time that’s all you need.

You can find the fontnames of any of your installed fonts by using your font browser or indexing command provided by your operating system.

font-selector

On Unix & GNU/Linux systems, and on Windows systems with TEX Live installed, the command fc-list can be used to list your installed fonts, giving the filename (location), fontname (and synonyms), and the style, eg

$ fc-list Cabin
/usr/share/fonts/opentype/
  cabin/Cabin-Bold.otf: Cabin:style=Bold
  cabin/Cabin-BoldItalic.otf: Cabin:style=Bold Italic
  cabin/Cabin-Italic.otf: Cabin:style=Italic
  cabin/Cabin-Medium.otf: Cabin:style=Medium
  cabin/Cabin-MediumItalic.otf: Cabin:style=Medium Italic
  cabin/Cabin-Regular.otf: Cabin:style=Regular
  cabin/Cabin-SemiBold.otf: Cabin:style=SemiBold
  cabin/Cabin-SemiBoldItalic.otf: Cabin:style=SemiBold Italic
/usr/share/texlive/texmf-dist/fonts/opentype/
  impallari/cabin/Cabin-Bold.otf: Cabin:style=Bold
  impallari/cabin/Cabin-BoldItalic.otf: Cabin:style=Bold Italic
  impallari/cabin/Cabin-Italic.otf: Cabin:style=Italic
  impallari/cabin/Cabin-Medium.otf: Cabin:style=Medium
  impallari/cabin/Cabin-MediumItalic.otf: Cabin:style=Medium Italic
  impallari/cabin/Cabin-Regular.otf: Cabin:style=Regular
  impallari/cabin/Cabin-SemiBold.otf: Cabin:style=SemiBold
  impallari/cabin/Cabin-SemiBoldItalic.otf: Cabin:style=SemiBold Italic

From which you can see that, on my own system, I have Cabin installed twice: once by the operating system and once by TEX Live. The important bit is between the first and second colons: the fontname Cabin, in this case a font family because there are no other values. Each entry gives the filename, the fontname, and any variants, separated by colons. If I do the same for Almendra, I get:

$ fc-list Almendra
/usr/share/texlive/texmf-dist/fonts/truetype/public/
  almendra/AlmendraSmallCaps.ttf: AlmendraSmallCaps:style=Regular
  almendra/Almendra-Bold.ttf: Almendra:style=Bold
  almendra/Almendra-Regular.ttf: Almendra:style=Regular
  almendra/Almendra-BoldItalic.ttf: Almendra:style=Bold Italic
  almendra/Almendra-Italic.ttf: Almendra:style=Italic

Some font entries have multiple values for the fontname, separated by commas, like Alegreya,Alegreya Black. In these cases the font family’s fontname is the first one (before the first comma).

6.2.2.3 OpenType and TrueType fonts and faces by filename

Both TT and OT fonts are usually named in a pattern where the font family name (eg LiberationSerif, all one word) is followed by the variant (regular, italic, bold, bold-italic, etc) separated by a hyphen or underscore character, or sometimes by ‘camel-casing’, where descriptors starting mid-word use a capital letter. Here is the directory listing of my installation of the Liberation typeface:

$ ls -l /usr/share/fonts/truetype/liberation
total 2088
-rw-r--r-- 1 root root 118296 Feb 22  2020 LiberationMono-BoldItalic.ttf
-rw-r--r-- 1 root root 105460 Feb 22  2020 LiberationMono-Bold.ttf
-rw-r--r-- 1 root root 124012 Feb 22  2020 LiberationMono-Italic.ttf
-rw-r--r-- 1 root root 108172 Feb 22  2020 LiberationMono-Regular.ttf
-rw-r--r-- 1 root root 135124 Feb 22  2020 LiberationSans-BoldItalic.ttf
-rw-r--r-- 1 root root 137052 Feb 22  2020 LiberationSans-Bold.ttf
-rw-r--r-- 1 root root 162036 Feb 22  2020 LiberationSans-Italic.ttf
-rw-r--r-- 1 root root 128468 Feb 22  2020 LiberationSansNarrow-BoldItalic.ttf
-rw-r--r-- 1 root root 110252 Feb 22  2020 LiberationSansNarrow-Bold.ttf
-rw-r--r-- 1 root root 132452 Feb 22  2020 LiberationSansNarrow-Italic.ttf
-rw-r--r-- 1 root root 113028 Feb 22  2020 LiberationSansNarrow-Regular.ttf
-rw-r--r-- 1 root root 139512 Feb 22  2020 LiberationSans-Regular.ttf
-rw-r--r-- 1 root root 151452 Feb 22  2020 LiberationSerif-BoldItalic.ttf
-rw-r--r-- 1 root root 147132 Feb 22  2020 LiberationSerif-Bold.ttf
-rw-r--r-- 1 root root 145028 Feb 22  2020 LiberationSerif-Italic.ttf
-rw-r--r-- 1 root root 152408 Feb 22  2020 LiberationSerif-Regular.ttf

As you can see, there are four families of the Liberation typeface: Mono, Sans, Sans Narrow, and Serif. In each case there is a Regular (roman), Italic, Bold, and Bold Italic variant. The fontspec lets you load a font by specifying the filetype (extension) of the font file, where it is installed (the path), and how the font filenames fit the pattern:

\setmainfont{LiberationSerif}[Extension=.ttf,
  Path=/usr/share/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]

The pattern-matching is done by an asterisk which gets replaced by the font family name you give in the first argument, and the filetype (extension) is added to the end, so that fontspec can construct the whole filename. Repeating this for the sans and mono variants gives us the full set (the Narrow face is an exception and less commonly used):

\setsansfont{LiberationSans}[Extension=.ttf,
  Path=/usr/share/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]
\setmonofont{LiberationMono}[Extension=.ttf,
  Path=/usr/share/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]

These three now automatically fill the LATEX roles of the rm, sf, and tt families. The advantage of using filenames is that you do not have to rely on XƎLATEX and LuaLATEX accessing the fonts via the font index/cache system, as it goes straight to the filename in the directory you specify.

If you are mixing OT or TT fonts from different families, you can use the Scale=MatchLowercase option for the sans and mono setups, making them scale to match the roman face, exactly as in the example ‘Try setting up fonts by fontname’ above.

6.2.3 Changing the font-family temporarily

To use a different font [family] for a specific purpose, use the command \newfontfamily. This works exactly the same as the commands above for setting the main, sans, and mono font families but takes an extra parameter first, to specify the command you want it known by, so it does not replace the Roman, Sand, or Monospace defaults but is available in addition to them. To make the command \tablesfont invoke Liberation Sans Narrow, for example, you would use:

\newfontfamily{\tablesfont}{Liberation Sans Narrow}
If you want to use the filename, the format is:
\newfontfamily{\tablesfont}{LiberationSansNarrow}[
  Extension=.ttf,
  Path=/home/peter/texmf/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]

Then the new command (here, \tablesfont) can be used to switch to that typeface.

To load a solitary font (that is, not a whole family), there is a command \newfontface, which also works in the same way, by creating a new command to switch to it.

\newfontfamily{\headlinefont}{LobsterTwo-Bold}
  [Extension=.otf,
   Path=/usr/share/fonts/opentype/lobstertwo/]
...
{\centering\headlinefont\fontsize{20}{24}\selectfont
  Lobster Rolls\dotfill \$3.95\par}

\centering\headlinefont \fontsize{20}{24}\selectfont Lobster Rolls\dotfill \$3.95

These commands created by \newfontfamily, like the ones in Table 6.2 below, are called ‘unscoped’ because they have global effect from that point on. In order to restrict the effect to a smaller scope (a few words, for example), you MUST put the command and the text inside a group (enclosed in curly braces as in the example, or within an environment), otherwise they will apply to the end of the document. See the sidebar ‘Grouping’ below for more detail.

In a normal document, of course, arbitrary typeface changes like this are rare: people don’t (or at least, probably shouldn’t) randomly flip from one font to another. You select your default typefaces once, using packages or commands, at the start of the document, and stick with them — bold and italics are handled by the document class or stylesheet packages you use.

However, in advertising or magazines, a wide range of typefaces changes is common, but they are usually part of predefined styles for handling that type of formatting, built into the document class, so it is rare to have to do them manually.

Most cases where people want unusual typeface changes involve things like special symbols or effects on a repetitive basis, and LATEX provides much easier (programmable) ways to make these changes into shorthand commands (called macros: see Chapter 7 ‘Programmability’ below).

This is jumping ahead a bit, but you could, for example, define a new macro called \product which would let you typeset product names in a distinct typeface (usually italics):

Andlinger, Inc., has replaced \product{Splosh} with 
\product{SuperSplosh}.

This is one of LATEX’s most powerful features. It means that if you needed to change your \product command at some later stage to use a different font, you only have to change the font-family name in the macro, and you don’t need to edit your document text at all. What’s more, a macro could do other things at the same time, like add an entry to an index of products.

Vastly more common are changes to type style, while staying within the same font-family.

6.2.4 Changing type style

Within each typeface or font family there are usually several different ‘looks’ to the type design. LATEX distinguishes mainly between font shape and font series. Italics is a shape (look carefully: the actual shape of the letters changes, as well as their slope); whereas bold is a series (same shapes, same slope, just thicker strokes).

Table 6.2: Typeface styles, families, shapes, and series (unscoped)

Type styleCommandExample
Upright\upshape*The quick brown fox jumps over the lazy dog
Italic\itshape
Slanted\slshape*
Small Caps\scshape*
Bold\bfseries*
Extended\bfseries
Sans-serif\sffamilyThe quick brown fox jumps over the lazy dog
Monospace\ttfamilyquick brown fox jumps over the lazy
  • These are unscoped commands (see the sidebar ‘Scope and style’ below).

  • *  Not all typefaces have all variants! Some only have bold and italics.

  • †  Some typefaces do not have both bold and bold extended: by default LATEX uses \bfseries for bold extended.

Beware of pushing your fonts beyond their limits unless you have typographic skills. It is not normally meaningful to combine one shape or series class with another of the same class, such as trying to get slanted-italics. It’s also sometimes impossible to combine one family with another (such as seriffed sans-serif type!). Slanted plus italics, for example, doesn’t make any sense, as italics are already slanted; and while some typefaces may well possess sans-serif italic small caps, they are not in common use.

If you really feel you need such combinations, try the fontaxes package, which splits the ‘shape’ axis into a primary axis (upright, italic, slanted, upright italic, etc) and a secondary axis (small caps on or off). It redefines the \itshape and \scshape commands to combine instead of override each other. The fontspec package loads fontaxes. So do many legacy font packages. (Thanks to @Davislor on tex.stackexchange for this information.)

Sans-serif and monospace (typewriter) are not just different fonts, they are often different typeface families entirely.

To avoid the problem of forgetting to put curly braces around the commands and text you want formatted, there is an alternative set of scoped commands for the most common type shape and series commands. These use curly braces in the ‘argument’ manner, so their effect applies only to the text in curly braces. These are the normal commands for changing the style of a word or phrase.

Table 6.3: Typeface styles, families, shapes, and series (scoped)

Type styleCommandExample (using Computer Modern)
Italic\textit{text}puts text into italics
Slanted\textsl{text}puts text into slanted type*
Small Capitals\textsc{text}puts TEXT into small caps
Bold\textbf{text}puts text into bold type
Sans-serif\textsf{text}puts text into sans-serif type
Monospace\texttt{text}puts text into typewriter type
  • *  If slanted is available separately from italics.

These are commutative too, so you can nest them inside one another:

...\textbf{bold \itshape{italic \textsf{sans-serif}}} type...

What we know as underlining isn’t a font: it was used in the days of typewriters where italics were not available, and it is extremely rare in typography except for specialist purposes. If you think you need it, use the ulem package with the normalem option, which provides a \uline command.

6.2.5 Font sizes

LATEX has built into its defaults a set of predefined font size steps corresponding more or less to the traditional sizes available to metal typesetters. This is deliberate, as these sizes have grown up over 500 years of experience in printing as those which go best together for book-work, which is where TEX originated.

Table 6.4: LATEX font step sizes

CommandExampleNominal point sizeExact point size
\tinyThe quick brown fox jumps over the lazy dog55
\scriptsizeThe quick brown fox jumps over the lazy dog77
\footnotesizeThe quick brown fox jumps over the lazy dog88
\smallThe quick brown fox jumps over the lazy dog99
\normalsizeThe quick brown fox jumps over the lazy dog1010
\largeThe quick brown fox jumps over the lazy dog1212
\LargeThe quick brown fox jumps over the lazy dog1414.40
\LARGEThe quick brown fox jumps over the lazy dog1817.28
\hugeThe quick brown fox jumps over the lazy dog2020.74
\HugeThe quick brown fox jumps over the lazy dog2424.88
  • •  Note that these are unscoped commands (see the sidebar ‘Scope and style’ above), so they should be used inside a group, either an environment or a set of curly braces terminated with a \par inside the closing brace. There are no scoped equivalents of these commands.

  • •  Mathematics users should not confuse the text-mode \scriptsize command here with mathematics-mode \scriptstyle. [Thanks to Doug McKenna and David Carlisle on the TEXhax mailing list.]

These sizes are also reflected in the size steps at which Computer Modern was designed in the METAFONT program. It often comes as a surprise to new users that many typefaces are not designed as a single font and just scaled up or down, but specially drawn at different sizes to make them more legible.

As an example, , and {\font\cmbig=cmr5 at12pt\cmbig here's 5pt Computer Modern scaled up to 12pt}, and {\font\cmsmall=cmr17 at12pt\cmsmall here's 17pt Computer Modern scaled down to 12pt} so you can see there really is a significant difference.

Modern type formats have hinting parameters that allow scaling to implement the effects of design-sizes, but in general, you probably don’t want to go scaling fonts too far beyond their design size because the spacing will start to look very odd.

  • The default sizes (and the commands that operate them) are based on the use of a 10pt font, which is the default size for book work.

  • Using the larger document class options (11pt and 12pt) will use 11pt and 12pt designs (explicit or hinted), with the other sizes (such as for headings) rescaled to match.

  • The exact sizes used are listed in the macros in the Class Option files size10.clo, size11.clo and size12.clo.

  • LATEX’s default fonts above 10pt are in fact scaled by a factor of 1.2, as shown in the fourth column of Table 6.4 above.

While these shorthand commands relieve the beginner of having to worry about the appropriate point-size for a given task, if you need very specific sizes you can use the \fontsize command to specify exact sizes. This takes two arguments: the point size and the baseline distance. The example below gives you 22pt type on a 28pt baseline (ie with 6pt extra space or ‘leading’ between the lines).

{\fontsize{22}{28}\selectfont The example below gives you
  22pt type on a 28pt baseline (ie with 6pt extra space or
  `leading' between the lines).\par}

\fontsize{22}{28}\selectfont The example below gives you 22pt type on a 28pt baseline (ie with 6pt extra space or ‘leading’ between the lines).

The term ‘leading’ comes from the old metal-type practice of adding a strip of typemetal between the lines, or casting the type on a deeper body, to increase the line spacing, so it’s pronounced ‘ledding’ after the metal.

If you are using pdflatex or the original latex processor, you will need to use the fix-cm package to override the step sizes. This needs special placement: it MUST come at the start of the document, even before the \documentclass command, and MUST be invoked with the \RequirePackage command normally used only by document class designers:

\RequirePackage{fix-cm}
\documentclass{article}
...

6.2.6 Logical markup

All this playing around with fonts is very pretty but you normally only do it for a reason, even if that reason is just to be decorative. Italics, for example, are used for many things:

CauseEffect
Foreign wordsex officio
Scientific namesRanunculus ficaria
Emphasismust not
Titles of documentsAccounting in Business
Product namesCorel WordPerfect
Variables in mathsE=mc²
Subtitles or headings42. How to get started
Use of a letter as a wordWho knocked the L out of London?
DecorationFREE UPGRADE!!!

Humans usually have no problem telling the difference between these reasons, because they can read and understand the meaning and context, and we’ve been exposed to many of these meanings since we started to read. Computers cannot (yet) do this reliably, so it has become conventional to use descriptive names which make the distinction explicit, even though the appearance may be the same.

LATEX has some of these built in, like \emph, which provides emphasis. This has a special feature because when the surrounding text is already italic, emphasis automatically reverts to upright type, which is the normal practice in typesetting.

This has a special feature because {\itshape when 
the surrounding text is already italic, 
\emph{emphasis} automatically reverts to 
\emph{upright type}}, which is the normal practice 
in typesetting.

This sensitivity to logic is programmed into the definition of \emph and it’s not hard to make up other commands of your own which could do the same, such as \foreign or \product.

But why would you bother? In a short document it’s probably not important, but if you’re writing a long report, or a formal document like an article, a book, or a thesis, it makes writing and editing hugely easier if you can control whole groups of special effects with a single command, such as italicising, indexing, or cross-referencing to a glossary. If a format needs changing, you only have to change the definition, and every occurrence automatically follows suit.

A warning from the past

Beware of this ‘vaine conceipt of simple men, which judge things by ther effects, and not by ther causes’. (Edmund Spenser, 1633)

It’s hugely more efficient and productive to have control of the cause than the effect.

It also makes it possible to find and act on groups of meanings — such as making an index of scientific names, or retrieving all product names — if they are identified as such. Otherwise you’d spend weeks hunting manually through every \textit command to find the ones you wanted. This is the bottom line of automation: it can save you time and money.

In Chapter 7 ‘Programmability’ below we will see how to make your own simple commands to do things like this.

6.2.7 Colour

You can typeset anything in LATEX in any colour you want using the xcolor package. Adding the command \usepackage{xcolor} to your Preamble (note the US spelling of color) makes available a default palette of primary colours: red, green, and blue for the RGB colour model used for emitted light (computer and television screens), and cyan, magenta, yellow, and black for the CMYK colour model used for reflected light (printing).

For the occasional word or phrase in colour, use the command \textcolor with two arguments, the colour name and the text: \textcolor{red}{like this} to get red like this. There is an unscoped \color command as well, for use within groups:

...{\color{blue}some text in blue}...

There are several package options for additional colours: two popular ones are dvipsnames, which provides a 64-colour palette of predefined colour names exactly matching the big box of 64 Crayola™ colouring pencils much favoured by artists and designers; and svgnames, which provides the 256 colours defined in the specification for the Scalable Vector Graphics (SVG) drawing and diagramming language (which includes the 64 colours of dvipsnames). There are others too: see the documentation for the xcolor package.

If you want the Crayola colour Crimson, and you have loaded xcolor with the svgnames or dvipsnames option, you can use it as a colour name (colour names are case-sensitive):

{\color{Crimson}some red text}
\textcolor{Crimson}{some red text}

As some of the predefined colour names are quite long, you can create a short name of your own for colours you use frequently, using the \definecolor command:

\definecolor{mb}{named}{MidnightBlue}

The \definecolor command needs three arguments: your shorthand name, the name of the colour model, and the colour specification. In the case of the named model, the last argument is one of the colour names specified by the named option you loaded the package with.

Using the \definecolor command, you can also define any colour you want by giving it a name, specifying which colour model, and providing the Red-Green-Blue (RGB) or Cyan-Magenta-Yellow-Black (CMYK) colour values expressed as decimal fractions of 255, separated by commas. For example, an RGB colour given as (37,125,224) in decimal integer form can be given as:

\definecolor{midblue}{rgb}{0.145,0.490,0.882}

To get the fractional value, divide the integer value by 255, the maximum for each of the hues in the Red-Green-Blue colour model. You can then use \textcolor with your new colour name: midblue looks like this if you’re reading in colour. Alternatively, use the HTML hexadecimal colour model, the same as used in web pages and CSS stylesheets:

\definecolor{midblue}{HTML}{250FE0}

The xcolor package also provides two colour versions of \fbox (see § 4.6.2 above) called \colorbox and \fcolorbox which create a box with a coloured background:

\colorbox{midblue}{\color{magenta}Magenta on midblue}

The material in the second argument can have its own text colour, as in the example. The \fcolorbox has an extra first argument to specify the colour of the frame or border placed around the box. The border width is controlled by the \fboxrule setting and the separation between rule and content is controlled by the \fboxsep setting as we already saw in § 4.6.2 above.

However, combining colours is an art and a skill: using the command above to get the effect magenta on midblue illustrates why it is important to learn about colour models and palettes before trying to use them!

  1. In some cases, FontBook may believe them to have missing tables, and in others, they may duplicate existing Mac system fonts, and FontBook’s behaviour seems to be to use the TEX Live fonts in preference to its own. 

  2. The licence for Utopia does not allow it to be distributed automatically to users, but you can download it personally. 

  3. Although if you’re a typographer wanting to experiment with typewriter typefaces with and without serifs, you can use METAFONT or FontForgeto do exactly this kind of thing. But that’s way outside the scope of this document.