tmac.gr: axis labels
[neatroff_make.git] / demo / neateqn.ms
blob03721684b0a3e1a647d931cab436a9af68723f0e
1 .\" PSTITLE: Typesetting Mathematics with Neateqn
2 .so neat__.ms
3 .ds en.cl "#936
4 .ps.info "Typesetting Mathematics with Neateqn" "Ali Gholami Rudi"
5 .HD
6 .TL
7 \f(HD\s+8Typesetting Mathematics with Neateqn\m0\s-8\fP
8 .AU
9 \fIA. G. Rudi\fP
10 .sp 3
11 This document briefly introduces Neateqn, an eqn implementation for
12 typesetting mathematical formulas in Neatroff.  For further
13 information about Neatroff and Neateqn, see
14 http:/\h'-.3n'/litcave.rudi.ir/.
16 .SH "The Algorithm"
17 Neatroff follows the rules described in appendix \s-1G\s+1 of Knuth's
18 Texbook, which explains Tex's algorithm for typesetting mathematical
19 formulas.  In Tex, the sub-formulas of a formula are always typeset in
20 one of the eight predefined styles.  The formulas inside
21 \&\s-1.EQ/.EN\s+1 blocks are rendered in displayed styles and inline
22 equations are rendered in text styles.
23 Their main difference is that in text styles formulas are
24 vertically more compact to reduce the amount of extra
25 spacing required to be inserted between lines.
27 The default value of the parameters of the typesetting algorithm,
28 such as the position of subscripts, can be changed.
29 These parameters are described in appendix \s-1G\s+1 of the Texbook
30 and can be modified in Neatroff with Groff eqn-style \(lqset\(rq command.
31 See Groff eqn manual page or the Texbook for their list and explanations.
33 .SH "Defining Custom Brackets
34 It is possible to adjust the default brackets or define new ones.  Two
35 commands are available for this purpose: one for specifying different
36 bracket sizes (bracketsizes) and one for specifying bracket building
37 glyphs (bracketpieces):
39 .cc.beg
40 bracketsizes sign N glyph1 glyph2 ... glyphN
41 bracketpieces sign top mid bot cen
42 .cc.end
44 .LP
45 In these commands, sign is the token placed after the \(lqleft\(rq and
46 \(lqright\(rq keywords in equations.  In bracketsizes command, the
47 glyphs should be ordered based on their size with the smallest glyph
48 appearing first.  Neateqn tries the specified glyphs in the same order
49 until it finds the glyph that is large enough for the enclosed
50 formula.  If this fails, it tries to build the bracket if its pieces
51 are defined (by default or with bracketpieces).  The four arguments of
52 bracketpieces specify the glyphs required for building the bracket.
53 The last argument can be empty if the bracket has no centre (\\(lk is
54 the centre of {, for instance).
56 As an example, the following lines show how the default opening and
57 closing parenthesis can be defined:
59 .cc.beg
60 bracketpieces ( "\\(LT" "\\(LX" "\\(LB" ""
61 bracketpieces ) "\\(RT" "\\(RX" "\\(RB" ""
62 .cc.end
64 .LP
65 The following lines do so for braces:
67 .cc.beg
68 bracketpieces { "\\(lt" "\\(bv" "\\(lb" "\\(lk"
69 bracketpieces } "\\(rt" "\\(bv" "\\(rb" "\\(rk"
70 .cc.end
72 .LP
73 Also the following line instructs Neateqn to use Tex's open
74 parenthesis glyphs with different sizes (note that in Neatroff \\\s-1N\s+1'gid' is
75 the glyph with device-dependent name gid):
77 .cc.beg
78 bracketsizes ( 5 "(" "\\N'parenleftbig'" "\\N'parenleftBig'"
79         "\\N'parenleftbigg'" "\\N'parenleftBigg'"
80 .cc.end
82 .EQ
83 delim $$
84 .EN
85 .SH "Adjusting the Syntax"
86 The logic used in eqn to partition equations may seem odd to its new
87 users; for instant in \(lqO(n sup 2)\(rq, the expected result may
88 be $O ( n sup 2 )$, instead of $O(n sup {2)}$.
89 Even experienced eqn users occasionally make these
90 mistakes and some insert spaces around most tokens to prevent possible
91 surprises.  Equations like \(lqO ( n sup 2 )\(rq, which prevent
92 most of these problems, do not look as good as the alternative, however.  This
93 issue is one of the main advantages of Tex's more concise syntax.  In
94 Neateqn it is possible to make equations like the first work.
96 Neateqn splits (chops) equations at specific characters.  Equations
97 are always chopped at spaces and before and after open and close
98 braces.  By default, equations are also chopped before and after \(ha,
99 \(ti, and " (but these can be changed).  The -c option of Neateqn
100 allows specifying the characters, around which equations are chopped.
101 For instance, if \(lq\(ti\(ha"(),\(rq is passed with -c to Neateqn,
102 \(lqO(n sup 2)\(rq is interpreted as \(lqO ( n sup 2 )\(rq.  This
103 may be considered an improvement but a more important advantage in
104 the author's opinion is that these characters may be redefined.  For
105 instance, one may redefine open and close parenthesis as follows:
106 .cc.beg
107 define ( @{ left (@
108 define ) @right ) }@
109 .cc.end
111 Then, it is possible to write \(lq(a over b) sup (c + 5)\(rq
112 to get $left ( a over b right ) sup left ( c + 5 right )$.
113 Note that macro arguments are never split away from macro name,
114 thus one can safely call \(lqlog(a, n)\(rq, if log is defined
115 as \(lqroman "log" sub {\N'dollar'1}({\N'dollar'2})\(rq.
117 .SH "Assigning Character Type
118 Neateqn determines the spacing between characters in an equation based
119 on their type (see chapter 18 of the Texbook for more information).
120 It is possible to specify or change the type of a character in Neateqn
121 with \(lqchartype\(rq command.  Possible types are \(lqord\(rq for
122 ordinary atoms, \(lqop\(rq for large operators, \(lqbin\(rq for
123 binary operators, \(lqrel\(rq for relations, \(lqopen\(rq for opening
124 brackets, \(lqclose\(rq for closing brackets, \(lqpunct\(rq for
125 punctuations, \(lqinner\(rq for fractions.
126 As an example, the following line declares backslash as a binary operator:
127 .cc.beg
128 chartype bin \\(rs
129 .cc.end
132 The second argument of \(lqchartype\(rq command should be a Troff
133 character name.  If the operator is not a character, it can be defined as one.
134 For instance, for \(lq>>\(rq and \(lqlog\(rq
135 operators, one may define the following two characters (note that
136 the following two lines are Neatroff requests and should be outside
137 \&\s-1.EQ/.EN\s+1 blocks):
138 .cc.beg
139 \&.char \\[eqn.log] "log
140 \&.char \\[eqn.>>]  ">\\h'-.1n'>
141 .cc.end
144 Then, the type of the operators can be specified as explained above:
145 .cc.beg
146 chartype op  \\[eqn.log]
147 chartype rel \\[eqn.>>]
148 .cc.end
151 Finally, macros like the following may be defined to improve the readability:
152 .cc.beg
153 define >>  @\\[eqn.>>]@
154 define log @\\[eqn.log]@
155 .cc.end
157 .SH "Breaking Equations"
158 Neateqn can break equations after top-level operators; This is
159 important especially when there are long inline equations in the text.
160 The \(lqbreakcost\(rq command can specify the cost of a line break
161 after different character types: its first argument is the character
162 type, as enumerated in the previous section, and its second argument
163 is the cost of line breaks after the given character type.  Costs are
164 specified via Neatroff's \\j escape sequence (\(lqNeatroff
165 Introduction\(rq explains the meaning of these costs).  The default
166 values are:
168 .cc.beg
169 breakcost rel 100
170 breakcost bin 200
171 breakcost punct 1000
172 .cc.end
175 A value of 0 disables breaking equations for the specified character.
176 Note that Neateqn breaks equations after top-level operators only.
177 Thus, equations surrounded by braces will not be broken.  The
178 following command instructs Neateqn never to break equations:
180 .cc.beg
181 breakcost any 0
182 .cc.end
184 .SH "Using Tex Mathematical Symbols"
185 In order to use Tex's mathematical symbols in Neatroff, \s-1CMEX10\s+1 and
186 \s-1CMSY10\s+1 fonts (or their equivalents, for instance \s-1TXEX\s+1 and \s-1TXSY\s+1 for
187 Txfonts or \s-1PXEX\s+1 and \s-1PXSY\s+1 for Pxfonts) should be mounted and declared
188 as the special font of eqn Roman font (the font declared as grfont in
189 Neateqn).
191 .cc.beg
192 \&.fp - CMEX CMEX10
193 \&.fp - CMSY CMSY10
194 \&.fspecial R CMEX CMSY
195 .cc.end
198 If the italic font lacks Greek characters, \s-1CMMI10\s+1 (or its equivalents,
199 like \s-1RTXMI\s+1 for Txfonts or \s-1RPXMI\s+1 for Pxfonts) can be mounted and
200 declared as a special font of eqn italic font (the font declared as
201 gfont in Neateqn).
203 .cc.beg
204 \&.fp - CMMI RPXMI
205 \&.fspecial I CMMI
206 .cc.end
209 Standard symbol can also be redefined to use Computer Modern glyphs,
210 like those for summation and product:
212 .cc.beg
213 define sum @{vcenter roman "\\N'summationdisplay'"}@
214 define tsum @{vcenter roman "\\N'summationtext'"}@
215 define prod @{vcenter roman "\\N'productdisplay'"}@
216 define tprod @{vcenter roman "\\N'producttext'"}@
217 .cc.end
220 define sum @{vcenter roman "\N'summationdisplay'"}@
221 define tsum @{vcenter roman "\N'summationtext'"}@
222 define prod @{vcenter roman "\N'productdisplay'"}@
223 define tprod @{vcenter roman "\N'producttext'"}@
224 define small @size -4@
227 .SH "Some Samples For Different Fonts
230 Palatino and Computer Modern mathematical symbols:
232 (x + y) sup n = sum from i=0 to n left ( pile {n above i} right ) x sup i y sup n-i
234 .sp -.5
236 left [ a right ] +
237 left ( a over b right ) +
238 left { {x + a over b} over {y + c over d} }
240 sqrt {a} + sqrt {a over b} + sqrt { {x + a over b} over {y + c over d} }
244 Palatino and Pxfonts mathematical symbols:
245 .fp - CMEX Pxex
246 .fp - CMSY Pxsy
248 (x + y) sup n = sum from i=0 to n left ( pile {n above i} right ) ^ x sup i y sup n-i
250 .sp -.5
252 left [ a right ] +
253 left ( a over b right ) +
254 left { {x + a over b} over {y + c over d} }
256 sqrt {a} + sqrt {a over b} + sqrt { {x + a over b} over {y + c over d} }
260 Times Roman and Txfonts mathematical symbols:
261 .fp - R R
262 .fp - I I
263 .fp - B B
264 .fp - CMEX txex
265 .fp - CMSY txsy
267 (x + y) sup n = sum from i=0 to n left ( pile {n above i} right ) ^ x sup i y sup n-i
269 .sp -.5
271 left [ a right ] +
272 left ( a over b right ) +
273 left { {x + a over b} over {y + c over d}  }
275 sqrt {a} + sqrt {a over b} + sqrt { {x + a over b} over {y + c over d} }
279 Computer Modern:
280 .fp - R CMR10
281 .fp - I CMMI10
282 .fp - B CMB10
283 .fp - HD CMBX12
284 .fp - CMSY CMSY10
285 .fp - CMEX CMEX10
286 .fp - CMMI CMMI10
287 .fspecial R CMSY CMEX10
288 .fspecial I CMMI
290 (x + y) sup n = sum from i=0 to n left ( pile {n above i} right ) x sup i y sup n-i
292 .sp -.5
294 left [ a right ] +
295 left ( a over b right ) +
296 left { {x + a over b} over {y + c over d}  }
298 sqrt {a} + sqrt {a over b} + sqrt { {x + a over b} over {y + c over d} }