BSD 3 development
[unix-history] / usr / doc / eqn / e4
.NH
The Language
.PP
We will not try to describe the language precisely here;
interested readers may refer to the appendix for more details.
Throughout this section, we will write expressions
exactly
as they are handed to the typesetting program (hereinafter called
.UC ``EQN'' ),
except that we won't show the delimiters
that the user types to mark the beginning and end of the expression.
The interface between
.UC EQN
and
.UC TROFF
is described at the end of this section.
.PP
As we said, typing x=y+z+1 should produce $x=y+z+1$,
and indeed it does.
Variables are made italic, operators and digits become roman,
and normal spacings between letters and operators are altered slightly
to give a more pleasing appearance.
.PP
Input is free-form.
Spaces and new lines in the input are used by
.UC EQN
to separate pieces of the input;
they are not used to create space in the output.
Thus
.P1
x = y
+ z + 1
.P2
also gives $x=y+z+1$.
Free-form input is easier to type initially;
subsequent editing is also easier,
for an expression may be typed as many short lines.
.PP
Extra white space can be forced into the output by several
characters of various sizes.
A tilde ``\|~\|'' gives a space equal
to the normal word spacing in text;
a circumflex gives half this much,
and a tab charcter spaces to the next tab stop.
.PP
Spaces (or tildes, etc.)
also serve to delimit pieces of the input.
For example, to get
.EQ
f(t) = 2 pi int sin ( omega t )dt
.EN
we write
.P1
f(t) = 2 pi int sin ( omega t )dt
.P2
Here spaces are
.ul
necessary
in the input
to indicate that
.ul
sin, pi, int,
and
.ul
omega
are special, and potentially worth special treatment.
.UC EQN
looks up each such string of characters
in a table, and if appropriate gives it a translation.
In this case,
.ul
pi
and
.ul
omega
become their greek equivalents,
.ul
int
becomes the integral sign
(which must be moved down and enlarged so it looks ``right''),
and
.ul
sin
is made roman, following conventional mathematical practice.
Parentheses, digits and operators are automatically made roman
wherever found.
.PP
Fractions are specified with the keyword
.ul
over:
.P1
a+b over c+d+e = 1
.P2
produces
.EQ
a+b over c+d+e = 1
.EN
.PP
Similarly, subscripts and superscripts are introduced by the keywords
.ul
sub
and
.ul
sup:
.EQ
x sup 2 + y sup 2 = z sup 2
.EN
is produced by
.P1
x sup 2 + y sup 2 = z sup 2
.P2
The spaces after the 2's are necessary to mark the end of
the superscripts;
similarly the keyword
.ul
sup
has to be marked off by spaces or
some equivalent delimiter.
The return to the proper baseline is automatic.
Multiple levels of subscripts or superscripts
are of course allowed:
``x\|\|sup\|\|y\|\|sup\|\|z'' is
$x sup y sup z$.
The construct
``something
.ul
sub
something
.ul
sup
something''
is recognized as a special case,
so
``x sub i sup 2''
is
$x sub i sup 2$ instead of ${x sub i} sup 2$.
.PP
More complicated expressions can now be formed with these
primitives:
.EQ
{partial sup 2 f} over {partial x sup 2} =
x sup 2 over a sup 2 + y sup 2 over b sup 2
.EN
is produced by
.P1
.ce 0
{partial sup 2 f} over {partial x sup 2} =
x sup 2 over a sup 2 + y sup 2 over b sup 2
.P2
Braces {} are used to group objects together;
in this case they indicate unambiguously what goes over what
on the left-hand side of the expression.
The language defines the precedence of
.ul
sup
to be higher than that of
.ul
over,
so
no braces are needed to get the correct association on the right side.
Braces can always be used when in doubt
about precedence.
.PP
The braces convention is an example of the power
of using a recursive grammar
to define the language.
It is part of the language that if a construct can appear
in some context,
then
.ul
any expression
in braces
can also occur in that context.
.PP
There is a
.ul
sqrt
operator for making square roots of the appropriate size:
``sqrt a+b'' produces $sqrt a+b$,
and
.P1
x = {-b +- sqrt{b sup 2 -4ac}} over 2a
.P2
is
.EQ
x={-b +- sqrt{b sup 2 -4ac}} over 2a
.EN
Since large radicals look poor on our typesetter,
.ul
sqrt
is not useful for tall expressions.
.PP
Lim