8

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.

Cheers!

2 Answers2

12

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:

\DeclareFontShape{T1}{uzc}{mb}{it}{
   <-> 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,

texmf-dist/tex/latex/ebgaramond/T1EBGaramond-OsF.fd

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.)

cfr
  • 198,882
  • Wow, this was such a deep (an interesting) explanation. Also, +1 for explaining what to do if the font is not loaded and why that even happens. I have almost no custom fonts installed in my texlive-dist, and I always used XeTeX to load the installed ones or set a Path to non-installed ones. It's good to know the origin of the things you use! @egreg answer was great, but I will accept this one, since it is a bit more complete. – Xirux Nefer Sep 23 '14 at 22:21
  • @XiruxNefer Thank you! I almost didn't post this as egreg's answer works fine for this particular case. The links posted by Sverre are very informative, too. But using the .fd files is a bit more general as it works whether the font uses the Berry scheme or not and whether there is a .sty file or not. And it also helps explain why the .sty file does the things it does, if there is one. [You can probably tell that this is my preferred method!] – cfr Sep 23 '14 at 22:32
4

The Alegreya (serif and Sans) fonts don't use the Berry scheme, where the family name is a three (or four) letter abbreviation.

You find the family names in Alegreya.sty and AlegreyaSans.sty.

Alegreya

220 \else % type1
221 
222   \def\Alegreyafamily{Alegreya-\Alegreya@figurealign \Alegreya@figurestyle}
223   \def\Alegreya{\fontfamily{\Alegreyafamily}\selectfont}
224   \def\AlegreyaLF{\fontfamily{Alegreya-LF}\selectfont}
225   \def\AlegreyaOsF{\fontfamily{Alegreya-OsF}\selectfont}
226   \def\AlegreyaTLF{\fontfamily{Alegreya-TLF}\selectfont}
227   \def\AlegreyaTOsF{\fontfamily{Alegreya-TOsF}\selectfont}

AlegreyaSans

235 \else % type1
236 
237   \def\AlegreyaSansfamily{AlegreyaSans-\AlegreyaSans@figurealign \AlegreyaSans@figurestyle}
238   \def\AlegreyaSans{\fontfamily{\AlegreyaSansfamily}\selectfont}
239   \def\AlegreyaSansLF{\fontfamily{AlegreyaSans-LF}\selectfont}
240   \def\AlegreyaSansOsF{\fontfamily{AlegreyaSans-OsF}\selectfont}
241   \def\AlegreyaSansTLF{\fontfamily{AlegreyaSans-TLF}\selectfont}
242   \def\AlegreyaSansTOsF{\fontfamily{AlegreyaSans-TOsF}\selectfont}

I added the line numbers for reference. The last four lines in each code snippet tell you what to use as argument to \fontfamily.

The acronyms LF, OsF, TLF and TOsF stand for “lining figures”, “oldstyle figures”, “tabular lining figures” and “tabular oldstyle figures”.

For XeLaTeX or LuaLaTeX it's easier: type

\newfontfamily{\alegreyasans}[
  <options>
]{AlegreyaSans}

and use \alegreyasans when you want this font.

egreg
  • 1,121,712
  • Thanks! Yeah, XeTeX is great! So any time I want to find the code for a specific custom font I just have to look into the .sty of that font and search for the \defs in there? I have it installed in my system (Ubuntu 14.04), but not in my LaTeX distribution, so thank you for pasting the code here. Also, I had no idea that something like "the Berry scheme" even existed! So maybe I can Google search for something like "the Berry scheme name for X font"? – Xirux Nefer Sep 23 '14 at 20:24
  • @XiruxNefer Well, it's not so easy in general, but in many instances it works. – egreg Sep 23 '14 at 20:25