[Tex/LaTex] Function and usage of \font command

fontsplain-tex

I have seen the use of the \font. For example

\font\Cal=cmsy10 at 25pt

I can't find any information about this command. Could anyone tell me what's the function of it, how works and how use it?

Best Answer

Well, to really learn about it, you should probably turn to a good TeX reference; but the basics are pretty simple.

\font is the plain TeX way to change fonts in a document. You say \font to tell TeX that you want to declare a font, then you give TeX a control sequence by which you will refer to the font, then you say =filename so that TeX knows which font to grab when you use that control sequence. E.g.:

\documentclass{book}
\begin{document}
\font\boldface=cmb10
\font\normalweight=cmr10
Now is \boldface the time \normalweight for all good...
\end{document}

will give you this:

Font change demonstrated.

Of course, it can be used for much more significant changes, including a complete change of typeface (say, \font\feta=ffmr10\feta will change to ten-point Fetamont). But in a single document, you're mostly sticking with the same family of fonts and switching between sizes, shapes, and weights, so that's the most common use case.

The trick with this method is that you need to know the exact filename of the font you want; and by "exact filename", I mean exactly that. You can't just know that Computer Modern fonts start with cm, you need to know that Computer Modern Roman in ten point is the file cmr10. The mental overhead can be significant.

Most fonts have LaTeX packages to make this sort of thing easy; these packages typically work their fonts into the New Font Selection Scheme (NFSS), which means that all you'll have to do is set the document font to, say, GreatFont (which I just made up), and then all the normal LaTeX commands, like \textit and \textbf and such, will work as expected, but with your new font. Without NFSS, you'd have to specify new commands, with new \font declarations, for all the different style, weight, shape, and sizes that you're likely to use. NFSS is a wonderful thing.

I understand that, in XeTeX and LuaTeX, fontspec takes care of these things in a pretty transparent way, such that you don't even really need a font package if the OTF files are set up correctly. But I know little about this.

P.S. The at directive tells TeX to scale the fonts in some way; so, for example, you could say \font\something=cmr5 at 10pt to get ten-point Computer Modern Roman by scaling up five-point Computer Modern Roman. This is typically a bad idea, though, as fonts are designed for a specific size and don't look as good when used at a size too different from that design size. NFSS also provides ways for package authors to ensure that, when the requested size isn't available as a design size, the requested size will be obtained by scaling up the closest available design size, minimizing this degradation in quality which inevitably follows from scaling.