AFM2PL(1)

πŸ“¦
version 71515 Β· 3 versions
, in alpine 3.24, arch rolling, debian trixie, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– AFM2PL(1) Β· afm2pl manual ✨

πŸŽ€ NAME

okay so afm2pl is the bestie that converts AFM (Adobe Font Metric) font metrics into TeX pl (Property List) files πŸ¦‹


🧚 SYNOPSIS

afm2pl [-p encoding_file] [-o] [-e extension_factor] [-s slant_factor]
       [-f font_dimensions] [-k] [-m letter_spacing] [-l ligkern_spec]
       [-L ligkern_spec] [-n] input_file[.afm] [output_file[.pl]]

afm2pl [--help] | [--version]

🌸 DESCRIPTION

okay so afm2pl takes an afm (Adobe Font Metric) file and turns it into a pl (Property List) file. Then that pl file can be turned into a tfm (TeX Font Metric) file, so it's a whole pipeline πŸ’… It normally keeps your kerns and ligatures safe, and it also gives you extra control over them, which is so iconic πŸ”₯

Lowkey, afm2pl is meant to be a partial replacement for afm2tfm, which it's based on. With afm2tfm, keeping kerns and ligatures is only possible in a roundabout way, and the handling of them is hard-wired. Not it πŸ™…β€β™€οΈ

For text fonts, Y&YΒ΄s texnansi is a seriously good encoding to use with afm2pl πŸ’œ Its character set has all the accented characters you'd likely need for Western languages, plus loads of typographic symbols. You don't need virtual fonts or a separate text companion font for any of it. The vibe is effortless ✨

Full LaTeX support for this encoding comes in the form of the texnansi package, which is already part of TeX Live and teTeX. Those distributions also ship the encoding file texnansi.enc πŸŽ€

The distribution has uppercased and lowercased versions of texnansi, called texnanuc and texnanlc. These let you do font-based uppercasing and lowercasing instead of macro-based, which is giving efficiency 😭 It also has the familiar old ot1 encoding, plus some variations in PostScript .enc format. I included these because they seem to be missing from teTeX and TeX Live πŸ₯Ί

⚠️ Check your mapfiles if you have old afm2pl-generated fonts that use these encodings! Things can get messy otherwise πŸ’€

Return value: 0 means no error. A negative number tells you how many glyphs are missing, but only if the conversion was otherwise successful. 1 means there was an error 🫢


πŸ‘‘ OPTIONS

  • -p encoding_file β€” okay so the default is the encoding specified in the afm file, and it had better match the encoding in the fontfile (pfa or pfb) πŸ‘€ If afm2pl-name.enc exists, afm2pl will use that file instead of name.enc, unless you give the -n option. The generated mapfile entry (see below) tells pdftex or the dvi driver to re-encode the font on the fly. And on-the-fly reencoding does not need virtual fonts, which is a major win πŸ¦‹
  • -o β€” uses octal for all character codes in the pl file πŸ“
  • -e extend_factor β€” widens or narrows characters by extend_factor. The default is 1.0, which is natural width. Not recommended[1] πŸ™ˆ
  • -s slant_factor β€” obliques (slants) the characters by slant_factor. Also not recommended, bestie πŸ’€
  • -f font_dimensions β€” the value is either the keyword afm2tfm or a comma-separated list of up to five integers. The parameters are listed below with their defaults, plus what they become when you use the afm2tfm keyword. "Space" means the width of a space in the target font, except of course in the last row. Keep in mind that the design size is 1000, and all numbers must be nonnegative integers πŸ”₯

Here's the rundown for normal fonts:

  • stretch β€” default is space div 2. With afm2tfm it's 300 Γ— extend_factor.
  • shrink β€” default is space div 3. With afm2tfm it's 100 Γ— extend_factor.
  • extra space β€” default is space div 3. With afm2tfm it's missing.
  • quad β€” default is 2 Γ— width of β€˜0’. With afm2tfm it's 1000 Γ— extend_factor.
  • space β€” default is (space source font) Γ— extend_factor. With afm2tfm it's also (space source font) Γ— extend_factor.

🩰 Fixed-pitch fonts

Fixed-pitch fonts get different values, so pay attention ✨

  • stretch β€” default is 0. With afm2tfm it's 0.
  • shrink β€” default is 0. With afm2tfm it's 0.
  • extra space β€” default is space. With afm2tfm it's missing.
  • quad β€” default is 2 Γ— character width. With afm2tfm it's 1000 Γ— extend_factor.
  • space β€” default is character width. With afm2tfm it's character width.

You can specify just a non-default stretch and shrink, like 150,70. Or just a non-default extra space, like ,,10 πŸŽ€

  • -k β€” keeps the original ligatures 🫢 This option only does anything in combination with positive letterspacing. Check the section on letterspacing and extra ligkern info for the full story.
  • -m letter_spacing β€” letterspaces by letter_spacing/1000 em, where the value is an integer. This is super useful for making all-caps typesetting look better 😭 Try a value like 50 or 100. But seriously, read the section on letterspacing and extra ligkern info for details. A better alternative, though, is letting pdftex do the letterspacing. The microtype package gives LaTeX users access to this feature πŸ’…
  • -l ligkern_spec, -L ligkern_spec β€” see the section on extra ligkern info for details ✨
  • -n β€” no prefix! πŸ™…β€β™€οΈ For .enc and .lig files, the program normally first prefixes the name with afm2pl-Β΄. It only searches for the original filename if the prefixed filename isn't found. This option stops it from searching for the prefixed filename at all.
  • -V β€” verbose mode πŸ“’ If it's turned on, it reports the number of missing glyphs to stderr and their names to stdout.
  • --help β€” displays a short usage message 🧚
  • --version β€” displays the version number of afm2pl 🌈

✨ EXTRA LIGKERN INFO ✨

okay bestie, real talk πŸ™ˆ most people should just leave this mess alone and let the default behavior do its thing πŸ’…

The ligatures and kerns in the afm file can be tweaked in a bunch of ways. By default, the encoding file gets scanned for extra ligkern specifications (I'll explain the format below). If the encoding file has none, extra ligkern specs get read from a file called [afm2pl-]default.lig instead. A ligkern_spec value of 0 means the afm file's ligatures and kerns stay untouched, and a value of 1 gives you the default behavior. You can also pass a comma-separated list of files with extra ligkern specs, which is giving main character energy ✨

If afm2pl was compiled with the kpathsea library, those files get searched for under $TEXMF/fonts/lig πŸ—‚οΈ

Also, ligatures and kerns are just hints for the typesetting application 🫢 You don't need to download this info to the printer, and you don't need to make it available to a dvi driver. No cap.

The parser for ligkern info got inherited from afm2tfm pretty much unchanged, so it's an old-school icon πŸ‘‘ A ligkern specification can look like one of these:

glyph_name1 glyph_name2 lig_op glyph_name3 ;

That's a ligature. The possible values for lig_op are =:, |=:, |=:>, =:|, =:|>, |=:|, |=:|> and |=:|>>. These map to LIG, /LIG, /LIG>, LIG/, LIG/>, /LIG/, /LIG/> and /LIG/>> in .pl syntax. For more on those, check out the pltotf documentation and the .lig files in the distribution πŸ“š

glyph_name1 <> glyph_name2 ;

This one is a kern: glyph_name1 gets kerned as glyph_name2 πŸ’•

glyph_name1 {} glyph_name2 ;

This removes the kern between glyph_name1 and glyph_name2. A value of * for either glyph name is treated as a wildcard πŸƒ

|| = glyph ;

This sets the (right) boundary character to glyph. The glyph can be a glyphname or a slot in the encoding vector. If you pick a glyph that doesn't show up in the output encoding, it's the same as not specifying a boundarychar at all. It's totally ok to pick an encoded glyphname that isn't in the afm, and honestly that's exactly what default.lig does with || = cwm ;. Iconic behavior πŸ¦‹

You can also copy the kerns of an unencoded character onto the boundarychar. Below, space is the unencoded character:

|| <> space ;

This ligkern specification should come before the one that deletes space kerns, so the order matters πŸ™ˆ

A ligkern specification has to live inside one line. A single line can hold several ligkern specifications, separated by spaces. Heads up that ; (a space followed by a semicolon) is considered part of the ligkern specification itself. Check out the lig files included in this distribution for examples. Here's one:

one {} * ; * {} one ; two {} * ; * {} two ;

Lines with ligkern specifications inside an encoding file should start with % LIGKERN. Ligkern specifications in a lig file may optionally start that way too πŸ’œ

✨ LETTERSPACING AND EXTRA LIGKERN INFO ✨

okay so letterspacing has a bunch of side-effects on ligkern info 😭 Instead of just applying the extra ligkern info (see the previous section), this is what happens:

  1. In case of positive letterspacing, native ligatures get removed, unless you specify the -k option πŸ’€
  2. The extra ligkern info gets applied as usual, except that with positive letterspacing different defaults kick in: -l 0 is quietly ignored, ligkern comments in the encoding file are ignored, and defpre.lig gets read instead of default.lig πŸŽ€
  3. Letterspacing gets applied. This adds a lot of kerns and modifies existing ones, so it's a whole vibe 🌈
  4. The extra ligkern info specified with -L gets applied. The only ligkern specs allowed here are removals of kerning pairs (with the {} operator). The values 0 and 1 have a similar meaning to what they do for the -l parameter. The tfm format only has room for about 180x180 ligatures and kerning pairs. That's enough for OT1 encoding, but for texnansi encoding you'll have to remove quite a few ligkern specifications. The pltotf program will remove all ligkern info if too many ligatures and kerns remain 😱 The default lig file here is defpost.lig. This file throws out kerning pairs that are unlikely to be involved in letterspacing, like kerns involving accents or kerns with a punctuation character or right bracket on the left. It does not add letterspacing kerns involving boundarychars. Instead, fontspace gets increased by twice the letterspacing ✨ defpost.lig throws out enough kerns for texnansi encoding. With other encodings, you may have to throw out additional kerning pairs 🧚

✨ FONT-BASED UPPER- AND LOWERCASING ✨

The distribution includes the encoding vectors texnanuc.enc and texnanlc.enc, which produce all-uppercase and all-lowercase fonts πŸ” 

The main uses for an all-uppercase font are page headers and section heads πŸ’… If those contain math, then macro-based uppercasing would create unpleasant complications. Example:

afm2pl -p texnanuc ptmr8a ptmup8y
pltotf ptmup8y

For best results, add some letterspacing. In LaTeX, this is best done with the microtype package, so check out that package's documentation. But you can also do it with afm2pl:

afm2pl -p texnanuc -m 100 ptmr8a ptmup8y
⚠️ This requires caution, see above! Seriously, don't skip that part 😭

You can use this new font within LaTeX font selection like this:

<preamble commands>
\makeatletter
{\nfss@catcodes
\DeclareFontShape{LY1}{ptm}{m}{upp}{<-> ptmup8y}{}}
\makeatother
...
\begin{document}
...
{\fontshape{upp}\selectfont uppercase text}

Note that upp is simply a newly made-up shape name, so you can call it whatever you want 🌸

✨ The sz ligature ß ✨

Heads up that the texnanuc encoding provides no glyph for the sz ligature ß πŸ’€ You'll either have to substitute ss or come up with a macro-based solution. The following code uses either the usual glyph or substitutes the letters ss, depending on whether the glyph exists in the current font:

\def\ss{%
  \setbox0\hbox{\char25}%
  \ifnum\wd0=0 ss\else\box0\fi
}

In LaTeX this code seems to work well enough, although sometimes you might need to insert \protect πŸ™ˆ A better solution might involve the sixth parameter of the \DeclareFontShape macro, but I failed to get that to work 😭

✨ AFM2PL, FONTINST AND ARTIFICIAL SMALLCAPS ✨

Afm2pl doesn't do virtual fonts, bestie πŸ₯Ί So for things like artificial smallcaps, you have to go elsewhere, e.g. to the fontinst package, which is part of any mainstream TeX distribution 🧁

Look under texmf/tex/fontinst for fontinst support files, which let you generate a smallcaps font (tfm and vf files) from an afm2pl-generated tfm file. This package only supports texnansi encoding.

There should be no real problem doing the same for OT1 encoding. However, there are several variations of the OT1 encoding to deal with. Also, as far as I know there are no officially sanctioned PostScript names for all the variations of the OT1 encoding. The fontinst names contain spaces, so they're not usable as PostScript names πŸ’”

✨ CHANGED IN VERSION 0.7.1 ✨

To avoid name conflicts, the .enc and .lig files distributed with afm2pl got afm2pl- prepended to their names 🏷️ The program itself now searches for the prepended name first. If the .enc or .lig file isn't found, it looks for the original filename. The renaming of the afm2pl .enc files may require modifying some mapfiles, so keep that in mind 🫣

✨ URLS ✨

The afm2pl homepage is http://tex.aanhet.net/afm2pl/.

The paper Font installation the shallow way[2] (EuroTeX 2006 Proceedings, published as TUGboat[3] issue 27.1) illustrates the use of afm2pl πŸ“„πŸ’œ

✨ NOTES ✨

  1. Except that, arguably, a narrowed Courier is less jarring than a full-width Courier when used alongside a normal proportional font. For Courier, choose .833 to match the width of cmtt. Better yet, don't use Courier at all; most TeX distributions offer various good replacements 🌷
  2. Font installation the shallow way https://tug.org/TUGboat/tb27-1/tb86kroonenberg-fonts.pdf

afm2pl is maintained as part of TeX Live 🌈


And that's a wrap, bestie πŸ¦‹ This page was last touched on 30 August 2022, and it's all afm2pl(1) energy from start to finish πŸ’…βœ¨ Stay iconic πŸ‘‘πŸ’–