Go to the first, previous, next, last section, table of contents.


5. Using PostScript Fonts

Thanks to Donald E. Knuth, the dvips driver now supports PostScript fonts through the virtual font capability. PostScript fonts are (or should be) accompanied by a font metric file such as `Times-Roman.afm', which describes characteristics of a font called Times-Roman. To use such fonts with TeX, we need `tfm' files that contain similar information. These can be generated from `afm' files by running the program `afm2tfm', supplied with dvips. This program also creates virtual fonts with which you can use normal plain TeX conventions. See Donald E. Knuth, TUGboat v. 11, no. 1, Apr. 1990, pp. 13--23, "Virtual Fonts: More Fun for Grand Wizards", for a general introduction to virtual fonts.

Non-resident downloaded PostScript fonts tend to use a great deal of printer virtual memory. PostScript printers typically have between 130,000 and 400,000 bytes of available virtual memory; each downloaded font will require approximately 30,000 bytes of that. For many applications, bitmapped fonts work much better, even at typesetter resolutions (with the `-Z' option).

Even resident PostScript fonts can take a fair amount of memory, but less with this release of dvips than previously. Also, bitmapped fonts tend to image faster than PostScript fonts.

5.1 The Afm2tfm Program

In its simplest use, `afm2tfm' converts an Adobe `afm' file (e.g., `Times-Roman.afm') into a `raw' TeX TFM file (say, `rptmr.tfm' with the command

afm2tfm Times-Roman rptmr

This file is raw because it does no character remapping; it simply converts the character information on a one-to-one basis to TeX characters with the same code. (It would be better to have eschewed the use of the `r' prefix in favor of using a variant letter to specify the encoding; but we didn't think of that at the time, and it's too late to change existing fonts. See section `Top' in Filenames for TeX fonts.)

In the following examples, we will use the font Times-Roman to illustrate the conversion process. For the standard 35 LaserWriter fonts, however, it is highly recommended that you use the supplied `tfm' and `vf' files that come with dvips, as these files contain some additional changes that make them work better with TeX than they otherwise would.

Standard PostScript fonts have a different encoding scheme from that of plain TeX. Although both schemes are based on ASCII, special characters such as ligatures and accents are handled quite differently. Therefore we obtain best results by using a `virtual font' interface, which makes TeX see a standard TeX encoding for the PostScript font. Such a virtual font can be obtained, for example, by the command

afm2tfm Times-Roman -v ptmr rptmr

This produces two files as output, namely the `virtual property list' file `ptmr.vpl', and the raw font metric file `rptmr.tfm'. (The upper case `-V' also produces a `vpl' file, but maps a set of small caps into the lower case alphabet.) To use the font in TeX, you should first run

vptovf ptmr.vpl ptmr.vf ptmr.tfm

and then install the virtual font file `ptmr.vf' where Dvips will see it, and install `ptmr.tfm' and `rptmr.tfm' where TeX and Dvips will see them.

You can also make more complex virtual fonts by editing `ptmr.vpl' before running `vptovf'; such editing might add the uppercase Greek characters in the standard TeX positions, for instance. (This has already been done for the font files that come with Dvips.) Once this has been done, you're all set. You can use code like this in TeX henceforth:

\font\myfont = ptmr at 12pt
\myfont Hello, I am being typeset in 12-point Times-Roman.

Thus we have two fonts, one actual (`rptmr', which is analogous to the font in the printer) and one virtual (`ptmr', which has been remapped to the standard TeX encoding (almost), and has typesetting know-how added. You could also say

\font\PTR = rptmr at 10pt

and typeset directly with that, but then you would have no ligatures or kerning, and you would have to use Adobe character positions for special letters like The virtual font called `ptmr' not only has ligatures and kerning, and most of the standard accent conventions of TeX, it also has a few additional features not present in the Computer Modern fonts. For example, it includes all the Adobe characters (such as the Polish ogonek and the French guillemots). The only things you lose from ordinary TeX text fonts are the dotless `j' (which can be hacked into the VPL file with literal PostScript specials if you have the patience) and uppercase Greek letters (which just don't exist unless you buy them separately).

The remapped p* fonts mostly follow plain TeX conventions for accents. The exceptions: the Hungarian umlaut (which is at position `0x7D' in `cmr10', but position `0xCD' in `ptmr'); the dot accent (at positions `0x5F' and `0xC7', respectively); and `\AA', which neds different tweaking. In order to use these accents with PostScript fonts or in math mode when `\textfont0' is a PostScript font, you will need to use the following definitions. These definitions will not work with the Computer Modern fonts for the relevant accents. They are already part of the distributed `psfonts.sty' for use with LaTeX.

\def\H#1{{\accent"CD #1}}
\def\.#1{{\accent"C7 #1}}
\def\dot{\mathaccent"70C7 }
\newdimen\aadimen
\def\AA{\leavevmode\setbox0\hbox{h}\aadimen\ht0
  \advance\aadimen-1ex\setbox0\hbox{A}\rlap{\raise.67\aadimen
  \hbox to \wd0{\hss\char'27\hss}}A}

These PostScript fonts can be scaled to any size. Go wild! Using PostScript fonts, however, does use up a great deal of the printer's memory and it does take time. You may find downloading bitmapped fonts (possibly compressed) to be faster than using the built-in PostScript fonts!

5.2 Changing a Font's Encoding

The `afm2tfm' program also allows you to specify a different encoding for a PostScript font. This can be done at two levels.

You can specify a different output encoding with `-t'. This only applies when you are building a virtual font, and it tells `afm2tfm' to attempt to remap the font to match the output encoding as closely as possible. In such an output encoding, you can also specify ligature pairs and kerning information that will be used in addition to the information in the `afm' file.

You can also specify a different PostScript encoding with `-p'. This changes both the raw `tfm' file created by Afm2tfm and the `vf' and `tfm' files created by VPtoVF. It also requires that the encoding file be downloaded as part of any document that uses this font. This is the only way to access characters in a PostScript font that are neither encoded in the `afm' file nor built from other characters (constructed characters). For instance, `Times-Roman' contains the extra characters `trademark' and `registered' (among others) that can only be accessed through such a PostScript reencoding. Any ligature or kern information specified in the PostScript encoding is ignored by `afm2tfm'.

To combine the effects of `-p' and `-t', use `-T'. If you make regular use of a private non-standard reencoding `-T' is usually the better idea, since you can get unexpected inconsistencies in mapping otherwise.

Afm2tfm's encoding files have precisely the same format as an encoding vector in any PostScript font. Specifically:

% Comments are ignored, unless the first word after the percent sign
% is LIGKERN -- see below.
/MyEncoding [ /Alpha /Beta /Gamma /Delta ...
     /A /B ... /Z % exactly 256 entries, each with a / at the front
     /wfooaccent /xfooaccent /yfooaccent /zfooaccent ] def

Comments, which start with a percent sign and continue until the end of the line, are ignored unless they start with `LIGKERN'. The first `word' of the file must start with a forward slash (a PostScript literal name) and defines the name of the encoding. The next word must be an left bracket `['. Following that must be precisely 256 character names; use `/.notdef' for any that you do not want defined. Finally, there must be a matching right bracket ]. A final `def' token is optional. All names are case sensitive.

Any ligature or kern information is given in the comments. If the first word after the percent sign is `LIGKERN', then the entire rest of the line is parsed for ligature and kern information. This ligature and kern information is given in groups of words, each group of which must be terminated by a semicolon (with a space before and after it, unless it occurs at the end of a line.)

In these `LIGKERN' statements, three types of information may be specified. These three types are ligature pairs, kerns to remove or ignore, and the character value of this font's boundary character. Which of the types the particular set of words corresponds to is automatically determined by the allowable syntax.

Throughout a `LIGKERN' statement, the boundary character is specified as `||'.

To set the boundary character value, a command such as `|| = 39 ;' must be used.

To indicate a kern to remove, give the names of the two characters (without the leading slash) separated by `{}', as in `one {} one ;'. This is similar to the way you might use `{}' in a TeX file to turn off ligatures or kerns at a particular location. Either or both of the character names can be given as `*', which is a wild card matching any character; thus, all kerns can be removed with `* {} * ;'.

To specify a ligature, specify the names of the pair of characters, followed by the ligature `operation' (as in METAFONT), followed by the replacing character name. Either (but not both) of the first two characters can be `||' to indicate a word boundary.

Normally the `operation' is `=:' meaning that both characters are removed and replaced by the third character, but by adding `|' characters on either side of the `=:', you can specify which of the two leading characters to retain. In addition, by suffixing the ligature operation with one or two `>' signs, you can indicate that the ligature scanning operation should skip that many characters before proceeding. This works just like in METAFONT. A typical ligature might be specified with `ff i =: ffi ;'. A more convoluted ligature is `one one |=:|>> exclam ;' which indicates that every pair of adjacent `1''s should be separated by an exclamation point, and then two of the resulting characters should be skipped over before continuing searching for ligatures and kerns. You cannot give more `>''s in an ligature operation as you did `|', so there are a total of eight possible ligature operations:

=: |=: |=:> =:| =:|> |=:| |=:|> |=:|>>

The default set of ligatures and kerns built in to `afm2tfm' can be specified with:

% LIGKERN question quoteleft =: questiondown ;
% LIGKERN exclam quoteleft =: exclamdown ;
% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;
% LIGKERN quoteleft quoteleft =: quotedblleft ;
% LIGKERN quoteright quoteright =: quotedblright ;
% LIGKERN space {} * ; * {} space ; 0 {} * ; * {} 0 ;
% LIGKERN 1 {} * ; * {} 1 ; 2 {} * ; * {} 2 ; 3 {} * ; * {} 3 ;
% LIGKERN 4 {} * ; * {} 4 ; 5 {} * ; * {} 5 ; 6 {} * ; * {} 6 ;
% LIGKERN 7 {} * ; * {} 7 ; 8 {} * ; * {} 8 ; 9 {} * ; * {} 9 ;

5.3 Special Font Effects

Afm2tfm can do other manipulations as well. For example, to make an obliqued variant of Times Roman:

afm2tfm Times-Roman -s .167 -v ptmro rptmro

which creates `ptmro.vpl' and `rptmro.tfm'. To use this, put the line

rptmro Times-Roman ".167 SlantFont"

into `psfonts.map'. Then `rptmro' (our name for the obliqued Times) will act as if it were a resident font, although it is actually constructed from Times-Roman via the PostScript routine SlantFont (which slants everything 1/6 to the right, in this case).

Similarly, you can get an expanded font with

afm2tfm Times-Roman -e 1.2 -v ptmrre rptmrre

and by recording the pseudo-resident font

rptmrre Times-Roman "1.2 ExtendFont"

in `psfonts.map'.

You can also create a small caps font with a command such as

afm2tfm Times-Roman -V ptmrc rptmrc

This will generate a set of small caps mapped into the usual lower case positions and scaled down to 0.8 of the normal cap dimensions. You can also specify the scaling as something other than the default 0.8:

afm2tfm Times-Roman -c 0.7 -V ptmrc rptmrc

It is unfortunately not possible to increase the width of the small caps independently of the rest of the font. If you want a really professional looking set of small caps you will have to make up a custom pair of ``tfm'' and ``vpl'' files using the `-e' option, change the name and checksum of the D 1 font in `ptmrc.vpl' to match the customized raw `tfm', and replace the small caps at the lower case mappings with the small caps in the customized file. You can then throw away the customized `vpl' file, but not the customized `tfm'. That must be identified with an appropriate line in `psfonts.map'.

To change the PaintType in a font from filled (0) to outlined (2), you can add "/PaintType 2 store" to `psfonts.map', as in the following:

rphvrl   Helvetica "/PaintType 2 store"

If you change the PostScript encoding of a font, you must specify the input file as a header file, as well as give a reencoding command. For instance, let us say we are using Times-Roman reencoded according to the encoding `MyEncoding' (stored in the file `myenc.enc') as `rptmrx'. In this case, our `psfonts.map' entry would look like

rptmrx Times-Roman "MyEncoding ReEncodeFont" <myenc.enc

The `afm2tfm' program prints out the precise line you need to add to `psfonts.map' to use that font, assuming the font is resident in the printer; if the font is not resident, you must add the header command to download the font yourself. Each identical line only needs to be specified once in the `psfonts.map' file, even though many different fonts (small caps variants, or ones with different output encodings) may be based on it.

5.4 Non-resident PostScript Fonts

If you want to use a non-printer-resident PostScript font for which you have a `pfb' or `pfa' file (an Adobe Type 1 font program), you can make it act like a resident font by putting a `<' sign and the name of the `pfb' or `pfa' file just after the font name in the `psfonts.map' file entry. For example,

rpstrn StoneInformal <StoneInformal.pfb

will cause dvips to include `StoneInformal.pfb' in your document as if it were a header file, whenever the pseudo-resident font StoneInformal is used in a document. Similarly, you can generate transformed fonts and include lines like

rpstrc StoneInformal <StoneInformal.pfb ".8 ExtendFont"

in `psfonts.map', in which case `StoneInformal.pfb' will be loaded whenever StoneInformal-Condensed is used. Each header file is loaded at most once per document.

If you are using a `pfb' file that is also has a different PostScript encoding, you need to download multiple header files in `psfonts.map'. If, for instance, `Optima' was both non-resident and you wanted to reencode it in PostScript with `MyEncoding' stored in `myenc.enc', you need:

rpstrnx Optima "MyEncoding ReEncodeFont" <myenc.enc <Optima.pfb

When using PFB files, dvips is smart enough to unpack the binary PFB format into printable ASCII so there is no need to perform this conversion yourself. In addition, it will scan the font to determine its memory usage, as it would for any header file.

Here is a brief description of the contents of `psfonts.map'. If a line is empty or begins with a space, percent, asterisk, semicolon, or hash mark, it is ignored. Otherwise, the line is separated into words, where words are separated by spaces or tabs, except that if a word begins with a double quote, it extends until the next double quote or the end of the line. If a word starts with a less than character, it is treated as a font header file (or a downloaded PostScript font). There can be more than one such header for a given font. If a word starts with a double quote, it is a special instruction for generating that font. Otherwise it is a name. The first such name is the TFM file that a virtual font file can refer to. If there is another name, it is used as the PostScript name; if there is only one name, it is used for both the TeX name and the PostScript name.

5.5 Invoking Afm2tfm

The command line switches to `afm2tfm' are:

`-c ratio'
See `-V'; overrides the default ratio of 0.8 for the scaling of small caps.
`-e ratio'
All characters are stretched horizontally by the stated ratio; if it is less than 1.0, you get a condensed font.
`-O'
This option forces all character codes in the output `vpl' file be given as octal values; this is useful for symbol or other special-purpose fonts where character names such as `A' have no meaning.
`-p file'
This specifies a file to use for the PostScript encoding of the font. This file must also be mentioned as a header file for the font in `psfonts.map', and that ligature and kern information in this file is ignored.
`-T file'
This option specifies that file is to be used for both the PostScript and target TeX encodings of the font.
`-t file'
This specifies a file to use for the target TeX encoding of the font. Ligature and kern information may also be specified in this file; the file need not be mentioned in `psfonts.map'.
`-s slant'
All characters are slanted to the right by slant. If slant is negative, the letters slope to the left (or they might be upright if you start with an italic font).
`-u'
This option indicates that `afm2tfm' should use only those characters that are required by the output encoding, and no others. Normally, `afm2tfm' tries to include both characters that fit the output encoding and any additional characters that might exist in the font. This option forbids those additional characters from being added.
`-v file'
Generate a virtual property list `vpl' file as well as a `tfm' file.
`-V file'
Same as `-v', but the virtual font generated is a small caps font obtained by scaling uppercase letters by 0.8 to typeset lowercase. This font handles accented letters and retains proper kerning.

Here are the `CODINGSCHEMES' that result from the various possible choices for reencoding.

`default encoding'
(CODINGSCHEME TeX text + AdobeStandardEncoding)
`-p DC.enc'
(CODINGSCHEME TeX text + DCEncoding)
`-t DC.enc'
(CODINGSCHEME DCEncoding + AdobeStandardEncoding)
`-T DC.enc'
(CODINGSCHEME DCEncoding + DCEncoding)


Go to the first, previous, next, last section, table of contents.