Using Opentype Fonts in Lual Tex: A Will Robertson January 5, 2019
Using Opentype Fonts in Lual Tex: A Will Robertson January 5, 2019
Will Robertson
January 5, 2019
1 Introduction
This is an example of using the fontspec package in LuaLATEX (which is
LATEX running on the LuaTEX engine). Follow along in the source to see
how it works.
You’re probably familiar with using pdfLATEX and selecting a few dif-
ferent fonts by loading a few different packages, such as mathpazo for
Palatino and mathptmx for Times New Roman. LuaLATEX with the fontspec
package allows you to use not just pre-packaged TEX fonts, but almost
every font installed in your computer.
To start, put \usepackage{fontspec} in the preamble of your docu-
ment. At the very beginning, you’ll be interested in using three main
commands:
\setmainfont \setsansfont \setmonofont
These three commands specify the fonts to use for the default roman,
sans serif, and typewriter (or monospaced) fonts, respectively. They all
take the same arguments: one optional argument to specify font features
and a mandatory argument for the font name. A typical example is
\setmainfont[Numbers=OldStyle]{TeX Gyre Pagella}
2 Installing fonts
The first time that you run fontspec, a database of font names must be
created based on the fonts installed in your computer. This can take
several minutes, so don’t worry if it seems like LuaTEX has hung while
compiling your document. It’s only slow the first time.
LuaLATEX will find fonts in the following folders:
~/Library/Fonts /Library/Fonts
/System/Library/Fonts /Network/Library/Fonts
1
as well as in any folders searched by TEX, including
~/Library/texmf/fonts/opentype/*/*
/usr/local/texlive/texmf-local/fonts/opentype/*/*
LuaLATEX is able to load fonts with extensions .otf, .ttf, and .dfont.
Unfortunately many of the bundled fonts in Mac OS X 10.6 (Snow Leop-
ard) are distributed as .ttc fonts, which currently do not work in LuaTEX.
These include ‘Hoefler Text’, ‘Cochin’, ‘American Typewriter’, and others.
3 Loading fonts
Fonts may be loaded by font name or by file name. For example, the
following two commands are equivalent:
However, when you load fonts by their name (not filename), fontspec will
attempt to automatically locate any accompanying bold and italic fonts.
If you need to specify these manually, the syntax is
\setmainfont [
ItalicFont = texgyrepagella-italic.otf ,
BoldFont = texgyrepagella-bold.otf ,
BoldItalicFont = texgyrepagella-bolditalic.otf ,
] {texgyrepagella-regular.otf}
4 Font features
OpenType fonts can be created with in-built font features that allow cus-
tomisation in the way the font looks. For example, your font might have
both lining numerals (0123456789) and old-style numerals (012356789).
You would choose between these with either, respectively,
2
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
Unlike regular LATEX, you may also scale the relative sizes of the fonts
as you load them. The amount of scaling can be specified either nu-
merical (Scale=1.1) or fontspec can automatically scale a font to match
either the uppercase or lowercase letters of the default font; either one
of
All of the font features above can be combined as you like, just sep-
arate multiple features with commas:
\setsansfont
[Ligatures=TeX, Scale=MatchLowercase]
{Latin Modern Sans}
There are many, many font features you can choose from. See the
fontspec documentation for a full listing.
5 Using Unicode
LuaTEX fully supports Unicode input, which makes it ideal for multilin-
gual documents. As a very brief example, consider the following:
Take a look at the source to this document; it looks exactly like the
output; each letter can be typed directly without needing macros for
the accents or letters.
Multilingual typesetting can become a little more involved than just
typing in the Unicode letters; it’s important to adjust the hyphenation for
different languages and it’s often necessary to switch fonts for different
scripts. But you get the idea.