<<

Font installation the shallow way∗

SIEP KROONENBERG Rijksuniversiteit Groningen Department of Economics P.. Box 800 9700 AV Groningen, The Netherlands siepo (at) cybercomm nl

Abstract For one-off projects, you can cut corners with font installation and end up with a more manageable set of files and a cleaner TEX installation. This article shows how and why.

Keywords Font installation, afm2pl, afm2tfm, TrueType, , mapfiles

If you are putting together a flyer or invitation or other system, whether or not it contains afm2pl or book cover, then it would be nice if you could test afm2tfm. a batch of fonts from your CorelDRAW or Illustra- An example tor CD, or your Windows font directory, without too We use a decorative script font Pepita that Adobe bun- much trouble and without polluting your TEX instal- lation with a lot of stuff you are never going to use dles (or used to bundle) with some of its software. again. pdftex needs the actual font file epscr___.pfb, its This article takes you through the steps needed TEX font metrics file epscr7t.tfm and a mapfile con- to use one or more fonts in one particular document. taining an entry relating the two. First, we copy not We won’ really install the fonts; we just generate the only epsrc___.pfb but also epsrc___.afm to the working directory. We need the latter file to generate files that TEX needs and leave them where TEX will find them, i.. in the working directory. This makes the .tfm file. Next, we enter the following commands it easy to take the project to another system, and easy on a command line: to clean things up. afm2pl -p ot1 epscr___.afm epscr7t.pl We will primarily use afm2pl to generate .tfm pltotf epscr7t (TEX Font Metric) files. Later on, we show the steps The extensions .afm and .pl are optional. The required for afm2tfm. Both programs are simpler and first command converts the .afm file to an (almost) much faster to use than the usual choice, fontinst. human-readable text version of the desired .tfm file. They create few intermediate or unnecessary files and The second command creates the more compact bi- do their job without virtual fonts. Virtual fonts and nary version. fontinst have their place, but sometimes there is no Before we can use this font, we must tell LATEX good reason to put up with the inevitable mess. about it. We do this with a font family definition file afm2tfm is available on all major free TEX imple- ot1myfontfam.fd: mentations. afm2pl is part of current TEX Live distri- \ProvidesFile{ot1myfontfam.fd} butions. Note that these programs are needed only to \DeclareFontFamily{OT1}{myfontfam}{} \DeclareFontShape{OT1}{myfontfam}{}{}{ create the necessary font support files for TEX; once these files have been created, they can be used on any <-> epscr7t }{} The prefix ot1 indicates the encoding, which tells ∗This article appeared originally in slightly different form in MAPS 33, fall 2005. which characters occur at what positions. The next section will say more about encodings. The param- eters to \DeclareFontShape are successively encod-

66 TUGboat, Volume 27 (2006), No. 1 — Proceedings of EuroTEX 2006 Font installation the shallow way ing, family name, weight (e.. bold), shape, font file We hope that mainstream TEX will eventually (without extension) and special options. You can nor- move to , which is a comprehensive encod- mally leave this last parameter empty. With just one ing of all conceivable characters, including far-eastern family member, we are not fussy about font charac- alphabets and mathematical symbols. When that hap- teristics and just pick defaults. We also leave this file pens, we can forget about encodings and also do away in the working directory. with many applications of virtual fonts. There are This is the code of our first testfile exabasic., already some Unicode-based variants of TEX.2 which uses this font: For a PostScript .pfb or .pfa font, character met- \documentclass{article} rics are stored in a separate .afm file. These metrics \pagestyle{empty} are associated with characters, not with character po- \pdfmapfile{=epscr7t.map} sitions. Therefore you should specify an encoding to afm2pl or afm2tfm.3 The same encoding must also \newcommand{\fancyfont}% be specified in the mapfile entry. A PostScript font {\fontfamily{myfontfam}\selectfont} usually has more characters than fit into a single TEX \begin{document} encoding. \fancyfont A command-line option such as ‘-p texnansi’ or Hello, world! ‘-p texnansi.enc’ means that the encoding should be read from a file texnansi.enc. This encoding Accents: \’el\‘eve bl\"of \"i; probably has a different internal name. : WAV, LTa \end{document} OT1 encoding The \pdfmapfile command causes pdflatex to If you don’t tell TEX otherwise, it assumes that you read the file epscr7t.map, which tells pdftex how are using the OT1 encoding. This encoding uses only to get the font into the output file. The prepended ‘=’ 128 of the 256 available slots. TEX creates missing tells pdftex that it should read epscr7t.map in addi- accented characters from an unaccented base charac- tion to, not instead of, the default mapfile, and that in ter and a separate accent character. Unfortunately, case of a conflict epscr7t.map wins. this interferes with hyphenation. Apart from this, the Now we are ready to compile exabasic.tex: OT1 encoding has various other oddities, and is best pdflatex exabasic avoided. OT1-encoded fonts often have a TEX name 7t 4 ot1.enc This is the result: ending in . Note that comes with afm2pl and is probably not available if you don’t have afm2pl Hello, world! on your system. Accents: ´el`eve bl¨of ¨ı; Kerning: WAV, LTa T1 encoding Encodings T1 is the successor to OT1. It uses all available slots, and has lots of accented characters, including those for We already mentioned encodings briefly. Now it is Eastern European languages. Because the T1 encoding time to dig a little deeper, because it is a topic that left no room for symbols such as ‘‰’ or ‘©’ or ‘‡’ you can easily trip you up. will need to get those from a second encoding of the An encoding defines what character corresponds same font. This second encoding is called TS1 or ‘text to which number. Only numbers between 0 and 255 companion’. are allowed. A .tfm file associates character metrics di- rectly with character positions and doesn’t know what 2Omega and its offshoot Aleph are Unicode-based. Users may also be interested in T X(http://scripts.sil.org/xetex), position represents what character. TEX simply makes E E which is built on top of a regular TEX implementation and lets you assumptions about this correspondence or encoding, use Unicode fonts installed on the system directly with TEX. and if you disagree with those assumptions then you 3If you don’t specify an encoding, then you get the encoding from the .afm file, which is almost certainly not what you want. need to load some macro package or other to tell TEX 4For afm2pl and afm2tfm, font names have no particular meaning. otherwise. This is one more difference with fontinst. I add encoding suffixes such as 7t and 8y to font names just as reminders to myself.

TUGboat, Volume 27 (2006), No. 1 — Proceedings of EuroTEX 2006 67 Siep Kroonenberg

For most traditional PostScript fonts, some of the Accents: \’el\‘eve bl\"of \"i; accented characters in the T1 encoding aren’t actually Symbols: present and must be created with virtual font tech- \textparagraph{} \textdaggerdbl{} \texttrademark{} \textcopyright nology from a base character and an accent. Since \end{document} it doesn’t have to be done by TEX itself, this is no obstacle to hyphenation. And this is the result. Notice the extra symbols. Although you can tell afm2pl to use T1 encoding, These are absent from the T1 encoding and would it can’t create composite characters, and such compos- have required a text companion font. ite characters will be missing unless they are already Hello, world! present in the original font. Accents: élève blöf ï; Symbols: ¶ ‡ ™ © T1-encoded fonts often have a TEX name ending in 8t. TrueType Another scalable font format is TrueType, which is Texnansi encoding supported by pdftex but currently not by . Font The texnansi encoding, known as LY1 to LATEX, was metrics are stored in the font file itself. Using True- introduced by &Y, the now-defunct company be- Type is somewhat more work; the following com- hind Y&YTEX, dviwindo and dvipsone. It combines mands are required to import a TrueType font such a good selection of both accented letters and typo- as Trebuchet: graphic symbols, and normally contains everything ttf2afm trebuc.ttf >trebuc.afm you need in a single encoding, at least for Western Eu- afm2pl -p texnansi trebuc trebuc8y ropean languages. Texnansi-encoded fonts often have pltotf trebuc8y a name ending in 8y. The package texnansi selects the texnansi encod- ttf2afm extracts the metric information from the ing and contains some additional code to smooth out .ttf file.5 incompatibilities with T1 and OT1. afm2pl has no way of knowing that the .afm de- A texnansi example scribes a TrueType font, and guesses that the actual For this example, we choose Augie, a handwriting font fontfile is trebuc.pfb. Therefore you have to fix the mapfile afterwards. from TEX Live. These are the commands for generat- ing the .tfm and .map files: We leave it as an exercise for the reader to write the A afm2pl -p texnansi augie___.afm augie8y.pl .fd file and LTEX source for the following example: pltotf augie8y Hello, world! This is ly1augie.fd (notice the ly1 prefix): Accents: élève blöf ï; Kerning: WAV, LTa, WAV, LTa. Symbols: ¶ ‡ ™ © \ProvidesFile{ly1augie.fd} \DeclareFontFamily{LY1}{augie}{} \DeclareFontShape{LY1}{augie}{m}{n}{ Font-based uppercasing and letterspacing <-> augie8y }{} afm2pl comes with an uppercased version texnanuc of This is the LATEX code: texnansi. Uppercasing, e.g. in headings, works best in \documentclass{article} combination with letterspacing. For this, afm2pl has \usepackage{texnansi} a parameter ‘-m’. \pagestyle{empty} Warning: afm2pl implements letterspacing with \pdfmapfile{=augie8y.map} kerns. Unfortunately, the .tfm format can contain only a limited number of kerns. If there are too many \newcommand{\fancyfont}% in the .pl file then all kerns and ligatures will be {\fontfamily{augie}\selectfont} dropped from the generated .tfm file! So use this \begin{document} feature with care. fontinst implements letterspacing \fancyfont 5This will result in an empty encoding, unless you specify an en- Hello, world! coding parameter. But we are going to ignore the encoding in the .afm anyhow.

68 TUGboat, Volume 27 (2006), No. 1 — Proceedings of EuroTEX 2006 Font installation the shallow way by adding sidebearings via virtual fonts, and doesn’t \DeclareFontShape{LY1}{trebuc}{m}{upp}{ suffer from this limitation. <-> trebucupp8y }{} We can create a letterspaced, uppercased version And this is the LATEX code using it: of Trebuchet with the following commands: \documentclass{article} ttf2afm trebuc.ttf >trebuc.afm \usepackage{texnansi} afm2pl -p texnanuc -m 100 trebuc trebucupp8y \pagestyle{empty} pltotf trebucupp8y % better combine these mapfiles! \pdfmapfile{=trebuc8y.map} \pdfmapfile{=trebucbd8y.map} A corresponding fontfamily and fontshape decla- \pdfmapfile{=trebucit8y.map} ration might look as follows: \pdfmapfile{=trebucbi8y.map} \ProvidesFile{ly1trebuc.fd} \pdfmapfile{=trebucupp8y.map} \DeclareFontFamily{LY1}{trebuc}{} \DeclareFontShape{LY1}{trebuc}{m}{upp}{ \begin{document} <-> trebucupp8y }{} \fontfamily{trebuc}\selectfont The fontshape upp for uppercasing is not an offi- Hello, \textbf{world!} cial LATEX shape but that doesn’t seem to matter. You Accents: \’el\‘eve bl\"of \"i; can use the font as follows: Kerning: WAV, LTa, \textit{WAV, \documentclass{article} \textbf{LTa.}} \usepackage{texnansi} \pagestyle{empty} Symbols: \pdfmapfile{=trebucupp8y.map} \textparagraph{} \textdaggerdbl{} \texttrademark{} \textcopyright \begin{document} \fontfamily{trebuc}\fontshape{upp} \fontshape{upp}\selectfont \selectfont Letterspaced uppercasing Letterspaced uppercasing \end{document} \end{document} And this is the result: And this is the result: Hello, world! LETTERSPACEDUPPERCASING Accents: élève blöf ï; Kerning: WAV, LTa, WAV, LTa. Symbols: ¶ ‡ ™ © A font family LETTERSPACEDUPPERCASING The next example uses a real font family, consisting of the usual four family members plus our letterspaced Using dvips font. So we will need not only trebuc.ttf, as in the If you go the dvips route, then you cannot use the previous example, but also trebucbd.ttf, trebucit.ttf, \pdfmapfile macro. Instead, you have to enter addi- and trebucbi.ttf. For each of these we’ll have to run tional mapfiles on the command line: the ttf2afm — afm2pl — pltotf sequence, and we’ll have dvips -u +mapfile dvifile to edit each of the generated map files, or create a The prefix + to the mapfile parameter is analo- combined mapfile. gous to the = prefix for the \pdfmapfile macro: it Here is the .fd file: tells dvips to use the named mapfile in addition to the \ProvidesFile{ly1trebuc.fd} default one. \DeclareFontFamily{LY1}{trebuc}{} \DeclareFontShape{LY1}{trebuc}{bx}{n}{ Using afm2tfm <-> trebucbd8y }{} The original intention of afm2tfm was not to create \DeclareFontShape{LY1}{trebuc}{m}{n}{ fonts which are used directly by T X. Instead, they <-> trebuc8y }{} E \DeclareFontShape{LY1}{trebuc}{bx}{it}{ were to serve as a basis for virtual fonts, i.e. recipes <-> trebucbi8y }{} to compose fonts from other fonts. But it is not too \DeclareFontShape{LY1}{trebuc}{m}{it}{ difficult to subvert this intention. The less optimal <-> trebucit8y }{} way is to use the output of afm2tfm directly:

TUGboat, Volume 27 (2006), No. 1 — Proceedings of EuroTEX 2006 69 Siep Kroonenberg afm2tfm kuen408i -p texnansi.enc \ afm2pl also has some options for manipulating the quick.tfm >a2t.map ligkern table and for setting spacing parameters. For casual use, you don’t need to bother with these. Note that the .afm filename comes before the op- tions. The .enc extension must be included. OpenType The better way is to pretend to create a virtual We are seeing more and more OpenType fonts, which font: are Unicode-based. These consist of either PostScript/ afm2tfm kuen408i -T texnansi.enc \ Type 1 or TrueType outlines inside a TrueType wrap- - slow.vpl null.tfm >a2t.map per. OpenType fonts may contain huge character sets, vptovf slow.vpl sometimes including smallcaps and oldstyle figures. rm slow.vf OpenType fonts with TrueType outlines have an extension .ttf and can be treated just like TrueType vptovf generates two files from slow.vpl, named fonts. slow.vf and slow.tfm. You should remove slow.vf, OpenType fonts with Type 1 outlines have an otherwise the dvi driver or pdftex would think that .otf extension. You can get an .afm for an OpenType slow is a virtual font. file by first converting it with FontForge to TrueType Mapfile information is written to standard output, (tip from Taco Hoekwater): which therefore has to be redirected, as shown above. fontforge - ’Open($1); Generate($2);’ \ It contains the following string: ofont.otf ofont.ttf quick Kuenstler480BT-Italic ttf2afm ofont.ttf >ofont.afm " TeXnANSIEncoding ReEncodeFont " afm2pl -p texnansi ofont ofont8y slow Kuenstler480BT-Italic Note the <<, which means that the font is to be in- " TeXnANSIEncoding ReEncodeFont "

70 TUGboat, Volume 27 (2006), No. 1 — Proceedings of EuroTEX 2006