|
|
1.1 root 1: .so ../ADM/mac
2: .XX eqn 25 "Typesetting Mathematics \(em User's Guide"
3: .nr PI .2i
4: .nr PD .1v
5: .EQ
6: delim $$
7: .EN
8: .TL
9: Typesetting Mathematics \(em User's Guide\(dg
10: .AU 2C-518 6021
11: Brian W. Kernighan
12: Lorinda L. Cherry
13: .AI
14: .MH
15: .AB
16: .PP
17: This is the user's guide for
18: .IT eqn ,
19: a system for typesetting
20: mathematics.
21: Mathematical expressions are described in a language
22: designed to be easy to use
23: by people who know neither mathematics nor typesetting.
24: Enough of the language to set in-line expressions like
25: $lim from {x-> pi /2} ( tan~x) sup{sin~2x}~=~1$
26: or display equations like
27: .EQ I
28: G(z)~mark =~ e sup { ln ~ G(z) }
29: ~=~ exp left (
30: sum from k>=1 {S sub k z sup k} over k right )
31: ~=~ prod from k>=1 e sup {S sub k z sup k /k}
32: .EN
33: .EQ I
34: lineup = left ( 1 + S sub 1 z +
35: { S sub 1 sup 2 z sup 2 } over 2! + ".\^.\^." right )
36: left ( 1+ { S sub 2 z sup 2 } over 2
37: + { S sub 2 sup 2 z sup 4 } over { 2 sup 2 cdot 2! }
38: + ".\^.\^." right ) ".\^.\^."
39: .EN
40: .EQ I
41: lineup = sum from m>=0 left (
42: sum from
43: pile { k sub 1 ,k sub 2 ",\^.\^.\^.\^," k sub m >=0
44: above
45: k sub 1 +2k sub 2 + ".\^.\^." +mk sub m =m}
46: { S sub 1 sup {k sub 1} } over {1 sup k sub 1 k sub 1 ! } ~
47: { S sub 2 sup {k sub 2} } over {2 sup k sub 2 k sub 2 ! } ~
48: ".\^.\^."
49: { S sub m sup {k sub m} } over {m sup k sub m k sub m ! }
50: right ) z sup m
51: .EN
52: can be learned in an hour or so.
53: .PP
54: The language interfaces directly with
55: the formatting language
56: .IT troff ,
57: so mathematical expressions can be embedded in the running
58: text
59: of a manuscript,
60: and the entire document produced in one process.
61: This user's guide is an example of its output.
62: .AE
63: .2C
64: .FS
65: \(dg This is a revised version of |reference(eqn cstr).
66: .FE
67: .NH
68: Introduction
69: .PP
70: .IT Eqn
71: is a
72: program and a language for typesetting mathematics.
73: The
74: .IT eqn
75: language was designed to be easy to use
76: by people who know neither mathematics
77: nor typesetting.
78: Thus
79: .IT eqn
80: knows relatively little about mathematics.
81: In particular, mathematical symbols like
82: +, \(mi, \(mu, parentheses, and so on have no special meanings.
83: .IT Eqn
84: is quite happy to set garbage (but it will look good).
85: .PP
86: .IT Eqn
87: is a preprocessor for the typesetter formatter
88: .IT troff ,
89: so the normal mode of operation is to prepare
90: a document with both mathematics and ordinary text
91: interspersed,
92: and let
93: .IT eqn
94: set the mathematics while
95: .IT troff
96: does the body of the text.
97: .PP
98: To use
99: .IT eqn
100: on
101: .UX ,
102: .P1
103: eqn files | troff
104: .P2
105: .PP
106: The design and implementation of
107: .I eqn
108: is discussed in |reference(kernighan cherry cacm).
109: .NH
110: Display Equations
111: .PP
112: To tell
113: .IT eqn
114: where a mathematical expression begins and ends,
115: one marks it with lines beginning
116: .CW .EQ
117: and
118: .CW .EN .
119: Thus
120: if you type the lines
121: .P1
122: \&.EQ
123: x=y+z
124: \&.EN
125: .P2
126: your output will look like
127: .EQ
128: x=y+z
129: .EN
130: The
131: .CW .EQ
132: and
133: .CW .EN
134: are copied through untouched;
135: they
136: are not otherwise processed
137: by
138: .IT eqn .
139: This means that you have to take care
140: of things like centering, numbering, and so on
141: yourself.
142: The most common way is to use a
143: .IT troff
144: macro package like
145: .CW -ms
146: or
147: .CW -mm ,
148: which allow you to center, indent, left-justify, and number equations.
149: .PP
150: With the
151: .CW -ms
152: package,
153: equations are centered by default.
154: To left-justify an equation, use
155: .CW \&.EQ\ L
156: instead of
157: .CW .EQ .
158: To indent it, use
159: .CW .EQ\ I .
160: Any of these can be followed by an arbitrary `equation number'
161: which will be placed at the right margin.
162: For example, the input
163: .P1
164: \&.EQ I (3.1a)
165: x = f(y/2) + y/2
166: \&.EN
167: .P2
168: produces the output
169: .EQ I (3.1a)
170: x = f(y/2) + y/2
171: .EN
172: .PP
173: For stupid historical reasons, the
174: .CW -mm
175: macros package requires you to surround
176: .CW .EQ
177: and
178: .CW .EN
179: with a pair of totally unnecessary commands,
180: .CW .DS
181: and
182: .CW .DE :
183: .P1
184: \&.DS \f2for \fP-mm\f2 only\fP
185: \&.EQ
186: \f2your equation\fP
187: \&.EN
188: \&.DE
189: .P2
190: .PP
191: There is also a shorthand notation so
192: in-line expressions
193: like
194: $pi sub i sup 2$
195: can be entered without
196: .CW .EQ
197: and
198: .CW .EN .
199: We will talk about it in section 9.
200: .NH
201: Input spaces
202: .PP
203: Spaces, tabs, and newlines within an expression are thrown away by
204: .IT eqn .
205: (Normal text is left absolutely alone.)
206: Thus
207: between
208: .CW .EQ
209: and
210: .CW .EN ,
211: .P1
212: x=y+z
213: .P2
214: and
215: .P1
216: x = y + z
217: .P2
218: and
219: .P1
220: x = y
221: + z
222: .P2
223: and so on
224: all produce the same
225: output:
226: .EQ
227: x=y+z
228: .EN
229: You should use spaces and newlines freely to make your input equations
230: readable and easy to edit.
231: In particular, very long lines are a bad idea,
232: since they are often hard to fix if you make a mistake.
233: .NH
234: Output spaces
235: .PP
236: To force extra spaces into the
237: .IT output,
238: use a tilde
239: .CW ~ '' ``
240: for each space you want:
241: .P1
242: x~=~y~+~z
243: .P2
244: gives
245: .EQ
246: x~=~y~+~z
247: .EN
248: You can also use a circumflex
249: .CW ^ '', ``
250: which gives a space half the width of a tilde.
251: It is mainly useful for fine-tuning.
252: .NH
253: Symbols, Special Names, Greek
254: .PP
255: .IT Eqn
256: knows some mathematical symbols,
257: some mathematical names, and the Greek alphabet.
258: For example,
259: .P1
260: x=2 pi int sin ( omega t)dt
261: .P2
262: produces
263: .EQ
264: x = 2 pi int sin ( omega t)dt
265: .EN
266: Here the spaces in the input are
267: necessary
268: to tell
269: .IT eqn
270: that
271: .CW int ,
272: .CW pi ,
273: .CW sin ,
274: and
275: .CW omega
276: are separate entities that should get special treatment.
277: The
278: .CW sin ,
279: digit 2, and parentheses are set in roman type instead of italic;
280: .CW pi
281: and
282: .CW omega
283: are made Greek;
284: and
285: .CW int
286: becomes the integral sign.
287: .PP
288: When in doubt, leave spaces around separate parts of the input.
289: A
290: common error is to type
291: .CW f(pi)
292: without leaving spaces on both sides of the
293: .CW pi .
294: As a result,
295: .IT eqn
296: does not recognize
297: .CW pi
298: as a special word, and you get
299: $f(pi)$
300: instead of
301: $f( pi )$.
302: .PP
303: A list of
304: .IT eqn
305: names appears in section 24.
306: Knowledgeable users can also use
307: .IT troff
308: four-character names
309: for anything
310: .IT eqn
311: doesn't know about,
312: like
313: .CW \e(L1
314: for the AT&T death-star \(L1.
315: .NH
316: Spaces, Again
317: .PP
318: The only way
319: .IT eqn
320: can deduce that some sequence
321: of letters might be special
322: is if that sequence is separated from the letters
323: on either side of it.
324: This can be done by surrounding a special word by spaces,
325: tabs, or newlines,
326: as we did in the previous section.
327: .PP
328: You can also make special words stand out by surrounding them
329: with tildes or circumflexes:
330: .P1
331: x~=~2~pi~int~sin~(~omega~t~)~dt
332: .P2
333: is much the same as the last example,
334: except that the tildes
335: not only
336: separate the magic words
337: like
338: .CW sin ,
339: .CW omega ,
340: and so on,
341: but also add extra spaces,
342: one space per tilde:
343: .EQ
344: x~=~2~pi~int~sin~(~omega~t~)~dt
345: .EN
346: .PP
347: Special words can also be separated by braces
348: .CW {}
349: and double quotes
350: .CW \&"" ,
351: which have special meanings that we will
352: see soon.
353: .......
354: .NH
355: Subscripts and Superscripts
356: .PP
357: Subscripts and superscripts are
358: obtained with the words
359: .CW sub
360: and
361: .CW sup .
362: .P1
363: x sup 2 + y sub k
364: .P2
365: gives
366: .EQ
367: x sup 2 + y sub k
368: .EN
369: .IT Eqn
370: takes care of all the size changes and vertical motions
371: needed to make the output look right.
372: The words
373: .CW sub
374: and
375: .CW sup
376: must be surrounded by spaces;
377: .CW "x sub2"
378: will give you
379: $x sub2$ instead of $x sub 2$.
380: Furthermore, don't forget to leave a space
381: (or a tilde, etc.)\&
382: to mark the end of a subscript or superscript.
383: A common error is to say
384: something like
385: .P1
386: y = (x sup 2)+1
387: .P2
388: which causes
389: .EQ
390: y = (x sup 2)+1
391: .EN
392: instead of
393: the intended
394: .EQ
395: y = (x sup 2 )+1
396: .EN
397: .PP
398: Subscripted subscripts and superscripted superscripts
399: also work:
400: .P1
401: x sub i sub 1
402: .P2
403: is
404: .EQ
405: x sub i sub 1
406: .EN
407: A subscript and superscript on the same thing
408: are printed one above the other
409: if the subscript comes
410: .IT first :
411: .P1
412: x sub i sup 2
413: .P2
414: is
415: .EQ
416: x sub i sup 2
417: .EN
418: .PP
419: Other than this special case,
420: .CW sub
421: and
422: .CW sup
423: group to the right, so
424: .IT "x\ sup\ y\ sub\ z
425: means
426: $x sup {y sub z}$, not ${x sup y} sub z$.
427: .NH
428: Braces for Grouping
429: .PP
430: Normally, the end of a subscript or superscript is marked
431: simply by a blank (or tab or tilde, etc.)
432: What if the subscript or superscript is something that has to be typed
433: with blanks in it?
434: In that case, you can use the braces
435: { and } to mark the
436: beginning and end of the subscript or superscript:
437: .P1
438: e sup {i omega t}
439: .P2
440: is
441: .EQ
442: e sup {i omega t}
443: .EN
444: .sp
445: Rule: Braces can
446: always
447: be used to force
448: .IT eqn
449: to treat something as a unit,
450: or just to make your intent perfectly clear.
451: Thus:
452: .P1
453: x sub {i sub 1} sup 2
454: .P2
455: is
456: .EQ
457: x sub {i sub 1} sup 2
458: .EN
459: with braces, but
460: .P1
461: x sub i sub 1 sup 2
462: .P2
463: is
464: .EQ
465: x sub i sub 1 sup 2
466: .EN
467: which is rather different.
468: .PP
469: Braces can occur within braces:
470: .P1
471: e sup {i pi sup {rho +1}}
472: .P2
473: is
474: .EQ
475: e sup {i pi sup {rho +1}}
476: .EN
477: The general rule is that anywhere you could use some single
478: thing like
479: .CW x ,
480: you can use an arbitrarily complicated thing if you enclose
481: it in braces.
482: .IT Eqn
483: will look after all the details of positioning it and making
484: it the right size.
485: .PP
486: In all cases, make sure you have the
487: right number of braces.
488: Leaving one out or adding an extra will cause
489: .IT eqn
490: to complain bitterly.
491: .PP
492: Occasionally you will have to
493: print braces.
494: To do this,
495: enclose them in double quotes,
496: like
497: .CW \&"{" .
498: Quoting is discussed in more detail in section 15.
499: .NH
500: Shorthand for In-line Equations
501: .PP
502: With the
503: .CW -ms
504: and
505: .CW -mm
506: macro packages,
507: .CW .EQ
508: and
509: .CW .EN
510: imply a displayed equation.
511: But in most documents,
512: it is necessary to follow mathematical conventions
513: not just in display equations,
514: but also in the body of the text,
515: for example by making variable names like $x$ italic.
516: .PP
517: .IT Eqn
518: provides a shorthand for short in-line expressions.
519: You can define two characters to mark the left and right ends
520: of an in-line equation, and then type expressions right in the middle of text
521: lines.
522: To set both the left and right characters to dollar signs, for example,
523: add to the beginning of your document the three lines
524: .EQ
525: delim off
526: .EN
527: .P1
528: \&.EQ
529: delim $$
530: \&.EN
531: .P2
532: Having done this, you can then say things like
533: .P1
534: .fi
535: Let $alpha sub i$ be positive,
536: and let $beta$ be zero.
537: Then we can show that $alpha sub 1$ is $>=0$.
538: .P2
539: .EQ
540: delim $$
541: .EN
542: This works as
543: you might expect\(emspaces, newlines, and so on are significant
544: in the text, but not in the equation part itself.
545: Multiple equations can occur in a single input line.
546: .PP
547: Enough room is left before and after a line that contains
548: in-line expressions
549: that something tall like
550: $sum from i=1 to n x sub i$
551: does not interfere with the lines surrounding it.
552: .PP
553: To turn off the delimiters,
554: .P1
555: \&.EQ
556: delim off
557: \&.EN
558: .P2
559: Warning: don't use braces, tildes, circumflexes,
560: or double quotes as delimiters\(emchaos will result.
561: .NH
562: Fractions
563: .PP
564: To make a fraction,
565: use the word
566: .CW over :
567: .P1
568: a+b over 2c = 1
569: .P2
570: gives
571: .EQ
572: a+b over 2c = 1
573: .EN
574: The line is made the right length and positioned automatically.
575: Braces can be used to make clear what goes over what:
576: .P1
577: {alpha + beta} over {sin (x)}
578: .P2
579: is
580: .EQ
581: {alpha + beta} over {sin (x)}
582: .EN
583: What happens when there is both an
584: .CW over
585: and a
586: .CW sup
587: in the same expression?
588: In such an apparently ambiguous case,
589: .IT eqn
590: does the
591: .CW sup
592: before the
593: .CW over ,
594: so
595: .P1
596: -b sup 2 over pi
597: .P2
598: is
599: $-b sup 2 over pi$
600: instead of
601: $-b sup {2 over pi}$.
602: The rules
603: that decide which operation is done first in cases like this
604: are summarized in section 24.
605: When in doubt, however,
606: use braces
607: to make clear what goes with what.
608: .NH
609: Square Roots
610: .PP
611: To draw a square root, use
612: .CW sqrt :
613: .P1 2
614: sqrt a+b + 1 over sqrt {ax sup 2 +bx+c}
615: .P2
616: is
617: .EQ
618: sqrt a+b + 1 over sqrt {ax sup 2 +bx+c}
619: .EN
620: Warning\(emsquare roots of tall quantities look bad,
621: because a root-sign
622: big enough to cover the quantity is
623: too dark and heavy:
624: .P1
625: sqrt {a sup 2 over b sub 2}
626: .P2
627: is
628: .EQ
629: sqrt {a sup 2 over b sub 2}
630: .EN
631: Big square roots are generally better written as something
632: to the power \(12:
633: .EQ
634: (a sup 2 /b sub 2 ) sup half
635: .EN
636: which is
637: .P1
638: (a sup 2 /b sub 2 ) sup half
639: .P2
640: .NH
641: Summation, Integral, Etc.
642: .PP
643: Summations, integrals, and similar constructions
644: are easy:
645: .P1
646: sum from i=0 to {i= inf} x sup i
647: .P2
648: produces
649: .EQ
650: sum from i=0 to {i= inf} x sup i
651: .EN
652: Notice that we used
653: braces to indicate where the upper
654: part
655: $i= inf$
656: begins and ends.
657: No braces were necessary for the lower part $i=0$,
658: because it contained no blanks.
659: The braces will never hurt,
660: and if the
661: .CW from
662: and
663: .CW to
664: parts contain any blanks, you must use braces around them.
665: .PP
666: The
667: .CW from
668: and
669: .CW to
670: parts are both optional,
671: but if both are used,
672: they have to occur in that order.
673: .PP
674: Other useful characters can replace the
675: .CW sum
676: in our example:
677: .P1
678: int prod union inter
679: .P2
680: become, respectively,
681: .EQ
682: int ~~~~~~ prod ~~~~~~ union ~~~~~~ inter
683: .EN
684: Since the thing before the
685: .CW from
686: can be anything,
687: even something in braces,
688: .CW from\f2-\fPto
689: can often be used in unexpected ways:
690: .P1
691: lim from {n \(mi> inf} x sub n =0
692: .P2
693: is
694: .EQ
695: lim from {n-> inf} x sub n =0
696: .EN
697: .PP
698: Notice the difference between
699: .CW from\f2-\fPto
700: and
701: .CW sub\f2-\fPsup :
702: .P1
703: int from a to b ~~~ int sub a sup b
704: .P2
705: is
706: .EQ
707: int from a to b ~~~ int sub a sup b
708: .EN
709: .NH
710: Size and Font Changes
711: .PP
712: By default, equations are set in
713: the current point size (this text is 10-point type),
714: with standard mathematical conventions
715: to determine what characters are in roman and what in italic.
716: Although
717: .IT eqn
718: makes a valiant attempt to use
719: aesthetically pleasing sizes and fonts,
720: it is not perfect.
721: To change sizes and fonts, use
722: .CW size
723: .IT n
724: and
725: .CW roman ,
726: .CW italic ,
727: .CW bold
728: and
729: .CW fat .
730: Like
731: .CW sub
732: and
733: .CW sup ,
734: size
735: and font changes affect only the thing that follows
736: them, and revert to the normal situation
737: at the end of it. Thus
738: .P1
739: bold x y
740: .P2
741: is
742: .EQ
743: bold x y
744: .EN
745: and
746: .P1
747: size 12 bold x = y +
748: size 12 {alpha + beta}
749: .P2
750: gives
751: .EQ
752: size 12 bold x = y +
753: size 12 {alpha + beta}
754: .EN
755: As always, you can use braces if you want to affect something
756: more complicated than a single letter.
757: For example, you can change the size of an entire equation by
758: .P1
759: size 8 { ... }
760: .P2
761: You can also change the size
762: by
763: a given amount;
764: for example, you can say
765: .CW size\ +2
766: to make the size two points bigger,
767: or
768: .CW size\ -3
769: to make it three points smaller.
770: This has the advantage that you don't have
771: to know what the current size is.
772: .PP
773: If you are using fonts other than roman, italic and bold,
774: you can say
775: .CW font
776: .IT X
777: where
778: .IT X
779: is a
780: .IT troff
781: name or number for the font,
782: one or two characters long.
783: Since
784: .IT eqn
785: is tuned for roman, italic and bold,
786: other fonts may not give quite as good an appearance.
787: .PP
788: The
789: .CW fat
790: operation takes the current font and widens it by overstriking:
791: .CW fat\ grad
792: is
793: $fat grad$ and
794: .CW fat
795: .CW "{x sub i}
796: is
797: $fat {x sub i}$.
798: .PP
799: If an entire document is to be in a non-standard size
800: or font, it is a severe nuisance
801: to have to write out a size and font change for each
802: equation.
803: Accordingly, you can set a ``global'' size or font
804: which thereafter affects all equations.
805: At the beginning of any equation, you might say, for instance,
806: .P1
807: \&.EQ
808: gsize 16
809: gfont R
810: \&...
811: \&.EN
812: .P2
813: to set the size to 16 and the font to roman thereafter.
814: In place of R, you can use any of the
815: .IT troff
816: font names.
817: The size after
818: .CW gsize
819: can be a relative change with
820: .CW +
821: or
822: .CW - .
823: .PP
824: Generally,
825: .CW gsize
826: and
827: .CW gfont
828: will appear at the beginning of a document
829: but they can also appear
830: throughout a document: the global font and size
831: can be changed as often as needed.\(dd
832: .FS
833: \l'1i'
834: .br
835: \(ddIn a footnote like this one, in which we have a
836: few random
837: expressions like $x sub i$ and $pi sup 2$,
838: .IT eqn
839: handles the size change automatically.
840: .FE
841: .PP
842: Since
843: .IT eqn
844: manages most size changes automatically,
845: .CW gsize
846: is rarely necessary.
847: .NH
848: Diacritical Marks
849: .PP
850: To get diacritical marks on top of letters,
851: there are several words:
852: .P1
853: .ta 1i
854: .vs +3
855: x dot $x dot$
856: x dotdot $x dotdot$
857: x hat $x hat$
858: x tilde $x tilde$
859: x vec $x vec$
860: x dyad $x dyad$
861: x bar $x bar$
862: x under $x under$
863: x utilde $x utilde$
864: .vs -3
865: .P2
866: The diacritical mark is placed at the right height.
867: The
868: .CW bar
869: and
870: .CW under
871: are made the right length for the entire construct,
872: as in $x+y+z bar$;
873: other marks are centered.
874: .PP
875: Sometimes
876: .IT eqn
877: guesses wrong on the height for bars.
878: As an interim fix, the words
879: .CW highbar
880: and
881: .CW lowbar
882: are synonymous with
883: .CW bar,
884: but force the bar to be either high
885: (as with $X bar$)
886: or low (as with $x bar$) regardless of the apparent height of the object.
887: This is useful for constructions like
888: ${x sub 1} lowbar$, which is
889: .CW "{x sub 1} lowbar" .
890: .......
891: .NH
892: Quoted Text
893: .PP
894: Any input entirely within quotes
895: .CW \&"\f2...\fP"
896: is not subject to any of the normal font changes and spacing
897: adjustments.
898: This provides a way to do your own spacing and adjusting if needed:
899: .P1
900: italic "sin(x)" + sin (x)
901: .P2
902: is
903: .EQ
904: italic "sin(x)" + sin (x)
905: .EN
906: .PP
907: Quotes are also used to get braces and other
908: .IT eqn
909: keywords printed:
910: .P1
911: "{ size alpha }"
912: .P2
913: is
914: .EQ
915: "{ size alpha }"
916: .EN
917: and
918: .P1
919: roman "{ size alpha }"
920: .P2
921: is
922: .EQ
923: roman "{ size alpha }"
924: .EN
925: .PP
926: The construction
927: .CW \&""
928: is often used as a place-holder
929: when grammatically
930: .IT eqn
931: needs something, but you don't actually want anything in your output.
932: For example, to make
933: $"" sup 2 roman He$,
934: you can't just type
935: .CW "sup 2 roman He
936: because a
937: .CW sup
938: has to be a superscript
939: .IT on
940: something.
941: Thus you must say
942: .P1
943: "" sup 2 roman He
944: .P2
945: .PP
946: To get a literal quote
947: use
948: .CW \&"\e"" .
949: If delimiters are set with
950: .CW delim ,
951: you can include them in a quoted string too.
952: .IT Troff
953: special-character names like
954: .CW \e(bs
955: can appear unquoted, but all other
956: .IT troff
957: constructions
958: should
959: always
960: be quoted.
961: .NH
962: Lining up Equations
963: .PP
964: Sometimes it's necessary to line up a series of equations
965: at some horizontal position, often at an equals sign.
966: This is done with two operations called
967: .CW mark
968: and
969: .CW lineup .
970: .PP
971: The word
972: .CW mark
973: may appear once at any place in an equation.
974: It remembers the horizontal position where it appeared.
975: Successive equations can contain one occurrence of the word
976: .CW lineup .
977: The place where
978: .CW lineup
979: appears is made to line up
980: with the place marked by the previous
981: .CW mark
982: if possible.
983: Thus, for example,
984: you can say
985: .P1
986: \&.EQ I
987: x+y mark = z
988: \&.EN
989: \&.EQ I
990: x lineup = 1
991: \&.EN
992: .P2
993: to produce
994: .EQ I
995: x+y mark = z
996: .EN
997: .EQ I
998: x lineup = 1
999: .EN
1000: For reasons too complicated to talk about,
1001: when you use
1002: .IT eqn
1003: and
1004: .CW -ms ,
1005: use either
1006: .CW .EQ\ I
1007: or
1008: .CW .EQ\ L ;
1009: .CW mark
1010: and
1011: .CW lineup
1012: don't work with centered equations.
1013: Also bear in mind that
1014: .CW mark
1015: doesn't look ahead;
1016: .P1
1017: x mark =1
1018: \&...
1019: x+y lineup =z
1020: .P2
1021: will not work if there isn't room
1022: for the
1023: .CW x+y
1024: part after the
1025: .CW mark
1026: remembers where the
1027: .CW x
1028: is.
1029: If you use
1030: .CW .EQ
1031: .CW I ,
1032: that may suffice;
1033: if not, use tildes to move the first equation to the right.
1034: .NH
1035: Big Brackets, Etc.
1036: .PP
1037: To get big brackets,
1038: braces, parentheses, and bars
1039: around things, use the
1040: .CW left
1041: and
1042: .CW right
1043: commands:
1044: .P1
1045: left { a over b + 1 right }
1046: ~=~ left ( c over d right )
1047: + left [ e right ]
1048: .P2
1049: is
1050: .EQ
1051: left { a over b + 1 right } ~=~ left ( c over d right ) + left [ e right ]
1052: .EN
1053: The resulting brackets are made big enough to cover whatever they enclose.
1054: Other characters can be used besides these,
1055: but are not likely to look very good.
1056: The
1057: .CW floor
1058: and
1059: .CW ceiling
1060: characters are exceptions:
1061: .P1 .2i
1062: left floor x over y right floor <=
1063: left ceiling a over b right ceiling
1064: .P2
1065: produces
1066: .EQ
1067: left floor x over y right floor
1068: <= left ceiling a over b right ceiling
1069: .EN
1070: .PP
1071: Several warnings about brackets are in order.
1072: First, braces are typically bigger than brackets and parentheses,
1073: because they are made up of three, five, seven, etc., pieces,
1074: while brackets can be made up of two, three, etc.
1075: Second, big left and right parentheses often look poor,
1076: because the character set is poorly designed.
1077: .PP
1078: The
1079: .CW right
1080: part may be omitted:
1081: a ``left something'' need not have a
1082: corresponding
1083: ``right
1084: something''.
1085: If the
1086: .CW right
1087: part is omitted,
1088: put braces around the thing you want the left bracket
1089: to encompass.
1090: Otherwise, the resulting brackets may be too large.
1091: .PP
1092: If you want to omit the
1093: .CW left
1094: part, things are more complicated,
1095: because technically you can't have a
1096: .CW right
1097: without a corresponding
1098: .CW left .
1099: Instead you have to say
1100: .P1
1101: left "" ... right )
1102: .P2
1103: for example.
1104: The
1105: .CW
1106: left ""
1107: .R
1108: means a ``left nothing''.
1109: This satisfies the rules without hurting your output.
1110: .NH
1111: Piles
1112: .PP
1113: There is a general facility for making vertical piles
1114: of things; it comes in several flavors.
1115: For example:
1116: .P1
1117: A ~=~ left [
1118: pile { a above b above c }
1119: ~~ pile { x above y above z }
1120: right ]
1121: .P2
1122: will make
1123: .EQ
1124: A ~=~ left [
1125: pile { a above b above c } ~~ pile { x above y above z }
1126: right ]
1127: .EN
1128: The elements of the pile (there can be as many as you want)
1129: are centered one above another, at the right height for
1130: most purposes.
1131: The keyword
1132: .CW above
1133: is used to separate the pieces;
1134: braces are used around the entire list.
1135: The elements of a pile can be as complicated as needed, even containing more piles.
1136: .PP
1137: Three other forms of pile exist:
1138: .CW lpile
1139: makes a pile with the elements left-justified;
1140: .CW rpile
1141: makes a right-justified pile;
1142: and
1143: .CW cpile
1144: makes a centered pile, just like
1145: .CW pile.
1146: The vertical spacing between the pieces
1147: is somewhat larger for
1148: .CW l ,
1149: .CW r ,
1150: and
1151: .CW cpiles
1152: than it is for ordinary piles.
1153: .P1 .1i
1154: roman sign (x)~=~
1155: left {
1156: lpile {1 above 0 above -1}
1157: ~~ lpile
1158: {if~x>0 above if~x=0 above if~x<0}
1159: .P2
1160: makes
1161: .EQ
1162: roman sign (x)~=~
1163: left {
1164: lpile {1 above 0 above -1}
1165: ~~ lpile
1166: {if~x>0 above if~x=0 above if~x<0}
1167: .EN
1168: Notice the left brace
1169: without a matching right one.
1170: .PP
1171: It is possible to change the default vertical separation
1172: between elements of a pile,
1173: by adding a number immediately after the word
1174: .CW lpile ,
1175: etc. The number is in units of 1/100's of an em
1176: (an em is about the width of the letter `m');
1177: .CW "lpile 33
1178: makes the spacing 1/3 of an em.
1179: .NH
1180: Matrices
1181: .PP
1182: It is also possible to make matrices.
1183: For example, to make
1184: a neat array like
1185: .EQ
1186: matrix {
1187: ccol { x sub i above y sub i }
1188: ccol { x sup 2 above y sup 2 }
1189: }
1190: .EN
1191: you have to type
1192: .P1
1193: matrix {
1194: ccol { x sub i above y sub i }
1195: ccol { x sup 2 above y sup 2 }
1196: }
1197: .P2
1198: This produces a matrix with
1199: two centered columns.
1200: The elements of the columns are then listed just as for a pile,
1201: each element separated by the word
1202: .CW above.
1203: You can also use
1204: .CW lcol
1205: or
1206: .CW rcol
1207: to left or right adjust columns.
1208: Each column can be separately adjusted,
1209: and there can be as many columns as you like.
1210: .PP
1211: The words
1212: .CW pile
1213: and
1214: .CW col ,
1215: .CW lpile
1216: and
1217: .CW lcol ,
1218: etc., are synonyms.
1219: .PP
1220: The reason for using a matrix instead of two adjacent piles, by the way,
1221: is that if the elements of the piles don't all have the same height,
1222: they won't line up properly.
1223: A matrix forces them to line up,
1224: because it looks at the entire structure before deciding what
1225: spacing to use.
1226: .PP
1227: A word of warning about matrices\(emeach column must have the same number of elements in it.
1228: The world will end if you get this wrong.
1229: .NH
1230: Local Motions
1231: .EQ
1232: delim $$
1233: .EN
1234: .PP
1235: Although
1236: .IT eqn
1237: tries to print things at the right place,
1238: it isn't perfect, and occasionally you will need to tune
1239: the output to make it just right.
1240: Small extra horizontal spaces can be obtained with
1241: tilde and circumflex.
1242: You can also say
1243: .CW back
1244: .IT n
1245: and
1246: .CW fwd
1247: .IT n
1248: to move small amounts horizontally.
1249: .IT n
1250: is how far to move in 1/100's of an em.
1251: Thus
1252: .CW back
1253: .CW 50
1254: moves back about half the width of an m.
1255: For example,
1256: .CW <<
1257: produces
1258: $<<$, while
1259: .CW "< back 50 <
1260: produces $< back 50 <$.
1261: .PP
1262: Similarly you can move things up or down with
1263: .CW up
1264: .IT n
1265: and
1266: .CW down
1267: .IT n .
1268: .P1
1269: x sub down 20 i sup up 20 j
1270: .P2
1271: produces $x sub down 20 i sup up 20 j$ instead of the usual $x sub i sup j$.
1272: .PP
1273: As with
1274: .CW sub
1275: or
1276: .CW sup ,
1277: the local motions affect the next thing in the input,
1278: and this can be something arbitrarily complicated if it is enclosed
1279: in braces.
1280: .NH
1281: Definitions
1282: .PP
1283: .IT Eqn
1284: provides a facility so you can give
1285: a frequently-used string of characters a name,
1286: and thereafter just type the name instead of the
1287: whole string.
1288: For example, if the sequence
1289: .P1
1290: x sub i + y sub i
1291: .P2
1292: appears repeatedly throughout a paper,
1293: you can save re-typing it each time by defining it like this:
1294: .P1 2
1295: define xy 'x sub i + y sub i'
1296: .P2
1297: This makes
1298: .CW xy
1299: a shorthand for whatever characters occur between the single quotes
1300: in the definition.
1301: You can use any character instead of quote to mark the ends of the definition,
1302: so long as it doesn't appear inside the definition.
1303: .PP
1304: Now you can use
1305: .CW xy
1306: like this:
1307: .P1
1308: \&.EQ
1309: f(x) = xy ...
1310: \&.EN
1311: .P2
1312: and so on.
1313: Each occurrence of
1314: .CW xy
1315: will expand into what it was defined as.
1316: Be careful to leave spaces or their equivalent
1317: around the name
1318: when you actually use it, so
1319: .IT eqn
1320: will be able to identify it as special.
1321: .PP
1322: There are several things to watch out for.
1323: First, although definitions can use previous definitions,
1324: as in
1325: .P1
1326: \&.EQ
1327: define xi ' x sub i '
1328: define xi1 ' xi sub 1 '
1329: \&.EN
1330: .P2
1331: .ul
1332: Don't define something in terms of itself!
1333: A favorite error is to say
1334: .P1
1335: define X ' roman X '
1336: .P2
1337: This is a guaranteed disaster,
1338: since
1339: .CW X
1340: is
1341: now defined in terms of itself.
1342: If you say
1343: .P1
1344: define X ' roman "X" '
1345: .P2
1346: however, the quotes
1347: protect the second
1348: .CW X ,
1349: and everything works fine.
1350: .PP
1351: .IT Eqn
1352: keywords can be redefined.
1353: You can make
1354: .CW /
1355: mean
1356: .CW over
1357: by saying
1358: .P1
1359: define / ' over '
1360: .P2
1361: or redefine
1362: .CW over
1363: as
1364: .CW /
1365: with
1366: .P1
1367: define over ' / '
1368: .P2
1369: .PP
1370: .EQ
1371: delim off
1372: .EN
1373: It is possible to create a parameterized definition, which will
1374: expand into something different each time it is used.
1375: If a definition contains occurrences of
1376: .CW $1 ,
1377: .CW $2 ,
1378: etc., as in
1379: .P1
1380: define f 'font $1 {"$2"}'
1381: .P2
1382: then subsequent uses of that name that are followed by a parenthesized
1383: list of values will have the values substituted for the
1384: .CW $\f2n\fP\f1's:\fP
1385: .P1
1386: f(CW, a phrase)
1387: .P2
1388: will print
1389: .CW "a phrase
1390: in the constant-width font
1391: .CW CW .
1392: .PP
1393: You can test whether something is defined with
1394: .CW ifdef :
1395: .P1
1396: ifdef f / \f2anything at all\fP /
1397: .P2
1398: is replaced by
1399: .IT "anything at all
1400: if
1401: .CW f
1402: is defined.
1403: .NH
1404: File Inclusion
1405: .PP
1406: You can include a file of
1407: .IT eqn
1408: input as part of an equation by the construction
1409: .P1
1410: include "\f2filename\fP"
1411: .P2
1412: For historical reasons,
1413: .CW copy
1414: is a synonym for
1415: .CW include .
1416: .NH
1417: A Large Example
1418: .PP
1419: Here is the complete source for the three display equations
1420: in the abstract of this guide.
1421: .br
1422: .ps -3
1423: .vs -3
1424: .P1 0
1425: \&.EQ I
1426: G(z)~mark =~ e sup { ln ~ G(z) }
1427: ~=~ exp left (
1428: sum from k>=1 {S sub k z sup k} over k right )
1429: ~=~ prod from k>=1 e sup {S sub k z sup k /k}
1430: \&.EN
1431: \&.EQ I
1432: lineup = left ( 1 + S sub 1 z +
1433: { S sub 1 sup 2 z sup 2 } over 2! + .\^.\^. right )
1434: left ( 1+ { S sub 2 z sup 2 } over 2
1435: + { S sub 2 sup 2 z sup 4 } over { 2 sup 2 cdot 2! }
1436: + .\^.\^. right ) .\^.\^.
1437: \&.EN
1438: \&.EQ I
1439: lineup = sum from m>=0 left (
1440: sum from
1441: pile { k sub 1 ,k sub 2 ,\^.\^.\^.\^, k sub m >=0
1442: above
1443: k sub 1 +2k sub 2 + .\^.\^. +mk sub m =m}
1444: { S sub 1 sup {k sub 1} } over {1 sup k sub 1 k sub 1 ! } ~
1445: { S sub 2 sup {k sub 2} } over {2 sup k sub 2 k sub 2 ! } ~
1446: \&.\^.\^.
1447: { S sub m sup {k sub m} } over {m sup k sub m k sub m ! }
1448: right ) z sup m
1449: \&.EN
1450: .P2
1451: .ps +3
1452: .vs +3
1453: ......
1454: .NH
1455: Keywords, Precedences, Etc.
1456: .PP
1457: Here are the keywords of
1458: .IT eqn
1459: in order of decreasing precedence:
1460: .P1 .1i
1461: dyad vec under utilde bar tilde
1462: hat dot dotdot
1463: left right
1464: fwd back down up
1465: fat roman italic bold size
1466: sub sup
1467: sqrt over
1468: from to
1469: .P2
1470: These operations group to the left:
1471: .P1 .1i
1472: over sqrt left right
1473: .P2
1474: All others group to the right.
1475: .PP
1476: Digits, parentheses, brackets, punctuation marks, and these mathematical words
1477: are converted
1478: to Roman font when encountered:
1479: .P1 .1i
1480: sin cos tan sinh cosh tanh arc
1481: max min lim log ln exp
1482: Re Im and if for det
1483: .P2
1484: These character sequences are recognized and translated as shown.
1485: .EQ
1486: delim $$
1487: .EN
1488: .P1
1489: >= $>=$ nothing $nothing$
1490: <= $<=$ cdot $cdot$
1491: == $==$ times $times$
1492: != $!=$ del $del$
1493: +- $+-$ grad $grad$
1494: -> $->$ \&... $"..."$
1495: <- $<-$ ,..., $",...,"$
1496: << $<<$ sum $sum$
1497: .sp 3p
1498: >> $>>$ int $int$
1499: inf $inf$ prod $prod$
1500: partial $partial$ union $union$
1501: half $half$ inter $inter$
1502: prime $prime$ dollar $dollar$
1503: approx $approx$
1504: .P2
1505: .PP
1506: To obtain Greek letters,
1507: simply spell them out in whatever case you want:
1508: .P1
1509: .ta .7i 1.4i 2.1i
1510: DELTA $DELTA$ iota $iota$
1511: GAMMA $GAMMA$ kappa $kappa$
1512: LAMBDA $LAMBDA$ lambda $lambda$
1513: OMEGA $OMEGA$ mu $mu$
1514: PHI $PHI$ nu $nu$
1515: PI $PI$ omega $omega$
1516: PSI $PSI$ omicron $omicron$
1517: SIGMA $SIGMA$ phi $phi$
1518: THETA $THETA$ pi $pi$
1519: UPSILON $UPSILON$ psi $psi$
1520: XI $XI$ rho $rho$
1521: alpha $alpha$ sigma $sigma$
1522: beta $beta$ tau $tau$
1523: chi $chi$ theta $theta$
1524: delta $delta$ upsilon $upsilon$
1525: epsilon $epsilon$ xi $xi$
1526: eta $eta$ zeta $zeta$
1527: gamma $gamma$
1528: .P2
1529: .IT Eqn
1530: really ought to know the whole Greek alphabet,
1531: but the missing upper-case characters are identical to Roman ones.
1532: .PP
1533: These are all the words known to
1534: .IT eqn ,
1535: except for characters with names.
1536: .P1
1537: above fat lcol size
1538: back font left space
1539: bar from lineup sqrt
1540: bold fwd lowbar sub
1541: ccol gfont lpile sum
1542: col gsize mark sup
1543: copy hat matrix tilde
1544: cpile highbar over to
1545: define ifdef pile under
1546: delim include prod union
1547: dot int rcol up
1548: dotdot integral right utilde
1549: down inter roman vec
1550: dyad italic rpile
1551: .P2
1552: .NH
1553: Troubleshooting
1554: .PP
1555: If you make a mistake in an equation,
1556: like leaving out a brace (very common)
1557: or having one too many (very common)
1558: or having a
1559: .CW sup
1560: with nothing before it (common),
1561: .IT eqn
1562: will tell you with the message
1563: .P1 2
1564: syntax error near line \f2n\fP, file \f2f\fP,
1565: context is >>> \f2something\fP <<<
1566: .P2
1567: where
1568: .IT n
1569: is approximately the line
1570: where the trouble occurred,
1571: .IT f
1572: is the name
1573: of the input file, and
1574: .IT something
1575: is a guess about what input was in error.
1576: The line number and context is approximate\(emlook nearby as well.
1577: There are also self-explanatory messages that arise if you leave out a quote
1578: or try to run
1579: .IT eqn
1580: on a non-existent file.
1581: .PP
1582: If you want to check a document before actually printing it,
1583: .P1
1584: eqn files >/dev/null
1585: .P2
1586: will
1587: throw away the output but print the messages.
1588: .PP
1589: If you use something like dollar signs as delimiters,
1590: it is easy to leave one out.
1591: This causes very strange troubles.
1592: The program
1593: .CW checkeq
1594: checks for misplaced or missing delimiters
1595: and similar troubles.
1596: .PP
1597: In-line equations can only be so big
1598: because of an internal limit in
1599: .IT troff .
1600: If you get the message
1601: ``word overflow,''
1602: you have exceeded this limit.
1603: If you print the equation as a displayed equation
1604: this message will usually go away.
1605: The message
1606: ``line overflow''
1607: indicates you have exceeded a different, bigger internal limit.
1608: The only cure for this is to break the equation into two separate ones.
1609: .PP
1610: On a related topic,
1611: .IT eqn
1612: does not break equations by itself\(emyou must split long equations up across multiple lines
1613: by yourself,
1614: marking each by a separate
1615: .CW .EQ
1616: \&...\&
1617: .CW .EN
1618: sequence.
1619: .NH
1620: Use on UNIX
1621: .PP
1622: To print a document that contains mathematics,
1623: .P1
1624: eqn files | troff
1625: .P2
1626: If
1627: there are any
1628: .IT troff
1629: options, they go after the
1630: .IT troff
1631: part of the command. For example,
1632: .P1
1633: eqn files | troff -ms
1634: .P2
1635: .IT Eqn
1636: assumes the output is aimed at a Postscript device.
1637: If you are using some other typesetter or printer,
1638: you have to tell
1639: .IT eqn
1640: with the same
1641: .CW -T
1642: argument that you use with
1643: .IT troff :
1644: .P1
1645: eqn -Taps files | troff -Taps ...
1646: .P2
1647: .IT Eqn
1648: also uses the environment variable
1649: .CW TYPESETTER ;
1650: the default is
1651: .CW post ,
1652: as it is for
1653: .IT troff .
1654: .PP
1655: .IT Eqn
1656: can be used with the
1657: .IT tbl
1658: program
1659: for setting tables that contain mathematics.
1660: Use
1661: .IT tbl
1662: before
1663: .IT eqn ,
1664: like this:
1665: .P1
1666: tbl files | eqn | troff
1667: .P2
1668: .PP
1669: When
1670: .IT eqn
1671: is used with
1672: .IT pic
1673: or
1674: .IT grap ,
1675: the additional vertical space
1676: that
1677: .IT eqn
1678: adds to a line to keep it from colliding
1679: with adjacent lines will conflict with
1680: .IT pic
1681: and
1682: .IT grap
1683: spacing.
1684: The phrase
1685: .CW "space 0
1686: at the beginning of an equation will turn off the extra space.
1687: .SH
1688: Acknowledgements
1689: .PP
1690: We are deeply indebted to the late J. F. Ossanna,
1691: the author of
1692: .IT troff ,
1693: for his willingness to extend
1694: .IT troff
1695: to make our task easier,
1696: and for his
1697: continuous assistance during the development
1698: and evolution
1699: of
1700: .IT eqn .
1701: We are also grateful to A. V. Aho
1702: for advice on language design,
1703: to S. C. Johnson for assistance with
1704: the
1705: .IT yacc
1706: compiler-compiler,
1707: and to all the
1708: .IT eqn
1709: users
1710: who have made helpful suggestions and criticisms.
1711: .SH
1712: References
1713: .LP
1714: |reference_placement
1715: .SH
1716: Appendix 1. Tuning \fIeqn\fP Output
1717: .PP
1718: There are numerous values that can be adjusted to tune the output
1719: of
1720: .IT eqn
1721: for a particular output device.
1722: In general, it is necessary to have access to the source code
1723: to do this tuning.
1724: .PP
1725: Some values can be set without access to the source.
1726: The names shown below (together with their default values) control the positioning
1727: of diacritical marks and special characters.
1728: They can be defined with any string value,
1729: as in
1730: .P1 0
1731: define vec_def " \ev'-.5m'\es-3\e(->\es0\ev'.5m'
1732: .P2
1733: .1C
1734: .KF bottom
1735: .nr dP 1
1736: .nr dV 2p
1737: .SP
1738: .P1 20n
1739: vec_def \ev'-.5m'\es-3\e(->\es0\ev'.5m'
1740: dyad_def \ev'-.5m'\es-3\ez\e(<-\e|\e(->\es0\ev'.5m'
1741: hat_def \ev'-.05m'\es+1^\es0\ev'.05m'
1742: tilde_def \ev'-.05m'\es+1~\es0\ev'.05m'
1743: dot_def \ev'-.67m'.\ev'.67m'
1744: dotdot_def \ev'-.67m'..\ev'.67m'
1745: utilde_def \ev'1.0m'\es+2~\es-2\ev'-1.0m'
1746: sum_def \e|\ev'.3m'\es+5\e(*S\es-5\ev'-.3m'\e|
1747: union_def \e|\ev'.3m'\es+5\e(cu\es-5\ev'-.3m'\e|
1748: inter_def \e|\ev'.3m'\es+5\e(ca\es-5\ev'-.3m'\e|
1749: prod_def \e|\ev'.3m'\es+5\e(*P\es-5\ev'-.3m'\e|
1750: int_def \ev'.1m'\es+4\e(is\es-4\ev'-.1m'
1751: Subbase 0.2
1752: Supbase 0.4
1753: .P2
1754: .KE
1755: .2C
1756: The amount by which a subscript is shifted down
1757: and a superscript shifted up are controlled by
1758: .CW Subbase
1759: and
1760: .CW Supbase .
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.