summaryrefslogtreecommitdiff
path: root/info/simple-nfss.tex
blob: b25264fb960f20d59aaaaabe12340d88b60136fa (plain)
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

\documentclass[12pt,a4paper]{article}

\catcode`\"=\active
\def"{\begingroup\let"=\endgroup\tt
  \catcode`\{=12 \catcode `\} = 12 \catcode`\^=12
  \catcode`\|=0 \catcode`\\=12 } % Swap control characters inside "..."

\title{A few words on fonts}

\author{Timothy Murphy\\
(\texttt{tim@maths.tcd.ie})}

\date{20 June 1994}

\begin{document}

\maketitle

\begin{abstract}
The New Font Selection Scheme (NFSS)
is now an official part of \LaTeX.
The concept is beautifully executed
but --- in this author's eyes ---
poorly documented.
This brief note is intended as a simple introduction
to NFSS.\footnotemark
\end{abstract}

\footnotetext{Any comments, corrections or criticisms gratefully received.}

\section{The 5 parameters}

A font $F$ in \LaTeX\ is specified by 5 parameters:
encoding, family, shape, series and size.
In mathematical terminology, the font $F$ 
is a function of 5 arguments,
\[
F(e, f, s, s', s''),
\]
where $e$ is the encoding, $f$ the family,
$s$ the shape, $s'$ the series and $s''$ the size.

The aim of the font selection mechanism
is to associate to each such specification
a real or virtual font at a particular magnification.
For example, if the "12pt" option is given
at the start of the document, eg
\begin{verbatim}
  \documentclass[12pt,a4paper]{article}
\end{verbatim}
then the default font is
\[
F("OT1", "cmr", m, n, 12) \mapsto "cmr12".
\]
(Where no magnification is specified, as here,
it is understood that the font is unmagnified.)

In other words, the font selection scheme
sets up a mapping
\[
F: "encoding" \times "family" \times "shape" \times "series" \times "size"
\to "font" \times "magnification".
\]
This mapping is usually defined
in Font Definition (or ".fd") files,
as we shall see shortly.

Each of the 5 parameters can be changed 
independently of the others by the commands:
"\fontencoding", "\fontfamily", "\fontshape", "\fontseries" and "\fontsize",
followed by an argument and "\selectfont".
(A change only comes into effect
when the command "\selectfont" is given;
this allows more than 1 of the parameters to be changed at the same time.)
For example, the command
\begin{verbatim}
  \fontshape{cmss}\fontseries{bx}\fontsize{12}\selectfont
\end{verbatim}
will change the font to
\[
F("OT1", "cmss", bx, n, 12) \mapsto "cmssbx10".
\]

\section{Short cuts}

In practice these commands "\fontencoding", etc,
rarely if ever appear in \LaTeX\ documents,
because \LaTeX\ offers a number of simplifications.

For example, one would normally write "\textss{...}"
rather than \linebreak
"\fontfamily{cmss}\selectfont".

Similarly the only shape change encountered in most documents 
is effected by "\emph{...}",
which changes the shape from `roman' (upright) to italic,
or italic to roman, according to the context.
(Actually, most of these commands do a little more 
than just change the font ---
for example "\emph" also checks
that there is appropriate spacing
when coming in or out of the font change.)

Again, the only series change commonly met is
"\textbf{...}",
which is (almost) equivalent to "\fontseries{bx}\selectfont".

Font sizes are rarely expressed in absolute terms;
rather, the commands "\small", "\large", "\Large",
"\LARGE", "\huge", "\Huge" are used.
The actual font sizes defined by these commands
depend on the default font size.
For example, if the "12pt" option was specified
at the start of the document
then "\large" is 14.4 points.

\section{Font definition files}

For convenience, the definition of the font selection mapping $F$
is normally `hived off' into separate \emph{Font Definition} (".fd") files.

When \LaTeX\ encounters a change of family
it looks to see if there exists an appropriate ".fd" file,
and if there is, it reads it in.
The name of the ".fd" file is formed 
by concatenating the encoding and the family name, 
and adding the extension ".fd".
For example
if the family is "cmss", say, and the encoding is "OT1"
(Knuth's original 128-character encoding)
then the file is called "OT1cmss.fd".
If the family is "cmr" and the encoding is "T1"
(the new 256-character Cork encoding)
\LaTeX\ will look for the file "T1cmr.fd",
which specifies DC fonts, eg 
\[
F("T1", "cmr", m, n, 12) \mapsto "dcr12".
\]

Thus the effect of specifying "T1" encoding
is to replace the usual CM fonts by their DC counterparts.
The easiest way to do this is to use the "t1enc" package:
\begin{verbatim}
  \documentclass[12pt]{article}
  \usepackage{t1enc}
\end{verbatim}
No further change is needed.

(\LaTeX\ remembers which ".fd" files it has read in,
and will not read them in a second time.
In particular a number of standard ".fd" files
such as "OT1cmr.fd"
have already been read into the format file "latex.fmt"
and so are always available.)

\section{Introducing a new family}

Now suppose we want to introduce a new font.
In principal one can introduce a single font at a single size
by a command like
\begin{verbatim}
  \font\quengwar = tengwar scaled \magstep2
\end{verbatim}
and then write eg "{\quengwar \^e l\^u\.r\'i \^l\^DR}".
But it is almost as easy,
and much more versatile,
to introduce a new family, "Tengwar" say,
with the command
\begin{verbatim}
  \newcommand{\quengwar}{\fontfamily{Tengwar}\selectfont}
\end{verbatim}
Now when \LaTeX\ reads "{\quengwar \^e l\^u\.r\'i \^l\^DR}",
if this is its first encounter with Tengwar,
it will read in the file "OT1Tengwar.fd".

We are assuming here that "tengwar" is in the old (but still standard)
Knuth "OT1" encoding,
as will be the case unless the contrary is specified.
If we had wanted to assign it the `unknown' encoding "U"
we would have said
\begin{verbatim}
\newcommand{\quengwar}{\fontencoding{U}\fontfamily{Tengwar}\selectfont}
\end{verbatim}
and \LaTeX\ would have looked for the file "UTengwar.fd".

But to tell the truth,
the encoding does not make any practical difference;
the only difference lies 
in the contents of the corresponding ".fd" files.

\section{Inside a font definition file}

Let's suppose first that we have created the file "tengwar.tfm"
from the \textsf{Metafont} file "tengwar.mf", eg by the command
{\catcode`\"=12
\begin{verbatim}
  mf "\mode=nullmode; input tengwar"
\end{verbatim}}
Then the only "Tengwar" fonts at our disposal are "tengwar"
at various magnifications.

The following file "OT1Tengwar.fd" will serve our purpose
\begin{verbatim}
  \DeclareFontFamily{OT1}{Tengwar}{}
  \DeclareFontShape{OT1}{Tengwar}{m}{n}{ <-> tengwar }{}
  \endinput
\end{verbatim}
The first line here introduces the family name "Tengwar";
while the second specifies that if Tengwar is encountered
anywhere in normal text
then the font "tengwar" is to be used at the appropriate magnification.
For example, if the document is being printed in 12pt
then the font "tengwar scaled 1200" will be used.

(If we are using "dvips" ---
and the same of true of some other drivers ---
we do not need to create any "pk" files;
they will be created automagically as and when required.)

But suppose some Tengwar appears in the title of the document.
The title is printed in bold type.
Since we have not specified any bold Tengwar font,
the rules of \LaTeX\ prescribe that the default font family
(normally Computer Modern)
should be used, in bold at the appropriate size.

This is almost certainly not what we wanted.
We can specify that we still want to use our single "tengwar" font
in this situation
by adding the following `substitution rule' to the ".fd" file
(before the "\endinput"!):
\begin{verbatim}
\DeclareFontShape{OT1}{Tengwar}{bx}{n}{ <-> ssub * Tengwar/m/n }{}
\end{verbatim}
This specifies that the non-bold Tengwar font should be substituted
whenever bold Tengwar is requested.
Other substitution rules should be added if necessary,
eg if Tengwar is likely to encountered in italic (or emphasized) text.

It is not possible, unfortunately, to say that \emph{whenever} Tengwar
is encountered the "tengwar" font is to be used.
The various substitutions have to be specified individually.

\section{Another example}

We only had 1 Tengwar font, in a single size.
Often of course a font is provided in several sizes.
Consider for example Knuth's "concrete" fonts.
The distribution contains the following ".mf" files:
"ccr5.mf", "ccr6.mf", "ccr7.mf", "ccr8.mf", "ccr9.mf", "ccr10.mf",
"cccsc10.mf", "ccmi10.mf", "ccsl10.mf", "ccslc9.mf", "ccti10.mf".
We might start "OT1concrete.fd" with the lines
\begin{verbatim}
  \DeclareFontFamily{OT1}{concrete}{}
  \DeclareFontShape{OT1}{concrete}{m}{n}
    { <5> <6> <7> <8> <9> sgen * ccr <10-> s * ccr10 }{}
\end{verbatim}
This specifies that if the font is requested say at size 7
then the file "ccr7" is to be used,
while for any size $\ge 10$ the file "ccr10" is to be used,
suitably magnified.
(The `s' in "sgen" and "s *" stands for \emph{silent} ---
meaning that we do not want to be told about font changes.)

There doesn't appear to be a bold font included,
so we might want to substitute the above fonts in this case, by
\begin{verbatim}
  \DeclareFontShape{OT1}{concrete}{bx}{n} { ssub * concrete/m/n }{}
\end{verbatim}

We can use "ccti10" for text italic, in all sizes:
\begin{verbatim}
  \DeclareFontShape{OT1}{concrete}{m}{it} { <-> ccti10 }
\end{verbatim}

As for substitutions, the simplest plan is to look at the file
"OT1cmr.fd" and consider what combinations of shape and series
are likely to arise.

It remains to see how we can use the fonts.
If we want to mix "concrete" and CM we could introduce the command
\begin{verbatim}
  \newcommand{\concrete}{\fontfamily{concrete}\selectfont}
\end{verbatim}
and then we could say, for example,
\begin{verbatim}
  The {\concrete concrete} fonts ...
\end{verbatim}
On the other hand, if we want to replace "cmr" throughout by "ccr"
we can say
\begin{verbatim}
  \renewcommand{\familydefault}{concrete}
\end{verbatim}
in the preamble to our document,
and the whole document will be printed using the "concrete" fonts.

\section*{Am I too loud?}

One last small point.
You might consider the Tengwar font (say)
too large in comparison with normal text.
NFSS offers a simple solution.
If we change the line in the "OT1Tengwar.fd" file to read, for example,
\begin{verbatim}
  \DeclareFontShape{OT1}{Tengwar}{m}{n}{ <-> s * [0.95] tengwar }{}
\end{verbatim}
then the font will be reduced in size by 5\%.

\section*{Mathematical fonts}

In this document we have only considered \emph{text} fonts.
The use of fonts in mathematics (whether displayed or not)
is another story, for another day \dots.

\end{document}

-- 
Timothy Murphy  
e-mail: tim@maths.tcd.ie
tel: +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland