BSD 4_1_snap development
[unix-history] / usr / doc / eqn / e4
CommitLineData
f2a0d81d
C
1.NH
2The Language
3.PP
4We will not try to describe the language precisely here;
5interested readers may refer to the appendix for more details.
6Throughout this section, we will write expressions
7exactly
8as they are handed to the typesetting program (hereinafter called
9.UC ``EQN'' ),
10except that we won't show the delimiters
11that the user types to mark the beginning and end of the expression.
12The interface between
13.UC EQN
14and
15.UC TROFF
16is described at the end of this section.
17.PP
18As we said, typing x=y+z+1 should produce $x=y+z+1$,
19and indeed it does.
20Variables are made italic, operators and digits become roman,
21and normal spacings between letters and operators are altered slightly
22to give a more pleasing appearance.
23.PP
24Input is free-form.
25Spaces and new lines in the input are used by
26.UC EQN
27to separate pieces of the input;
28they are not used to create space in the output.
29Thus
30.P1
31x = y
32 + z + 1
33.P2
34also gives $x=y+z+1$.
35Free-form input is easier to type initially;
36subsequent editing is also easier,
37for an expression may be typed as many short lines.
38.PP
39Extra white space can be forced into the output by several
40characters of various sizes.
41A tilde ``\|~\|'' gives a space equal
42to the normal word spacing in text;
43a circumflex gives half this much,
44and a tab charcter spaces to the next tab stop.
45.PP
46Spaces (or tildes, etc.)
47also serve to delimit pieces of the input.
48For example, to get
49.EQ
50f(t) = 2 pi int sin ( omega t )dt
51.EN
52we write
53.P1
54f(t) = 2 pi int sin ( omega t )dt
55.P2
56Here spaces are
57.ul
58necessary
59in the input
60to indicate that
61.ul
62sin, pi, int,
63and
64.ul
65omega
66are special, and potentially worth special treatment.
67.UC EQN
68looks up each such string of characters
69in a table, and if appropriate gives it a translation.
70In this case,
71.ul
72pi
73and
74.ul
75omega
76become their greek equivalents,
77.ul
78int
79becomes the integral sign
80(which must be moved down and enlarged so it looks ``right''),
81and
82.ul
83sin
84is made roman, following conventional mathematical practice.
85Parentheses, digits and operators are automatically made roman
86wherever found.
87.PP
88Fractions are specified with the keyword
89.ul
90over:
91.P1
92a+b over c+d+e = 1
93.P2
94produces
95.EQ
96a+b over c+d+e = 1
97.EN
98.PP
99Similarly, subscripts and superscripts are introduced by the keywords
100.ul
101sub
102and
103.ul
104sup:
105.EQ
106x sup 2 + y sup 2 = z sup 2
107.EN
108is produced by
109.P1
110x sup 2 + y sup 2 = z sup 2
111.P2
112The spaces after the 2's are necessary to mark the end of
113the superscripts;
114similarly the keyword
115.ul
116sup
117has to be marked off by spaces or
118some equivalent delimiter.
119The return to the proper baseline is automatic.
120Multiple levels of subscripts or superscripts
121are of course allowed:
122``x\|\|sup\|\|y\|\|sup\|\|z'' is
123$x sup y sup z$.
124The construct
125``something
126.ul
127sub
128something
129.ul
130sup
131something''
132is recognized as a special case,
133so
134``x sub i sup 2''
135is
136$x sub i sup 2$ instead of ${x sub i} sup 2$.
137.PP
138More complicated expressions can now be formed with these
139primitives:
140.EQ
141{partial sup 2 f} over {partial x sup 2} =
142x sup 2 over a sup 2 + y sup 2 over b sup 2
143.EN
144is produced by
145.P1
146.ce 0
147 {partial sup 2 f} over {partial x sup 2} =
148 x sup 2 over a sup 2 + y sup 2 over b sup 2
149.P2
150Braces {} are used to group objects together;
151in this case they indicate unambiguously what goes over what
152on the left-hand side of the expression.
153The language defines the precedence of
154.ul
155sup
156to be higher than that of
157.ul
158over,
159so
160no braces are needed to get the correct association on the right side.
161Braces can always be used when in doubt
162about precedence.
163.PP
164The braces convention is an example of the power
165of using a recursive grammar
166to define the language.
167It is part of the language that if a construct can appear
168in some context,
169then
170.ul
171any expression
172in braces
173can also occur in that context.
174.PP
175There is a
176.ul
177sqrt
178operator for making square roots of the appropriate size:
179``sqrt a+b'' produces $sqrt a+b$,
180and
181.P1
182x = {-b +- sqrt{b sup 2 -4ac}} over 2a
183.P2
184is
185.EQ
186x={-b +- sqrt{b sup 2 -4ac}} over 2a
187.EN
188Since large radicals look poor on our typesetter,
189.ul
190sqrt
191is not useful for tall expressions.
192.PP
193Limits on summations, integrals and similar
194constructions are specified with
195the keywords
196.ul
197from
198and
199.ul
200to.
201To get
202.EQ
203sum from i=0 to inf x sub i -> 0
204.EN
205we need only type
206.P1
207sum from i=0 to inf x sub i -> 0
208.P2
209Centering and making the $SIGMA$ big enough and the limits smaller
210are all automatic.
211The
212.ul
213from
214and
215.ul
216to
217parts are both optional,
218and the central part (e.g., the $SIGMA$)
219can in fact be anything:
220.P1
221lim from {x -> pi /2} ( tan~x) = inf
222.P2
223is
224.EQ
225lim from {x -> pi /2} ( tan~x) = inf
226.EN
227Again,
228the braces indicate just what goes into the
229.ul
230from
231part.
232.PP
233There is a facility for making braces, brackets, parentheses, and vertical bars
234of the right height, using the keywords
235.ul
236left
237and
238.ul
239right:
240.P1
241left [ x+y over 2a right ]~=~1
242.P2
243makes
244.EQ
245left [ x+y over 2a right ]~=~1
246.EN
247A
248.ul
249left
250need not have a corresponding
251.ul
252right,
253as we shall see in the next example.
254Any characters may follow
255.ul
256left
257and
258.ul
259right,
260but generally only various parentheses and bars are meaningful.
261.PP
262Big brackets, etc.,
263are often used with another facility,
264called
265.ul
266piles,
267which make vertical piles of objects.
268For example,
269to get
270.EQ
271sign (x) ~==~ left {
272 rpile {1 above 0 above -1}
273 ~~lpile {if above if above if}
274 ~~lpile {x>0 above x=0 above x<0}
275.EN
276we can type
277.P1
278sign (x) ~==~ left {
279 rpile {1 above 0 above -1}
280 ~~lpile {if above if above if}
281 ~~lpile {x>0 above x=0 above x<0}
282.P2
283The construction ``left {''
284makes a left brace big enough
285to enclose the
286``rpile {...}'',
287which is a right-justified pile of
288``above ... above ...''.
289``lpile'' makes a left-justified pile.
290There are also centered piles.
291Because of the recursive language definition,
292a
293pile
294can contain any number of elements;
295any element of a pile can of course
296contain piles.
297.PP
298Although
299.UC EQN
300makes a valiant attempt
301to use the right sizes and fonts,
302there are times when the default assumptions
303are simply not what is wanted.
304For instance the italic
305.ul
306sign
307in the previous example would conventionally
308be in roman.
309Slides and transparencies often require larger characters than normal text.
310Thus we also provide size and font
311changing commands:
312``size 12 bold {A~x~=~y}''
313will produce
314$size 12 bold{ A~x~=~y}$.
315.ul
316Size
317is followed by a number representing a character size in points.
318(One point is 1/72 inch;
319this paper is set in 9 point type.)
320.PP
321If necessary, an input string can be quoted in "...",
322which turns off grammatical significance, and any font or spacing changes that might otherwise be done on it.
323Thus we can say
324.P1
325lim~ roman "sup" ~x sub n = 0
326.P2
327to ensure that the supremum doesn't become a superscript:
328.EQ
329lim~ roman "sup" ~x sub n = 0
330.EN
331.PP
332Diacritical marks, long a problem in traditional typesetting,
333are straightforward:
334.EQ
335x dot under + x hat + y tilde + X hat + Y dotdot = z+Z bar
336.EN
337is made by typing
338.P1
339x dot under + x hat + y tilde
340+ X hat + Y dotdot = z+Z bar
341.P2
342.PP
343There are also facilities for globally changing default
344sizes and fonts, for example for making viewgraphs
345or for setting chemical equations.
346The language allows for matrices, and for lining up equations
347at the same horizontal position.
348.PP
349Finally, there is a definition facility,
350so a user can say
351.P1
352define name "..."
353.P2
354at any time in the document;
355henceforth, any occurrence of the token ``name''
356in an expression
357will be expanded into whatever was inside
358the double quotes in its definition.
359This lets users tailor
360the language to their own specifications,
361for it is quite possible to redefine
362keywords
363like
364.ul
365sup
366or
367.ul
368over.
369Section 6 shows an example of definitions.
370.PP
371The
372.UC EQN
373preprocessor reads intermixed text and equations,
374and passes its output to
375.UC TROFF.
376Since
377.UC TROFF
378uses lines beginning with a period as control words
379(e.g., ``.ce'' means ``center the next output line''),
380.UC EQN
381uses the sequence ``.EQ'' to mark the beginning of an equation and
382``.EN'' to mark the end.
383The ``.EQ'' and ``.EN'' are passed through to
384.UC TROFF
385untouched,
386so they can also be used by a knowledgeable user to
387center equations, number them automatically, etc.
388By default, however,
389``.EQ'' and ``.EN'' are simply ignored by
390.UC TROFF ,
391so by default equations are printed in-line.
392.PP
393``.EQ'' and ``.EN'' can be supplemented by
394.UC TROFF
395commands as desired;
396for example, a centered display equation
397can be produced with the input:
398.P1
399.ce 0
400.in 5
401 .ce
402 .EQ
403 x sub i = y sub i ...
404 .EN
405.in 0
406.P2
407.PP
408Since it is tedious to type
409``.EQ'' and ``.EN'' around very short expressions
410(single letters, for instance),
411the user can also define two characters to serve
412as the left and right delimiters of expressions.
413These characters are recognized anywhere in subsequent text.
414For example if the left and right delimiters have both been set to ``#'',
415the input:
416.P1
417Let #x sub i#, #y# and #alpha# be positive
418.P2
419produces:
420.P1
421Let $x sub i$, $y$ and $alpha$ be positive
422.P2
423.PP
424Running a preprocessor is strikingly easy on
425.UC UNIX.
426To typeset
427text stored in file
428``f\|'',
429one issues the command:
430.P1
431eqn f | troff
432.P2
433The vertical bar connects the output
434of one process
435.UC (EQN)
436to the input of another
437.UC (TROFF) .