Whole document tree

Whole document tree

Font HOWTO: TeX / LaTeX Next Previous Contents

9. TeX / LaTeX

9.1 A Quick Primer on LaTeX/TeX fonts

Adding fonts to TeX and LaTeX is a somewhat complex procedure. However, like a lot of things, it's easy if you know how to do it. Some fonts are distributed in metafont format, and some in Type1 format. Usually, the Type1 formats are more easily available. However, metafont fonts have the distinct advantage that they can adjust their shape at different sizes, while Type1 and TrueType fonts at different point sizes are simply magnified or reduced versions of precisely the same shape. The main reason why this feature is desirable is that ideally, fonts should be ( relatively ) wider at smaller sizes and narrower at larger sizes.

For this discussion, we focus on Type1 fonts, since they are more widely available, and more problematic to install.

Here's a quick primer on LaTeX fonts. LaTeX uses the following types of font files for handling Type1 fonts:

  • .pl -- property list. This is a human readable version of a tex font metric file.
  • .vpl -- virtual property list. Human readable version of a virtual font file.
  • .fd -- font definition. Used to define a family of fonts.
  • .tfm -- tex font metric. This is a metric file, as explained in the glossary. It is completely analogous to the .afm files used by Type1 fonts. TeX needs the font metrics to properly layout the page.
  • .vf -- virtual font. These files contain encoding details, and act as interpreters. TeX treats them as fonts. For example, Imagine that there's some wacky font foobar-exp.pfb which consists of a few ( say 20 ) alternate characters, and there's a virtual font which uses a few of these alternate characters ( and it gets the rest of the characters from font foobar.pfb ). Dvips might say ``I want character 65 of virtual font foo.vf''. Dvips knows that 65 is always an ``a'' in TeX's scheme. Then the virtual font maps TeX's request to a request for character 14 of the Type1 font foobar.pfb ( which might be the alternate ``a'' in the Type1 font foobar.pfb ). The virtual font mechanism is very flexible and allows fonts to be constructed from many different font files. This is useful when using fonts such as adobe's ``expert'' fonts.
  • .pk -- a device dependent bitmap font. These are usually constructed on an as-needed basis ( they are renderings of Type1 and metafont fonts ). They are typically high resolution ( about 300-1200dpi ), and are intended to be rendered on a printer. Because of their high resolution, and the fact that each point size of each font requires a .pk file, they require a lot of disk space, so they are cached, but not stored.
  • .mf -- metafont files. Metafont is a graphics programming language widely used for font design ( though it can also be used for graphics ). It has many advantages over TrueType and Type1 schemes. However, it's main weakness is that it is not as ubiquitous as TrueType or Type1 ( and it is also not terribly well suited to WYSIWYG publishing. Of course, this isn't a major disadvantage when TeX is your typesetting system. )

It's good to know your way around the TeX directory structure. Here are the main directories you'll need to know about:

  • $TEXMF/fonts -- the main font directory
  • $TEXMF/fonts/type1 -- the type1 font directory
  • $TEXMF/fonts/type1/foundry -- the directory for the shape files in a given foundry
  • $TEXMF/fonts/type1/foundry/fontname -- contains the font called name. The name is usually plain English, and needn't follow TeX's cryptic naming scheme for fonts.
  • $TEXMF/fonts/afm/foundry/fontname -- the directory containing the afm files corresponding to the font name belonging to foundry foundry.
  • $TEXMF/fonts/tfm/foundry/fontname -- analogous to the afm directory, but contains tfm files instead.
  • $TEXMF/fonts/vf/foundry/fontname -- similar to the above, but contains the virtual fonts.
  • $TEXMF/fonts/source/foundry/fontname -- similar to the above, but contains metafont files.
  • $TEXMF/dvips/config/psfonts.map -- fontmap file for dvips. This file is similar in both function and format to ghostscript's Fontmap file.
  • $TEXMF/tex/latex/psnfss -- this is where all the font definition files go.

9.2 Adding Type1 fonts

Naming the fonts

First, you need to appropriately name your fonts. See the fontinst documentation on your system for instructions on how to name fonts ( it should be fontinst subdirectory of the directory containing your tetex documentation ). To make a long story very short, the naming scheme is FNW{V}E{n} where:

  • F is a one-letter abbreviation for the foundry ( m = monotype, p = adobe, b = bitstream, f = free )
  • N is a two letter abbreviation for the font name ( for example, ag = ``avant garde'' )
  • W is the font weight ( r = regular, b = bold, l = light d = demibold )
  • V is an optional slope variant ( i = italic , o = oblique )
  • E is an abbreviation for the encoding ( almost always 8a which is adobe standard encoding ).
  • N is an optional width variant ( n = narrow )
For example, the font Adobe Garamond demibold is pgad8a.

Creating the virtual fonts and tex font metrics

Now you can run fontinst as follows:

        latex `kpsewhich fontinst.sty`
then you type at the prompt:
where font_name is the first three letters of your font file name ( for example, pad for adobe garamond ). Now fontinst will generate a number of files -- font description files, property list files and virtual property list files. It also generates a lot of .mtx files. These are created by fontinst, but you don't need to use them. You need to convert the property lists and virtual property lists to metrics and virtual fonts. This is done using the utilities vptovf and pltotf.
        for X in *.pl; do pltotf $X; done
        for X in *.vpl; do vptovf $X; done
Then remove the old vpl, pl and mtx files.

Configure dvips

You will need to edit your dvips config file, psfonts.map. The best way to explain the format of the file is to give an example.

     marr8r          ArialMT <8r.enc <farr8a.pfa
     marbi8r         Arial_BoldItalicMT <8r.enc <farbi8a.pfa
     marb8r          Arial_BoldMT <8r.enc <farb8a.pfa
     marri8r         Arial_ItalicMT <8r.enc <farri8a.pfa
     marr8rn         Arial_Narrow <8r.enc <farr8an.pfa
The 8r.enc is simply there to inform dvips of the encoding scheme used ( in all our examples, it's 8r, because of the way fontinst constructs the virtual fonts ). The leftmost column is the font name TeX uses. The second column is the real name of the font, which is hardcoded into the font file ( this name can be deduced by opening the afm file in a text editor, and looking for the FontName directive ). The last column is the filename of the shape file corresponding with the font. It is not necessary to provide a directory path -- tex knows where to look.

Test the font

Try running latex on a document like this:

        Testing a new font \dots the quick red fox jumped over the lazy brown dogs
where you replace pga with the outline of your font. If this works, you are almost done. All you have to do now is put all the files in the right directories ( as explained in the primer ), then run
         texconfig rehash
so that tex can update the directory lists.

Create a .sty file

You may want to create a .sty file so that you can more easily use fonts. Use the files in $TEXMF/tex/latex/psnfss as a template.

Next Previous Contents