SysIII/usr/src/man/docs/eqn_guide

.ds :? EQN Guide
.de PT
.lt \\n(LLu
.pc %
.nr PN \\n%
.if \\n%-1 .if o .tl '\s9\f2\*(:?\fP''\\n(PN\s0'
.if \\n%-1 .if e .tl '\s9\\n(PN''\f2\*(:?\^\fP\s0'
.lt \\n(.lu
..
.tr %$
.de SC
.NH
\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 
..
.de UC
\&\\$3\s-2\\$1\\s+2\\$2
..
.de P1
.nf
.tr -\(mi
.tr ^.
.tr '\(fm
.ss 18
.if \\n(.$ .DS I \\$1
.if !\\n(.$ .DS
..
.de P2
.DE
.fi
.ss 12
.tr --
.tr ^^
.tr ''
..
.tr _\(em
.hy 14
.EQ
delim $$
.EN
'\"	.ND "June 2, 1976"
.TL
Typesetting Mathematics_User's Guide
(Second\ Edition)
.AU 2C-518 6021
Brian W. Kernighan
.AU
Lorinda L. Cherry
.AI
.MH
.AB
.in
.ll
.PP
This is the user's guide for a system for typesetting
mathematics,
using
the phototypesetters on the
.UX
and
.UC GCOS
operating systems.
.PP
Mathematical expressions are described in a language
designed to be easy to use
by people who know neither mathematics nor typesetting.
Enough of the language to set in-line expressions like
$lim from {x-> pi /2} ( tan~x) sup{sin~2x}~=~1$
or display equations like
.in .5i
.EQ I
G(z)~mark =~ e sup { ln ~ G(z) }
~=~ exp left ( 
sum from k>=1 {S sub k z sup k} over k right )
~=~  prod from k>=1 e sup {S sub k z sup k /k}
.EN
.EQ I
lineup = left ( 1 + S sub 1 z + 
{ S sub 1 sup 2 z sup 2 } over 2! + ... right )
left ( 1+ { S sub 2 z sup 2 } over 2
+ { S sub 2 sup 2 z sup 4 } over { 2 sup 2 cdot 2! }
+ ... right ) ...
.EN
.EQ I
lineup =  sum from m>=0 left (
sum from
pile { k sub 1 ,k sub 2 ,..., k sub m  >=0
above
k sub 1 +2k sub 2 + ... +mk sub m =m}
{ S sub 1 sup {k sub 1} } over {1 sup k sub 1 k sub 1 ! } ~
{ S sub 2 sup {k sub 2} } over {2 sup k sub 2 k sub 2 ! } ~
...
{ S sub m sup {k sub m} } over {m sup k sub m k sub m ! } 
right ) z sup m
.EN
.in 0
can be learned in an hour or so.
.PP
The language interfaces directly with
the phototypesetting language
.UC TROFF ,
so mathematical expressions can be embedded in the running
text
of a manuscript,
and the entire document produced in one process.
This user's guide is an example of its output.
.PP
The same language
may be used with the 
.UX
formatter
.UC NROFF
to set mathematical expressions on 
.UC DASI
and
.UC GSI
terminals
and Model 37 teletypes.
.AE
.CS 11 0 11 0 0 3
.if t .2C
.SC Introduction
.PP
.UC EQN
is a
program for typesetting mathematics
on the Graphics Systems phototypesetters on
.UX
and
.UC GCOS .
The 
.UC EQN
language was designed to be easy to use
by people who know neither mathematics
nor typesetting.
Thus
.UC EQN
knows relatively little about mathematics.
In particular, mathematical symbols like
+, \(mi, \(mu, parentheses, and so on have no special meanings.
.UC EQN
is quite happy to set garbage (but it will look good).
.PP
.UC EQN
works as a preprocessor for the typesetter formatter,
.UC TROFF [1],
so the normal mode of operation is to prepare
a document with both mathematics and ordinary text
interspersed,
and let
.UC EQN
set the mathematics while
.UC TROFF
does the body of the text.
.PP
On
.UX ,
.UC EQN
will also produce mathematics on
.UC DASI 
and
.UC GSI
terminals and on
Model 37 teletypes.
The input is identical, but you have to use the programs
.UC NEQN 
and
.UC NROFF
instead of
.UC EQN 
and
.UC TROFF .
Of course, some things won't look as good
because terminals 
don't provide the variety of characters, sizes and fonts
that a typesetter does,
but the output is usually adequate for proofreading.
.PP
To use 
.UC EQN
on
.UX ,
.P1
eqn files | troff
.P2
.UC GCOS
use is discussed in section 26.
.SC Displayed Equations
.PP
To tell
.UC EQN
where a mathematical expression begins and ends,
we mark it with lines beginning
.UC .EQ
and
.UC .EN .
Thus
if you type the lines
.P1
^EQ
x=y+z
^EN
.P2
your output will look like
.EQ
x=y+z
.EN
The
.UC .EQ
and
.UC .EN
are copied through untouched;
they
are not otherwise processed
by
.UC EQN .
This means that you have to take care
of things like centering, numbering, and so on
yourself.
The most common way is to use the
.UC TROFF
and
.UC NROFF
macro package package `\(mims'
developed by M. E. Lesk[3],
which allows you to center, indent, left-justify and number equations.
.PP
With the `\(mims' package,
equations are centered by default.
To left-justify an equation, use
.UC \&.EQ\ L
instead of
.UC .EQ .
To indent it, use
.UC .EQ\ I .
Any of these can be followed by an arbitrary `equation number'
which will be placed at the right margin.
For example, the input
.P1
^EQ I (3.1a)
x = f(y/2) + y/2
^EN
.P2
produces the output
.EQ I (3.1a)
x = f(y/2) + y/2
.EN
.PP
There is also a shorthand notation so
in-line expressions
like
$pi sub i sup 2$
can be entered without
.UC .EQ
and
.UC .EN .
We will talk about it in section 19.
.SC Input spaces
.PP
Spaces and newlines within an expression are thrown away by
.UC EQN .
(Normal text is left absolutely alone.)
Thus
between
.UC .EQ
and
.UC .EN ,
.P1
x=y+z
.P2
and
.P1
x = y + z
.P2
and
.P1
x   =   y   
   + z
.P2
and so on
all produce the same
output
.EQ
x=y+z
.EN
You should use spaces and newlines freely to make your input equations
readable and easy to edit.
In particular, very long lines are a bad idea,
since they are often hard to fix if you make a mistake.
.SC Output spaces
.PP
To force extra spaces into the 
.ul
output,
use a tilde ``\|~\|''
for each space you want:
.P1
x~=~y~+~z
.P2
gives
.EQ
x~=~y~+~z
.EN
You can also use a circumflex ``^'', 
which gives a space half the width of a tilde.
It is mainly useful for fine-tuning.
Tabs may also be used to position pieces
of an expression,
but the tab stops must be set by 
.UC TROFF
commands.
.SC "Symbols, Special Names, Greek"
.PP
.UC EQN
knows some mathematical symbols,
some mathematical names, and the Greek alphabet.
For example,
.P1
x=2 pi int sin ( omega t)dt
.P2
produces
.EQ
x = 2 pi int sin ( omega t)dt
.EN
Here the spaces in the input are
.B
necessary
.R
to tell
.UC EQN
that
.ul
int,
.ul
pi,
.ul
sin
and
.ul
omega
are separate entities that should get special treatment.
The
.ul
sin,
digit 2, and parentheses are set in roman type instead of italic;
.ul
pi
and
.ul
omega
are made Greek;
and
.ul
int
becomes the integral sign.
.PP
When in doubt, leave spaces around separate parts of the input.
A
.ul
very
common error is to type
.ul
f(pi)
without leaving spaces on both sides of the
.ul
pi.
As a result,
.UC EQN
does not recognize
.ul
pi
as a special word, and it appears as
$f(pi)$
instead of
$f( pi )$.
.PP
A complete list of
.UC EQN
names appears in section 23.
Knowledgeable users can also use
.UC TROFF
four-character names
for anything 
.UC EQN
doesn't know about,
like
.ul
\\(bs
for the Bell System sign \(bs.
.SC "Spaces, Again"
.PP
The only way
.UC EQN
can deduce that some sequence
of letters might be special
is if that sequence is separated from the letters
on either side of it.
This can be done by surrounding a special word by ordinary spaces
(or tabs or newlines),
as we did in the previous section.
.PP
.tr ~~
You can also make special words stand out by surrounding them
with tildes or circumflexes:
.P1
x~=~2~pi~int~sin~(~omega~t~)~dt
.P2
is much the same as the last example,
except that the tildes
not only
separate the magic words
like
.ul
sin,
.ul
omega,
and so on,
but also add extra spaces,
one space per tilde:
.EQ
x~=~2~pi~int~sin~(~omega~t~)~dt
.EN
.PP
Special words can also be separated by braces { }
and double quotes "...",
which have special meanings that we will
see soon.
.tr ~
.SC "Subscripts and Superscripts"
.PP
Subscripts and superscripts are
obtained with the words
.ul
sub
and
.ul
sup.
.P1
x sup 2 + y sub k
.P2
gives
.EQ
x sup 2 + y sub k
.EN
.UC EQN
takes care of all the size changes and vertical motions
needed to make the output look right.
The words
.ul
sub
and
.ul
sup
must be surrounded by spaces;
.ul
x sub2
will give you
$x sub2$ instead of $x sub 2$.
Furthermore, don't forget to leave a space
(or a tilde, etc.)
to mark the end of a subscript or superscript.
A common error is to say
something like
.P1
y = (x sup 2)+1
.P2
which causes
.EQ
y = (x sup 2)+1
.EN
instead of
the intended
.EQ
y = (x sup 2 )+1
.EN
.PP
Subscripted subscripts and superscripted superscripts
also work:
.P1
x sub i sub 1
.P2
is
.EQ
x sub i sub 1
.EN
A subscript and superscript on the same thing
are printed one above the other
if the subscript comes
.ul
first:
.P1
x sub i sup 2
.P2
is
.EQ
x sub i sup 2
.EN
.PP
Other than this special case,
.ul
sub
and
.ul
sup
group to the right, so
.ul
x\ sup\ y\ sub\ z
means
$x sup {y sub z}$, not ${x sup y} sub z$.
.SC "Braces for Grouping"
.PP
Normally, the end of a subscript or superscript is marked
simply by a blank (or tab or tilde, etc.)
What if the subscript or superscript is something that has to be typed
with blanks in it?
In that case, you can use the braces
{ and } to mark the
beginning and end of the subscript or superscript:
.P1
e sup {i omega t}
.P2
is
.EQ
e sup {i omega t}
.EN
.sp
Rule:  Braces can
.ul
always
be used to force 
.UC EQN
to treat something as a unit,
or just to make your intent perfectly clear.
Thus:
.P1
x sub {i sub 1} sup 2
.P2
is
.EQ
x sub {i sub 1} sup 2
.EN
with braces, but
.P1
x sub i sub 1 sup 2
.P2
is
.EQ
x sub i sub 1 sup 2
.EN
which is rather different.
.PP
Braces can occur within braces if necessary:
.P1
e sup {i pi sup {rho +1}}
.P2
is
.EQ
e sup {i pi sup {rho +1}}
.EN
The general rule is that anywhere you could use some single
thing like
.ul
x,
you can use an arbitrarily complicated thing if you enclose
it in braces.
.UC EQN
will look after all the details of positioning it and making
it the right size.
.PP
In all cases, make sure you have the
right number of braces.
Leaving one out or adding an extra will cause 
.UC EQN
to complain bitterly.
.PP
Occasionally you will have to
print braces.
To do this,
enclose them in double quotes,
like "{".
Quoting is discussed in more detail in section 14.
.SC Fractions
.PP
To make a fraction,
use the word
.ul
over:
.P1
a+b over 2c =1
.P2
gives
.EQ
a+b over 2c =1
.EN
The line is made the right length and positioned automatically.
Braces can be used to make clear what goes over what:
.P1
{alpha + beta} over {sin (x)}
.P2
is
.EQ
{alpha + beta} over {sin (x)}
.EN
What happens when there is both an
.ul
over
and a
.ul
sup
in the same expression?
In such an apparently ambiguous case,
.UC EQN
does the
.ul
sup
before the
.ul
over,
so
.P1
\(mib sup 2 over pi
.P2
is
$-b sup 2 over pi$
instead of
$-b sup {2 over pi}$
The rules
which decide which operation is done first in cases like this
are summarized in section 23.
When in doubt, however,
.ul
use braces
to make clear what goes with what.
.SC "Square Roots"
.PP
To draw a square root, use
.ul
sqrt:
.P1 2
sqrt a+b + 1 over sqrt {ax sup 2 +bx+c}
.P2
is
.EQ
sqrt a+b + 1 over sqrt {ax sup 2 +bx+c}
.EN
Warning _ square roots of tall quantities look lousy,
because a root-sign 
big enough to cover the quantity is
too dark and heavy:
.P1
sqrt {a sup 2 over b sub 2}
.P2
is
.EQ
sqrt{a sup 2 over b sub 2}
.EN
Big square roots are generally better written as something
to the power \(12:
.EQ
(a sup 2 /b sub 2 ) sup half
.EN
which is
.P1
(a sup 2 /b sub 2 ) sup half
.P2
.SC "Summation, Integral, Etc."
.PP
Summations, integrals, and similar constructions
are easy:
.P1
sum from i=0 to {i= inf} x sup i
.P2
produces
.EQ
sum from i=0 to {i= inf} x sup i
.EN
Notice that we used
braces to indicate where the upper
part
$i= inf$
begins and ends.
No braces were necessary for the lower part $i=0$,
because it contained no blanks.
The braces will never hurt,
and if the 
.ul
from
and
.ul
to
parts contain any blanks, you must use braces around them.
.PP
The
.ul
from
and
.ul
to
parts are both optional,
but if both are used,
they have to occur in that order.
.PP
Other useful characters can replace the
.ul
sum
in our example:
.P1
int   prod   union   inter
.P2
become, respectively,
.EQ
int ~~~~~~ prod ~~~~~~ union ~~~~~~ inter
.EN
Since the thing before the 
.ul
from
can be anything,
even something in braces,
.ul
from-to
can often be used in unexpected ways:
.P1
lim from {n \(mi> inf} x sub n =0
.P2
is
.EQ
lim from {n-> inf} x sub n =0
.EN
.SC "Size and Font Changes"
.PP
By default, equations are set in 10-point type (the same size as this guide),
with standard mathematical conventions
to determine what characters are in roman and what in italic.
Although 
.UC EQN
makes a valiant attempt to use
esthetically pleasing sizes and fonts,
it is not perfect.
To change sizes and fonts, use
.ul
size n
and
.ul
roman, italic, 
.ul
bold
and
.ul
fat.
Like
.ul
sub
and
.ul
sup,
size
and font changes affect only the thing that follows
them, and revert to the normal situation
at the end of it. Thus
.P1
bold x y
.P2
is
.EQ
bold x y
.EN
and
.P1
size 14 bold x = y +
   size 14 {alpha + beta}
.P2
gives
.EQ
size 14 bold x = y +
   size 14 {alpha + beta}
.EN
As always, you can use braces if you want to affect something
more complicated than a single letter.
For example, you can change the size of an entire equation by
.P1
size 12 { ... }
.P2
.PP
Legal sizes which may follow 
.ul
size
are
6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36.
You can also change the size
.ul
by
a given amount;
for example, you can say
.ul
size~+2
to make the size two points bigger,
or
.ul
size~\(mi3
to make it three points smaller.
This has the advantage that you don't have
to know what the current size is.
.PP
If you are using fonts other than roman, italic and bold,
you can say
.ul
font X
where 
.ul
X
is a one character
.UC TROFF
name or number for the font.
Since
.UC EQN
is tuned for roman, italic and bold,
other fonts may not give quite as good an appearance.
.PP
The
.ul
fat 
operation takes the current font and widens it by overstriking:
.ul
fat\ grad
is
$fat grad$ and
.ul
fat {x sub i}
is
$fat {x sub i}$.
.PP
If an entire document is to be in a non-standard size
or font, it is a severe nuisance
to have to write out a size and font change for each
equation.
Accordingly, you can set a ``global'' size or font
which thereafter affects all equations.
At the beginning of any equation, you might say, for instance,
.P1
^EQ
gsize 16
gfont R
 ...
^EN
.P2
to set the size to 16 and the font to roman thereafter.
In place of R, you can use any of the
.UC TROFF
font names.
The size after
.ul
gsize
can be a relative change with + or \(mi.
.PP
Generally,
.ul
gsize
and
.ul
gfont
will appear at the beginning of a document
but they can also appear
thoughout a document: the global font and size
can be changed as often as needed.
For example, in a footnote\(dd
.FS
\(ddLike this one, in which we have a
$gsize -2$few random
expressions like $x sub i$ and $pi sup 2$.
The sizes for these were set by the command
.ul
gsize~\(mi2.
.FE $gsize +2$
you will typically want the size of equations to match
the size of the footnote text, which is two points smaller
than the main text.
Don't forget to reset the global size
at the end of the footnote.
.SC "Diacritical Marks"
.PP
To get funny marks on top of letters,
there are several words:
.P1
.tr ^^
.tr ~~
.ta 1i
x dot	$x dot$
x dotdot	$x dotdot$
x hat	$x hat$
x tilde	$x tilde$
x vec	$x vec$
x dyad	$x dyad$
x bar	$x bar$
x under	$x under$
.P2
The diacritical mark is placed at the right height.
The 
.ul
bar
and
.ul
under
are made the right length for the entire construct,
as in $x+y+z bar$;
other marks are centered.
.SC "Quoted Text"
.PP
Any input entirely within quotes (\|"..."\|)
is not subject to any of the font changes and spacing
adjustments normally done by the equation setter.
This provides a way to do your own spacing and adjusting if needed:
.P1
italic "sin(x)" + sin (x)
.P2
is
.EQ
italic "sin(x)" + sin (x)
.EN
.PP
Quotes are also used to get braces and other
.UC EQN
keywords printed:
.P1
"{ size alpha }"
.P2
is
.EQ
"{ size alpha }"
.EN
and
.P1
roman "{ size alpha }"
.P2
is
.EQ
roman "{ size alpha }"
.EN
.PP
The construction "" is often used as a place-holder
when grammatically
.UC EQN
needs something, but you don't actually want anything in your output.
For example, to make
$"" sup 2 roman He$,
you can't just type
.ul
sup 2 roman He
because a
.ul
sup
has to be a superscript
.ul
on
something.
Thus you must say
.P1
"" sup 2 roman He
.P2
.PP
To get a literal quote
use ``\\"''.
.UC TROFF 
characters like
.ul
\e(bs
can appear unquoted, but more complicated things like
horizontal and vertical motions with
.ul
\eh
and
.ul
\ev
should
always
be quoted.
(If you've never heard of
.ul
\\h
and
.ul
\\v,
ignore this section.)
.SC "Lining Up Equations"
.PP
Sometimes it's necessary to line up a series of equations
at some horizontal position, often at an equals sign.
This is done with two operations called
.ul
mark
and
.ul
lineup.
.PP
The word
.ul
mark
may appear once at any place in an equation.
It remembers the horizontal position where it appeared.
Successive equations can contain one occurrence of the word
.ul
lineup.
The place where
.ul
lineup
appears is made to line up
with the place marked by the previous
.ul
mark
if at all possible.
Thus, for example,
you can say
.P1
^EQ I
x+y mark = z
^EN
^EQ I
x lineup = 1
^EN
.P2
to produce
.EQ I
x+y mark = z
.EN
.EQ I
x lineup = 1
.EN
For reasons too complicated to talk about,
when you use
.UC EQN
and
`\(mims',
use either
.UC .EQ\ I
or
.UC .EQ\ L .
mark
and
.ul
lineup
don't work with centered equations.
Also bear in mind that 
.ul
mark
doesn't look ahead;
.P1
x mark =1
 ...
x+y lineup =z
.P2
isn't going to work, because there isn't room
for the
.ul
x+y
part after the
.ul
mark
remembers where the
.ul
x
is.
.SC "Big Brackets, Etc."
.PP
.tr ~
To get big brackets [~],
braces {~}, parentheses (~), and bars |~|
around things, use the
.ul
left 
and
.ul
right
commands:
.tr ~~
.P1
left { a over b + 1 right }
 ~=~ left ( c over d right )
 + left [ e right ]
.P2
is
.EQ
left { a over b + 1 right } ~=~ left ( c over d right ) + left [ e right ]
.EN
The resulting brackets are made big enough to cover whatever they enclose.
Other characters can be used besides these,
but the are not likely to look very good.
One exception is the
.ul
floor
and
.ul
ceiling 
characters:
.P1
left floor x over y right floor 
<= left ceiling a over b right ceiling
.P2
produces
.EQ
left floor x over y right floor 
<= left ceiling a over b right ceiling
.EN
.PP
Several warnings about brackets are in order.
First, braces are typically bigger than brackets and parentheses,
because they are made up of three, five, seven, etc., pieces,
while brackets can be made up of two, three, etc.
Second, big left and right parentheses often look poor,
because the character set is poorly designed.
.PP
The
.ul
right
part may be omitted:
a ``left something'' need not have a
corresponding 
``right
something''.
If the
.ul
right
part is omitted,
put braces around the thing you want the left bracket
to encompass.
Otherwise, the resulting brackets may be too large.
.PP
If you want to omit the
.ul
left
part, things are more complicated,
because technically you can't have a
.ul
right
without a corresponding
.ul
left.
Instead you have to say
.P1
left "" ..... right )
.P2
for example.
The
.ul
left ""
means a ``left nothing''.
This satisfies the rules without hurting your output.
.SC "Piles"
.PP
There is a general facility for making vertical piles
of things; it comes in several flavors.
For example:
.P1
.tr ~~
A ~=~ left [
  pile { a above b above c }
  ~~ pile { x above y above z }
right ]
.P2
will make
.EQ
A ~=~ left [
pile { a above b above c } ~~ pile { x above y above z }
right ]
.EN
The elements of the pile (there can be as many as you want)
are centered one above another, at the right height for
most purposes.
The keyword
.ul
above
is used to separate the pieces;
braces are used around the entire list.
The elements of a pile can be as complicated as needed, even containing more piles.
.PP
Three other forms of pile exist:
.ul
lpile
makes a pile with the elements left-justified;
.ul
rpile
makes a right-justified pile;
and
.ul
cpile
makes a centered pile, just like
.ul
pile.
The vertical spacing between the pieces
is somewhat larger for
.ul
l-,
.ul
r-
and
.ul
cpiles
than it is for ordinary piles.
.P1 2
roman sign (x)~=~ 
left {
   lpile {1 above 0 above -1} 
   ~~ lpile
    {if~x>0 above if~x=0 above if~x<0}
.P2
makes
.EQ
roman sign (x)~=~ 
left {
   lpile {1 above 0 above -1} 
   ~~ lpile
    {if~x>0 above if~x=0 above if~x<0}
.EN
Notice the left brace
without a matching right one.
.SC Matrices
.PP
It is also possible to make matrices.
For example, to make
a neat array like
.EQ
matrix {
  ccol { x sub i above y sub i }
  ccol { x sup 2 above y sup 2 }
}
.EN
you have to type
.P1
matrix {
  ccol { x sub i above y sub i }
  ccol { x sup 2 above y sup 2 }
}
.P2
This produces a matrix with
two centered columns.
The elements of the columns are then listed just as for a pile,
each element separated by the word
.ul
above.
You can also use
.ul
lcol
or
.ul
rcol
to left or right adjust columns.
Each column can be separately adjusted,
and there can be as many columns as you like.
.PP
The reason for using a matrix instead of two adjacent piles, by the way,
is that if the elements of the piles don't all have the same height,
they won't line up properly.
A matrix forces them to line up,
because it looks at the entire structure before deciding what
spacing to use.
.PP
A word of warning about matrices _
.ul
each column must have the same number of elements in it.
The world will end if you get this wrong.
.SC "Shorthand for In-line Equations"
.PP
In a mathematical document,
it is necessary to follow mathematical conventions
not just in display equations,
but also in the body of the text,
for example by making variable names like $x$ italic.
Although this could be done by surrounding the appropriate parts
with
.UC .EQ
and
.UC .EN ,
the continual repetition of
.UC .EQ
and
.UC .EN
is a nuisance.
Furthermore, with `\(mims',
.UC .EQ
and
.UC .EN
imply a displayed equation.
.PP
.UC EQN
provides a shorthand for short in-line expressions.
You can define two characters to mark the left and right ends
of an in-line equation, and then type expressions right in the middle of text
lines.
To set both the left and right characters to dollar signs, for example,
add to the beginning of your document the three lines
.P1
 .EQ
 delim %%
 .EN
.P2
Having done this, you can then say things like
.P1
.fi
Let %alpha sub i% be the primary variable,
and let %beta% be zero.
Then we can show that %x sub 1% is %>=0%.
.P2
This works as
you might expect _
spaces, newlines, and so on are significant
in the text, but not in the equation part itself.
Multiple equations can occur in a single input line.
.PP
Enough room is left before and after a line that contains
in-line expressions
that something like
$sum from i=1 to n x sub i$
does not interfere with the lines surrounding it.
.PP
To turn off the delimiters,
.P1
 .EQ
 delim off
 .EN
.P2
Warning: don't use braces, tildes, circumflexes, or double quotes as delimiters _
chaos will result.
.SC "Definitions"
.PP
.UC EQN
provides a facility so you can give
a frequently-used string of characters a name,
and thereafter just type the name instead of the
whole string.
For example, if the sequence
.P1
x sub i sub 1 + y sub i sub 1
.P2
appears repeatedly throughout a paper,
you can save re-typing it each time by defining it like this:
.P1 2
define  xy  'x sub i sub 1 + y sub i sub 1'
.P2
This makes
.ul
xy
a shorthand for whatever characters occur between the single quotes
in the definition.
You can use any character instead of quote to mark the ends of the definition,
so long as it doesn't appear inside the definition.
.PP
Now you can use
.ul
xy
like this:
.P1
^EQ
f(x) = xy ...
^EN
.P2
and so on.
Each occurrence of
.ul
xy
will expand into what it was defined as.
Be careful to leave spaces or their equivalent
around the name
when you actually use it, so
.UC EQN
will be able to identify it as special.
.PP
There are several things to watch out for.
First, although definitions can use previous definitions,
as in
.P1
 .EQ
 define  xi  ' x sub i '
 define  xi1  ' xi sub 1 '
 .EN
.P2
.ul
don't define something in terms of itself!
A favorite error is to say
.P1
define  X  ' roman X '
.P2
This is a guaranteed disaster,
since X
.ul
is
now defined in terms of itself.
If you say
.P1
define  X  ' roman "X" '
.P2
however, the quotes
protect the second X,
and everything works fine.
.PP
.UC EQN
keywords can be redefined.
You can make
/ mean
.ul
over
by saying
.P1
define  /  ' over '
.P2
or redefine
.ul
over
as /
with
.P1
define  over  ' / '
.P2
.PP
If you need different things
to print on a terminal and on the typesetter, it may be worth
defining a symbol differently in
.UC NEQN
and
.UC EQN .
This can be done with
.ul
ndefine
and
.ul
tdefine.
A definition made with
.ul
ndefine
only takes effect if you are running
.UC NEQN ;
if you use
.ul
tdefine,
the definition only applies for
.UC EQN .
Names defined with plain
.ul
define
apply to both
.UC EQN 
and
.UC NEQN .
.SC "Local Motions"
.PP
Although
.UC EQN
tries to get most things at the right place on the paper,
it isn't perfect, and occasionally you will need to tune
the output to make it just right.
Small extra horizontal spaces can be obtained with
tilde and circumflex.
You can also say
.ul
back n
and
.ul
fwd n
to move small amounts horizontally.
.ul
n
is how far to move in 1/100's of an em (an em is about the width
of the letter
`m'.)
Thus
.ul
back 50
moves back about half the width of an m.
Similarly you can move things up or down with
.ul
up n
and
.ul
down n.
As with 
.ul
sub
or
.ul
sup,
the local motions affect the next thing in the input,
and this can be something arbitrarily complicated if it is enclosed
in braces.
.SC "A Large Example"
.PP
Here is the complete source for the three display equations
in the abstract of this guide.
.sp
.nf
.ps -2
.vs -2
 .EQ I
 G(z)~mark =~ e sup { ln ~ G(z) }
 ~=~ exp left ( 
 sum from k>=1 {S sub k z sup k} over k right )
 ~=~  prod from k>=1 e sup {S sub k z sup k /k}
 .EN
 .EQ I
 lineup = left ( 1 + S sub 1 z + 
 { S sub 1 sup 2 z sup 2 } over 2! + ... right )
 left ( 1+ { S sub 2 z sup 2 } over 2
 + { S sub 2 sup 2 z sup 4 } over { 2 sup 2 cdot 2! }
 + ... right ) ...
 .EN
 .EQ I
 lineup =  sum from m>=0 left (
 sum from
 pile { k sub 1 ,k sub 2 ,..., k sub m  >=0
 above
 k sub 1 +2k sub 2 + ... +mk sub m =m}
 { S sub 1 sup {k sub 1} } over {1 sup k sub 1 k sub 1 ! } ~
 { S sub 2 sup {k sub 2} } over {2 sup k sub 2 k sub 2 ! } ~
 ...
 { S sub m sup {k sub m} } over {m sup k sub m k sub m ! } 
 right ) z sup m
 .EN
.sp
.fi
.ps +2
.vs +2
.SC "Keywords, Precedences, Etc."
.PP
If you don't use braces,
.UC EQN
will
do operations in the order shown in this list.
.P1 3
.ft I
dyad vec under bar tilde hat dot dotdot
fwd  back  down  up
fat  roman  italic  bold  size
sub  sup  sqrt  over
from  to
.ft R
.P2
These operations group to the left:
.P1
.ft I
over  sqrt  left  right
.ft R
.P2
All others group to the right.
.PP
Digits, parentheses, brackets, punctuation marks, and these mathematical words
are converted
to Roman font when encountered:
.P1
sin  cos  tan  sinh  cosh  tanh  arc
max  min  lim  log  ln  exp
Re  Im  and  if  for  det
.P2
These character sequences are recognized and translated as shown.
.sp
.nf
.tr -\(mi
.in .5i
.ta 1i
>=		$>=$
<=		$<=$
==		$==$
!=		$!=$
+-		$+-$
->		$->$
<-		$<-$
<<		$<<$
>>		$>>$
inf		$inf$
partial		$partial$
half		$half$
prime		$prime$
approx		$approx$
nothing		$nothing$
cdot		$cdot$
times		$times$
del		$del$
grad		$grad$
\&...		$...$
,...,		$,...,$
sum		$sum$
.sp 3p
int		$int$
.sp 2p
prod		$prod$
union		$union$
inter		$inter$
.sp
.in
.fi
.tr --
.PP
To obtain Greek letters,
simply spell them out in whatever case you want:
.sp
.nf
.in .2i
.ta .7i 1.4i 2.1i
DELTA	$DELTA$	iota	$iota$
GAMMA	$GAMMA$	kappa	$kappa$
LAMBDA	$LAMBDA$	lambda	$lambda$
OMEGA	$OMEGA$	mu	$mu$
PHI	$PHI$	nu	$nu$
PI	$PI$	omega	$omega$
PSI	$PSI$	omicron	$omicron$
SIGMA	$SIGMA$	phi	$phi$
THETA	$THETA$	pi	$pi$
UPSILON	$UPSILON$	psi	$psi$
XI	$XI$	rho	$rho$
alpha	$alpha$	sigma	$sigma$
beta	$beta$	tau	$tau$
chi	$chi$	theta	$theta$
delta	$delta$	upsilon	$upsilon$
epsilon	$epsilon$	xi	$xi$
eta	$eta$	zeta	$zeta$
gamma	$gamma$
.sp
.in
.fi
.PP
These are all the words known to
.UC EQN
(except for characters with names),
together with the section where they are discussed.
.sp
.nf
.in .2i
.ta .7i 1.4i 2.1i
above	17, 18	lpile	17
back	21	mark	15
bar	13	matrix	18
bold	12	ndefine	20
ccol	18	over	9
col	18	pile	17
cpile	17	rcol	18
define	20	right	16
delim	19	roman	12
dot	13	rpile	17
dotdot	13	size	12
down	21	sqrt	10
dyad	13	sub	7
fat	12	sup	7
font	12	tdefine	20
from	11	tilde	13
fwd	21	to	11
gfont	12	under	13
gsize	12	up	21
hat	13	vec	13
italic	12	~, ^	4, 6
lcol	18	{ }	8
left	16	"..."	8, 14
lineup	15
.sp
.in 0
.fi
.SC Troubleshooting
.PP
If you make a mistake in an equation,
like leaving out a brace (very common)
or having one too many (very common)
or having a
.ul
sup
with nothing before it (common),
.UC EQN
will tell you with the message
.P1 2
.ft I
syntax error between lines x and y, file z
.ft R
.P2
where
.ul
x
and
.ul
y
are approximately the lines
between which the trouble occurred, and
.ul
z
is the name
of the file in question.
The line numbers are approximate _ look nearby as well.
There are also self-explanatory messages that arise if you leave out a quote
or try to run
.UC EQN
on a non-existent file.
.PP
If you want to check a document before actually printing it
(on
.UX
only),
.P1
eqn  files >/dev/null
.P2
will
throw away the output but print the messages.
.PP
If you use something like dollar signs as delimiters,
it is easy to leave one out.
This causes very strange troubles.
The program
.ul
checkeq
(on
.UC GCOS ,
use
.ul
\&./checkeq
instead)
checks for misplaced or missing dollar signs
and similar troubles.
.PP
In-line equations can only be so big
because of an internal buffer in
.UC TROFF .
If you get a message
``word overflow'',
you have exceeded this limit.
If you print the equation as a displayed equation
this message will usually go away.
The message
``line overflow''
indicates you have exceeded an even bigger buffer.
The only cure for this is to break the equation into two separate ones.
.PP
On a related topic,
.UC EQN
does not break equations by itself _
you must split long equations up across multiple lines
by yourself,
marking each by a separate
.UC .EQ
\&...\&
.UC .EN
sequence.
.UC EQN
does warn about equations that are too long
to fit on one line.
.SC "Use on UNIX"
.PP
To print a document that contains mathematics on
the
.UX
typesetter,
.P1
eqn files | troff
.P2
If
there are any 
.UC TROFF
options, they go after the
.UC TROFF 
part of the command. For example,
.P1
eqn files | troff -ms
.P2
To run the same document on the
.UC GCOS
typesetter, use
.P1
eqn files | troff -g (other options) | gcat
.P2
.PP
A compatible version of
.UC EQN
can be used on devices like teletypes and
.UC DASI
and
.UC GSI
terminals
which have half-line forward and reverse capabilities.
To print
equations on a Model 37 teletype, for example, use
.P1
neqn files | nroff
.P2
The language for equations recognized by
.UC NEQN
is identical to that of
.UC EQN,
although of course the output is more restricted.
.PP
To use a
.UC GSI
or
.UC DASI
terminal as the output device,
.P1
neqn files | nroff -T\fIx\fP
.P2
where
.ul
x
is the terminal type you are using,
such as
.ul
300
or
.ul
300S.
.PP
.UC EQN
and
.UC NEQN
can be used with the 
.UC TBL
program[2]
for setting tables that contain mathematics.
Use
.UC TBL
before
.UC [N]EQN ,
like this:
.P1
tbl  files  |  eqn  |  troff
tbl  files  |  neqn  |  nroff
.P2
.SC "Acknowledgments"
.PP
We are deeply indebted to J. F. Ossanna,
the author of
.UC TROFF ,
for his willingness to extend
.UC TROFF
to make our task easier,
and for his
continuous assistance during the development
and evolution
of
.UC EQN .
We are also grateful to A. V. Aho
for advice on language design,
to S. C. Johnson for assistance with
the
.UC YACC
compiler-compiler,
and to all the
.UC EQN
users
who have made helpful suggestions and criticisms.
.SH
References
.LP
.IP [1]
J. F. Ossanna,
.UC NROFF/TROFF \& ``
User's Manual'',
Bell Laboratories, 1976.
.IP [2]
M. E. Lesk,
``Typing Documents on
.UX '',
Bell Laboratories, 1976.
.IP [3]
M. E. Lesk,
.UC TBL \& ``
\(em A Program for Setting Tables'',
Bell Laboratories, 1976.
.in 0
.sp
.I "June 1980"