Table 24.1 lists the keywords for Greek letters.
Note that there is no provision for the upper-case letters that are identical to their roman cousins (A, B, E, H, I, K, M, N, O, P, T, X, and Z). If you want an upper-case alpha, just type A.
eqn also includes the following terms, which are printed in roman, not italic, type:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Desired Output |
Code |
Actual Output |
|
a + b = c |
a~+~b~=~c |
(as desired) |
|
a + b = c |
a + b = c |
a+b=c |
|
a=(x2)+1 |
a=(x sup 2) + 1 |
(as desired) |
|
a=(x2)+1 |
a=(x sup 2)+ 1 |
a=(x2)+1 |
|
x2 |
x sub 2 |
(as desired) |
|
x2 |
x sub2 |
xsub2 |
|
xi2 |
x sub i sup 2 |
(as desired) |
|
xi2 |
x sup 2 sub i |
x2i |
Fractions are produced in a straightforward way. Simply use the word over. For example, the code
# a over b #
produces

More complex fractions present additional problems. Think about the following equation for a moment:
a + b over c
This code line could mean # {a+b} over c # or # a + {b over c} #. The most important thing to remember about fractions is to use braces.
You can, of course, produce an expression with a fraction like this:

The keyword sqrt produces the root sign. Consider these expressions:

They are produced with the following code:
sqrt a+b=x
sqrt {X bar}
y= sqrt {a-b}
y = sigma over {sqrt N}
You can also produce large root signs. For example,
sqrt {{a sup x} over b sub y}
When you do this, however, the root sign doesn't just get bigger; it gets thickerand uglier. In cases like this, you're better off using a fractional power. For example,
{( a sup x /b sub y ) } sup half
produces

In their simplest form, sums, integrals, and limits are produced by sum, int, and lim. Of course, you never see them in their simplest form. Usually included is a from or even a from and a to. For example,
sum from 1=0 to {i=inf} x sup i
int from a to b
lim from {n -> inf} sum from i=0 to m c sup i
produces

In addition, you can use prod, union, and inter to produce the symbols used with sets.
You can create big braces and brackets by enclosing expressions that require them. Consider the following code:
#left [ {a over b} + {c over d} right ]#
#left { {s over t} - {r over q} right }#
The expression that this code produces is

You can specify floor and ceiling characters. For example,
left floor a over b right floor => left ceiling x over y right ceiling
produces

Although piles look like big brackets, they are actually different. Piles line up in three ways: left, right, and centered. For example,
A= left [
pile { a above b above c }
pile { x above y above z }
right ]
produces

If you require only one brace, you must include a null argument for the missing side. Consider
left ""
lpile
{SIGMA X sub 3 above SIGMA X sub 1
X sub 3 above SIGMA X sub 2 X sub 3}
right )
which produces

To create an array or a matrix, use the keyword matrix, as in
matrix {
lcol { 0 above {x over y} }
rcol { 1 above {x sup 2} }
}
This code produces

You could use ccol to center columns. The main advantage of using the matrix keyword, though, is that the elements align themselves horizontally better.
If you use a complex term over and over again, you can define it as something short. A good choice, for example, is &. Then, instead of typing
x= sqrt {SIGMA {x sup 2}} over N
you can type
x= &
define works like this:
.EQ
define & 'sqrt {SIGMA {x sup 2}} over N'
x = &
.EN
You can select any characters you wantfg, xy, and so onbut be sensible. Don't choose ^ or ~. Don't choose your eqn delimiters. And don't choose an eqn keyword, even though it is permitted.
Without braces to force it to look at terms as groups, eqn recognizes the following orders of precedence:
dyad vec under bar tilde hat dot dotdot
left right
fwd back down up
fat roman italic bold size
sub sup
sqrt over
from to
All operations group to the right, except for sqrt, left, and right, which group to the left.
eqn offers several ways for you to beautify your output. You can line up several equations, change fonts and point sizes, and insert vertical and horizontal movement.
To line up several equations, use mark and lineup. mark, which can be used only once in an equation, marks the horizontal position where lineup aligns the other equations. For example,
.EQ a mark = b .EN .EQ lineup = b+1 .EN .EQ lineup = b+c+1 .EN
produces

You can also change fonts and point sizes in an equation. Table 24.5 describes the keywords used.
Keyword |
Description |
|
bold |
Prints the next character or term in bold type |
|
fat |
Prints the next character or term in pseudo-bold, by overstriking |
|
font f |
Changes to font f any font that troff recognizes (such as R, B, I, CW, and HB) |
|
italic |
Prints the next character or term in italic type |
|
roman |
Prints the next character or term in roman type |
|
size n |
Changes to point size n, which can be specified as a number or as a relative quantity (such as size -2 or size +3) |
There is a gsize option for setting a global point size. Similarly, there is a gfont. You should put these options near the top of your file; otherwise, eqn uses the default point size (usually 10).
You can use eqn to put diacritical marks on foreign words. Just remember that eqn prints words in italics. So you need to specify roman. Consider the following code:
No# roman e dotdot #l Coward Georg H# roman a dotdot #ndel malague# roman n tilde #a
It produces
Noël Coward
Georg Händel
malagueña
You can also use eqn to produce the service mark symbol if it isn't available as a troff special character. The service mark is like the trademark except that it reads SM. For example,
XYZZY-Box# sup roman SM #
produces
XYZZY-BoxSM
Okay, it's not as neat as XYZZY-BOX\(SM, but it's a whole lot better than XYZZY-Box\v' -3p'\s-3SM\s+3\v' +3p'!
Sometimes, despite your best efforts, your equations just don't come out right. Here are some suggestions for detecting and correcting faulty code, and for dealing with some of eqn's more arcane characteristics.
At its best, eqn is quirky. So, before you print a 50-page chapter containing 70 equations, check your equations. This pinpoints syntax errors such as unmatched delimiters. The checkeq program is a good place to start. Use checkeq like this:
checkeq myeqnfile
If checkeq finds no errors, it displays the following:
myeqnfile
or
myeqnfile:
New delims: ##, line 2
If you have an odd number of delimiters, you'll see something like this:
myeqnfile:
myeqnfile:
New delims: ##, line 2
3 line ##, lines 7-9
3 line ##, lines 9-11
3 line ##, lines 11-13
3 line ##, lines 13-15
3 line ##, lines 15-17
Unfinished ##
If, for some reason, you've specified bad delimiters (#$, for example, or #), checkeq announces:
myeqnfile
Strange delims at Line 2
or
myeqnfile
Unfinished
checkeq isn't good for much more than this.
Because checkeq lets a lot of mistakes slip by, you can also process your equation and send output to /dev/null (so you don't clutter your directory with a lot of troff output).
To do this:
eqn myeqnfile > /dev/null
When errors are found, you see a message like the following:
eqn: syntax error near line 19, file nyeqnfile
context is
!a = (x >>> {sup <<<< 2}) + 1!
The line number is not guaranteed, but it should be close.
Again, this is not foolproof because, if eqn can process your code, it will. You'll get no error message, even if your output is garbled or nonexistent.
If you get no output at all:
If your file contains nothing but an equation, try inserting a line of text before the equation. If you don't want text, use translated tildes:
.tr ~ ~ ~ ~ .EQ x sup 2 + y sup 2 = z sup 2 .EN
Oddly enough, this does not seem to affect eqn codeeven code with tildes in it.
If the vertical spacing is wrong: Try printing your file with a different macro packageor with no macro package. (If you're using a home-grown package, you may have to pipe your file through eqn before you send it through troff.) Try
processing the eqn code and replacing the code with the processed code in your file. Try using space 0 as the first line of your eqn code:
.EQ space 0 code . . . .EN
If you're using the .EQ/.EN macros to delimit your equation, try using delimiters (## or !!)and, of course, vice versa.
If your equation is garbled: Check for omitted spaces and braces. (Use them, even if you don't really need them.) Count braces and parentheses to make sure you have an even number of each. checkeqand eqn itselfdoesn't always find this
problem. If your equation contains a sup, make sure you use spaces around its argument, even if there's a brace. Make sure you have keywords in the right order. For example, #x highbar tilde# produces no error message, but it prints the bar right on the
tilde. (The correct order is #x tilde highbar#.) If your equation is long or complicated, use lots of spaces and newlines to make it easy to read.
You can use eqn with any of the other preprocessors (pic, grap, and tbl), but only with delimitersnot with .EQ/.EN macros. Before you do this, however, ask yourself if it's really necessary. You could always get another job, or move to a tiny
island with no electricity and no telephone lines.
The sections that follow provide some help if you can't face life without grap.
You cannot use ## as eqn delimiters with pic code. You can use $$ and !! and %%. I wouldn't experiment with anything else.
Complicated equations inside pic pictures will come out wrong if eqn has to provide extra vertical spacefor example, for an integral sign. Use space 0 to (try to) prevent this, as follows:
.EQ delim !! . . . pic code "!space 0 eqn code!"
You need the quotation marks for pic.
A simple example of pic and eqn is

The code is as follows:
.EQ delim !! .EN .PS box ht .75i wid i.5i "!a sup 2 + b sup 2 = c sup 2!" .PE
Because grap is built on pic, you can expect similar problems if you use eqn with grap. You can use the same delimiters, and you can expect to have to use space 0 to correct vertical spacing problems. eqn tries to override grap's spacing unless you do.
Do just as you did for pic; here's an example:
.EQ
delim !!
.EN
.G1
label left "!y= sqrt { (2x sup 3 + 1)/3}!"
.G2
You must use quotation marks, as with pic.
There are a few simple rules for using eqn in tables. (tbl is discussed in detail in Chapter 23.)
To put an equation in a table, do the following:
With me and ms, you can use arguments to the .EQ macro to position your equation horizontally. Both packages accept the following:
.EQ C \centers the equation .EQ I \indents the equation .EQ L \left justifies the equation
eqn is a limited use program, but a very useful one. It's easy to learn, easy to use (except for the spaces), and it does an excellent job of setting mathematical expressions.
multipage table, use the .TS H and .TH macros.
Use .TS H to start your table if you are going to specify a column heading. Then use .TH after the lines that constitute the heading. Be sure to include underscores and spaces if they are part of the heading.
tbl accommodates both horizontal and vertical spanning. Use horizontal spanning to center a column heading over more than one column, as in
c s s
Figure 23.2 illustrates horizontal spanning.
Figure 23.2. A table with horizontal spanning.
You can code vertical spanning in the tbl format options or in the table data. Vertical spanning in the column headings is produced by using ^ in the format specifications. Vertical spanning in the table data is produced by using \^.
A text block is a block of texta paragraphused as a table entry. Figure 23.3 shows a table with text blocks.
Figure 23.3. A table with text blocks.
The text block is coded as part of the table entry:
1990-1991[TAB]T{
.na
Writer. \f2Jurassic Park II\fP, \f2Daughter of the Firm\fP, \f2The
Cat in the Hat Spends a Year in Provence\fP. Took best-selling ideas
and capitalized on them. Raised my income 576% in just one year.
T}
.sp .5
1991-date[TAB]T{
.na
Law Student. Attending Harvard Law School; expect to receive degree
this year.
T}
Because tbl right-justifies text blocks, you might want to turn off adjustment inside the text blocks, as in the previous example. Use .na to do this.
The number of text blocks that can be used within a single table varies, depending on the tbl version. If you're using a recent version, don't worry about this. Even if you're using an old version, don't worry. tbl will complain loudly if you use too
many text blocks. Your only remedy is to break the table into smaller tables.
Text blocks complicate a table. The first time you use them, you're almost certain to leave out the beginning or ending T-brace or to use an opening brace instead of a closing one. If you do this, tbl assumes your unmatched T-brace is data and prints
it, so the error is easy to find.
The default gap between columns is 3 ens. You can adjust this gap by putting a number between your format options, as in
cB 2 lB 2 lB 1 cB
You can even set the gap to 0.
You can use .sp to put more space between table rows. (Don't use macros; use the troff primitive.) Using .sp .25 before and after an underscore and with column headings usually improves the appearance of the table.
If you have some two-line column heads and some one-line column heads, the allbox global option looks really awful. Similarly, if you've spanned any column, allbox doesn't work correctly. You can insert vertical lines between columns by using the pipe
character (|). You can even combine vertical lines with changes in the column gap.
You can change format options in the middle of a table. You can't change the number of columns, but you can change anything else. Use spanning to change the apparent number of columns.
To change tbl format options, use the .T& macro and insert a line (or several lines) of format options.
The following code illustrates the advanced formatting techniques described in the previous sections. It produces the table shown in Figure 23.4.
.TS center; c s s s lB cB cB cB l l l l. \fb\s14Old Garden Roses\s0\fP .sp .25 Type[TAB]Examples[TAB]Color[TAB]Date .sp .25 \_[TAB]\_[TAB]\_[TAB]\_ .sp .25 Alba[TAB]Celestial[TAB]milky peach[TAB]before1848 \^[TAB]Felicite Parmentier[TAB]pale pink[TAB]before 1834 .sp .5 Bourbon[TAB]La Reine Victoria[TAB]rich pink[TAB]1872 \^[TAB]Louise Odier[TAB]deep pink[TAB]1851 \^[TAB]Souvenir de la Malmaison[TAB]soft pink[TAB]1843 .sp .5 .Centifolia[TAB]Fantin-Latour[TAB]rich pink[TAB]unknown .sp .5 China[TAB]Mutabilis[TAB]warm pink[TAB]unknown .sp .5 Damask[TAB]Celsiana[TAB]soft pink[TAB]before 1750 \^[TAB]Mme. Hardy[TAB]white[TAB]1832 .sp .5 Gallica[TAB]Cardinal de Richelieu[TAB]rosy violet[TAB]1840 \^[TAB]Rosa Mundi[TAB]striped crimson[TAB]before 1581 [TAB][TAB][TAB]\0\0and pale pink .TE
When you use tbl, keep the following points in mind:
tbl is one of the most used, yet least liked programs, offered by the UNIX system. It is well worth the effort to learn at least the rudiments of tbl, because you can use tables to your advantage in unexpected situations. You can also make friends and
influence supervisors if you take the time to learn tbl thoroughly. A good tbl debugger is hard to find.