Back to Table of Contents

Appendices


Adding fonts to groff

<prefix>, in this section, refers to the directory in which groff is installed, typically
/usr/share/groff/ (for distro-specific, pre-compiled groff packages) or
/usr/local/share/groff/ (if you’ve built groff from source).

<version> refers to the groff version number, which can be found, if necessary, by typing
groff -v at the command line.

Groff comes with a small library of families (see the FAMILY macro for a list). The families have four fonts associated with them. These fonts are a combination of weight and shape:
R (Roman, usually Medium weight), I (Italic, usually Medium weight), B (Bold, usually Roman shape) and BI (Bold Italic) If you work with mom a lot, sooner or later you’ll find that these families and their associated fonts aren’t sufficient. You’ll want to supplement them, either with more fonts for the families already provided—Damn! I need Helvetica Bold Condensed Italic—or with entire new families.

Extending groff families / adding new families and fonts

The traditional approach

The traditional approach to extending groff families has been to create new families for non-default weights and shapes (e.g. Light, which is a weight, or Condensed, which is a shape), then to associate them with groff’s predefined R, I, B and BI font styles. An example of this can be seen in the groff PostScript font library itself, which is found in
<prefix>/<version>/font/devps/ There’s one “family” for Helvetica (HR, HI, HB, HBI) and another for Helvetica Narrow (HNR, HNI, HNB, HNBI).

The difficulty with this approach is that typographers tend to think of families as referring to the entire set of font weights and shapes associated with a family name. For example, when a typesetter says “the Helvetica family”, s/he is including the weights Helvetica Thin, Helvetica Light, Helvetica Regular, Helvetica Bold, Helvetica Heavy, etc, and all their associated shapes (Roman, Italic, Condensed, Narrow, Extended, Outline, etc).

Thus, intuitively, when a typesetter gives mom a .FAMILY H directive, s/he reasonably expects that any subsequent .FT directive will access the desired font from the Helvetica family—without the need to state explicitly both family and font to .FT, as it is explained one can do in the FAMILY and FT sections of these documents.

If one had, say, Helvetica Light Roman and Helvetica Light Italic as well as Helvetica Light Condensed Roman and Helvetica Light Condensed Italic, the established groff approach would require two “partial” families, HL (for Helvetica Light) and HLCD (for Helvetica Light Condensed), with R and I fonts for both:
HLR HLI HLCDR HLCDI Accessing these family/font combos routinely throughout a document would then require changing the family (with .FAMILY) and selecting the desired font (with .FT R or .FT I), or passing .FT the lengthy family+fontname (.e.g. .FT HLCDI).

The simpler way with mom

Fortunately, groff provides a mechanism whereby it’s possible to extend the basic R, I, B and BI fonts (“styles” in groff-speak) so that one can, in fact, create extensive type families, and access all the fonts in them with .ft (groff) or .FT (mom).

Mom uses this mechanism to offer, in addition to groff’s default font styles, the following:

UL = Ultra Light ULI = Ultra Light Italic ULCD = Ultra Light Condensed ULCDI = Ultra Light Condensed Italic ULEX = Ultra Light Extended ULEXI = Ultra Light Extended Italic XL = Extra Light XLI = Extra Light Italic XLCD = Extra Light Condensed XLCDI = Extra Light Condensed Italic XLEX = Extra Light Extended XLEXI = Extra Light Extended Italic TH = Thin THI = Thin Italic THCD = Thin Condensed THCDI = Thin Condensed Italic THEX = Thin Extended THEXI = Thin Extended Italic L = Light Roman LI = Light Italic LCD = Light Condensed LCDI = Light Condensed Italic LEX = Light Extended LEXI = Light Extended Italic BK = Book Roman BKI = Book Italic BKCD = Book Condensed BKCDI = Book Condensed Italic BKEX = Book Extended BKEXI = Book Extended Italic CD = Medium Condensed CDI = Medium Condensed Italic EX = Medium Extended EXI = Medium Extended Italic DB = DemiBold Roman DBI = DemiBold Italic DBCD = DemiBold Condensed DBCDI = DemiBold Condensed Italic DBEX = DemiBold Extended DBEXI = DemiBold Extended Italic SB = SemiBold Roman SBI = SemiBold Italic SBCD = SemiBold Condensed SBCDI = SemiBold Condensed Italic SBEX = SemiBold Extended SBEXI = SemiBold Extended Italic
BCD = Bold Condensed BCDI = Bold Condensed Italic BEX = Bold Extended BEXI = Bold Extended Italic BO = Bold Outline XB = Extra Bold XBI = Extra Bold Italic XBCD = Extra Bold Condensed XBCDI = Extra Bold Condensed Italic XBEX = Extra Bold Extended XBEXI = Extra Bold Extended Italic UB = Ultra Bold UBI = Ultra Bold Italic UBCD = Ultra Bold Condensed UBCDI = Ultra Bold Condensed Italic UBEX = Ultra Bold Extended UBEXI = Ultra Bold Extended Italic HV = Heavy HVI = Heavy Italic HVCD = Heavy Condensed HVCDI = Heavy Condensed Italic HVEX = Heavy Extended HVEXI = Heavy Extended Italic BL = Black BLI = Black Italic BLCD = Black Condensed BLCDI = Black Condensed Italic BLEX = Black Extended BLEXI = Black Extended Italic BLO = Black Outline XBL = Extra Black XBLI = Extra Black Italic XBLCD = Extra Black XBLCDI = Extra Black XBLEX = Extra Black Italic XBLEXI = Extra Black Italic UBL = Ultra Black UBLI = Ultra Black Italic UBLCD = Ultra Black Condensed UBLCDI = Ultra Black Condensed Italic UBLEX = Ultra Black Exteneded UBLEXI = Ultra Black Extended Italic SC = Small Caps Roman SCI = Small Caps Italic SCDB = Small Caps Demibold SCDBI = Small Caps Demibold Italic SCSB = Small Caps Semibold SCSBI = Small Caps Semibold Italic

Thus, with mom, if you’ve installed some extra Helvetica fonts and named them according to the convention <F><S> (where <F> means family and <S> means font style), once having entered
.FAMILY H you can access any of the extra Helvetica fonts simply by passing the correct argument to FT from the list, above. For example, if you were working in Medium Roman (.FT R) and you needed Medium Condensed Italic for a while (assuming it’s installed), you’d just type
.FT CDI to access the Medium Condensed Italic font from the Helvetica family.

Mom’s list of font styles doesn’t pretend to be exhaustive. The extension names are arbitrary and can be used in a flexible manner. For example, if you create a family that has a Demibold font (DB) but no Bold font (B), you might find it more convenient to give the Demibold font the extension “B”.

You may, at needs, want to add to mom’s list of font styles. You can do this by editing the file, om.tmac (typical location: <prefix>/<version>/tmac/om.tmac). Near the top, you’ll see lines of the form
.sty \n[.fp] XL \" Extra Light .sty \n[.fp] L \" Light Roman .sty \n[.fp] LI \" Light Italic .sty \n[.fp] LCD \" Light Condensed Roman Simply add your new font style by imitating what you see, above, and plugging in your new font style (having, of course, added the font to groff, correctly named). directory; see Step-by-step instructions).

For example, if you already have some fonts from the Univers family installed and have called the family Univers, you might decide at some point to add the Bold Outline font (UniversBO). In which case, you’d add
.sty \n[.fp] BO \" Bold Outline to the .sty \n[.fp]  <font style> list in om.tmac.

Note: Mom’s font extensions are not “user-space” controllable via a macro. If you’ve been using groff for a long time, and have already rolled your own solution to adding families and fonts to groff, you may find that mom’s font extensions conflict with your own scheme. Should that be the case, comment out the .sty \n[.fp] <font style> lines found near the top of the om.tmac file.

Important: Be careful that any styles you add do not conflict with family names that already exist. “C”, for example, conflicts with the Courier family (CR, CI, CB, CI). Were you to create a font style “C”, thinking that .FT C would give you access to font style once you’d given a .FAMILY directive, you’d get a nasty surprise: your type would come out in Courier Roman!


Step-by-step instructions

There are a number of ways to approach making fonts available to groff. These instructions aren’t meant to cover all possibilities, merely one.

GNU/Linux distributions being what they are, directory locations may differ and the presence of some executables can’t be guaranteed. I run a Debian-based system. The instructions reflect that. Users of other distros may have to interpret them according to the way their distro operates.

What you need before you start

Initial preparation (you only need do this once)

  1. Locate the groff directory, site-font. The exact location is difficult to predict, owing to differences between distros and whether you’re using a pre-packaged groff or have built it from source. Some typical locations are:
    /usr/share/groff/ /usr/local/share/groff/ /etc/groff/ If you can’t find the site-font directory, locate groff’s site-tmac directory, and, as root, create site-font in the same directory. Eg, if you find site-tmac in /usr/share/groff/, create site-font in /usr/share/groff/
    sudo mkdir site-font
  2. Create two files, generate-t42.pe and generate-pfa.pe, as you see them below. Place them in a convenient and easily-remembered location, like your home directory.
    generate-t42.pe
    # generate-t42.pe Open($1); Generate($fontname + ".pfa"); Generate($fontname + ".t42");

    generate-pfa.pe
    # generate-pfa.pe Open($1); Generate($fontname + ".pfa");

Step 1: Acquire the font

The two most commonly available types of fonts are PostScript Type1 (extension .pfb) and TrueType (extension .ttf). Either can be made available to groff. There are many websites holding collections of both.

Step 2: Prepare to convert the font to the correct format

Change into the directory holding the new font.

For convenience in the next step, make a symbolic link to the file 'textmap':
ln -s <prefix>/<version>/font/devps/generate/textmap . See here for an explanation of <prefix> and <version>.

In addition, unless you're installing fonts from your home directory, make links to the files 'generate-t42.pe' and 'generate-pfa.pe'.
ln -s $HOME/generate-t42.pe . ln -s $HOME/generate-pfa.pe .

Step 3: Convert the font and put it in the right place

TrueType fonts (.ttf) need to be converted to .t42. Type 1 fonts (.pfb) need to be converted to .pfa.

 • TTF Fonts

For .ttf fonts, run
fontforge -script generate-t42.pe <file>.ttf This will create three new files with the extensions .t42, .pfa, and .afm. Next, run
afmtodit <afm file> textmap <groff font> This will create a groff font with the name you give. (See here for advice on naming groff fonts.)

Move the .t42 and groff font files to <prefix>/site-font/devps/.

If you're running a recent version of groff that includes the native pdf device (gropdf), move the .pfa file to <prefix>/<version>/font/devpdf/. If not, you may safely remove it. You may also safely remove the .afm file.

 • Type1 Fonts

For .pfb fonts, run
fontforge -script generate-pfa.pe <file>.ttf This will create two new files with the extensions .pfa, and .afm. Next, run
afmtodit <afm file> textmap <groff font> Move the .pfa and groff font files to <prefix>/<site-font>/devps/. (See here for advice on naming groff fonts.)

If you're running a recent version of groff that includes the native pdf device (gropdf), link the .pfa and groff font files, now in <prefix>/<site-font>/devps/, to the devpdf directory. Start by changing into the <prefix>/<version>/font/devpdf/ directory, then:
ln -s <prefix>/<version>/font/devps/<file>.pfa . ln -s <prefix>/<version>/font/devps/<groff font> . You may safely remove the .afm file.

Step 4: Update the download file

 • Get the internal font name

Inspect your new groff font file. Near the top, you will see a line of the form
internalname <name> Usually, the internal name is helpfully descriptive, eg,
internalname Optima-Bold Make a note of the internal name.

 • Add the font to the download file

Open the file <prefix>/<version>/font/devps/download. In it you will see lines of the form
Symbol-Slanted symbolsl.pfa ZapfDingbats-Reverse zapfdr.pfa FreeEuro freeeuro.pfa where the spaces are the tab character from the keyboard, not literal spaces. Thus,
Symbol-Slanted symbolsl.pfa is really
Symbol-Slanted<tab>symbolsl.pfa

The download file maps the internal names used by groff to the actual fonts. To add your new font to the download file, append a line containing the internal name, followed by a tab (make sure your text editor is inserting the tab character, not spaces), followed by the .t42 or .pfa font to which the internal name refers.

For example, if the internal name is Optima-Bold and the font is a .pfa file called Optima-Bold.pfa, your updated download file will contain
Optima-Bold<tab>Optima-Bold.pfa

 • Updating the gropdf download file

If you're running a recent version of groff that includes the native pdf device (gropdf), you must update its download file as well, which is found in <prefix>/<version>/font/devpdf/. The instructions are identical to those above, but with one important difference: all lines must begin with a tab character. Thus, using our Optima example, your devpdf download line for the same font is
<tab>Optima-Bold<tab>Optima-Bold.pfa

Naming groff fonts

For convenience when using mom, and to keep your font collection organized, choose meaningful groff font names following the scheme <Family><FONT>, where Family is something like Optima or Univers or Clarendon, and FONT is either
R  (roman/regular)
I  (italic)
B  (bold)
BI (bold italic)
or one of the 1–5 character fontstyles listed here. Thus, for the fonts Optima Light Italic and Optima Extra Black, your font names would be
OptimaLI OptimaXBL This scheme allows you to enter .FAMILY Optima to make Optima the current family, and .FT LI or .FT XBL when you need the fonts Light Italic or Extra Black.

Groff font names are, in fact, arbitrary; you can call your fonts anything you like, provided the internal name in the download file matches the internal name found in the groff font file. When calling a font that does not follow the recommended naming convention, you must pass the full font name to .FT whenever you wish to use it.

For example, the font, Goudy Stout, isn't really part of the Goudy family, and while "stout" describes it, Stout is not a recognized font style. Therefore, its groff name could simply be GoudyStout, and whenever you needed it, you could call it with .FT GoudyStout.

Automate the whole process – the install-font script

A bash script to make the entire process of installing fonts a painless no-brainer has been posted online at http://www.schaffter.ca/mom/install-font. Be sure to make the script executable (chmod 755 install-font) after you download it, then type ./install-font -H for usage.


Some reflections on mom

If, as Eric Raymond asserts, open source begins with a programmer scratching a personal itch, then mom can truly be called open source.

Mom had her origins in a library of groff routines I wrote over the years to handle various aspects of typesetting and document processing that weren’t adequately covered by ms, me, mm, and friends. Typically, I’d use the library to cobble together macro sets for new challenges as they came my way.

As a writer living in a perpetual state of penury, all the computers I’ve ever owned have been hand-me-downs—several generations out-of-date and resource challenged. Disk space has always been an issue, as has processor speed and available RAM. One of the reasons I run GNU/Linux rather than the offering from Redmond is that it has helped enormously to get the most out of my poor little boxes.

In Linux-land (all Unix variants, in fact), the choice of typesetting systems basically comes down to groff or TeX. Both are wonderful—monumental achievements if you ask me—and both have their own particular strengths. However, for people in my financial position (and there are millions of us around the globe, in both developed and developing countries), TeX and groff have one big difference: size. TeX is huge. Even its most ardent supporters agree it suffers from bloat, on top of being complex and unwieldy to manage. Groff is tiny by comparison, occupying minimal disk space and having only a small memory footprint while at the same time being flexible and powerful, typographically speaking. Back in the Jurassic Period, I ran it successfully on a 386 with 8 megs of RAM and a 250 meg hard disk.

However, groff has always had a liability: it’s incredibly geeky. Owing to its very long history, it—and its power users —seem to have remained stuck in a time warp. The canonical macro packages still look as they did back in those decades when memory was exorbitantly expensive and every byte mattered.

For some time now, groff users and macro writers have had the option to use “long” names for macros (i.e. longer than two letters, the original limit), yet have mostly chosen not to. With long names, it’s possible to create macro sets that are humanly readable and easy to interpret, encouraging development and evolution. What’s more, the macros themselves need not be terse, intimidating, and easily forgotten 1- or 2-letter commands inserted in the body of a document. They can be sensible and helpful to everyone, groff newbies and old hands alike.

Mom’s macro file, om.tmac, uses long names, aliases, and a host of other groff goodies that have become part of the whole groff picture. The function of nearly every macro, number register and string can be infered simply from its name. The file is heavily commented. A consistent, if idiosyncratic, indenting style is used as well, significantly improving readability. Anyone wanting to futz around with mom’s macros should be able to do so with a minimum of head scratching.

Note: The main macro file, om.tmac, is stripped of comments when groff is built from sources. om.tmac, in the sources themselves, still contains the comments, as do the tarballs posted on mom’s homepage.


Contact the author

If you have any questions or comments about mom, suggestions to make, criticisms to offer, or bugs to report, use the groff mailing list (subscription information available here) or contact me, Peter Schaffter, directly at the following address:
peter@schaffter.ca Please include the word “mom” or “groff” in the Subject line of any message sent to my personal address or you risk the wrath of my implacable spam filters.

If you want to visit mom’s website, you’ll find a link to it at
http://www.schaffter.ca The site contains links to some of my fiction, all of which was typeset with mom and groff.


Back to Table of Contents Top