
\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

.
