ma-cb-en-math.tex /size: 13 Kb    last modification: 2020-07-01 14:35
1\startcomponent ma-cb-en-math
2
3\enablemode[**en-us]
4
5\project ma-cb
6
7\startchapter[reference=formulas,title=Typesetting math]
8
9\startsection[title=Introduction]
10
11\index {math}
12
13\TEX\ is {\em the} typesetting program for math. However, this is not the
14extensive chapter on typesetting math you might expect. We advise you to do some
15further reading on typesetting formulas in \TEX. See for example: \footnote{In
16this introduction on typesetting math we relied on the booklet {\em \TEX niques}
17by Arthur Samuel.}
18
19\startitemize[packed]
20\item {\em The \TeX Book} by D.E. Knuth
21\item {\em The Beginners Book of \TeX} by S. Levy and R. Seroul
22\stopitemize
23
24\startsection[title=Typesetting math]
25
26\index {math mode}
27\index {display mode}
28\index {text mode}
29
30Normally different conventions are applied for typesetting normal text and math
31text. These conventions are \quote{known} by \TEX\ and applied accordingly when
32generating a document. We can rely on \TEX\ for delivering high quality math
33output.
34
35A number of conventions for math are:
36
37\startitemize[n,packed]
38
39\item Characters are typeset in $math\ italic$ (don't confuse this with the
40      normal {\it italic characters} in a font).
41
42\item Symbols like Greek characters ($\alpha$, $\chi$) and math symbols ($\leq$,
43      $\geq$, $\in$) are used.
44
45\item Spacing will differ from normal spacing.
46
47\item Math expressions have a different alignment than that of the running text.
48
49\item The sub and superscripts are downsized automatically, like in $a^{b}_{c}$.
50
51\item Certain symbols have different appearances in the inline and display mode.
52
53\stopitemize
54
55When typesetting math you have to work in the so called math mode in which math
56expressions can be defined by means of plain \TEX||commands.
57
58Math mode has two alternatives: text mode and display mode. Math in text
59mode is activated by \type{$} and \type{$}, while display mode is activated by
60\type{$$} and \type{$$}. In \CONTEXT\ however, display mode is activated with
61the \type{\start ... \stopformula} command pair to have more grip on vertical
62spacing around the formula.
63
64\startbuffer
65The municipality of Hasselt covers an area of 42,05 \unit{Square Kilo
66Meter}. Now, if you consider a circular area of this size with the
67market place of Hasselt as the center point $M$ you can calculate its
68diameter with ${{1}\over{4}} \pi r^2$.
69\stopbuffer
70
71\typebuffer
72
73This will become:
74
75\getbuffer
76
77The many \type{{}} (grouping) in ${{1}\over{4}} \pi r^2$ are essential for
78separating operations in the expression. If you omit the outer curly braces like
79this: \type{${1}\over{4} \pi r^2$}, you would get a non desired result:
80${1}\over{4} \pi r^2$.
81
82The letters and numbers are typeset in three different sizes: text size $a+b$,
83script size $\scriptstyle a+b$ and scriptscript size $\scriptscriptstyle a+b$.
84These can be influenced by the commands \type{\scriptstyle} and
85\type{\scriptscriptstyle}.
86
87Symbols like $\int$ and $\sum$ will have a different form in text and display
88mode. If we type \type {$\sum_{n=1}^{m}$} or \type {$\int_{-\infty}^{+\infty}$}
89we will get {$\sum_{n=1}^{m}$} and {$\int_{-\infty}^{+\infty}$}. But when you
90type:
91
92\startbuffer
93\startformula
94  \sum_{n=1}^{m} \quad {\rm and} \quad \int_{-\infty}^{+\infty}
95\stopformula
96\stopbuffer
97
98\typebuffer
99
100to get displaymode you get:
101
102\getbuffer
103
104With the commands \type {\nolimits} and \type{\limits} you can influence the
105appearances of \type{\sum} and \type{\int}:
106
107\startbuffer
108\startformula
109  \sum_{n=1}^{m}\nolimits
110  \quad {\rm and} \quad
111  \int_{-\infty}^{+\infty}\limits
112\stopformula
113\stopbuffer
114
115\typebuffer
116
117which will result in:
118
119\getbuffer
120
121For typesetting fractions there is the command \type {\over}. In \CONTEXT\ you
122can use the alternative \type {\frac}. For ${\frac{a}{1+b}}+c$ we type for
123instance \type {${\frac{a}{1+b}}+c$}.
124
125Other commands to put one thing above the other, are:
126
127\startbuffer[atop]
128${a} \atop {b}$
129\stopbuffer
130\startbuffer[choose]
131${n+1} \choose {k}$
132\stopbuffer
133\startbuffer[brack]
134${m} \brack {n}$
135\stopbuffer
136\startbuffer[brace]
137${m} \brace {n-1}$
138\stopbuffer
139
140\starttabulate[|l|l|l|l|]
141\NC \type {\atop}
142\NC \typebuffer[atop]
143\NC \mathstrut\getbuffer[atop]
144\NC
145\NC\NR
146\NC \type {\choose}
147\NC \typebuffer[choose]
148\NC
149\NC \mathstrut\getbuffer[choose]
150\NC\NR
151\NC \type {\brack}
152\NC \typebuffer[brack]
153\NC \mathstrut\getbuffer[brack]
154\NC
155\NC\NR
156\NC \type {\brace}
157\NC \typebuffer[brace]
158\NC
159\NC \mathstrut\getbuffer[brace]
160\NC\NR
161\stoptabulate
162
163\TEX\ can enlarge delimiters like (~) and $\{~\}$ automatically if the left and
164right delimiter is preceeded by the commands \type {\left} and \type {\right}
165respectively. If you type:
166
167\startbuffer
168\startformula
169  1+\left(\frac{1}{1-x^{x-2}}\right)^3
170\stopformula
171\stopbuffer
172
173\typebuffer
174
175you will get:
176
177\getbuffer
178
179Sub and superscripts are invoked by \quote {\type{_}} and \quote {\type{^}}. They
180have effect on the next first character so grouping with $\{$~$\}$ is necessary
181in case of multi character sub and superscripts.
182
183In certain situations the delimiters can be preceeded by \type{\bigl},
184\type{\Bigl}, \type{\biggl} and \type{\Biggl} and their right counterparts. Even
185bigger delimiters can be produced by placing \type{\left} and \type{\right} in a
186\type{\vbox} construction. When we type a senseless expression like:
187
188\startbuffer
189\startformula
190  \left(\vbox to 16pt{}x^{2^{2^{2^{2}}}}\right)
191\stopformula
192\stopbuffer
193
194\typebuffer
195
196we get:
197
198\getbuffer
199
200In display mode the following delimiters will work in the automatic enlargement
201mechanism:
202
203\starttabulate[|l|l|l|l|l|l|l|l|]
204\NC \type{\lfloor}      \NC $\lfloor$
205\NC \type{\langle}      \NC $\langle$
206\NC \type{\vert}        \NC $\vert$
207\NC \type{\downarrow}   \NC $\downarrow$
208\NC\NR
209\NC \type{\rfloor}      \NC $\rfloor$
210\NC \type{\rangle}      \NC $\rangle$
211\NC \type{\Vert}        \NC $\Vert$
212\NC \type{\Downarrow}   \NC $\Downarrow$
213\NC\NR
214\NC \type{\lceil}       \NC $\lceil$
215\NC \type{/}            \NC $/$
216\NC \type{\uparrow}     \NC $\uparrow$
217\NC \type{\updownarrow} \NC $\updownarrow$
218\NC\NR
219\NC \type{\rceil}       \NC $\rceil$
220\NC \type{\backslash}   \NC $\backslash$
221\NC \type{\Uparrow}     \NC $\Uparrow$
222\NC \type{\Updownarrow} \NC $\Updownarrow$
223\NC\NR
224\stoptabulate
225
226In display mode we should typeset only one fraction and otherwise switch to the
227\type{a/b} notation. To get:
228
229\startformula
230  a_0 + {\frac{a}{a_1 + \frac{1}{a_2}}}
231\stopformula
232
233we will not type:
234
235\startbuffer
236\startformula
237  a_0+{\frac{a}{a_1+\frac{1}{a_2}}}
238\stopformula
239\stopbuffer
240
241\typebuffer
242
243but prefer:
244
245\startbuffer
246\startformula
247  a_0 + {\frac{a}{a_1 + 1/a_2}}
248\stopformula
249\stopbuffer
250
251\typebuffer
252
253to obtain:
254
255\getbuffer
256
257In addition we could also use the command \type{\displaystyle}. If we would type:
258
259\startbuffer
260\startformula
261  a_0 + {\frac{a}{a_1 + \frac{1}{\strut \displaystyle a_2}}}
262\stopformula
263\stopbuffer
264
265\getbuffer
266
267we will get:
268
269\getbuffer
270
271Below we demonstrate the commands \type{\matrix}, \type{\pmatrix}, \type{\ldots},
272\type{\cdots} and \type{\cases} without any further explanation.
273
274\startbuffer[a]
275\startformula
276\stopbuffer
277
278\startbuffer[c]
279\stopformula
280\stopbuffer
281
282\startbuffer[b]
283  A=\left(\matrix{x-\lambda & 1         & 0         \cr
284                  0         & x-\lambda & 1         \cr
285                  0         & 0         & x-\lambda \cr}\right)
286\stopbuffer
287
288\typebuffer[a,b,c] \startformula\getbuffer[b]\stopformula
289
290\startbuffer[b]
291  A=\left|\matrix{x-\mu& 1     & 0     \cr
292                  0    & x-\mu & 1     \cr
293                  0    & 0     & x-\mu \cr}\right|
294\stopbuffer
295
296\typebuffer[a,b,c] \startformula\getbuffer[b]\stopformula
297
298\startbuffer[b]
299  A=\pmatrix{a_{11} & a_{12} & \ldots & a_{1n} \cr
300             a_{21} & a_{22} & \ldots & a_{2n} \cr
301             \vdots & \vdots & \ddots & \vdots \cr
302             a_{m1} & a_{m2} & \ldots & a_{mn} \cr}
303\stopbuffer
304
305\typebuffer[a,b,c] \startformula\getbuffer[b]\stopformula
306
307\startbuffer[b]
308  A=\pmatrix{a_{11} & a_{12} & \ldots & a_{1n} \cr
309             a_{21} & a_{22} & \ldots & a_{2n} \cr
310             \vdots & \vdots & \ddots & \vdots \cr
311             a_{m1} & a_{m2} & \ldots & a_{mn} \cr}
312\stopbuffer
313
314\typebuffer[a,b,c] \startformula\getbuffer[b]\stopformula
315
316\startbuffer[b]
317  |x|=\cases{ x, & if $x\geq0$; \cr
318             -x, & otherwise    \cr}
319\stopbuffer
320
321\typebuffer[a,b,c] \startformula\getbuffer[b]\stopformula
322
323To typeset normal text in a math expression we have to consider the following.
324First a space is not typeset in math mode so we have to enforce one with
325\type{ \ } (backslash). Second we have to indicate a font switch, because the text should
326not appear in $math\ italic$ but in the actual font. So in \CONTEXT\ we have to
327type:
328
329\startbuffer
330\startformula
331  x^3+{\tf lower\ order\ terms}
332\stopformula
333\stopbuffer
334
335\typebuffer
336
337to get:
338
339\getbuffer
340
341The math functions like $\sin$ and $\tan$ that have to be typeset in the actual
342font are predefined functions in \TEX:
343
344\starttabulate[|l|l|l|l|l|l|l|l|]
345\NC \type{\arccos} \NC \type{\cos} \NC \type{\csc} \NC \type{\exp} \NC \type{\ker} \NC \type{\limsup} \NC \type{\min} \NC \type{\sinh} \NC\NR
346\NC \type{\arcsin} \NC \type{\cosh} \NC \type{\deg} \NC \type{\gcd} \NC \type{\lg} \NC \type{\ln} \NC \type{\Pr} \NC \type{\sup} \NC\NR
347\NC \type{\arctan} \NC \type{\cot} \NC \type{\det} \NC \type{\hom} \NC \type{\lim} \NC \type{\log} \NC \type{\sec} \NC \type{\tan} \NC\NR
348\NC \type{\arg} \NC \type{\coth} \NC \type{\dim} \NC \type{\inf} \NC \type{\liminf} \NC \type{\max} \NC \type{\sin} \NC \type{\tanh} \NC\NR
349\stoptabulate
350
351If we type the sinus or limit function:
352
353\startbuffer
354\startformula
355  \sin 2\theta=2\sin\theta\cos\theta
356  \quad {\tf or} \quad
357  \lim_{x\to0}{\frac{\sin x}{x}}=1
358\stopformula
359\stopbuffer
360
361\typebuffer
362
363we get:
364
365\getbuffer
366
367Alignment in math expressions may need special attention. In multi line
368expressions we sometimes need alignment at the \quote {$=$} sign. This is done by
369the command \type{\eqalign}. If we type:
370
371\startbuffer
372\startformula
373  \eqalign{
374    ax^2+bx+c &= 0                                \cr
375    x         &= \frac{-b \pm \sqrt{b^2-4ac}}{2a} \cr}
376\stopformula
377\stopbuffer
378
379\typebuffer
380
381we get:
382
383\getbuffer
384
385Sometimes alignment at more than one location is wanted. Watch the second line in
386the next example and see how it is defined:
387
388\startbuffer
389\startformula
390  \eqalign{
391    ax+bx+\cdots+yx+zx &         = x(a +b+ \cdots \cr
392                       &\phantom{= x(a~}+y+z)     \cr
393                       &         = y              \cr}
394\stopformula
395\stopbuffer
396
397\typebuffer
398
399This results in:
400
401\getbuffer
402
403Next to the command \type{\phantom} there are \type{\hphantom} without height and
404depth and \type{\vphantom} without width.
405
406You can rely on \TEX\ for spacing within a math expression. In some situations,
407however you may want to influence spacing. This is done by:
408
409\starttabulate[|l|r|]
410\NC \type{\!} \NC $-\frac{1}{6}$\type{\quad} \NC\NR
411\NC \type{\,} \NC $\frac{1}{6}$\type{\quad}  \NC\NR
412\NC \type{\>} \NC $\frac{2}{9}$\type{\quad}  \NC\NR
413\NC \type{\;} \NC $\frac{5}{18}$\type{\quad} \NC\NR
414\stoptabulate
415
416These \quote {spaces} are related to \type {\quad} that stands for the width of
417the capital \quote{M}.
418
419The use of the command \type{\prime} speaks for itself. For example if would want
420$y_1^\prime+y_2^{\prime\prime}$ you should type
421\type{$y_1^\prime+y_2^{\prime\prime}$}.
422
423An expression like $\root 3 \of {x^2+y^2}$ is obtained by \type{$\root 3 \of
424{x^2+y^2}$}.
425
426At the end of this section we point to the command \type{\mathstrut} which we can
427use to enforce consistency, for example within the root symbol. With
428\type{$\sqrt{\mathstrut a}+\sqrt{\mathstrut d}+\sqrt{\mathstrut y}$} we will get
429$\sqrt{\mathstrut a}+\sqrt{\mathstrut d}+\sqrt{\mathstrut y}$ in stead of
430$\sqrt{a}+\sqrt{d}+\sqrt{y}$.
431
432See \in{appendix}[overviews] for a complete overview of math commands.
433
434\stopsection
435
436\startsection[title=Placing formulas]
437
438\index{formula}
439
440\Command{\tex{placeformula}}
441\Command{\tex{startformula}}
442\Command{\tex{setupformulas}}
443
444You can typeset numbered formulas with:
445
446\shortsetup{placeformula}
447\shortsetup{startformula}
448
449Two examples:
450
451\startbuffer
452\placeformula[formula:aformula]
453  \startformula
454     y=x^2
455  \stopformula
456
457\placeformula
458  \startformula
459    \int_0^1 x^2 dx
460  \stopformula
461\stopbuffer
462
463\typebuffer
464
465\getbuffer
466
467The command \type{\placeformula} handles spacing around the formulas and the
468numbering. The bracket pair is optional and is used for referencing and to switch
469numbering on and off.
470
471\startbuffer
472\placeformula[first one]
473\startformula
474  y=x^2
475\stopformula
476
477\placeformula[middle one]
478\startformula
479  y=x^3
480\stopformula
481
482\placeformula[last one]
483\startformula
484  y=x^4
485\stopformula
486\stopbuffer
487
488\getbuffer
489
490\in{Formula}[middle one] was typed like this:
491
492\startbuffer
493\placeformula[middle one]
494  \startformula
495     y=x^3
496  \stopformula
497\stopbuffer
498
499\typebuffer
500
501The lable \type{[middle one]} is used for refering to this formula. Such a
502reference is made with \type{\in{formula}[middle one]}.
503
504If no numbering is required you type:
505
506\type{\placeformula[-]}
507
508Numbering of formulas is set up with \type{\setupnumbering}. In this manual
509numbering is set up with \type{\setupnumbering[way=bychapter]}. This means that
510the chapter number preceeds the formula number and numbering is reset with each
511new chapter. For reasons of consistency the tables, figures, intermezzi etc. are
512numbered in the same way. Therefore you use \type{\setupnumbering} in the set up
513area of your input file.
514
515Formulas can be set up with:
516
517\shortsetup{setupformulae}
518
519\stopsection
520
521\stopchapter
522
523\stopcomponent
524
525