[Tex/LaTex] Where to find the family code for a custom font


Is there a reference list for the encoding of fonts in LaTeX? A place where one can search for a specific font and get the relevant code that represents it. Some of them are not even logical, for example, for TeX Gyre Heros I would imagine a code like "tgh", but the code is "qhv":

{\usefont{T1}{qhv}{b}{n}\selectfont\huge}  %"qhv" - TeX Gyre Heros, "b" - bold
{\usefont{T2A}{qcr}{m}{n}qcr\selectfont}   % Another font

I was searching for the equivalent family code for Alegreya and Alegreya Sans but I can't find it. It must exist, me thinks, because my logic tells me every font in the world has a code like this associated to it? Or maybe not? Where would one search for such a code? I also opened the font in my font viewer with no success.


Best Answer

A more general way of finding the family name which does not require you to open files and does not depend on the existence of a .sty file, is to use the names of the font definition files (.fd). This will work with any font which is set up for use with LaTeX, regardless of whether a .sty file is supplied or not.

Suppose you would like to use Zapf Chancery. This is supplied by the zapfchan package, and is included in standard TeX distributions. Examining the contents of texmf-dist/tex/latex/zapfchan/ (TeX Live):

8ruzc.fd   omluzc.fd  omsuzc.fd  ot1uzc.fd  t1uzc.fd   ts1uzc.fd

There is no .sty file in this case. This makes it even more important to be able to figure out the family name since it is the only way of using the font with LaTeX.

It helps to know a little bit about font encodings at this point. 8r, oml, oms, ot1, t1 and ts1 are lower-case versions of different font encodings used by TeX: 8r, OML, OMS, OT1, T1 and TS1. To figure out the family name, it doesn't matter what these are. All that matters is that you know they are encodings.

  • Take the name of any .fd file. -> E.g. t1uzc.fd.
  • Delete the .fd suffix. -> E.g. t1uzc.
  • Delete the encoding prefix. -> E.g. uzc.
  • What remains is the name of a font family. E.g. uzc.

Some fonts may have several different font families, in addition to different encodings. In these cases, you would need to investigate further to figure out which family you wanted to use. For Zapf Chancery, however, there is just the single family uzc and that is what you would use to select the font in LaTeX.

The name of the font definition files tell you one other crucial thing: they tell you which encodings the font is available in. In this case, you have:

  • 8r: this is a 'raw' encoding - you can forget about this unless you are interested in creating font packages yourself;
  • OML/OMS: encodings supporting maths;
  • OT1: the default TeX text encoding and also used in maths;
  • T1: an enhanced text encoding with much better support than OT1 for accented characters, in particular;
  • TS1: a supplementary text encoding which supplies various symbols such as the copyright symbol, old style numbers etc.

You might be puzzled at this point to find that

\fontencoding{T1}\fontfamily{uzc}\selectfont Is this Zapf Chancery?

still produces Computer Modern Roman rather than Zapf Chancery. LaTeX will be warning you that it has substituted fonts on the console and in the log and (for pdfTeX) your PDF viewer will show you CMR is still being used. Why does the font selection fail?

To figure this out, you have to look inside the font definition file. (I only said you didn't have to open files to figure out the family - I didn't say you'd be able to use it!)

Reading t1uzc.fd, we find the following line:

   <-> uzcmi8t

This shows that the family includes a font in the series mb (medium bold) and shape it (italic).

The next two shape declarations:

\DeclareFontShape{T1}{uzc}{m}{it}{<->ssub * uzc/mb/it}{}
\DeclareFontShape{T1}{uzc}{mb}{sl}{<->ssub * uzc/mb/it}{}

tell us that this single font (uzc/mb/it) is silently substituted (i.e. without warning) if the italic shape in medium weight is requested (m series) or the slanting shape (sl) in the medium bold series.

The final shape declaration:

\DeclareFontShape{T1}{uzc}{m}{sl}{<->ssub * uzc/mb/sl}{}

tells us that the uzc/mb/sl is silently substituted if the slanting shape in the medium series is requested. Since the italic, medium bold is substituted for uzc/mb/sl anyway, this effectively means that no matter which of italic and slanting are requested, and no matter which of medium and medium bold, we will always get the italic, medium bold shape.

However, nothing is defined for the standard, upright shape. So to actually use Zapf Chancery, we need to also change to the italic or slanting shape. To be on the safe side, it would be best to specify the weight, too. That way, if bold is active, say, we won't get something unexpected (such as CMR in bold).

\fontencoding{T1}\fontfamily{uzc}\fontshape{it}\fontseries{mb}\selectfont Is this Zapf Chancery?

Note that this method of finding the family name will work whether or not the font name follows the Berry scheme. For example,


tells us that there is a font family available in the T1 encoding named EBGaramond-OsF which we could similarly select with \fontfamily{} if appropriate. [Although it would generally be better, in this case, to use the .sty file provided by the package.)

Related Question