-
Notifications
You must be signed in to change notification settings - Fork 5
/
fonts.tex
323 lines (298 loc) · 12.7 KB
/
fonts.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
\chapter{Fonts}
\label{fonts}
Digital fonts have completely changed since \LaTeX{} was created decades ago.
\LaTeX{} originally used \MF,
a format Donald Knuth designed specifically for \TeX{}.
As time went on, support for PostScript\footnote{One of
Adobe's original claims to fame,
PostScript is a language for defining and drawing computer graphics,
including type. It remains in widespread use today.} fonts was added.
Today, \LuaLaTeX{} and \XeLaTeX{} support the modern font formats you will find
on your computer:
TrueType and OpenType.\punckern\footnote{Mac versions of \LaTeX{} also support
Apple's \acronym{aat}, but let's limit this discussion to
more common formats.}
\begin{description}
\item[TrueType] was developed by Apple and Microsoft in the late 1980s.
Most fonts that come pre-installed on your system are probably
in this format.
TrueType files generally end in a \monobox{.ttf} extension.
\item[OpenType] was first released by Microsoft and Adobe in 1996.
Improvements over TrueType include its ability to embed
various features, such as alternative glyphs
and spacing options, into a single file.
OpenType files usually end in an \monobox{.otf} extension.
\end{description}
\section{Changing fonts}
By default, \LuaLaTeX{} and \XeLaTeX{} use Latin Modern,
an OpenType rendition of \LaTeX's original type family, Computer Modern.
While these are high-quality fonts,
they are not the only ones you ever want to use.
For other fonts, we turn to the \texttt{fontspec} package:
\begin{leftfigure}
\begin{lstlisting}
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Source Serif Pro}
\setsansfont[Ligatures=TeX]{Source Sans Pro}
\setmonofont{Source Code Pro}
\begin{document}
Hello, Source type family! Neat---no? \\
\sffamily Let's try sans serif! \\
\ttfamily Let's try monospaced!
\end{document}
\end{lstlisting}
\end{leftfigure}
should produce something like\footnote{Assuming, of course,
that you have Adobe's open-source fonts installed.\punckern\endnote{Adobe's
open-source typefaces are freely available at
\https{github.com/adobe-fonts}}}
\begin{leftfigure}
% lol it's bugged currently
\fontspec[Ligatures=TeX]{Source Serif Pro} Hello, Source type family! Neat—no? \\
\fontspec[Ligatures=TeX]{Source Sans Pro} Let's try sans serif! \\
\fontspec{Source Code Pro} Let's try monospaced!
\end{leftfigure}
The \verb|Ligatures=TeX| option lets you use the punctuation
shortcuts from \chapref{punctuation} (\texttt{--} for en dashes,
\texttt{``} and \texttt{''} for curly quotes, etc.)
instead of forcing you to enter the corresponding characters,
which probably aren't on your keyboard.
You usually don't want these substitutions with monospaced type, though.
Text that uses it---such as code---is often meant to be printed
verbatim. \verb|"Hello!"| should not become \verb|“Hello!“|.
\section{Selecting font files}
\texttt{fontspec} usually finds the files you need for a given typeface,
especially if you just want the basic set of
upright,
\textit{italic},
\textbf{bold}, and
\textit{\textbf{bold italic}} fonts.
But typefaces can have many more than that.
The version of Futura in this book, for example, comes in
{\fontspec[Scale=MatchLowercase]{Futura-Lig}light},
{\fontspec[Scale=MatchLowercase]{Futura-Boo}book},
{\fontspec[Scale=MatchLowercase]{Futura-Med}medium},
{\fontspec[Scale=MatchLowercase]{Futura-Dem}demi},
{\fontspec[Scale=MatchLowercase]{Futura-Bol}bold}, and
{\fontspec[Scale=MatchLowercase]{Futura-ExtBol}extra bold} weights.
Each of these weights has an oblique font, too.
A typeface could have other variations,
like {\fontspec[Scale=MatchLowercase]{FuturaSc-Boo}small capitals}\footnote{%
OpenType allows some styles, like small caps, to be placed in the same file(s)
as the ``main'' glyphs for a given weight.
If your font supports this, \texttt{fontspec}
will automatically switch to them whenever you use
\monobox{\textbackslash textsc} or \monobox{\textbackslash scshape}.
But for TrueType fonts,
and for OpenType fonts that don't leverage this feature,
you will have to specify separate files.}
or multiple optical sizes (see chapter \ref{formatting}).
We might want to hand-pick weights to achieve a certain look,
or to better match the
other fonts in our document.\punckern\footnote{Compare how
{\fontspec[Scale=MatchLowercase]{Futura-Lig}the light,}
{\fontspec[Scale=MatchLowercase]{Futura-Boo}book,}
{\fontspec[Scale=MatchLowercase]{Futura-Med}and medium weights}
of Futura look next to the rest of the type on this page.}
Continuing to use Futura as an example,
say we want ``book'' as our default weight
and ``demi'' for bold.
Assuming the font files are named:
\begin{itemize}
\item \monobox{Futura-Boo} for
{\fontspec[Scale=MatchLowercase]{Futura-Boo}upright book weight}
\item \monobox{Futura-BooObl} for
{\fontspec[Scale=MatchLowercase]{Futura-BooObl}oblique book weight}
\item \monobox{FuturaSC-Boo} for
{\fontspec[Scale=MatchLowercase]{FuturaSC-Boo}small caps, book weight}
\item \monobox{Futura-Dem} for
{\fontspec[Scale=MatchLowercase]{Futura-Dem}upright demi(bold)}
\item \monobox{Futura-DemObl} for
{\fontspec[Scale=MatchLowercase]{Futura-DemObl}oblique demibold}
\end{itemize}
\noindent Our setup might resemble:
\begin{leftfigure}
\begin{lstlisting}
\usepackage{fontspec}
\setmainfont[
Ligatures=TeX,
UprightFont = *-Boo,
ItalicFont = *-BooObl,
SmallCapsFont = *SC-Boo,
BoldFont = *-Dem,
BoldItalicFont = *-DemObl
]{Futura}
\end{lstlisting}
\end{leftfigure}
Note that instead of typing out \monobox{Futura-Boo},
\monobox{Futura-BooObl}, and so on, we can use \texttt{*} to insert the base
name.\punckern\footnote{This is
a place where \XeLaTeX{} and \LuaLaTeX{} differ.
The former uses system libraries---such as FontConfig on Linux---to
find font files.
The latter has its own font loader,
based on code from FontForge.\punckern\endnote{\textit{\LuaTeX{} Reference}
(Version 1.0.4, February 2017), 10}
Because the two look for files in different ways,
the expected name of a font might differ between the two engines.
See the \texttt{fontspec} package manual for details.}
\section{Scaling}
Creating a cohesive design with multiple fonts is tricky,
especially since they might look completely different
at the same point size.
\texttt{fontspec} can help by scaling fonts to match either the
x-height or the cap height\footnote{Refer back to \chapref{formatting}
for an explanation of these heights.} of your main font with
\verb|Scale=MatchLowercase| or \verb|Scale=MatchUppercase|,
respectively.
But one way to sidestep this issue is to use fewer
typefaces in the first place.
Just one or two, used carefully, can produce amazing results.
\section{OpenType features}
As mentioned at the start of the chapter,
OpenType fonts provide many features that can be switched on and off.
In \LaTeX{}, we do this with optional arguments to
\verb|\setmainfont| and friends.
Features can also be set for the current group with
\verb|\addfontfeature|.
Let's examine some common ones.
\subsection{Ligatures}
Many typefaces use \introduce{ligatures}, which combine multiple characters
into a single glyph.\punckern\footnote{Ligatures fell out
of style during the 20{\addfontfeature{VerticalPosition=Superior}th}
century due to limitations of printing technology and the increased popularity
of sans serif typefaces, which often lack them.
Today they are making a comeback,
thanks in no small part to their support in OpenType.}
OpenType groups them into three categories:
\begin{description}
\item[Standard] ligatures remedy spacing problems between certain characters.
Consider lowercase f and i: in many typefaces,
these combine to form the ligature fi---this avoids
awkward spacing between f's ascender and i's dot
{\addfontfeature{Ligatures=CommonOff} (\,fi\,)}.
Other common examples in English writing include ff,
ffi, fl, and ffl.
Standard ligatures are enabled by default.
\item[Discretionary] ligatures, such as
{\addfontfeature{Ligatures=Discretionary}ct},
are offered by some fonts.
They're disabled by default but enabled with
\verb|Ligatures=Discretionary|.
\item[Historical] ligatures are ones which have fallen out of common use,
such as those with a \introduce{long~s} (e.g., ſt).
These are also disabled by default
but can be enabled with \verb|Ligatures=Historic|.
\end{description}
Multiple options can be grouped together.
Say you want discretionary ligatures.
In the likely event that you also want \verb|Ligatures=TeX|,
you would enable both with
\verb|Ligatures={TeX,Discretionary}|.
Ligatures can also be disabled with corresponding \verb|*Off|
options. If you want to stop using discretionary ligatures for some passage,
\begin{leftfigure}
\begin{lstlisting}
{\addfontfeature{Ligatures=DiscretionaryOff}...}
\end{lstlisting}
\end{leftfigure}
does the trick.
Some words arguably look better without ligatures---\mbox{shelfful}
is a classic example.\punckern\endnote{Knuth, \textit{The \TeX book},
(Addison-Wesley, 1986), 19}
You can manually prevent a ligature by inserting a zero-width space, e.g.,
\verb|shelf\hspace{0pt}ful|.
Or, since life is too short, you can let the \texttt{selnolig} package
handle these cases for you.
\subsection{Figures}
When setting figures,\punckern\footnote{%
\introduce{Figures} is typography-speak for what we might also call
\introduce{digits} (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).}
you have two
choices to make: lining versus text,
and proportional versus tabular.
\introduce{Lining} figures, sometimes called \introduce{titling} figures,
have heights similar to capital letters:
\begin{leftfigure}
\addfontfeature{Numbers=LowercaseOff}
A B C D 1 2 3 4
\end{leftfigure}
\introduce{Text}, or \introduce{oldstyle} figures,
share more similarities with lowercase letters:
\begin{leftfigure}
Sitting cross-legged on the floor\dots{} 25 or 6 to 4?
\end{leftfigure}
Either choice is fine for body text, but don't mix capital letters with
text figures.
``F-15C'' looks odd, as does ``V2.3 Release''\quotekern.
{\addfontfeature{Numbers=LowercaseOff}
The terms \introduce{proportional} and \introduce{tabular} refer to spacing.
Tabular figures are set with a uniform width, so that 1 takes up
the same space as 8.
As their name suggests, this is great for tables and other scenarios
where figures line up in columns:}
\begin{leftfigure}
\addfontfeature{Numbers={Tabular,LowercaseOff}}
\begin{tabular}{l|c r}
Item & Qty. & Price \\
\hline
Gadgets & 42 & \$5.37 \\
Widgets & 18 & \$12.76 \\
\end{tabular}
\end{leftfigure}
Proportional figures are the opposite---their spacing is, well\dots{}
\emph{proportional} to the width of each figure.
They look a bit nicer in body text: 1837
looks more natural here than
{\addfontfeature{Numbers=Tabular}1837} does.
You select figures with the following options:
\begin{leftfigure}
\begin{tabular}{l l}
\texttt{Numbers=} & \texttt{Lining / Uppercase} \\
& \texttt{OldStyle / Lowercase} \\
& \texttt{Proportional} \\
& \texttt{Tabular / Monospaced}
\end{tabular}
\end{leftfigure}
Like ligature options, these can be combined:
proportional lining figures are set
with \texttt{Numbers=\allowbreak\{Proportional,\allowbreak Lining\}},
and tabular oldstyle figures are set with
\texttt{Numbers=\allowbreak\{Tabular,\allowbreak OldStyle\}}.
Each option also has a corresponding \verb|*Off|
variant.\punckern\footnote{This is especially useful since different fonts
have different defaults.
Some fonts use lining figures by default and enable text figures
with \monobox{Numbers=OldStyle}.
Others default to text figures and require \monobox{Numbers=Lining}.}
Finally, some fonts provide \introduce{superior and inferior} figures,
which are used to set ordinals
(\otford{1}{st}, \otford{2}{nd} \otford{3}{rd}, \dots),
fractions (\,\otffrac{25}{624}\,), and so on.
They have the same weight as the rest of the font's characters,
offering a more consistent look than shrunken versions of full-sized figures.
(Compare the examples above to their imposters:
{\fontspec[OpticalSize=0]{garamondpremrpro}%
\mbox{1\textsuperscript{st}},
\mbox{2\textsuperscript{nd}},
\mbox{3\textsuperscript{rd}},
and
\,\mbox{\textsuperscript{25}^^^^2044\textsubscript{624}}%
\,}.
Notice how this second set is too light compared to the surrounding
type.)
Superior figures are typeset with
\texttt{VerticalPosition=\allowbreak Superior},
and inferiors are set with \texttt{VerticalPosition=\allowbreak Inferior}.
\exercises{}
\begin{itemize}
\item Learn how \texttt{fontspec} can choose optical sizes based on
point size, either automatically from ranges embedded in OpenType fonts,
or manually using \texttt{SizeFeatures}.
\item Experiment with letter spacing---or \introduce{tracking}---with
the \texttt{LetterSpace} option.
Extra tracking is unnecessary in most cases,
but can be useful to make \textsc{small caps}
a little more \acronym{readable}.
\end{itemize}