Obtaining TeX font metrics

Metric files galore


TeX requires a TeX font metric (.tfm) file for a font in order to typeset using it. The .tfm files tells TeX important information such as the the width, depth, and height of each glyph, as well as the kerning pairs and ligature substitutions to be used with the font. For a font generated by METAFONT, this is no problem, since METAFONT output consists of .tfm metric files as well as .gf glyph files.

Most digital typefaces today, however, exist as postscript fonts. The metric information is stored in .afm (UNIX) or .pfm (PC) files or in FOND resources (Mac). These files must be converted to .tfm form in order for TeX to utilize the fonts. This chapter describes the conversion process.

Essentially all TeX distributions include the afm2tfm utility, which allows the straightforward production of .tfm files from .afm files, and whose use we will describe shortly. The existence and wide distribution of this utility solves the problem of .tfm extraction on UNIX systems, and makes changes the problem of obtaining a .tfm file into a problem of obtaing an .afm file on all other platforms. Many high-quality fonts from commercial vendors are distributed together with the corresponding .afm files.

In the absence of an .afm file, PC users need the pfm2afm conversion program; if this program was not included in your TeX distribution, it may be obtained via ftp from numerous archives.

Mac users will have more trouble extracting .afm data from FOND resources. The commercial font manipulation application Fontographer is up to the task, but is quite expensive. Bounding box data, but not kerning pair data, may be extracted from .pfa files using the getafm.ps postscript program.

Encoding vectors


One issue which must be addressed when converting metrics is that the order in which the characters appear in the original metric file may not be the order in which TeX expects them: when an afm file says "the width of character 250 is so-and-so", the afm file may think it is talking about the oe-ligature, but when using the T1 encoding, TeX expects the oe-ligature to appear in position 247 and position 250 to be occupied by the ú character. We must somehow tell the afm2tfm converter about the order we want the characters to appear in the tfm file.

This is accomplished by providing afm2tfm with an .enc file containing a list of the official Adobe character names in the order required by our encoding vector. For example the T1.enc file contains the lines:

  % T1 Encoding vector
  /T1Encoding [
  /grave /acute /circumflex /tilde /dieresis ...
  ... /yacute /thorn /germandbls ] def
  %
  % Ligatures to enforce
  % LIGKERN f f =: ff ; f i =: fi ; f l =: fl ;
  % LIGKERN ff f =: fff ; ff i =: ffi ; ff l =: ffl ;
  % LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;
  % LIGKERN quoteleft quoteleft =: quotedblleft ;
  % LIGKERN quoteright quoteright =: quotedblright ;
  % LIGKERN comma comma =: quotedblbase ;
  % LIGKERN less less =: guillemotleft ;
  % LIGKERN greater greater =: guillemotright ;
  % LIGKERN question quoteleft =: questiondown ;
  % LIGKERN exclam quoteleft =: exclamdown ;
  %
  % Kerns to eliminate
  % LIGKERN space {} * ; * {} space ;
  % LIGKERN zero {} * ; * {} zero ; one {} * ; * {} one ;
  % LIGKERN two {} * ; * {} two ; three {} * ; * {} three ;
  % LIGKERN four {} * ; * {} four ; five {} * ; * {} five ;
  % LIGKERN six {} * ; * {} six ; seven {} * ; * {} seven ;
  % LIGKERN eight {} * ; * {} eight ; nine {} * ; * {} nine ;
The encoding vector contains a list of exactly 256 Adobe official character names ordered according to the T1 encoding. The remaining lines describe the standard LaTeX ligatures and blow away any kerning associated with spaces (since TeX doesn't use space characters) and numerals (in order to maintain alignment in tables). The complete T1.enc file is available for download.

Be aware that, if you are converting a metric file for a font with additional ligatures you want automaticaly substituted (e.g. the ct- and st-ligatures of some 17th century typefaces), or want to preserve your font's kerning between numerals (e.g. because it contains oldstyle, nonlining numerals for use within body text), you may have to add or remove some LIGKERN commands.

afm to tfm conversion


Now we are ready to perform the conversion. To generate garrm.tfm with T1 encoding from garrm.afm, we run afm2tfm with the command line
  afm2tfm garrm garrm -v garrm -t T1.enc
This produces the files garrm.tfm (with bad character ordering) and garrm.vpl (which describes a so-called virtual font with good character ordering). Next we run vp2vf with
  vp2vf garrm garrm
to obtain a new garrm.tfm file (with good character ordering) and the virtual font file garrm.vf (which we will not be using). Mac users note that, upon launching the afm2tfm and vp2vf tools, you will be given the oportunity to enter options invoked on the command line.

Why the two-step process, first invoking afm2tfm, then vp2vf? Because it is sometimes useful to edit the .vpl file which acts as a messenger between the two tools. We discuss such cases later in the section on virtual fonts.

When you have made the relevant .tfm files available to TeX (often it suffices to place them in the same directory as the .tex file that uses them) you should be able to successfully produce a .dvi file. Does it work? You will not, however, be able to view or print this .dvi file until you have appropriately configured your .dvi printing and viewing utilities, which is the subject of the next chapter.


Back to the table of contents, or... ...on to the chapter on configuring dvi intrepreters