Format of troff
Width Tables
As discussed in Chapter 4, troff
uses width tables stored in the directory /usr/lib/font
to determine how to place text on the page. To do this, it needs to know how wide each character is.
For each type of troff
output device supported by your system, there should be a directory called /usr/lib/f ont/dev
xx, where xx is the name of the device. For example, on our system:
$ ls -F /usr/lib/font
devlj/
devps/
Within each of these directories resides an overall device description file, called DESC, and individual font files for the fonts on your system. These files exist both in ASCII and binary form. The binary files are created from the ASCII versions using a utility called makedev
, and have the suffix .out
.
On our system, here’s what the font directory for the HP Laserjet contains:
$ ls /usr/lib/font/devl
B DESC I S
B.out DESC.outI.out S.out
CW HB R TY
CW.out HB.out R.out TY.out
▪ The DESC File ▪
The DESC
file contains an overall description of the output device, including its resolution in dots per inch, the paper size, the fonts that will be mounted by default, the available point sizes, and a complete list of all the troff
special character names supported on that device.
A DESC file might look something like the following example:
# HP LaserJet
fonts 6 R I B HB CW S
sizes 7 8 10 12 14 17 22 27 0
res 300
hor 1
vert 1
unitwidth 12
paperwidth 2400
paperlength 3300
charset
\| \^ \-
fi fl ff Fi Fl
br vr ul ru
bu sq em hy 14 12 34 aa ga
.
.
.
sc gr no is pt es mo
dd rh lh bs or ci
lt lb rt rb lk rk bv lf rf lc rc
The following keywords are used in the DESC
file:
▪ Font Description Files ▪
For each font listed on the fonts
line of the DESC
file, there should be a font file with the same name. The font file contains a list of all the characters in the font, along with the width and other associated information.
A font file looks like this:
name R
internalname Roman
charset
4 0 0
8 0 0
vr 0 3 13
ru 25 0 17
.
.
.
A 42 2 65
B 35 2 66
C 37 2 67
.
.
.
w 40 0 119
x 28 0 120
y 28 1 121
z 25 0 122
.
.
.
Four columns, separated by tabs, are listed for each character.
The first column lists the character name—either the letter, digit, or symbol, or a two-character troff
special character name defined in the charset
section of DESC
.
The second column contains the width of the character in output device units. The width is the width of the character at the point size specified by the unitwidth
keyword in DESC
. For example, if unitwidth
is 12, then from the portion of the table just shown, we know that a 12-point A in the roman font is 42 units wide. The troff
formatter determines the width at other point sizes by scaling the unitwidth
size.
The third column describes the character type—that is, whether it is an descender (1), ascender (2), both (3), or neither (0).
The fourth column contains the typeset code for the character. This code is the value that the output device will recognize to generate the character. This information is obtained from the typesetter or laser printer vendor. The code can be in decimal or octal form. (Octal is specified by a leading zero.)
In general, whomever supplied the driver for the output device will provide you with appropriate width tables for the supported fonts. However, you may have access to other public domain fonts for output devices that support downloadable raster fonts. In this case, you may need to build your own tables.
In addition, you may want to “tune” tables by adjusting the widths slightly if you find that the character spacing is poor. Creating a font table from scratch requires a magnifying glass, a micrometer, a good eye, and a lot of patience.
▪ Compiling Font Files ▪
After you are satisfied with your width tables, they need to be compiled using the makedev utility:
$ makedev DESC
Compile all fonts in DESC
Running makedev
on DESC
will compile all of the fonts
listed on the fonts line in that file. You can compile a font that is not included in DESC
by specifying its name on the command line:
$ makedev B
Compile the bold font
▪ Font Usage Limitations ▪
The user is not restricted to using the “mounted” fonts that have been listed in DESC
. Any font supported by the output device, and for which a compiled width table exists, can be referred to from within a document. For example, if you had a Palatino font family named PA, PB
, and PI
, there should be files called:
One problem that is sometimes encountered is that troff
has problems if a font that is used in this way is larger (in absolute file size) than the largest of the mounted fonts specified in DESC
. The troff
formatter only allocates enough memory for the largest font in DESC
. If you encounter this problem, you can either strip unneeded characters out of the font, pad a font in DESC
, or add the large font that is giving you trouble to DESC
.
Get UNIX° TEXT PROCESSING now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.