LaTeX and fonts

Introduction

Computer fonts contain several distinct types of information:

Font glyphs

Glyphs are the printable character shapes — what most people think of when the word font is used. Glyphs include single letters, digits, and punctuation marks; ligatures; and special characters, such as %, ¢, &c.

Font metrics

Metrics tell how much space a glyph requires: height above the baseline, depth below the baseline, and width. These metrics describe a glyph's bounding box. In addition, there are the side bindings that tell how much room to leave between glyphs in a line of type. There may also be font hints that supply kerning information, etc.

Font encoding

A character is represented in a text (or other) file by a number. Most fonts contain fewer than 255 characters, so a single 8-bit byte (containing an integer less than 256) usually suffices to hold the number that represents a character of text. The correspondence between characters and numerical values is the font encoding.

Unfortunately, many different encodings are in use. ISO-8859-1 is an extension of the ASCII encoding. Adobe's PostScript uses a slightly different encoding. TeX uses another. Large character sets often use the multi-byte UTF-8 encoding from Unicode. If the wrong encoding is used, wrong characters will be displayed.

Fonts and TeX

TeX (or LaTeX) knows only the metrics of a font. The layout engine simply arranges the glyphs' bounding boxes in rows (lines of type).

But the post-processors that prepare the formatted page image for display on a terminal or printing on paper must be able to fill in the glyphs. Ultimately, that's done by breaking each glyph into arrays of little dots (like drops of ink from an injet printer): a bitmap.

However, to get the best result, the fonts should not be reduced to bitmaps until the final stages of display. For example, a computer terminal can display shades of gray, and so partly makes up for its poor resolution by shading the pixels that lie on the edge of a glyph — a process called anti-aliasing.

Resolution

A typical computer screen has about 100 dots per inch (dpi) these days. When text or graphics are displayed on the screen, that's the pixel density that is used to represent the glyphs you see.

On the other hand, printers typically have resolutions from 300 to 1200 dpi (or even more for commercial image-setters). The glyphs that represent the font characters have to be “rasterized” at the resolution of the printer.

This difference in resolution means that the actual representation of a font glyph in terms of dots is different on different output devices. But, to be portable, a formatted document must not depend on the resolution of the final output device; and TeX has no way to know the resolution of the device on which the document will be printed or displayed.

Hence, the output from the TeX compiler is a device-independent (DVI) file. It tells where each glyph goes, but says nothing about the representation of the glyph's shape as a two-dimensional array of dots — i.e., a bitmap.

So the glyphs that compose the text aren't present in the *.dvi file that LaTeX produces. It merely reserves space for them. But they must be present when the file is printed or displayed. The information about glyph shapes comes from font files.

Font types

There are two ways to generate a raster image of a font glyph. Either the glyph is stored as a bitmapped image at some particular resolution; or it's described in geometrical terms, and converted to an image at the required resolution when needed. The first method stores bitmapped fonts; the second, outline fonts.

Bitmapped fonts

Originally, TeX used only bitmapped fonts. That means a separate set of bitmaps for every point size: lots of files. These are kept track of by an elaborate directory structure, coupled to an equally elaborate file-naming scheme.

But the DVI file contains only a font name, not a file name (because different computers may actually keep the font files in different places, with different names). So there has to be a lookup table on the computer that maps fontnames to actual files on the hard disk. On Debian, an example would be the file /usr/share/texmf/fontname/texfonts.map, which stores the mapping for some fonts.

Outline fonts

Every PostScript interpreter has some standard Adobe Type 1 (outline) fonts built in, so these don't have to be included in a printable PostScript file. There are many other fonts of the same kind that can be purchased from Adobe, but the font data must be downloaded to a printer or other display device before printing.

Apple and Microsoft tried to circumvent Adobe's proprietary font coding by introducing TrueType fonts (a different outline-font coding scheme). Both systems are widely used.

Fonts in LaTeX

To make sure you get the scalable (Type 1) versions of fonts in your LaTeX document, put

	\usepackage{psfonts}

in the preamble of your *.tex input file. You may also want to add

	\usepackage{times}

to use the Adobe Times-Roman font family.

Font files

Because of TeX's separation of font metrics from font glyphs, a “font” usually consists of two files; but some font-file formats store everything together in a single file.

Furthermore, the X Window system requires much lower-resolution bitmaps for font glyphs than printers do. And it has its own way of keeping track of font files, which is different from TeX's. Consequently, calling for some particular font (like Times Roman at 10-point size) requires a variety of font files in several different places. The X-Window post-processors (like xdvi) use one set of files; a PostScript printer uses a different set.

TeX's general mechanism for finding font files is described on the formatting page. Clearly, the complexity of font formats poses administrative problems.

Font installation and management

Installing and maintaining fonts is a complex system-administration job. In general, the system is well described in Alan Hoenig's book TeX Unbound, and in the Font HOW-TO (at /usr/share/doc/HOWTO/en-txt/Font-HOWTO.gz on Debian systems). An old version is available at Font HOWTO, and the current HTML version is at http://tldp.org/HOWTO/Font-HOWTO/.

Debian also uses the poorly-documented Debian Font Manager, defoma, to assist the system administrator. (See  man defoma,  man defoma-font,  man defoma-app,  and  man defoma-subst.) For a thorough discussion of defoma, see http://wiki.debian.org/Fonts/Defoma.

 

Copyright © 2005, 2006, 2010 Andrew T. Young


Back to the . . .
website overview page