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