Thousands of TeX fonts at your fingertips

72

Author: Michael Stutz

Even if you’re relatively new to TeX, the open source typesetting program, you’re probably familiar with its default 12-point Computer Modern Roman font. TeX distributions actually ship with thousands of free fonts, however, and more are freely available from places such as the Comprehensive TeX Archive Network. Looking for a good way to show font charts and display samples of any TeX font on your system? Here’s how.

TeX uses bitmapped fonts, which normally consist of a number of files, including an .fd file, which contains the font definition, and an .mf file, which is the source file if the font was written in the Metafont language.

For purposes of knowing which TeX fonts are installed on your system, the only files you really need to know about are the .tfm files, which are the files that TeX needs when processing fonts. They contain the TeX font metrics for character spacing and ligatures, but don’t actually contain outlines of the fonts — it’s only later, when you want to view or process the DVI (device independent) file that TeX outputs, that the outlines of the fonts matter.

To get a list of all the TeX fonts on your system, use the kpathsea command to find all .tfm files in your TeX search path:

$ find `kpsexpand '$TEXMF' | sed -e 's/,/ /g;s/[!{}]//g;'` -name '*.tfm'

Chances are you’ll get a longer list than you expected. On a stock teTeX system, for instance, this command outputs nearly 3,000 font names.

For a number of technical reasons, even this number isn’t the precise number of TeX fonts you probably have. That’s because some existing .tfm files are really just partial or “helper” fonts that are used to generate other fonts, while other fonts use a different font metric and don’t have .tfm files at all. But it’s still as close to getting a complete listing of installed TeX fonts as you can get without laboriously examining thousands of files by hand.

Generate samples

TeX comes with a few nice facilities for displaying font samples. They’re actually TeX input files written by TeX’s author Donald E. Knuth. Since they show what’s contained in a font, they’re also a good way to test a new font install. Once you’ve added a font to your /usr/local/share/texmf or ~/texmf tree and have run texhash (as root) to update the TeX Kpathsea database, the first thing you should do is generate samples with these input files so that you know your new font is properly installed.

The first of the two TeX input files is testfont.tex, which is part of TeX’s base distribution. It can output a number of things useful for testing a font, including a chart of all glyphs contained in the font, and a font specimen of sample text.

On Linux systems that have the teTeX distribution installed, this file is normally at /usr/share/texmf/tex/plain/base/testfont.tex. Since it’s on the TeX search path, you don’t need to give the full path name when you process it.

Test commands for testfont.tex

init selects another font.

endorbye exits TeX.

table displays all glyphs in a table.

text prints sample text.

sample runs table and then text.

mixture prints a mixture of a background character with a series of other characters.

alternation prints a background character interleaved with a series of characters.

alphabet prints all lowercase letters within a specified background character.

ALPHABET prints all uppercase letters interleaved with a given background character.

series prints a series of letters within a given background character.

lowers prints a test of all lowercase letters.

uppers prints a test of all uppercase letters.

digits prints a test of all numerals.

math prints a test of all math characters.

names prints a mix of uppercase and lowercase letters.

punct prints a test of punctuation characters.

bigtest prints a combination of the other test commands.

help displays a help message with available commands.

You can use kpsewhich to verify you have it:

$ kpsewhich testfont.tex

If it returns the full path name, you’ve got it.

To get a sample for a font, process the file with TeX, and when prompted, enter the name of the font that you want to sample, such as cmr12. You can omit the path and the .tfm extension — only the base file name is necessary. If all goes well and it’s a valid font on your system (and TeX can find it), you’ll be prompted to enter a test command (see sidebar). Type sample to give the command to show a font chart and a font specimen, and then type bye to quit:

$ tex testfont
This is TeX, Version 3.14159 (Web2C 7.4.5)
(/usr/share/texmf/tex/plain/base/testfont.tex
Name of the font to test = cmr12
Now type a test command (help for help):)
*sample

*bye
[1]
Output written on testfont.dvi (1 pages, 7480 bytes).
Transcript written on testfont.log.
$

You’ll get a DVI output file, testfont.dvi, in your current directory. You can preview it in X with xdvi:

$ xdvi testfont.dvi

This output shows a small font chart with each glyph of the font and its respective character position (in octal), which is useful for specifying special characters. For instance, the chart for cmr12 will show you that the Greek Omega glyph is at position 012 octal in the font, so you can specify it in a TeX document like so:

char'012

The output also shows a text sample of the font in action. The sample is designed to show the font in use with uppercase and lowercase letters, numerals, punctuation, common glyph pairs, and ligatures such as “fl” and “ffl.”

The second TeX input file is fontchart.tex, which displays a four-page font chart in a slightly different format, with glyphs in larger boxes.

Like testfont.tex, it should also be on your TeX path, so you don’t need to specify the full path name when you process it:

$ tex fontchart
This is TeX, Version 3.14159 (Web2C 7.4.5)
(/usr/share/texmf/tex/plain/misc/fontchart.tex
Name of the font to chart = cmr12
[1] [2] [3] [4] )
Output written on fontchart.dvi (4 pages, 17796 bytes).
Transcript written on fontchart.log.
$

This also produces a DVI output file that you can preview with xdvi. If you want to print the DVI files out, use dvips to convert them to PostScript and print them:

$ dvips testfont.dvi
$ dvips fontchart.dvi

Some systems have dvips configured to output to a file by default; in that case, you’ll have to take another step here and use lpr to print them. But in either case, so long as your print system is properly configured, the PostScript files will be converted to something your printer understands — unless you have a PostScript printer, in which case they’ll be sent directly.