TeX Fonts (II): fd, def, and tfm

When we compile a TeX source, such as using “latex helloworld.tex”, the latex program searches for the font definition file ‹enc›‹family›.fd according to the font encoding and family specification inside the LaTeX source, loads the encoding definition ‹enc›enc.def, and typesets each individual character by consulting the TeX font metric file ‹family›[‹size›].tfm. These three files are key to generating the output dvi file.

The font definition file ‹enc›‹family›.fd simply declares the existence of some font, and provides a pointer to the metric file that the latex program should consult when typesetting the document. For example, in the txfont package, which provides characters in the Adobe Times font for both texts and formulas, there is one file t1txr.fd defining the txr font family using T1 encoding. The second and third commands read:

\DeclareFontFamily{T1}{txr}{}
\DeclareFontShape{T1}{txr}{m}{n}{t1xr}{}

It essentially says that a txr font with T1 encoding is defined. Whenever a T1 txr medium normal font is requested, LaTeX should use the t1xr.tfm metric file for all font sizes ( means “for all sizes”).

The corresponding encoding definition file ‹enc›enc.def defines the encoding. Let us see an example first to have an idea about what “encoding” means. In t1enc.def, there are four lines saying:

\DeclareFontEncoding{T1}{}{}
\DeclareTextAccent{\'}{T1}{1}
\DeclareTextSymbol{\ae}{T1}{230}
\DeclareTextComposite{\"}{T1}{a}{228}

The first line declares the existence of T1 encoding. The following lines mean that when this encoding is in effect the \'{x} command should superimpose character 1 (accent acute) over the character x, that \ae should produce character 230 (the æ ligature), and that \"a should produce character 228 (the umlaut ä). It would be much clearer to compare the above three commands with the corresponding ones in OT1 encoding (ot1enc.def):

\DeclareTextAccent{\'}{OT1}{19}
\DeclareTextSymbol{\ae}{OT1}{26}
(no composite command \"a defined)

One can see that, under different encodings, the same character has different indices in the character table. The same command can be issued to reference the same character, while it’s also possible that some characters exist in one encoding but not in the other. The encoding defined in LY1enc.def used by Y&Y TeX systems allows access to all the characters in a standard Adobe roman font.

Finally, the TeX font metric file ‹family›[‹size›].tfm is a binary file that defines width, depth, and height of each character, as well as the kerning pairs and ligature substitutions to be used with the font. LaTeX consults the tfm file to decide where to put characters when typesetting. The tfm file name has an optional [‹size›] field. For example, the cmr family has metric files cmr5.tfm, cmr6.tfm, cmr7.tfm, cmr8.tfm, cmr8.tfm, cmr10.tfm, cmr12.tfm, and cmr17.tfm. Each file fine tunes the size of each character and is used when different font sizes are correspondingly declared.

To summarize, when typesetting the document, latex requires three important files to get the correct encoding and character size information. Latex computes the locations of each character and outputs the dvi file.

Advertisements

0 Responses to “TeX Fonts (II): fd, def, and tfm”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Categories

Blog Stats

  • 246,216 hits

%d bloggers like this: