mmlprime.tex /size: 167 Kb    last modification: 2023-12-21 09:43
1% language=us runpath=texruns:manuals/mathml
2
3% author    : Hans Hagen
4% copyright : ConTeXt Development Team
5% license   : Creative Commons Attribution ShareAlike 4.0 International
6% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
7% origin    : the ConTeXt distribution
8%
9% comment   : Because this manual is distributed with TeX distributions it comes with a rather
10%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
11%             that they describe. Using parts of the content otherwise can therefore conflict
12%             with existing functionality and we cannot be held responsible for that. Many of
13%             the manuals contain characteristic graphics and personal notes or examples that
14%             make no sense when used out-of-context.
15%
16% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
17%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
18%             to users for testing, feedback and corrections.
19
20% The layout is made for the traditional lucida bright fonts. In the meantime we
21% use the opentype variant but it sometimes has different default shapes. So,
22% rendering has become less optimal. However, this is one of the oldest documents
23% that come with \CONTEXT, which has always supported \MATHML, so we keep it as it
24% is. The same is true for the style definition, which hasn't changed much.
25
26% \setupbackend[export=yes]
27
28\usemodule[abr-02,mathml,math-coverage,asciimath]
29
30% \enabletrackers[xml.entities]
31
32% \showframe
33
34\setupindenting
35  [medium,next,yes]
36
37\setupinteraction
38  [state=start,
39   color=,
40   style=]
41
42\placebookmarks
43  [chapter,section]
44
45% was: \doifelsemode {atpragma} { } { }
46
47\doifelsefontpresent {LucidaBrightOT.otf} {
48    \setupbodyfont[lucidaot,10pt]
49    \definefontsynonym[NiceBold][Handwriting]
50} {
51    \setupbodyfont[pagella,11pt]
52    \definefontsynonym[NiceBold][SerifBold]
53}
54
55\definefont[ChapterFont][NiceBold*default at 32pt]
56\definefont[SectionFont][NiceBold*default sa 1.2]
57\definefont[FormulaFont][NiceBold*default sa 1.0]
58
59\setuplayout
60  [topspace=15mm,
61   backspace=15mm,
62   header=10mm,
63   headerdistance=5mm,
64   footer=10mm,
65   footerdistance=5mm,
66   width=middle,
67   height=middle]
68
69\setuppagenumbering
70  [alternative=doublesided]
71
72\setuphead
73  [chapter]
74  [alternative=middle,
75   number=no,
76   style=ChapterFont,
77   color=darkred,
78   after={\blank[3*big]},
79   header=high,
80   footer=startofchapter]
81
82\setuphead
83  [section]
84  [command=\SectionCommand,
85   style=SectionFont,
86   textcolor=darkred,
87   after={\blank[big]}]
88
89\setuphead
90  [subsection]
91  [command=\SubSectionCommand,
92   style=SectionFont,
93   textcolor=darkred,
94   after={\blank[big]}]
95
96\protected\def\SectionCommand#1#2%
97% {\darkblue<--\enspace\ifconditional\headshownumber#1\quad\fi#2\enspace-->}
98  {\darkblue<--\enspace\ifconditional\headshownumber#1\enspace\fi#2\enspace-->}
99
100\protected\def\SubSectionCommand#1#2%
101% {\darkblue<?\enspace\ifconditional\headshownumber#1\quad\fi#2\enspace ?>}
102  {\darkblue<?\space\ifconditional\headshownumber#1\enspace\fi#2\enspace ?>}
103
104\setuplayout
105  [style=\hw]
106
107\setuppagenumbering
108  [color=darkblue]
109
110\setupheader
111  [color=darkblue]
112
113\setupfooter
114  [color=darkblue]
115
116\setuplinewidth
117  [1pt]
118
119\setuptabulate
120  [rulecolor=darkblue]
121
122\setuptables
123  [rulecolor=darkblue]
124
125\setupfootertexts
126  [chapter]
127
128\definetext
129  [startofchapter]
130  [footer][pagenumber]
131
132\definestartstop
133  [mmlelement]
134  [style=\it]
135
136\definestartstop
137  [attvalue]
138  [style=\it]
139
140\definestartstop
141  [entity]
142  [style=\it,
143   left=\textampersand,
144   right=;]
145
146\setuplist
147  [chapter]
148  [interaction=all,
149   alternative=b,
150   aligntitle=yes,
151   textstyle=bold,
152   numberstyle=bold,
153   textcolor=darkblue,
154   numbercolor=darkblue,
155   after=\blank]
156
157\setuplist
158  [section]
159  [interaction=all,
160   alternative=b,
161   maxwidth=.8\hsize,
162   aligntitle=yes]
163
164\definetabulate
165  [directives]
166  [| T l | T l | T l | l |]
167
168\definetabulate
169  [attributes]
170  [| T l | T l | l | l |]
171
172\definetabulate
173  [mathmlattributes]
174  [| B l w(2.5cm) T CT{darkred} | T l | c | p |]
175
176\starttabulatehead[mathmlattributes]
177    \FL
178\stoptabulatehead
179
180\starttabulatetail[mathmlattributes]
181    \LL
182\stoptabulatetail
183
184\starttexdefinition unexpanded ExampleLine #1
185    \noindentation % \dontleavehmode
186    \type[color=darkblue]{#1}\quad\quad\asciimath{#1}
187    \blank[big]
188\stoptexdefinition
189
190
191\setupformulas
192  [way=bytext]
193
194% isolated content
195
196\startbuffer[derivates]
197    \showXMLfile {derivate}{pc-d-001}
198    \showXMLfile {derivate}{pc-d-002}
199    \showXMLfile {derivate}{pc-d-003}
200    \showXMLfile {derivate}{pc-d-004}
201    \showXMLfile {derivate}{pc-d-005}
202    \showXMLfile {derivate}{pc-d-006}
203    \showXMLfile {derivate}{pc-d-007}
204    \showXMLfile {derivate}{pc-d-008}
205    \showXMLfile {derivate}{pc-d-009}
206    \showXMLfile {derivate}{pc-d-010}
207    \showXMLfile {derivate}{pc-d-011}
208    \showXMLfile {derivate}{pc-d-043}
209    %showXMLfile {derivate}{pc-d-051}
210\stopbuffer
211
212\startbuffer[integrals]
213    \showXMLfile {integral}{pc-i-022}
214    \showXMLfile {integral}{pc-i-061}
215    \showXMLfile {integral}{pc-i-380}
216\stopbuffer
217
218\startbuffer[series]
219    \showXMLfile {serie}{pc-s-001}
220    \showXMLfile {serie}{pc-s-002}
221    \showXMLfile {serie}{pc-s-003}
222    \showXMLfile {serie}{wh-s-001}
223    \showXMLfile {serie}{wh-s-002}
224\stopbuffer
225
226\startbuffer[logs]
227    \showXMLfile {log}{wh-l-001}
228    \showXMLfile {log}{wh-l-002}
229    \showXMLfile {log}{wh-l-003}
230    \showXMLfile {log}{wh-l-004}
231\stopbuffer
232
233\startbuffer[goniometrics]
234    \showXMLfile {gonio}{wh-g-001}
235    \showXMLfile {gonio}{wh-g-002}
236    \showXMLfile {gonio}{wh-g-003}
237    \showXMLfile {gonio}{wh-g-004}
238    \showXMLfile {gonio}{wh-g-005}
239    \showXMLfile {gonio}{wh-g-006}
240    \showXMLfile {gonio}{wh-g-007}
241    \showXMLfile {gonio}{wh-g-008}
242    \showXMLfile {gonio}{wh-g-009}
243    \showXMLfile {gonio}{wh-g-010}
244    \showXMLfile {gonio}{wh-g-011}
245    \showXMLfile {gonio}{wh-g-012}
246    \showXMLfile {gonio}{wh-g-013}
247    \showXMLfile {gonio}{wh-g-014}
248    \showXMLfile {gonio}{wh-g-015}
249    \showXMLfile {gonio}{wh-g-016}
250\stopbuffer
251
252\startbuffer[statistics]
253    \showXMLfile {statistic}{wh-o-001}
254    \showXMLfile {statistic}{wh-o-002}
255    \showXMLfile {statistic}{wh-o-003}
256\stopbuffer
257
258\startbuffer[matrices]
259    \showXMLfile {matrix}{wh-m-001}
260    \showXMLfile {matrix}{wh-m-002}
261\stopbuffer
262
263% buffers voor de presentational MathML attributes
264
265\startbuffer[mi-mn]
266    \startmathmlattributes
267    \NC mi, mn \NC class, id, style \NC -- \NC \NC\NR
268    \NC        \NC dir              \NC -- \NC \NC\NR
269    \NC        \NC href             \NC -- \NC \NC\NR
270    \NC        \NC mathbackground   \NC -- \NC \NC\NR
271    \NC        \NC mathcolor        \NC -- \NC \NC\NR
272    \NC        \NC mathsize         \NC -- \NC \NC\NR
273    \NC        \NC mathvariant      \NC -- \NC \NC\NR
274    \stopmathmlattributes
275\stopbuffer
276
277\startbuffer[mo]
278    \startmathmlattributes
279    \NC mo \NC accent           \NC -- \NC   \NC\NR
280    \NC    \NC class, id, style \NC -- \NC   \NC\NR
281    \NC    \NC dir              \NC -- \NC   \NC\NR
282    \NC    \NC fence            \NC -- \NC   \NC\NR
283    \NC    \NC form             \NC -- \NC   \NC\NR
284    \NC    \NC href             \NC -- \NC   \NC\NR
285    \NC    \NC largeop          \NC -- \NC   \NC\NR
286    \NC    \NC lspace           \NC -- \NC   \NC\NR
287    \NC    \NC mathbackground   \NC -- \NC   \NC\NR
288    \NC    \NC mathcolor        \NC -- \NC   \NC\NR
289    \NC    \NC mathsize         \NC -- \NC   \NC\NR
290    \NC    \NC mathvariant      \NC -- \NC   \NC\NR
291    \NC    \NC maxsize          \NC +  \NC If stretchy is true, this attribute specifies the maximum size of the operator. Allowed values are: \quote{infinity} or an arbitrary length. \NC\NR
292    \NC    \NC minsize          \NC -- \NC   \NC\NR
293    \NC    \NC movablelimits    \NC -- \NC   \NC\NR
294    \NC    \NC rspace           \NC -- \NC   \NC\NR
295    \NC    \NC separator        \NC -- \NC   \NC\NR
296    \NC    \NC stretchy         \NC -- \NC   \NC\NR
297    \NC    \NC symmetric        \NC -- \NC   \NC\NR
298    \stopmathmlattributes
299\stopbuffer
300
301\startbuffer[mrow]
302    \startmathmlattributes
303    \NC mrow \NC class, id, style \NC -- \NC \NC\NR
304    \NC      \NC dir              \NC -- \NC \NC\NR
305    \NC      \NC href             \NC -- \NC \NC\NR
306    \NC      \NC mathbackground   \NC -- \NC \NC\NR
307    \NC      \NC mathcolor        \NC -- \NC \NC\NR
308    \stopmathmlattributes
309\stopbuffer
310
311\startbuffer[msub]
312    \startmathmlattributes
313    \NC msub \NC class, id, style \NC -- \NC \NC\NR
314    \NC      \NC href             \NC -- \NC \NC\NR
315    \NC      \NC mathbackground   \NC -- \NC \NC\NR
316    \NC      \NC mathcolor        \NC -- \NC \NC\NR
317    \NC      \NC subscriptshift   \NC -- \NC \NC\NR
318    \stopmathmlattributes
319\stopbuffer
320
321\startbuffer[msup]
322    \startmathmlattributes
323    \NC msup \NC class, id, style \NC -- \NC \NC\NR
324    \NC      \NC href             \NC -- \NC \NC\NR
325    \NC      \NC mathbackground   \NC -- \NC \NC\NR
326    \NC      \NC mathcolor        \NC -- \NC \NC\NR
327    \NC      \NC superscriptshift \NC -- \NC \NC\NR
328    \stopmathmlattributes
329\stopbuffer
330
331\startbuffer[msubsup]
332    \startmathmlattributes
333    \NC msubsup \NC class, id, style \NC -- \NC \NC\NR
334    \NC         \NC href             \NC -- \NC \NC\NR
335    \NC         \NC mathbackground   \NC -- \NC \NC\NR
336    \NC         \NC mathcolor        \NC -- \NC \NC\NR
337    \NC         \NC subscriptshift   \NC -- \NC \NC\NR
338    \NC         \NC superscriptshift \NC -- \NC \NC\NR
339    \stopmathmlattributes
340\stopbuffer
341
342\startbuffer[mfrac]
343    \startmathmlattributes
344    \NC mfrac \NC bevelled         \NC +  \NC Specifies the way the fraction is displayed. If true, the fraction line is bevelled, which means that numerator and denominator are displayed side by side and separated by a slash (/). \NC\NR
345    \NC       \NC class, id, style \NC -- \NC \NC\NR
346    \NC       \NC denomalign       \NC -- \NC \NC\NR
347    \NC       \NC href             \NC -- \NC \NC\NR
348    \NC       \NC linethickness    \NC +  \NC The thickness of the horizontal fraction line. The default value is medium, but thin, thick, and other values can be set. \NC\NR
349    \NC       \NC mathbackground   \NC -- \NC \NC\NR
350    \NC       \NC mathcolor        \NC -- \NC \NC\NR
351    \NC       \NC numalign         \NC -- \NC \NC\NR
352    \stopmathmlattributes
353\stopbuffer
354
355\startbuffer[mfenced]
356    \startmathmlattributes
357    \NC mfenced \NC class, id, style \NC -- \NC \NC\NR
358    \NC         \NC close            \NC +  \NC A string for the closing delimiter. The default value is \quote{)} and any white space is trimmed. \NC\NR
359    \NC         \NC href             \NC -- \NC \NC\NR
360    \NC         \NC mathbackground   \NC -- \NC \NC\NR
361    \NC         \NC mathcolor        \NC -- \NC \NC\NR
362    \NC         \NC open             \NC +  \NC A string for the opening delimiter. The default value is \quote{(} and any white space is trimmed. \NC\NR
363    \NC         \NC separators       \NC +  \NC A sequence of zero or more characters to be used for different separators, optionally divided by white space, which is ignored. The default value is \quote{,}. \NC\NR
364    \stopmathmlattributes
365\stopbuffer
366
367\startbuffer[msqrt-mroot]
368    \startmathmlattributes
369    \NC msqrt, mroot \NC class, id, style \NC -- \NC \NC\NR
370    \NC              \NC href             \NC -- \NC \NC\NR
371    \NC              \NC mathbackground   \NC -- \NC \NC\NR
372    \NC              \NC mathcolor        \NC -- \NC \NC\NR
373    \stopmathmlattributes
374\stopbuffer
375
376\startbuffer[mtext]
377    \startmathmlattributes
378    \NC mtext \NC class, id, style \NC -- \NC \NC\NR
379    \NC       \NC dir              \NC -- \NC \NC\NR
380    \NC       \NC href             \NC -- \NC \NC\NR
381    \NC       \NC mathbackground   \NC -- \NC \NC\NR
382    \NC       \NC mathcolor        \NC -- \NC \NC\NR
383    \NC       \NC mathsize         \NC -- \NC \NC\NR
384    \NC       \NC mathvariant      \NC -- \NC \NC\NR
385    \stopmathmlattributes
386\stopbuffer
387
388\startbuffer[mover]
389    \startmathmlattributes
390    \NC mover \NC accent           \NC -- \NC \NC\NR
391    \NC       \NC align            \NC -- \NC \NC\NR
392    \NC       \NC class, id, style \NC -- \NC \NC\NR
393    \NC       \NC href             \NC -- \NC \NC\NR
394    \NC       \NC mathbackground   \NC -- \NC \NC\NR
395    \NC       \NC mathcolor        \NC -- \NC \NC\NR
396    \stopmathmlattributes
397\stopbuffer
398
399\startbuffer[munder]
400    \startmathmlattributes
401    \NC munder \NC accentunder      \NC -- \NC \NC\NR
402    \NC        \NC align            \NC -- \NC \NC\NR
403    \NC        \NC class, id, style \NC -- \NC \NC\NR
404    \NC        \NC href             \NC -- \NC \NC\NR
405    \NC        \NC mathbackground   \NC -- \NC \NC\NR
406    \NC        \NC mathcolor        \NC -- \NC \NC\NR
407    \stopmathmlattributes
408\stopbuffer
409
410\startbuffer[munderover]
411    \startmathmlattributes
412    \NC munderover \NC accent           \NC -- \NC \NC\NR
413    \NC            \NC accentunder      \NC -- \NC \NC\NR
414    \NC            \NC align            \NC -- \NC \NC\NR
415    \NC            \NC class, id, style \NC -- \NC \NC\NR
416    \NC            \NC href             \NC -- \NC \NC\NR
417    \NC            \NC mathbackground   \NC -- \NC \NC\NR
418    \NC            \NC mathcolor        \NC -- \NC \NC\NR
419    \stopmathmlattributes
420\stopbuffer
421
422\startbuffer[ms]
423    \startmathmlattributes
424    \NC ms \NC class, id, style \NC -- \NC \NC\NR
425    \NC    \NC dir              \NC -- \NC \NC\NR
426    \NC    \NC lquote           \NC +  \NC The opening quote character (depends on dir) to enclose the content. The default value is \type{"}. \NC\NR
427    \NC    \NC href             \NC -- \NC \NC\NR
428    \NC    \NC mathbackground   \NC -- \NC \NC\NR
429    \NC    \NC mathcolor        \NC -- \NC \NC\NR
430    \NC    \NC mathsize         \NC -- \NC \NC\NR
431    \NC    \NC mathvariant      \NC -- \NC \NC\NR
432    \NC    \NC rquote           \NC +  \NC The closing quote mark (depends on dir) to enclose the content. The default value is \type{"}. \NC\NR
433    \stopmathmlattributes
434\stopbuffer
435
436\startbuffer[menclose]
437    \startmathmlattributes
438    \NC menclose \NC class, id, style \NC -- \NC \NC\NR
439    \NC          \NC href             \NC -- \NC \NC\NR
440    \NC          \NC mathbackground   \NC -- \NC \NC\NR
441    \NC          \NC mathcolor        \NC -- \NC \NC\NR
442    \NC          \NC notation         \NC +  \NC A list of notations, separated by white space, to apply to the child elements. The symbols are each drawn as if the others are not present, and therefore may overlap. Supported values are:
443                                    longdiv, actuarial, radiacal, rule ({\em private}), box downdiagonalstrike, roundedbox updiagonalstrike, circle verticalstrike horizontalstrike, right bottom horizontalstrike, etc. \NC\NR
444    \stopmathmlattributes
445\stopbuffer
446
447\startbuffer[merror]
448    \startmathmlattributes
449    \NC merror \NC class, id, style \NC -- \NC \NC\NR
450    \NC        \NC href             \NC -- \NC \NC\NR
451    \NC        \NC mathbackground   \NC -- \NC \NC\NR
452    \NC        \NC mathcolor        \NC -- \NC \NC\NR
453    \stopmathmlattributes
454\stopbuffer
455
456\startbuffer[mmultiscripts]
457    \startmathmlattributes
458    \NC mmultiscripts \NC class, id, style \NC -- \NC \NC\NR
459    \NC               \NC href             \NC -- \NC \NC\NR
460    \NC               \NC mathbackground   \NC -- \NC \NC\NR
461    \NC               \NC mathcolor        \NC -- \NC \NC\NR
462    \NC               \NC subscriptshift   \NC -- \NC \NC\NR
463    \NC               \NC superscriptshift \NC -- \NC \NC\NR
464    \stopmathmlattributes
465\stopbuffer
466
467\startbuffer[mspace]
468    \startmathmlattributes
469    \NC mspace \NC class, id, style \NC -- \NC \NC\NR
470    \NC        \NC depth            \NC -- \NC \NC\NR
471    \NC        \NC height           \NC -- \NC \NC\NR
472    \NC        \NC linebreak        \NC -- \NC \NC\NR
473    \NC        \NC mathbackground   \NC -- \NC \NC\NR
474    \NC        \NC spacing          \NC -- \NC The desired width of the space. \NC\NR  % AFO: bestaat attribuut echt?
475    \NC        \NC width            \NC -- \NC The desired width of the space. \NC\NR
476    \stopmathmlattributes
477\stopbuffer
478
479\startbuffer[mphantom]
480    \startmathmlattributes
481    \NC mphantom \NC class, id, style \NC -- \NC \NC\NR
482    \NC          \NC mathbackground   \NC -- \NC \NC\NR
483    \stopmathmlattributes
484\stopbuffer
485
486\startbuffer[mpadded]
487    \startmathmlattributes
488    \NC mpadded \NC class, id, style \NC -- \NC \NC\NR
489    \NC         \NC depth            \NC -- \NC \NC\NR
490    \NC         \NC height           \NC -- \NC \NC\NR
491    \NC         \NC href             \NC -- \NC \NC\NR
492    \NC         \NC lspace           \NC -- \NC \NC\NR
493    \NC         \NC mathbackground   \NC -- \NC \NC\NR
494    \NC         \NC mathcolor        \NC -- \NC \NC\NR
495    \NC         \NC voffset          \NC -- \NC \NC\NR
496    \NC         \NC width            \NC -- \NC \NC\NR
497    \stopmathmlattributes
498\stopbuffer
499
500\startbuffer[mtable]
501    \startmathmlattributes
502    \NC mtable \NC align             \NC -- \NC \NC\NR
503    \NC        \NC alignmentscope    \NC -- \NC \NC\NR
504    \NC        \NC class, id, style  \NC -- \NC \NC\NR
505    \NC        \NC columnalign       \NC +  \NC Specifies the horizontal alignment of the cells. Multiple values separated by space are allowed and apply to the corresponding columns (e.g. \type{columnalign="left right center"}). Possible values are: left, center (default) and right. \NC\NR
506    \NC        \NC columnlines       \NC -- \NC \NC\NR
507    \NC        \NC columnspacing     \NC +  \NC Specifies the space between table columns. \NC\NR
508    \NC        \NC columnwidth       \NC -- \NC \NC\NR
509    \NC        \NC displaystyle      \NC -- \NC \NC\NR
510    \NC        \NC equalcolumns      \NC -- \NC \NC\NR
511    \NC        \NC equalrows         \NC -- \NC \NC\NR
512    \NC        \NC frame             \NC -- \NC \NC\NR
513    \NC        \NC framespacing      \NC -- \NC \NC\NR
514    \NC        \NC groupalign        \NC -- \NC \NC\NR
515    \NC        \NC href              \NC -- \NC \NC\NR
516    \NC        \NC mathbackground    \NC +  \NC The background color. \NC\NR
517    \NC        \NC mathcolor         \NC +  \NC The text color. \NC\NR
518    \NC        \NC minlabelspacing   \NC -- \NC \NC\NR
519    \NC        \NC rowalign          \NC -- \NC \NC\NR
520    \NC        \NC rowlines          \NC -- \NC \NC\NR
521    \NC        \NC rowspacing        \NC +  \NC Specifies the space between table rows. \NC\NR
522    \NC        \NC side              \NC -- \NC \NC\NR
523    \NC        \NC width             \NC -- \NC \NC\NR
524    \stopmathmlattributes
525\stopbuffer
526
527\startbuffer[mtr-mlabeledtr]
528    \startmathmlattributes
529    \NC mtr, labeledtr \NC class, id, style \NC -- \NC \NC\NR
530    \NC                \NC columnalign      \NC +  \NC Overrides the horizontal alignment of cells specified by <mtable> for this row. \NC\NR
531    \NC                \NC groupalign       \NC -- \NC \NC\NR
532    \NC                \NC href             \NC -- \NC \NC\NR
533    \NC                \NC mathbackground   \NC +  \NC The background color. \NC\NR
534    \NC                \NC mathcolor        \NC +  \NC The text color. \NC\NR
535    \NC                \NC rowalign         \NC -- \NC \NC\NR
536    \stopmathmlattributes
537\stopbuffer
538
539\startbuffer[mtd]
540    \startmathmlattributes
541    \NC mtd \NC class, id, style \NC -- \NC \NC\NR
542    \NC     \NC columnalign      \NC -- \NC \NC\NR
543    \NC     \NC columnspan       \NC -- \NC \NC\NR
544    \NC     \NC frame            \NC -- \NC Specifies whether the cell gets a frame. \NC\NR % AFO: wordt niet genoemd in Mozilla overview
545    \NC     \NC groupalign       \NC -- \NC \NC\NR
546    \NC     \NC href             \NC -- \NC \NC\NR
547    \NC     \NC mathbackground   \NC -- \NC \NC\NR
548    \NC     \NC mathcolor        \NC -- \NC \NC\NR
549    \NC     \NC rowalign         \NC -- \NC \NC\NR
550    \NC     \NC rowspan          \NC -- \NC \NC\NR
551    \stopmathmlattributes
552\stopbuffer
553
554\startbuffer[malignmark]
555    \startmathmlattributes
556    \NC malignmark \NC class, id, style \NC -- \NC \NC\NR
557    \NC            \NC edge             \NC -- \NC \NC\NR
558    \stopmathmlattributes
559\stopbuffer
560
561\startbuffer[mglyph]
562    \startmathmlattributes
563    \NC mglyph \NC alt              \NC  + \NC This attribute defines the alternative text describing the image. \NC\NR
564    \NC        \NC class, id, style \NC -- \NC \NC\NR
565    \NC        \NC height           \NC -- \NC \NC\NR
566    \NC        \NC href             \NC -- \NC \NC\NR
567    \NC        \NC mathbackground   \NC -- \NC \NC\NR
568    \NC        \NC src              \NC -- \NC \NC\NR
569    \NC        \NC valign           \NC -- \NC \NC\NR
570    \NC        \NC width            \NC -- \NC \NC\NR
571    \stopmathmlattributes
572\stopbuffer
573
574\startbuffer[mstyle]
575    \startmathmlattributes
576    \NC mstyle \NC dir                  \NC -- \NC \NC\NR
577    \NC        \NC decimalpoint         \NC -- \NC \NC\NR
578    \NC        \NC displaystyle         \NC -- \NC \NC\NR
579    \NC        \NC infixlinebreakstyle  \NC -- \NC \NC\NR
580    \NC        \NC scriptlevel          \NC +  \NC Controls mostly the font-size. The higher the scriptlevel, the smaller the font size. This attribute accepts a non-negative integer, as well as a \quote{+} or a \quote{--} sign, which increments or decrements the current value. \NC\NR
581    \NC        \NC scriptminsize        \NC -- \NC \NC\NR
582    \NC        \NC scriptsizemultiplier \NC -- \NC \NC\NR
583    \stopmathmlattributes
584\stopbuffer
585
586% some helpers
587
588\startxmlsetups xml:mmlprime
589    \xmlsetsetup {\xmldocument} {document} {xml:mmlprime:document}
590    \xmlsetsetup {\xmldocument} {textref}  {xml:mmlprime:textref}
591\stopxmlsetups
592
593\xmlregistersetup{xml:mmlprime}
594
595\startxmlsetups xml:mmlprime:document
596    \blank \start
597    \xmlflush{#1}
598    \stop \blank
599\stopxmlsetups
600
601\startxmlsetups xml:mmlprime:textref
602    \in {\xmlflush{#1}} [\xmlatt{#1}{label}]
603\stopxmlsetups
604
605% redefine to use lua and mkiv xml instead of slower mkii
606
607\startluacode
608    local gsub = string.gsub
609    local mapping = {
610        [";"] = "{{\\darkblue\\string;}}",
611     -- ["&"] = "{{\\ttx\\sl\\darkblue\\string&}}", -- too ugly
612        ["&"] = "{{\\darkblue\\string&}}", -- otherwise "et"
613        ["/"] = "{{\\darkblue\\string/}}",
614        ["<"] = "{{\\darkblue\\string<}}",
615        [">"] = "{{\\darkblue\\string>}}",
616    }
617    function document.filterxmltitlestuff(name)
618--      local data = io.loaddata(name) or ""
619local data = io.loaddata(resolvers.findfile(name)) or ""
620        if data then
621            data = gsub(data,"<math[^>]*>","<math>")
622            data = gsub(data,"[%s ]+"," ")
623            data = gsub(data,"(.)",mapping)
624            context(data)
625        end
626    end
627\stopluacode
628
629\starttexdefinition unexpanded showXMLfileA #1#2
630    \ignorespaces
631    \ctxlua{document.filterxmltitlestuff("#2.xml")}
632    \removeunwantedspaces
633    \space
634    \ignorespaces
635\stoptexdefinition
636
637\startluacode
638    function document.filenumber(str)
639        context(string.match(str,"([1-9][0-9]*)$"))
640    end
641\stopluacode
642
643\starttexdefinition unexpanded showXMLfileB #1#2
644    \bgroup
645        \setuplabeltext[formula=#1\space]
646        \setnumber[formula][\ctxlua{document.filenumber("#2")}]
647        \decrementnumber[formula]
648        \placeformula
649            \startformula
650                \processxmlfile{#2.xml}
651            \stopformula
652   \egroup
653   \typefile{#2.xml}
654   \page[bigpreference]
655\stoptexdefinition
656
657\startsetups showexamples
658
659    \setupformulas
660      [left=,
661       right=,
662       location=left,
663       numberstyle=FormulaFont,
664       numbercolor=darkblue]
665
666    \resetnumber[formula]
667
668    \let\showXMLfile\showXMLfileB
669
670\stopsetups
671
672\startsetups TitlePageBackground
673    \setbox\scratchbox=\vbox to \paperheight {
674        \hsize\paperwidth
675        \definedfont[NiceBold*default at 7pt]
676        \setupinterlinespace
677        \let\showXMLfile\showXMLfileA
678        \baselineskip=1\baselineskip plus 1pt
679        \getbuffer[derivates]
680        \getbuffer[integrals]
681        \getbuffer[series]
682        \getbuffer[logs]
683        \getbuffer[goniometrics]
684        \getbuffer[statistics]
685        \getbuffer[matrices]
686    }
687    \setbox\scratchbox=\vsplit\scratchbox to \paperheight
688    \vbox to \paperheight {
689        \unvbox\scratchbox
690        \vskip-.2ex
691    }
692\stopsetups
693
694\defineoverlay
695  [titlepage]
696  [\directsetup{TitlePageBackground}]
697
698\settaggedmetadata
699  [title={MathML},
700   author={Hans Hagen},
701   version={January 2001 / June 2008 / June 2011},
702   copyright={PRAGMA ADE, Hasselt, NL},
703   url={www.pragma-ade.com / www.pragma-ade.nl}]
704
705\starttext
706
707\setupbackgrounds
708  [page]
709  [background={foreground,titlepage}]
710
711\startelement[ignore]
712
713    \startstandardmakeup[footerstate=none,doublesided=no,page=]
714        \setupalign[left]
715        \definefont[BigFont][RegularBold at 108pt]
716        \definefont[MedFont][RegularBold at  48pt]
717        \vfill
718        \BigFont \darkred MathML     \par
719        \vskip6pt
720        \MedFont \darkred HANS HAGEN \par
721    \stopstandardmakeup
722
723\stopelement
724
725\setupbackgrounds
726  [page]
727  [background=]
728
729\startelement[ignore]
730
731    \startstandardmakeup[footerstate=none,doublesided=no,page=]
732        \startpacked
733        Hans Hagen \par
734        Hassel NL \par
735        \goto{www.pragma-ade.com}[url(http://www.pragma-ade.com)] \par
736        January  2001 /
737        June     2008 /
738        June     2011 /
739        February 2015\par
740        \stoppacked
741        \vfill
742      % More changes and additions can be expected when there is a definitive
743      % version of the \MATHML~3 specification and more correct testsuite. One
744      % thing we need to look into is the nesting model dealing with ()
745      % discussed in the spec.
746        \blank
747        \start
748        \starttabulate
749        \NC \color[darkblue]{copyright} \EQ PRAGMA ADE, Hasselt, NL \NC \NR
750        \NC \color[darkblue]{version}   \EQ \currentdate \NC \NR
751        \NC \color[darkblue]{renderer}  \EQ \doifmodeelse{mkiv}{version 1 / mkiv}{\doifsetupselse{mmc:apply:start}{version 2}{version 3} / mkii} \NC \NR
752        \stoptabulate
753        \stop
754    \stopstandardmakeup
755
756\stopelement
757
758\startfrontmatter
759
760\starttitle[title={Table of Contents}]
761
762\startmixedcolumns[n=3,separator=rule,rulecolor=darkblue,rulethickness=1pt,blank={line,fixed},balance=no]
763    \placelist[chapter,section]
764\stopmixedcolumns
765
766\stoptitle
767
768\startchapter[title={introduction}]
769
770It is a well known fact that \TEX\ can do a pretty good job on typesetting math.
771This is one reason why many scientific articles, papers and books are typeset
772using \TEX. However, in these days of triumphing angle brackets, coding in \TEX\
773looks more and more out of place.
774
775From the point of view of an author, coding in \TEX\ is quite natural, given that
776some time is spent on reading the manuals. This is because not only the natural
777flow of the definition suits the way mathematicians think, but also because the
778author has quite some control over the way his thoughts end up on paper. It will
779be no surprise that switching to a more restricted way of coding, which also
780demands more keystrokes, is not beforehand considered to be better.
781
782There are however circumstances that one wants to share formulas (or
783formula||like specifications) between several applications, one of which is a
784typesetting engine. In that case, a bit more work now, later saves you some
785headaches due to keeping the different source documents in sync.
786
787The moment coding math in \XML\ is discussed, those in favour stress that coding
788can be eased by using appropriate editors. Here we encounter a dilemma. For
789optimal usage, one should code in terms of content, that is, the principles that
790are expressed in a formula. Editors are not that strong in this area, and if they
791would be, editing would be not that much different from traditionally editing
792formulas: just keying in ideas using code that at first sight looks obscure. A
793more graphical oriented editor can help authors to compose formulas, but the
794underlaying coding will mainly be in terms of placing glyphs and boxes, and as a
795result the code will hardly be usable in other applications.
796
797So either we code in terms of concepts, which permits sharing code among
798applications, and poses strong limitations on the influence of authors on the
799visual appearance. Or we use an interactive editor to fine tune the appearance of
800a formula and take for granted that reuse will be minimal or suboptimal.
801
802In the following chapters we will discuss the mathematical language \MATHML\ in
803the perspective of typography. As a typesetting vehicle, we have used \CONTEXT.
804However, the principles introduced here and the examples that we provide are
805independent of \CONTEXT. For a more formal exploration we recommend the \MATHML\
806specification.
807
808This document is dedicated to all those \CONTEXT\ users who like typesetting
809math. I'm sure that my father, who was a math teacher, would have liked
810proofreading this document. His absence was compensated by Tobias Burnus, Wang
811Lei, Ton Otten, and later members of the \CONTEXT\ mailing list who carefully
812read the text, corrected the errors in my math, tested the functionality, and
813made suggestions. Any remaining errors are mine.
814
815When we started supporting \MATHML\ we were under the impression that it would be
816accepted and take of fast, but we were wrong. It toke much more than a decade for
817instance to see browsers support rendering. Being involved in typesetting
818educational content from \XML\ files, we could use this subsystem ourselves, and
819this was useful in the sense that we ran into lots of contradicting and
820suboptimal \MATHML\ code. However, the most interesting application has always
821been in the math4all project, where we went from \TEX\ math, via content \MATHML\
822and open math to presentational \MATHML. Nowadays web usage drives the coding and
823limitations in other programs (and rendering) are sometimes compensated by coding
824and our renderer then has to be able to recover nicely. Thanks to the enormous
825productivity of the main math4all author Frits Spijkers and the careful checking
826by my collegue Ton Otten, we could always keep op well. Development and support
827of the \CONTEXT\ typesetting system is mostly done without any commercial
828benefits and the amount of free time that we spend on it and especially its more
829obscure properties like \MATHML\ is compensated by flexible and tolerant users
830like them.
831
832One problem is that our own usage of \MATHML\ changes over time. Some of our
833projects demand the use of this standard but at the same time the used sources
834need to satisfy other needs, for instance rendering on the web. For some 15 years
835now the changing demands and quality have made us oscillate between (often
836suboptimal) solutions that deal with the suboptimal code that comes from
837compromises. For instance the mentioned project is now using a mixture of
838\MATHML\ and so called \ASCII math because that is the only way the enormous
839amount of math code can be rendered on the web. And even there we need to bend
840the rules, for instance to compensate for missing features or cultural
841differences. Eventually I will rewrite the rendering from scratch but I need time
842and a very good reason for that.
843
844This version of the manual is produced by \CONTEXT\ \MKIV\ and is also used as
845testcase. The version rendered at \PRAGMA\ uses the Lucida Bright fonts. These
846can be bought at \goto {www.tug.org} [url(http://{www.tug.org})] for a reasonable
847low price and are really worth the money.
848
849\startlines
850Hans Hagen
851PRAGMA ADE
852Hasselt NL
8532001 \emdash\ \currentdate[year]
854\stoplines
855
856\stopchapter
857
858\stopfrontmatter
859
860\startbodymatter
861
862\startchapter[title={What is \MATHML}]
863
864\startsection[title={backgrounds}]
865
866\MATHML\ showed up in the evolving vacuum between structural \SGML\ markup and
867presentational \HTML. Both \SGML\ and \HTML\ can be recognized by angle brackets.
868The disadvantage of \SGML\ was that it was so open ended, that general tools
869could hardly be developed. \HTML\ on the other hand was easy to use and became
870extremely popular and users as well as software vendors quickly spoiled the
871original ideas and created a mess. \SGML\ never became really popular, but thanks
872to \HTML\ people became accustomed to that kind of notation. So, when \XML\ came
873around as a more restricted cousin of \SGML, the world was kind of ready for it.
874It cannot be denied that by some clever marketing many of today's users think
875that they use something new and modern, while we are actually dealing with
876something from the early days of computing. A main benefit of \XML\ is that it
877brought the ideas behind \SGML\ (and medium neutral coding in general) to the
878users and at the same time made a major cleanup of \HTML\ possible.
879
880About the same time, \MATHML\ was defined, both to bring math to the \WWW, and to
881provide a way of coding math that will stimulate sharing the same code between
882different applications. At the end of 2000, the \MATHML\ version~2 draft became a
883recommendation. In the process of rewriting the interpreter for \CONTEXT\ \MKIV\
884mid 2008 a draft of \MATHML\ version~3 has been used.
885
886Now, imagine that we want to present a document on the internet using a format
887like \HTML, either for viewing or for being spoken. Converting text and graphics
888is, given proper source coding, seldom a problem, but converting formulas into
889some angle bracket representation is more tricky. A way out of this is \MATHML's
890presentational markup.
891
892\startbuffer
893<math xmlns="http://www.w3c.org/mathml" version="2.0">
894  <mrow>
895    <mi> a </mi>
896    <mo> + </mo>
897    <mi> b </mi>
898    <mo> = </mo>
899    <mi> c </mi>
900  </mrow>
901</math>
902\stopbuffer
903
904\processxmlbuffer
905
906This simple formula, when coded in \TEX, looks like:
907
908\starttyping
909$$ a + b = c $$
910\stoptyping
911
912In presentational \MATHML\ we get:
913
914\typebuffer
915
916In presentational \MATHML, we use mostly begintags (\type {<mi>}) and end tags
917(\type {</mi>}). The \mmlelement {mrow} element is the basic building block of a
918formula. The \mmlelement {mi} element specifies a math identifier and \mmlelement
919{mo} is used for operators. In the process of typesetting, both are subjected to
920interpretation in order to get the best visualization.
921
922Converting \TEX\ code directly or indirectly, using printable output or even
923in||memory produced math lists, has been one of the driving forces behind
924presentational \MATHML\ and other math related \DTD's like \EUROMATH. One may
925wonder if there are sound and valid reasons for going the opposite way. You can
926imagine that a converter from \TEX\ to \MATHML\ produces \mmlelement {menclose},
927\mmlelement {mspace}, \mmlelement {mstyle} and other elements that can have many
928spacing related attributes, but I wonder if any author is willing to think in
929those quantities. Visual editors of course are good candidates for producing
930presentational \MATHML.
931
932But wouldn't it be more efficient if we could express ideas and concepts in such
933a way that they could be handled by a broad range of applications, including a
934typesetting engine? This is why, in addition to presentational \MATHML, there is
935also content \MATHML. The previous formula, when coded in such a way, looks like:
936
937\startbuffer
938<math xmlns="http://www.w3c.org/mathml" version="2.0">
939  <apply> <eq/>
940    <apply> <plus/>
941      <ci> a </ci>
942      <ci> b </ci>
943    </apply>
944    <ci> c </ci>
945  </apply>
946</math>
947\stopbuffer
948
949\typebuffer
950
951This way of defining a formula resembles the so called polish (or stackwise)
952notation. Opposite to presentational markup, here a typesetting engine has to
953find out in what order and what way the content has to be presented. This may
954seem a disadvantage, but in practice implementing content markup is not that
955complicated. The big advantage is that, once we know how to typeset a concept,
956\TEX\ can do a good job, while in presentational markup much hard coded spacing
957can spoil everything. One can of course ignore specific elements, but it is more
958safe to start from less and enhance, than to leave away something with unknown
959quantities.
960
961Instead of using hard coded operators as in presentational \MATHML, content
962markup uses empty elements like \type {<plus/>}. Many operators and functions are
963predefined but one can also define his own; in \MATHML~3 this is further extended
964by adopting \OPENMATH\ as variant.
965
966Of course the main question to be answered now is to what extent the author can
967influence the appearance of a formula defined in content markup. Content markup
968has the advantage that the results can be more consistent, but taking away all
969control is counterproductive. The \MATHML\ level~2 draft mentions that this level
970covers most of the pre university math. If so, that is a proper starting point,
971but especially educational math often has to be typeset in such ways that it
972serves its purpose. Also, (re|)|using the formulas in other applications
973(simulators and alike) is useful in an educational setting, so content markup is
974quite suitable.
975
976How do we combine the advantages of content markup with the wish of an author to
977control the visual output and at the same time get an as high as possible typeset
978result. There are several ways to accomplish this. One is to include in the
979document source both the content markup and the \TEX\ specific code.
980
981\startbuffer
982<math xmlns="http://www.w3c.org/mathml" version="2.0">
983  <semantics>
984    <apply> <eq/>
985      <apply> <plus/>
986        <ci> a </ci>
987        <ci> b </ci>
988      </apply>
989    </apply>
990    <ci> c </ci>
991    <annotation encoding="TeX">a+b=c</annotation>
992  </semantics>
993</math>
994\stopbuffer
995
996\typebuffer
997
998The \mmlelement {annotation} element is one of the few that is permitted inside
999the \mmlelement {math} element. In this example, we embed pure \TEX\ code, which,
1000when enabled is typeset in math mode. It will be clear that for a simple formula
1001like this one, such redundant coding is not needed, but one can imagine more
1002complicated formulas. Because we want to limit the amount of work, we prefer just
1003content markup. \blank {\it Remark: Some characters, fillers or whatever may not
1004show up. This is due to the fact that the relevant tables for \CONTEXT\ \MKIV\
1005are defined stepwise. In due time most relevant symbols will be accessible.}
1006
1007\stopsection
1008
1009\startsection[title={two methods}]
1010
1011The best way to learn \MATHML\ is to key in formulas, so that is what we did as
1012soon as we started adding \MATHML\ support to \CONTEXT. In some areas, \MATHML\
1013provides much detail (many functions are represented by elements) while in other
1014areas one has to fall back on the more generic function element or a full
1015description. Compare the following definitions:
1016
1017\startbuffer[a]
1018<document>
1019  <math xmlns="http://www.w3c.org/mathml" version="2.0">
1020    <apply> <sin/> <ci> x </ci> </apply>
1021  </math>
1022  <math xmlns="http://www.w3c.org/mathml" version="2.0">
1023    <mrow> <mi> sin </mi> <mi> x </mi> </mrow>
1024  </math>
1025</document>
1026\stopbuffer
1027
1028\typebuffer[a]
1029
1030We prefer the first definition because it is more structured and gives more
1031control over the result. There is only one \quote {unknown} quantity, $x$, and
1032from the encapsulating element \mmlelement {ci} we know that it is an identifier.
1033
1034\processxmlbuffer[a]
1035
1036In the content example, from the \mmlelement {apply} \mmlelement {sin} we can
1037deduce that the following argument is an operand, either an \mmlelement {apply},
1038or a \mmlelement {ci} or \mmlelement {cn}. In the presentational alternative, the
1039following elements can be braces, a math identifier, a row, a sequence of
1040identifiers and operators, etc. There, the look and feel is hard coded.
1041
1042\startbuffer[b]
1043<?context-mathml-directive function reduction no ?>
1044\stopbuffer
1045
1046\typebuffer[b]
1047
1048This directive, either issued in the \XML\ file, or set in the style file,
1049changes the appearance of the function, but only in content markup. It is because
1050of this feature, that we favour content markup.
1051
1052\processxmlbuffer[b,a]
1053
1054Does this mean that we can cover everything with content markup? The answer to
1055this is still unclear. Consider the following definition.
1056
1057\processxmlfile {pc-i-380.xml}
1058
1059Here we combine several cases in one formula by using $\pm$ and $\mp$ symbols.
1060Because we only have \mmlelement {plus} and \mmlelement {minus} elements, we have
1061to revert to the generic function element \mmlelement {fn}. We show the complete
1062definition of this formula.
1063
1064\typefile {pc-i-380.xml}
1065
1066The \MATHML\ parser and typesetting engine have to know how to handle these
1067special cases, because the visualization depends on the function (or operator).
1068Here both composed signs are treated like the plus and minus signs, but in other
1069cases an embraced argument may be needed.
1070
1071\stopsection
1072
1073\stopchapter
1074
1075\startchapter[title={Presentational markup}]
1076
1077\startsection[title=Introduction]
1078
1079If a document contains presentational \MATHML, there is a good chance that the
1080code is output by an editor. Here we will discuss the presentation elements that
1081make sense for users when they want to manually code presentational \MATHML. In
1082this chapter we show the default rendering, later we will discuss options.
1083
1084Although much is permitted, we advise to keep the code as simple as possible,
1085because then \TEX\ can do a rather good job on interpreting and typesetting it.
1086Just let \TEX\ take care of the spacing.
1087
1088\stopsection
1089
1090\startsection[title={mi, mn, mo}]
1091
1092Presentational markup comes down to pasting boxes together in math specific ways.
1093The basic building blocks are these three character elements.
1094
1095\startbuffer
1096<math xmlns="http://www.w3c.org/mathml" version="2.0">
1097  <mrow>
1098    <mi> x </mi> <mo> = </mo> <mn> 5 </mn>
1099  </mrow>
1100</math>
1101\stopbuffer
1102
1103\processxmlbuffer \typebuffer
1104
1105\starttabulate[||||]
1106\HL
1107\NC \mmlelement {mi} \NC identifier \NC normally typeset in an italic font \NC \NR
1108\NC \mmlelement {mn} \NC number     \NC normally typeset in a normal font  \NC \NR
1109\NC \mmlelement {mo} \NC operator   \NC surrounded by specific spacing     \NC \NR
1110\HL
1111\stoptabulate
1112
1113Because numbers are taken from an upright font, special numbers are taken care of
1114automatically. Here are some from the \MATHML\ specification:
1115
1116\startbuffer
1117<math xmlns="http://www.w3c.org/mathml" version="2.0">
1118  <mrow>
1119    <mn> 2          </mn> <mtext>&nbsp;&nbsp;</mtext>
1120    <mn> 0.123      </mn> <mtext>&nbsp;&nbsp;</mtext>
1121    <mn> 0,000,000  </mn> <mtext>&nbsp;&nbsp;</mtext>
1122    <mn> 2.1e10     </mn> <mtext>&nbsp;&nbsp;</mtext>
1123    <mn> 0xFFeF     </mn> <mtext>&nbsp;&nbsp;</mtext>
1124    <mn> MCMLXIX    </mn> <mtext>&nbsp;&nbsp;</mtext>
1125    <mn> twenty one </mn> <mtext>&nbsp;&nbsp;</mtext>
1126  </mrow>
1127</math>
1128\stopbuffer
1129
1130\processxmlbuffer \typebuffer
1131
1132Special characters can be accessed by their \UNICODE\ point or by a corresponding
1133entity. For some reason there is quite some duplication in entities, but we don't
1134bother too much about it because after all \UNICODE\ math (which has its own
1135peculiarities) is the way to go. The specification has this somewhat strange
1136formula definition:
1137
1138\startbuffer
1139<math xmlns="http://www.w3c.org/mathml" version="2.0">
1140  <mrow>
1141    <mn> 2 </mn>
1142    <mo> + </mo>
1143    <mrow>
1144      <mn> 3</mn>
1145      <mo> &InvisibleTimes; </mo>
1146      <mi> &ImaginaryI; </mi>
1147    </mrow>
1148  </mrow>
1149  <mfrac>
1150    <mn> 1 </mn>
1151    <mn> 2 </mn>
1152  </mfrac>
1153  <mi> &pi; </mi>
1154  <mi> &ExponentialE; </mi>
1155</math>
1156\stopbuffer
1157
1158\processxmlbuffer \typebuffer
1159
1160And:
1161
1162\startbuffer
1163<math xmlns="http://www.w3c.org/mathml" version="2.0">
1164  <mfrac>
1165    <mo> &DifferentialD; </mo>
1166    <mrow>
1167      <mo> &DifferentialD; </mo>
1168      <mi> x </mi>
1169    </mrow>
1170  </mfrac>
1171</math>
1172\stopbuffer
1173
1174\processxmlbuffer \typebuffer
1175
1176Visualizing the \mmlelement {mo} element involved some heuristics. For instance
1177the size of fences depends on what they fence. In the following case you see how
1178we can influence this. For practical pusposes we only support size~1.
1179
1180\startbuffer
1181<math xmlns="http://www.w3c.org/mathml" version="2.0">
1182  <mrow>
1183    <mo> ( </mo> <mi> x </mi>  <mo> ) </mo>
1184  </mrow>
1185  <mtext> or </mtext>
1186  <mrow>
1187    <mo maxsize="1"> ( </mo>  <mi> x </mi>  <mo> ) </mo>
1188  </mrow>
1189  <mtext> or </mtext>
1190  <mrow>
1191    <mo maxsize="1"     > ( </mo>
1192        <mfrac> <mn> 1 </mn> <mn> 2 </mn> </mfrac>
1193    <mo stretchy="false"> ) </mo>
1194  </mrow>
1195</math>
1196\stopbuffer
1197
1198\processxmlbuffer \typebuffer
1199
1200\getbuffer[mi-mn]
1201
1202\getbuffer[mo]
1203
1204\stopsection
1205
1206\startsection[title={mrow}]
1207
1208The previous example demonstrated the use of \mmlelement {mrow}, the element that
1209is used to communicate the larger building blocks. Although this element from the
1210perspective of typesetting is not always needed, by using it, the structure of
1211the formula in the document source is more clear. There is some messy magic going
1212on when we try to fake fenced expressions.
1213
1214\startbuffer
1215<math xmlns="http://www.w3c.org/mathml" version="2.0">
1216  <mrow> <mi> x </mi> <mo> &geq; </mo> <mn> 2 </mn> </mrow>
1217</math>
1218\stopbuffer
1219
1220\processxmlbuffer \typebuffer
1221
1222\startbuffer
1223<math xmlns="http://www.w3c.org/mathml" version="2.0">
1224  <mrow>
1225    <mi> y </mi> <mo> &gt; </mo> <mn> 4 </mn>
1226  </mrow>
1227</math>
1228\stopbuffer
1229
1230\processxmlbuffer \typebuffer
1231
1232\startbuffer
1233<math xmlns="http://www.w3c.org/mathml" version="2.0">
1234  <mrow>
1235    <mo> &lt; </mo> <mi> x </mi> <mo> &gt; </mo>
1236  </mrow>
1237</math>
1238\stopbuffer
1239
1240\processxmlbuffer \typebuffer
1241
1242\startbuffer
1243<math xmlns="http://www.w3c.org/mathml" version="2.0">
1244  <mrow>
1245    <mi> a </mi> <mo> &lt; </mo> <mi> b </mi> <mo> &lt; </mo> <mi> c </mi>
1246  </mrow>
1247</math>
1248\stopbuffer
1249
1250\processxmlbuffer \typebuffer
1251
1252Spacing between a sign and the following token is taken care of automatically by
1253\TEX:
1254
1255\startbuffer
1256<math xmlns="http://www.w3c.org/mathml" version="2.0">
1257  <mrow>
1258    <mo> - </mo>
1259    <mn> 1 </mn>
1260    <mo> - </mo>
1261    <mn> 1 </mn>
1262  </mrow>
1263</math>
1264\stopbuffer
1265
1266\processxmlbuffer \typebuffer
1267
1268\getbuffer[mrow]
1269
1270\stopsection
1271
1272\startsection[title={msup, msub, msubsup}]
1273
1274Where in content markup super and subscript are absent and derived from the
1275context, in presentational markup they are quite present.
1276
1277\startbuffer
1278<math xmlns="http://www.w3c.org/mathml" version="2.0">
1279  <msup>
1280    <msub> <mi> x </mi> <mn> 1 </mn> </msub>
1281    <mn> 2 </mn>
1282  </msup>
1283</math>
1284\stopbuffer
1285
1286\processxmlbuffer \typebuffer
1287
1288\startbuffer
1289<math xmlns="http://www.w3c.org/mathml" version="2.0">
1290  <msubsup>
1291    <mi> x </mi>
1292    <mn> 1 </mn>
1293    <mn> 2 </mn>
1294  </msubsup>
1295</math>
1296\stopbuffer
1297
1298\processxmlbuffer \typebuffer
1299
1300Watch the difference between both definitions and appearances. You can influence
1301the default behaviour with processing instructions.
1302
1303\getbuffer[msub]
1304
1305\getbuffer[msup]
1306
1307\getbuffer[msubsup]
1308
1309\stopsection
1310
1311\startsection[title={mfrac}]
1312
1313Addition, subtraction and multiplication is hard coded using the \mmlelement {mo}
1314element with $+$, $-$, and $\times$ (or nothing). You can use $/$ for division,
1315but for more complicated formulas you have to fall back on fraction building.
1316This is why \MATHML\ provides the \mmlelement {mfrac}.
1317
1318\startbuffer
1319<math xmlns="http://www.w3c.org/mathml" version="2.0">
1320  <mfrac>
1321    <mrow> <mi> x </mi> <mo> + </mo> <mn> 1 </mn> </mrow>
1322    <mrow> <mi> y </mi> <mo> + </mo> <mn> 1 </mn> </mrow>
1323  </mfrac>
1324</math>
1325\stopbuffer
1326
1327\processxmlbuffer \typebuffer
1328
1329You can change the width of the rule, but this is generally a bad idea. For
1330special purposes you can set the line thickness to zero.
1331
1332\startbuffer
1333<math xmlns="http://www.w3c.org/mathml" version="2.0">
1334  <mfrac linethickness="0">
1335    <mrow> <mi> x </mi> <mo> &geq; </mo> <mn> 2 </mn> </mrow>
1336    <mrow> <mi> y </mi> <mo> &leq; </mo> <mn> 4 </mn> </mrow>
1337  </mfrac>
1338</math>
1339\stopbuffer
1340
1341\processxmlbuffer \typebuffer
1342
1343A different kind of rendering is also possible, as shown in the following
1344example.
1345
1346\startbuffer
1347<math xmlns="http://www.w3c.org/mathml" version="2.0">
1348  <mfrac bevelled="true">
1349    <mfrac>
1350      <mi> x </mi> <mn> 2 </mn>
1351      <mi> y </mi> <mn> 4 </mn>
1352    </mfrac>
1353    <mfrac>
1354      <mi> x </mi> <mn> 2 </mn>
1355      <mi> y </mi> <mn> 4 </mn>
1356    </mfrac>
1357  </mfrac>
1358</math>
1359\stopbuffer
1360
1361\processxmlbuffer \typebuffer
1362
1363\getbuffer[mfrac]
1364
1365\stopsection
1366
1367\startsection[title={mfenced}]
1368
1369Braces are used to visually group sub||expressions. In presentational \MATHML\
1370you can either hard code braces, or use the \mmlelement {mfenced} element to
1371generate delimiters automatically. In \CONTEXT, as much as possible, the
1372operators and identifiers are interpreted, and when recognized treated according
1373to their nature.
1374
1375\startbuffer
1376<math xmlns="http://www.w3c.org/mathml" version="2.0">
1377  <mfenced> <mi> a </mi> <mi> b </mi> <mn> 1 </mn> </mfenced>
1378</math>
1379\stopbuffer
1380
1381\processxmlbuffer \typebuffer
1382
1383The fencing symbols adapt their size to the content. Their dimensions also depend
1384on the way math fonts are defined. The standard \TEX\ fonts will give the same
1385height of braces around $x$ and $y$, but in other fonts the $y$ may invoke
1386slightly larger ones.
1387
1388\startbuffer
1389<math xmlns="http://www.w3c.org/mathml" version="2.0">
1390  <mfenced open="[" close=")" separators=",">
1391    <mn> 0 </mn> <mn> 1 </mn>
1392  </mfenced>
1393</math>
1394\stopbuffer
1395
1396\processxmlbuffer \typebuffer
1397
1398The separators adapt their size to the fenced content too, just like the fences.
1399
1400\startbuffer
1401<math xmlns="http://www.w3c.org/mathml" version="2.0">
1402  <mfenced open="[" close="]" separators="|">
1403    <mfrac> <mn> 1 </mn> <mi> x </mi> </mfrac>
1404    <mfrac> <mn> 1 </mn> <mi> y </mi> </mfrac>
1405    <mfrac> <mn> 1 </mn> <mi> z </mi> </mfrac>
1406  </mfenced>
1407</math>
1408\stopbuffer
1409
1410\processxmlbuffer \typebuffer
1411
1412\startbuffer
1413<math xmlns="http://www.w3c.org/mathml" version="2.0">
1414  <mfenced>
1415    <mrow> <mn> 1 </mn> <mo> + </mo> <mi> x </mi> </mrow>
1416  </mfenced>
1417</math>
1418\stopbuffer
1419
1420\processxmlbuffer \typebuffer
1421
1422\startbuffer
1423<math xmlns="http://www.w3c.org/mathml" version="2.0">
1424  <mfenced open="{" close="" separators="|+-">
1425    <mn> 1 </mn> <mn> 2 </mn> <mn> 3 </mn> <mn> 4 </mn>
1426  </mfenced>
1427</math>
1428\stopbuffer
1429
1430\processxmlbuffer \typebuffer
1431
1432\startbuffer
1433<math xmlns="http://www.w3c.org/mathml" version="2.0">
1434  <mfenced open="a" close="e" separators="bcd">
1435    <mn> 1 </mn> <mn> 2 </mn> <mn> 3 </mn> <mn> 4 </mn>
1436  </mfenced>
1437</math>
1438\stopbuffer
1439
1440\processxmlbuffer \typebuffer
1441
1442\getbuffer[mfenced]
1443
1444\stopsection
1445
1446\startsection[title={msqrt, mroot}]
1447
1448The shape and size of roots, integrals, sums and products can depend on the size
1449of the content.
1450
1451\startbuffer
1452<math xmlns="http://www.w3c.org/mathml" version="2.0">
1453  <msqrt>
1454    <mi> b </mi>
1455  </msqrt>
1456</math>
1457\stopbuffer
1458
1459\processxmlbuffer \typebuffer
1460
1461\startbuffer
1462<math xmlns="http://www.w3c.org/mathml" version="2.0">
1463  <mroot>
1464    <mi> b </mi>
1465    <mn> 2 </mn>
1466  </mroot>
1467</math>
1468\stopbuffer
1469
1470\processxmlbuffer \typebuffer
1471
1472\startbuffer
1473<math xmlns="http://www.w3c.org/mathml" version="2.0">
1474  <mroot>
1475    <mfrac> <mn> 1 </mn> <mi> b </mi> </mfrac>
1476    <mn> 2 </mn>
1477  </mroot>
1478</math>
1479\stopbuffer
1480
1481\processxmlbuffer \typebuffer
1482
1483\startbuffer
1484<math xmlns="http://www.w3c.org/mathml" version="2.0">
1485  <mroot>
1486    <mfrac>
1487      <mn> 1 </mn>
1488      <mrow> <mi> a </mi> <mo> + </mo> <mi> b </mi> </mrow>
1489    </mfrac>
1490    <mn> 3 </mn>
1491  </mroot>
1492</math>
1493\stopbuffer
1494
1495\processxmlbuffer \typebuffer
1496
1497\getbuffer[msqrt-mroot]
1498
1499\stopsection
1500
1501\startsection[title={mtext}]
1502
1503If you put text in a \mmlelement {mi} element, it will come out rather ugly. This
1504is due to the fact that identifiers are (at least in \TEX) not subjected to the
1505kerning that is normally used in text. Therefore, when you want to add some text
1506to a formula, you should use the \mmlelement {mtext} element.
1507
1508\startbuffer
1509<math xmlns="http://www.w3c.org/mathml" version="2.0">
1510  <mfrac>
1511    <mi> Some Text </mi>
1512    <mtext> Some Text </mtext>
1513  </mfrac>
1514</math>
1515\stopbuffer
1516
1517\processxmlbuffer \typebuffer
1518
1519As with all elements, leading and trailing spaces are ignored. If you really want
1520a space in front or at the end, you should use one of the space tokens other than
1521the ascii spacing tokens. You can also use entities like \type {&nbsp;}.
1522
1523\getbuffer[mtext]
1524
1525\stopsection
1526
1527\startsection[title={mover, munder, munderover}]
1528
1529Not all formulas are math and spacing and font rules may differ per discipline.
1530The following formula reflects a chemical reaction.
1531
1532\startbuffer
1533<math xmlns="http://www.w3c.org/mathml" version="2.0">
1534  <mrow>
1535    <mrow>
1536      <mn> 2 </mn>
1537      <msub> <mtext> H </mtext> <mn> 2 </mn> </msub>
1538    </mrow>
1539    <mo> + </mo>
1540    <msub> <mtext> O </mtext> <mn> 2 </mn> </msub>
1541    <munder>
1542      <mo> &RightArrow; </mo>
1543      <mtext> explosion </mtext>
1544    </munder>
1545    <mrow>
1546      <mn> 2 </mn>
1547      <msub> <mtext> H </mtext> <mn> 2 </mn> </msub>
1548      <mtext> O </mtext>
1549    </mrow>
1550  </mrow>
1551</math>
1552\stopbuffer
1553
1554\processxmlbuffer \typebuffer
1555
1556The \mmlelement {munder}, \mmlelement {mover} and \mmlelement {munderover}
1557elements can be used to put symbols and text or formulas on top of each other.
1558When applicable, the symbols will stretch themselves to span the natural size of
1559the text or formula.
1560
1561The following examples demonstrate how the relevant components of this threesome
1562are defined.
1563
1564\startbuffer
1565<math xmlns="http://www.w3c.org/mathml" version="2.0">
1566  <mrow>
1567    <mi> x </mi>
1568    <munder>
1569      <mo> &RightArrow; </mo>
1570      <mtext> maps to </mtext>
1571    </munder>
1572    <mi> y </mi>
1573  </mrow>
1574</math>
1575\stopbuffer
1576
1577\processxmlbuffer \typebuffer
1578
1579\startbuffer
1580<math xmlns="http://www.w3c.org/mathml" version="2.0">
1581  <mrow>
1582    <mi> x </mi>
1583    <munder>
1584      <mtext> maps to </mtext>
1585      <mo> &RightArrow; </mo>
1586    </munder>
1587    <mi> y </mi>
1588  </mrow>
1589</math>
1590\stopbuffer
1591
1592\processxmlbuffer \typebuffer
1593
1594\startbuffer
1595<math xmlns="http://www.w3c.org/mathml" version="2.0">
1596  <mrow>
1597    <mi> x </mi>
1598    <mover>
1599      <mtext> maps to </mtext>
1600      <mo> &RightArrow; </mo>
1601    </mover>
1602    <mi> y </mi>
1603  </mrow>
1604</math>
1605\stopbuffer
1606
1607\processxmlbuffer \typebuffer
1608
1609\startbuffer
1610<math xmlns="http://www.w3c.org/mathml" version="2.0">
1611  <mrow>
1612    <mi> x </mi>
1613    <mover>
1614      <mo> &RightArrow; </mo>
1615      <mtext> maps to </mtext>
1616    </mover>
1617    <mi> y </mi>
1618  </mrow>
1619</math>
1620\stopbuffer
1621
1622\processxmlbuffer \typebuffer
1623
1624\startbuffer
1625<math xmlns="http://www.w3c.org/mathml" version="2.0">
1626  <mrow>
1627    <munderover>
1628      <mi> &int; </mi>
1629      <mn> 1 </mn>
1630      <mi> &infin; </mi>
1631    </munderover>
1632  </mrow>
1633</math>
1634\stopbuffer
1635
1636\processxmlbuffer \typebuffer
1637
1638\startbuffer
1639<math xmlns="http://www.w3c.org/mathml" version="2.0">
1640    <mrow>
1641        <mover> <mi> x </mi> <mo> &#x2C6; </mo> </mover> <mo>+</mo>
1642        <mover> <mi> x </mi> <mo> &#x5E;  </mo> </mover> <mo>+</mo>
1643        <mover> <mi> x </mi> <mo> &Hat;   </mo> </mover>
1644    </mrow>
1645</math>
1646\stopbuffer
1647
1648\processxmlbuffer \typebuffer
1649
1650\getbuffer[munder]
1651
1652\getbuffer[mover]
1653
1654\getbuffer[munderover]
1655
1656\stopsection
1657
1658\startsection[title={ms}]
1659
1660This is a bit weird element. It behaves like \mmlelement {mtext} but puts quotes
1661around the text.
1662
1663\startbuffer
1664<math xmlns="http://www.w3c.org/mathml" version="2.0">
1665  <mfrac>
1666    <ms> Some Text </ms>
1667    <mtext> Some Text </mtext>
1668  </mfrac>
1669</math>
1670\stopbuffer
1671
1672\processxmlbuffer \typebuffer
1673
1674You can specify the left and right boundary characters, either directly or
1675(preferably) using entities like \type {&quot;}.
1676
1677\startbuffer
1678<math xmlns="http://www.w3c.org/mathml" version="2.0">
1679  <ms lquote="+" rquote="+"> A Famous Quotation </ms>
1680</math>
1681\stopbuffer
1682
1683\processxmlbuffer \typebuffer
1684
1685\getbuffer[ms]
1686
1687\stopsection
1688
1689\startsection[title={menclose}]
1690
1691This element is implemented but it is such a weird element that it's probably
1692seldom used.
1693
1694\startbuffer
1695<math xmlns="http://www.w3c.org/mathml" version="2.0">
1696  <menclose notation="longdiv"><mn>123</mn></menclose>
1697</math>
1698\stopbuffer
1699
1700\processxmlbuffer \typebuffer
1701
1702\startbuffer
1703<math xmlns="http://www.w3c.org/mathml" version="2.0">
1704  <menclose notation="actuarial"><mn>123</mn></menclose>
1705</math>
1706\stopbuffer
1707
1708\processxmlbuffer \typebuffer
1709
1710\startbuffer
1711<math xmlns="http://www.w3c.org/mathml" version="2.0">
1712  <menclose notation="radical"><mn>123</mn></menclose>
1713</math>
1714\stopbuffer
1715
1716\processxmlbuffer \typebuffer
1717
1718A bit more complex example (taken from the specification) demonstrates where
1719those somewhat strange rendering options are good for:
1720
1721\startbuffer
1722<math xmlns="http://www.w3c.org/mathml" version="2.0">
1723  <mtable columnspacing="0pt" rowspacing="0pt">
1724    <mtr>
1725      <mtd></mtd>
1726      <mtd columnalign="right"><mn>10</mn></mtd>
1727    </mtr>
1728    <mtr>
1729      <mtd columnalign="right"><mn>131</mn></mtd>
1730      <mtd columnalign="right">
1731        <menclose notation="longdiv"><mn>1413</mn></menclose>
1732      </mtd>
1733    </mtr>
1734    <mtr>
1735      <mtd></mtd>
1736      <mtd columnalign="right">
1737        <mrow>
1738          <munder>
1739            <mn>131</mn>
1740            <mo>&UnderBar;</mo>
1741          </munder>
1742          <mphantom><mn>3</mn></mphantom>
1743        </mrow>
1744      </mtd>
1745    </mtr>
1746    <mtr>
1747      <mtd></mtd>
1748      <mtd columnalign="right"><mn>103</mn></mtd>
1749    </mtr>
1750  </mtable>
1751</math>
1752\stopbuffer
1753
1754\processxmlbuffer \typebuffer
1755
1756In \MATHML~3 a few more notations showed up and to some extend we support them.
1757We assume that the previously mentioned variants are always applied to the
1758content first.
1759
1760\startbuffer
1761<math xmlns="http://www.w3c.org/mathml" version="2.0">
1762  <menclose notation="box downdiagonalstrike">
1763    <mtext>whatever</mtext>
1764  </menclose>
1765</math>
1766\stopbuffer
1767
1768\processxmlbuffer \typebuffer
1769
1770\startbuffer
1771<math xmlns="http://www.w3c.org/mathml" version="2.0">
1772  <menclose notation="roundedbox updiagonalstrike">
1773    <mtext>whatever</mtext>
1774  </menclose>
1775</math>
1776\stopbuffer
1777
1778\processxmlbuffer \typebuffer
1779
1780\startbuffer
1781<math xmlns="http://www.w3c.org/mathml" version="2.0">
1782  <menclose notation="circle verticalstrike horizontalstrike">
1783    <mtext>whatever</mtext>
1784  </menclose>
1785</math>
1786\stopbuffer
1787
1788\processxmlbuffer \typebuffer
1789
1790\startbuffer
1791<math xmlns="http://www.w3c.org/mathml" version="2.0">
1792  <menclose notation="left top verticalstrike">
1793    <mtext>whatever</mtext>
1794  </menclose>
1795</math>
1796\stopbuffer
1797
1798\processxmlbuffer \typebuffer
1799
1800\startbuffer
1801<math xmlns="http://www.w3c.org/mathml" version="2.0">
1802  <menclose notation="right bottom horizontalstrike">
1803    <mtext>whatever</mtext>
1804  </menclose>
1805</math>
1806\stopbuffer
1807
1808\processxmlbuffer \typebuffer
1809
1810\startbuffer
1811<math xmlns="http://www.w3c.org/mathml" version="2.0">
1812  <menclose notation="radical right bottom horizontalstrike">
1813    <mtext>whatever</mtext>
1814  </menclose>
1815</math>
1816\stopbuffer
1817
1818\processxmlbuffer \typebuffer
1819
1820\startbuffer
1821<math xmlns="http://www.w3c.org/mathml" version="2.0">
1822  <menclose notation="right bottom horizontalstrike radical">
1823    <mtext>whatever</mtext>
1824  </menclose>
1825</math>
1826\stopbuffer
1827
1828\processxmlbuffer \typebuffer
1829
1830The graphics are drawn at runtime by \METAPOST. Currently we don't combine them
1831into one which would be more efficient in terms of output (not so much in
1832runtime). You can define additional variants; as an example we show one of the
1833solutions:
1834
1835\startbuffer
1836\startuseMPgraphic{mml:enclose:box}
1837  draw OverlayBox
1838    withpen pencircle scaled (ExHeight/10) ;
1839\stopuseMPgraphic
1840
1841\defineoverlay [mml:enclose:box] [\useMPgraphic{mml:enclose:box}]
1842\stopbuffer
1843
1844\getbuffer \typebuffer
1845
1846You can roll out your own:
1847
1848\startbuffer
1849\startuseMPgraphic{mml:enclose:mybox}
1850  draw OverlayBox enlarged (ExHeight/5)
1851    withpen pencircle scaled (ExHeight/10) ;
1852\stopuseMPgraphic
1853
1854\defineoverlay [mml:enclose:mybox] [\useMPgraphic{mml:enclose:mybox}]
1855\stopbuffer
1856
1857\getbuffer \typebuffer
1858
1859\startbuffer
1860<math xmlns="http://www.w3c.org/mathml" version="2.0">
1861  <menclose notation="mybox">
1862    <mtext>whatever</mtext>
1863  </menclose>
1864</math>
1865\stopbuffer
1866
1867\processxmlbuffer \typebuffer
1868
1869\getbuffer[menclose]
1870
1871\stopsection
1872
1873\startsection[title={merror}]
1874
1875There is not much chance that this element will end up in a math textbook, unless
1876the typeset output of programs is part of the story.
1877
1878\startbuffer
1879<math xmlns="http://www.w3c.org/mathml" version="2.0">
1880  <merror>
1881    <mtext> Are you kidding? &ThickSpace; </mtext>
1882    <mfrac>
1883      <mrow> <mn> 1 </mn> <mo> + </mo> <mi> x </mi> </mrow>
1884      <mn> 0 </mn>
1885    </mfrac>
1886  </merror>
1887</math>
1888\stopbuffer
1889
1890\processxmlbuffer \typebuffer
1891
1892\getbuffer[merror]
1893
1894\stopsection
1895
1896\startsection[title={mmultiscripts, mprescripts}]
1897
1898This element is one of the less obvious ones. The next two examples are taken
1899from the specification. The \mmlelement {multiscripts} element takes an odd
1900number of arguments. The second and successive child elements alternate between
1901sub- and superscript. The empty element \mmlelement {none} |<|a dedicated element
1902\mmlelement {mnone} would have been a better choice|>| serves as a placeholder.
1903
1904\startbuffer
1905<math xmlns="http://www.w3c.org/mathml" version="2.0">
1906  <mmultiscripts>
1907    <mi> R </mi>
1908    <mi> i </mi>
1909    <none/>
1910    <none/>
1911    <mi> j </mi>
1912    <mi> k </mi>
1913    <none/>
1914    <mi> l </mi>
1915    <none/>
1916  </mmultiscripts>
1917</math>
1918\stopbuffer
1919
1920\processxmlbuffer \typebuffer
1921
1922The \mmlelement {mmultiscripts} element can also be used to attach prescripts to
1923a symbol. The next example demonstrates this. The empty \mmlelement {prescripts}
1924element signals the start of the prescripts section.
1925
1926\startbuffer
1927<math xmlns="http://www.w3c.org/mathml" version="2.0">
1928  <mmultiscripts>
1929    <mi> Qb </mi>
1930    <mn> 4 </mn>
1931    <none/>
1932    <mprescripts/>
1933    <mn> 427 </mn>
1934    <none/>
1935  </mmultiscripts>
1936</math>
1937\stopbuffer
1938
1939\processxmlbuffer \typebuffer
1940
1941\getbuffer[mmultiscripts]
1942
1943\stopsection
1944
1945\startsection[title={mspace}]
1946
1947Currently not all functionality of the \mmlelement {mspace} element is
1948implemented. Over time we will see what support is needed and makes sense,
1949especially since this command can spoil things. We only support the units that
1950make sense, so units in terms of pixels |<|a rather persistent oversight in
1951drafts|>| are kindly ignored.
1952
1953\startbuffer
1954<math xmlns="http://www.w3c.org/mathml" version="2.0">
1955  <?context-mathml-directive mspace option test ?>
1956  <mrow>
1957    <mtext> use  </mtext> <mspace width="1em" />
1958    <mtext> me   </mtext> <mspace width="1ex" />
1959    <mtext> with </mtext> <mspace width="10pt"/>
1960    <mtext> care </mtext>
1961  </mrow>
1962</math>
1963\stopbuffer
1964
1965\processxmlbuffer \typebuffer
1966
1967As you can see here, spaces inside a \type {mtext} matter too! The next example
1968is more tight.
1969
1970\startbuffer
1971<math xmlns="http://www.w3c.org/mathml" version="2.0">
1972  <?context-mathml-directive mspace option test ?>
1973  <mrow>
1974    <mtext>use</mtext>  <mspace width="1em" />
1975    <mtext>me</mtext>   <mspace width="1ex" />
1976    <mtext>with</mtext> <mspace width="10pt"/>
1977    <mtext>care</mtext>
1978  </mrow>
1979</math>
1980\stopbuffer
1981
1982\processxmlbuffer \typebuffer
1983
1984You can also pass a sample text:
1985
1986\startbuffer
1987<math xmlns="http://www.w3c.org/mathml" version="2.0">
1988  <mfrac>
1989     <mi> 44 </mi>
1990     <mfrac>
1991       <mrow>
1992         <mn> 11 </mn> <mn> 22 </mn> <mn> 33 </mn>
1993       </mrow>
1994       <mrow>
1995         <mn> 11 </mn> <mspace spacing="22"/> <mn> 33 </mn>
1996       </mrow>
1997     </mfrac>
1998  </mfrac>
1999</math>
2000\stopbuffer
2001
2002\processxmlbuffer \typebuffer
2003
2004\getbuffer[mspace]
2005
2006\stopsection
2007
2008\startsection[title={mphantom}]
2009
2010A phantom element hides its content but still takes its space. A phantom element
2011can contain other elements.
2012
2013\startbuffer
2014<math xmlns="http://www.w3c.org/mathml" version="2.0">
2015  <mrow>
2016    <mtext>    who is afraid of </mtext>    <mspace width=".5em" />
2017    <mphantom> phantom          </mphantom> <mspace width=".5em" />
2018    <mtext>    elements         </mtext>
2019  </mrow>
2020</math>
2021\stopbuffer
2022
2023\processxmlbuffer \typebuffer
2024
2025\getbuffer[mphantom]
2026
2027\stopsection
2028
2029\startsection[title={mpadded}]
2030
2031As with a few other elements, we first have to see some practical usage for this,
2032before we could implement the functionality needed.
2033
2034\getbuffer[mpadded]
2035
2036\stopsection
2037
2038\startsection[title={mtable, mtr, mtd, mlabeledtr}]
2039
2040As soon as you want to represent a matrix or other more complicated composed
2041constructs, you end up with spacing problems. This is when tables come into view.
2042Because presentational elements have no deep knowledge about their content,
2043tables made with presentational \MATHML\ will in most cases look worse than those
2044that result from content markup.
2045
2046We have implemented tables on top of the normal \XML\ (\HTML) based table support
2047in \CONTEXT, also known as natural tables. Depending on the needs, support for
2048the \mmlelement {mtable} element will be extended.
2049
2050The \mmlelement {mtable} element takes a lot of attributes. When no attributes
2051are given, we assume that a matrix is wanted, and typeset the content
2052accordingly.
2053
2054\startbuffer
2055<math xmlns="http://www.w3c.org/mathml" version="2.0">
2056  <mrow>
2057    <mo> ( </mo>
2058    <mtable>
2059      <mtr>
2060        <mtd> <msub> <mi> x </mi> <mn> 1,1 </mn> </msub> </mtd>
2061        <mtd> <mn> 1 </mn> </mtd>
2062        <mtd> <mn> 0 </mn> </mtd>
2063      </mtr>
2064      <mtr>
2065        <mtd> <mn> 0 </mn> </mtd>
2066        <mtd> <msub> <mi> x </mi> <mn> 2,2 </mn> </msub> </mtd>
2067        <mtd> <mn> 1 </mn> </mtd>
2068      </mtr>
2069      <mtr>
2070        <mtd> <mn> 0 </mn> </mtd>
2071        <mtd> <mn> 1 </mn> </mtd>
2072        <mtd> <msub> <mi> x </mi> <mn> 3,3 </mn> </msub> </mtd>
2073      </mtr>
2074    </mtable>
2075    <mo> ) </mo>
2076  </mrow>
2077</math>
2078\stopbuffer
2079
2080\processxmlbuffer \typebuffer
2081
2082\startbuffer
2083<math xmlns="http://www.w3c.org/mathml" version="2.0">
2084  <mtable columnalign="left center right">
2085    <mtr>
2086      <mtd frame="solid"> <mn> 100 </mn> </mtd>
2087      <mtd              > <mn> 100 </mn> </mtd>
2088      <mtd              > <mn> 100 </mn> </mtd>
2089    </mtr>
2090    <mtr>
2091      <mtd              > <mn> 10  </mn> </mtd>
2092      <mtd frame="solid"> <mn> 10  </mn> </mtd>
2093      <mtd              > <mn> 10  </mn> </mtd>
2094    </mtr>
2095    <mtr>
2096      <mtd              > <mn> 1   </mn> </mtd>
2097      <mtd              > <mn> 1   </mn> </mtd>
2098      <mtd frame="solid"> <mn> 1   </mn> </mtd>
2099    </mtr>
2100  </mtable>
2101</math>
2102\stopbuffer
2103
2104\processxmlbuffer \typebuffer
2105
2106A special case is the labeled row \mmlelement {mlabeledtr}. This one is meant for
2107numbering equations. However, in a properly formatted document there is probably
2108some encapsulating structure that takes care of this. Therefore we discard the
2109first child element. We show an example taken from the specification.
2110
2111\startbuffer
2112<math xmlns="http://www.w3c.org/mathml" version="2.0">
2113  <mtable>
2114    <mlabeledtr>
2115      <mtd>crap</mtd>
2116      <mtd>
2117        <mrow>
2118          <mi>E</mi>
2119          <mo>=</mo>
2120          <mrow>
2121            <mi>m</mi>
2122            <mi>&it;</mi>
2123            <msup>
2124              <mi>c</mi>
2125              <mn>2</mn>
2126            </msup>
2127          </mrow>
2128        </mrow>
2129      </mtd>
2130    </mlabeledtr>
2131  </mtable>
2132</math>
2133\stopbuffer
2134
2135\processxmlbuffer \typebuffer
2136
2137Although the underlying table mechanism can provide all the support needed (and
2138even more), not all attributes are yet implemented. We will make a useful
2139selection.
2140
2141\starttabulate[|l|l|]
2142\HL
2143\NC columnalign   \NC keyword: left center (middle) right \NC \NR
2144\NC columnspacing \NC a meaningful dimension              \NC \NR
2145\NC rowspacing    \NC a meaningful dimension              \NC \NR
2146\NC frame         \NC keyword: none (off) solid (on)      \NC \NR
2147\NC color         \NC a named color identifier            \NC \NR
2148\NC background    \NC a named color identifier            \NC \NR
2149\HL
2150\stoptabulate
2151
2152We only support properly named colors as back- and foreground colors. The normal
2153\CONTEXT\ color mapping mechanism can be used to remap colors. This permits
2154(read: forces) a consistent usage of colors. If you use named backgrounds
2155\unknown\ the sky is the limit.
2156
2157\getbuffer[mtable]
2158
2159\getbuffer[mtd]
2160
2161\getbuffer[mtr-mlabeledtr]
2162
2163\stopsection
2164
2165\startsection[title={mcolumn}]
2166
2167This element is new in \MATHML~3 and is kind of special in the sense that the
2168content is analyzed. It would have made more sense just to provide some proper
2169structure instead since it's intended use is rather well defined.
2170
2171Because it is not much fun to implement such a messy element we only support it
2172partially and add what comes on our way. Here are a few examples (more or less
2173taken from the reference).
2174
2175\startbuffer
2176<math xmlns="http://www.w3c.org/mathml" version="2.0">
2177  <mcolumn>
2178    <mn>12</mn>
2179    <mrow> <mo>&times;</mo> <mn>12</mn> </mrow>
2180    <mline spacing="000"/>
2181    <mn>24</mn>
2182    <mrow> <mn>12</mn> <mspace spacing="0"/> </mrow>
2183    <mline spacing="000"/>
2184    <mn>144</mn>
2185  </mcolumn>
2186</math>
2187\stopbuffer
2188
2189\processxmlbuffer \typebuffer
2190
2191\startbuffer
2192<math xmlns="http://www.w3c.org/mathml" version="2.0">
2193  <mcolumn>
2194    <mn>123</mn>
2195    <mrow> <mn>456</mn> <mo>+</mo> </mrow>
2196    <mline spacing="000+"/>
2197    <mn>579</mn>
2198  </mcolumn>
2199</math>
2200\stopbuffer
2201
2202\processxmlbuffer \typebuffer
2203
2204\startbuffer
2205<math xmlns="http://www.w3c.org/mathml" version="2.0">
2206  <mcolumn>
2207    <mn>1,23</mn>
2208    <mrow> <mn>4,56</mn> <mo>+</mo> </mrow>
2209    <mline spacing="0,00+"/>
2210    <mn>5,79</mn>
2211  </mcolumn>
2212</math>
2213\stopbuffer
2214
2215\processxmlbuffer \typebuffer
2216
2217\startbuffer
2218<math xmlns="http://www.w3c.org/mathml" version="2.0">
2219  <mcolumn>
2220    <mstyle mathsize="71%">
2221        <menclose notation="bottom"> <mn>10</mn> </menclose>
2222    </mstyle>
2223    <mn>52</mn>
2224    <mrow> <mo>&minus;</mo> <mn>7</mn> </mrow>
2225    <mline spacing="45"/>
2226    <mn>45</mn>
2227  </mcolumn>
2228</math>
2229\stopbuffer
2230
2231\processxmlbuffer \typebuffer
2232
2233Similar effects can be accomplished with the \mmlelement {mtable}
2234element.
2235
2236\stopsection
2237
2238\startsection[title={malignmark, maligngroup}]
2239
2240This element is used in tables and is not yet implemented, first because I still
2241have to unravel its exact usage, but second, because it is about the ugliest
2242piece of \MATHML\ markup you will encounter.
2243
2244% AFO: http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter3.html#presm.malign
2245
2246\getbuffer[malignmark]
2247
2248\stopsection
2249
2250\startsection[title={mglyph}]
2251
2252This element is for those who want to violate the ideas of general markup by
2253popping in his or her own glyphs. Of course one should use entities, even if they
2254have to be defined.
2255
2256\startbuffer
2257<math xmlns="http://www.w3c.org/mathml" version="2.0">
2258  <mrow>
2259    <mi> <mglyph fontfamily="Serif" index="65" alt="The Letter A"/></mi>
2260    <mo> + </mo>
2261    <mi> <mglyph fontfamily="Serif" index="66" alt="The Letter B"/></mi>
2262    <mo> = </mo>
2263    <mi> <mglyph fontfamily="Serif" index="67" alt="The Letter C"/></mi>
2264  </mrow>
2265</math>
2266\stopbuffer
2267
2268\processxmlbuffer \typebuffer
2269
2270\getbuffer[mglyph]
2271
2272\stopsection
2273
2274\startsection[title={mstyle}]
2275
2276This element is implemented but not yet discussed since we want more control over
2277its misuse.
2278
2279\getbuffer[mstyle]
2280
2281\stopsection
2282
2283\startsection[title={afterword}]
2284
2285You may have noticed that we prefer content \MATHML\ over presentational \MATHML.
2286So, unless you're already tired of any math coded in angle brackets, we invite
2287you to read the next chapter too.
2288
2289\stopsection
2290
2291\stopchapter
2292
2293\startchapter[title={Content markup}]
2294
2295\startsection[title={introduction}]
2296
2297In this chapter we will discuss the \MATHML\ elements from the point of view of
2298typesetting. We will not pay attention to other rendering techniques, like speech
2299generation. Some elements take attributes and those often make more sense for
2300other applications than for a typesetting engine like \TEX, which has a strong
2301math engine that knows how to handle math.
2302
2303One of the most prominent changes in \MATHML~3 is support for an \OPENMATH\ like
2304coding. Here the \mmlelement {csymbol} takes the place of the empty element as
2305first argument of an \mmlelement {apply}. There are more symbols in \OPENMATH\
2306then we supported in the interpreter, but in due time (depending on demand) we
2307will add more. At the time of writing this the draft was really a draft which
2308made it hard to grasp all the implications for rendering so we probably need to
2309overhaul the code sometime in the future.
2310
2311Another change is the usage of \mmlelement {apply} that has been delegated to
2312\mmlelement {bind}. One may wonder why this hadn't happen before. For the moment
2313we treat the \mmlelement {bind} as if it were an \mmlelement {apply}.
2314
2315\stopsection
2316
2317\startsection[title={apply}]
2318
2319If you are dealing with rather ordinary math, you will only need a subset of
2320content \MATHML. For this reason we will start with the most common elements.
2321When you key in \XML\ directly, you will encounter the \mmlelement {apply}
2322element quite often, even in a relatively short formula like the following.
2323
2324\startbuffer
2325<math xmlns="http://www.w3c.org/mathml" version="2.0">
2326    <apply> <minus/>
2327        <cn> 1 </cn>
2328    </apply>
2329</math>
2330\stopbuffer
2331
2332\processxmlbuffer \typebuffer
2333
2334In most cases the \mmlelement {apply} element is followed by a specification
2335disguised as an empty element.
2336
2337Later we will see more complex examples but here we already show the different
2338ways of encoding. First we show the traditional \MATHML~2 method:
2339
2340\startbuffer
2341<math xmlns="http://www.w3c.org/mathml" version="2.0">
2342    <apply> <forall/>
2343        <bvar> <ci>x</ci> </bvar>
2344        <apply> <geq/>
2345            <ci>x</ci>
2346            <cn>4</cn>
2347        </apply>
2348    </apply>
2349</math>
2350\stopbuffer
2351
2352\processxmlbuffer \typebuffer
2353
2354This is now called \quote {pragmatic} \MATHML. Using symbols and \mmlelement
2355{bind} this becomes \quote {strict} \MATHML:
2356
2357\startbuffer
2358<math xmlns="http://www.w3c.org/mathml" version="3.0">
2359    <bind> <csymbol cd="quant1">forall</csymbol>
2360        <bvar> <ci>x</ci> </bvar>
2361        <apply> <csymbol cd="relation1">geq</csymbol>
2362            <ci>x</ci>
2363            <cn>4</cn>
2364        </apply>
2365    </bind>
2366</math>
2367\stopbuffer
2368
2369\processxmlbuffer \typebuffer
2370
2371\stopsection
2372
2373\startsection[title={ci, cn, sep}]
2374
2375These elements are used to specify identifiers and numbers. Both elements can
2376be made more explicit by using attributes.
2377
2378\startattributes
2379\HL
2380\NC type \NC set      \NC use a representation appropriate for sets \NC \NR
2381\NC      \NC vector   \NC mark this element as vector               \NC \NR
2382\NC      \NC function \NC consider this element to be a function    \NC \NR
2383\NC      \NC fn       \NC idem \NC \NR
2384\HL
2385\stopattributes
2386
2387When \attvalue {set} is specified, a blackboard symbol is used when available.
2388
2389\startbuffer
2390<math xmlns="http://www.w3c.org/mathml" version="2.0">
2391  <apply> <in/>
2392    <ci> x </ci>
2393    <ci type="set"> N </ci>
2394  </apply>
2395</math>
2396\stopbuffer
2397
2398\processxmlbuffer \typebuffer
2399
2400The \attvalue {function} specification makes sense when the \mmlelement {ci}
2401element is used in for instance a differential equation.
2402
2403\startattributes
2404\HL
2405\NC type \NC integer           \NC a whole number with an optional base \NC \NR
2406\NC      \NC logical           \NC a boolean constant \NC \NR
2407\NC      \NC rational          \NC a real number \NC \NR
2408\NC      \NC complex-cartesian \NC a complex number in $x+iy$ notation \NC \NR
2409\NC      \NC complex           \NC idem \NC \NR
2410\NC      \NC complex-polar     \NC a complex number in polar notation \unknown \NC \NR
2411\HL
2412\stopattributes
2413
2414You're lucky when your document uses decimal notation, otherwise you will end up
2415with long specs if you want to be clear in what numbers are used.
2416
2417\startbuffer
2418<math xmlns="http://www.w3c.org/mathml" version="2.0">
2419  <apply> <eq/>
2420    <apply> <plus/>
2421      <cn type="integer" base="16"> 1A2C </cn>
2422      <cn type="integer" base="16"> 0101 </cn>
2423    </apply>
2424    <cn type="integer" base="16"> 1B2D </cn>
2425  </apply>
2426</math>
2427\stopbuffer
2428
2429\processxmlbuffer \typebuffer
2430
2431Complex numbers have two components. These are separated by the \mmlelement {sep}
2432element. In the following example we see that instead of using a \mmlelement {ci}
2433with set specifier, the empty element \mmlelement {complexes} can be used. We
2434will see some more of those later.
2435
2436\startbuffer
2437<math xmlns="http://www.w3c.org/mathml" version="2.0">
2438  <apply> <in/>
2439    <cn type="complex"> 2 <sep/> 5 </cn>
2440    <complexes/>
2441  </apply>
2442</math>
2443\stopbuffer
2444
2445\processxmlbuffer \typebuffer
2446
2447\stopsection
2448
2449\startsection[title={eq, neq, gt, lt, geq, leq}]
2450
2451Expressions, and especially those with \mmlelement {eq} are typical for math.
2452Because such expressions can be quite large, there are provisions for proper
2453alignment.
2454
2455\starttabulate[||c||c|] % we want inline math
2456\HL
2457\NC lt  \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><lt/> <ci>a</ci><ci>b</ci></apply></math>} \NC
2458    leq \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><leq/><ci>a</ci><ci>b</ci></apply></math>} \NC \NR
2459\NC eq  \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><eq/> <ci>a</ci><ci>b</ci></apply></math>} \NC
2460    neq \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><neq/><ci>a</ci><ci>b</ci></apply></math>} \NC \NR
2461\NC gt  \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><gt/> <ci>a</ci><ci>b</ci></apply></math>} \NC
2462    geq \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><geq/><ci>a</ci><ci>b</ci></apply></math>} \NC \NR
2463\HL
2464\stoptabulate
2465
2466\startbuffer
2467<math xmlns="http://www.w3c.org/mathml" version="2.0">
2468  <apply> <leq/>
2469    <ci> a </ci>
2470    <ci> b </ci>
2471    <ci> c </ci>
2472  </apply>
2473</math>
2474\stopbuffer
2475
2476\processxmlbuffer \typebuffer
2477
2478\stopsection
2479
2480\startsection[title={equivalent, approx, implies}]
2481
2482Equivalence, approximations, and implications are handled like \mmlelement {eq}
2483and alike and have their own symbols.
2484
2485\startbuffer
2486<math xmlns="http://www.w3c.org/mathml" version="2.0">
2487  <apply> <equivalent/>
2488    <apply> <plus/> <ci> a </ci> <ci> b </ci> </apply>
2489    <apply> <plus/> <ci> b </ci> <ci> a </ci> </apply>
2490  </apply>
2491</math>
2492\stopbuffer
2493
2494\processxmlbuffer \typebuffer
2495
2496This document is typeset with \LUATEX\ built upon \TEX\ version $3.14159$, and
2497given that \TEX\ is written by a mathematician, it will be no surprise that:
2498
2499\startbuffer
2500<math xmlns="http://www.w3c.org/mathml" version="2.0">
2501  <apply> <approx/>
2502    <cn> 3.14159 </cn>
2503    <pi/>
2504  </apply>
2505</math>
2506\stopbuffer
2507
2508\processxmlbuffer \typebuffer
2509
2510\startbuffer
2511<math xmlns="http://www.w3c.org/mathml" version="2.0">
2512  <apply> <implies/>
2513    <apply> <eq/>
2514      <apply> <plus/>
2515        <ci> x </ci>
2516        <cn> 4 </cn>
2517      </apply>
2518      <cn> 9 </cn>
2519    </apply>
2520    <apply> <eq/>
2521      <ci> x </ci>
2522      <cn> 5 </cn>
2523    </apply>
2524  </apply>
2525</math>
2526\stopbuffer
2527
2528\processxmlbuffer \typebuffer
2529
2530\stopsection
2531
2532\startsection[title={minus, plus}]
2533
2534Addition and subtraction are main building blocks of math so you will meet them
2535often.
2536
2537\startbuffer
2538<math xmlns="http://www.w3c.org/mathml" version="2.0">
2539  <apply> <minus/>
2540    <cn> 37 </cn>
2541    <ci> x </ci>
2542  </apply>
2543</math>
2544\stopbuffer
2545
2546\processxmlbuffer \typebuffer
2547
2548In most cases there will be more than one argument to take care of, but
2549especially \mmlelement {minus} will be used with one argument too. Although \typ
2550{<cn> -37 </cn>} is valid, using \mmlelement {minus} is sometimes more clear.
2551
2552\startbuffer
2553<math xmlns="http://www.w3c.org/mathml" version="2.0">
2554  <apply> <minus/>
2555    <cn> 37 </cn>
2556  </apply>
2557</math>
2558\stopbuffer
2559
2560\processxmlbuffer \typebuffer
2561
2562You should pay attention to combinations of \mmlelement {plus} and \mmlelement
2563{minus}. Opposite to presentational \MATHML, in content markup you don't think
2564and code sequential.
2565
2566\startbuffer
2567<math xmlns="http://www.w3c.org/mathml" version="2.0">
2568  <apply> <plus/>
2569    <apply> <minus/>
2570      <ci> x </ci>
2571    </apply>
2572    <cn> 37 </cn>
2573  </apply>
2574</math>
2575\stopbuffer
2576
2577\processxmlbuffer \typebuffer
2578
2579In \MATHML~3 we can also be more vebose:
2580
2581\startbuffer
2582<math xmlns="http://www.w3c.org/mathml" version="3.0">
2583    <apply> <csymbol cd="arith1">plus</csymbol>
2584        <ci>a</ci>
2585        <ci>x</ci>
2586    </apply>
2587</math>
2588\stopbuffer
2589
2590\processxmlbuffer \typebuffer
2591
2592\stopsection
2593
2594\startsection[title={times}]
2595
2596Multiplication is another top ten element. Although \type {3p} as content of the
2597\mmlelement {ci} element would have rendered the next example as well, you really
2598should split off the number and mark it as \mmlelement {cn}. When this is done
2599consistently, we can comfortably change the font of numbers independent of the
2600font used for displaying identifiers.
2601
2602\startbuffer
2603<math xmlns="http://www.w3c.org/mathml" version="2.0">
2604  <apply> <times/>
2605    <cn> 3 </cn>
2606    <ci> p </ci>
2607  </apply>
2608</math>
2609\stopbuffer
2610
2611\processxmlbuffer \typebuffer
2612
2613In a following chapter we will see how we can add multiplication signs between
2614variables and constants.
2615
2616\stopsection
2617
2618\startsection[title={divide}]
2619
2620When typeset, a division is characterized by a horizontal rule. Some elements,
2621like the differential element \mmlelement {diff}, generate their own division.
2622
2623\processxmlfile{pc-s-001.xml}
2624
2625This example also demonstrates how to mix \mmlelement {plus} and \mmlelement
2626{minus}.
2627
2628\typefile{pc-s-001.xml}
2629
2630\startbuffer
2631<math xmlns="http://www.w3c.org/mathml" version="2.0">
2632    <apply><divide/>
2633        <apply><minus/>
2634            <apply><minus/><ci>b</ci></apply>
2635            <apply><minus/><ci>b</ci></apply>
2636            <apply><root/> <ci>a</ci></apply>
2637        </apply>
2638        <apply><minus/>
2639            <apply><minus/><ci>b</ci><ci>b</ci></apply>
2640            <apply><minus/><ci>b</ci></apply>
2641            <apply><root/> <ci>a</ci></apply>
2642        </apply>
2643    </apply>
2644</math>
2645\stopbuffer
2646
2647\processxmlbuffer \typebuffer
2648
2649\stopsection
2650
2651\startsection[title={power}]
2652
2653In presentational \MATHML\ you think in super- and subscripts, but in content
2654\MATHML\ these elements are not available. There you need to think in terms of
2655\mmlelement {power}.
2656
2657\startbuffer
2658<math xmlns="http://www.w3c.org/mathml" version="2.0">
2659  <apply> <plus/>
2660    <apply> <power/>
2661      <ci> x </ci>
2662      <cn> 2 </cn>
2663    </apply>
2664    <apply> <power/>
2665      <apply> <sin/>
2666        <ci> x </ci>
2667      </apply>
2668      <cn> 2 </cn>
2669    </apply>
2670  </apply>
2671</math>
2672\stopbuffer
2673
2674\processxmlbuffer \typebuffer
2675
2676The \mmlelement {power} element is clever enough to determine where the
2677superscript should go. In the case of the sinus function, by default it will go
2678after the function identifier.
2679
2680\stopsection
2681
2682\startsection[title={root, degree}]
2683
2684If you study math related \DTD's |<|these are the formal descriptions for \SGML\
2685or \XML\ element collections|>| you will notice that there are not that many
2686elements that demand a special kind of typography: differential equations,
2687limits, integrals and roots are the most distinctive ones.
2688
2689\startbuffer
2690<math xmlns="http://www.w3c.org/mathml" version="2.0">
2691  <apply> <eq/>
2692    <apply> <root/>
2693      <degree> 3 </degree>
2694      <ci> 64 </ci>
2695    </apply>
2696    <cn> 4 </cn>
2697  </apply>
2698</math>
2699\stopbuffer
2700
2701\processxmlbuffer \typebuffer
2702
2703Contrary to \mmlelement {power}, the \mmlelement {root} element uses a
2704specialized child element to denote the degree. The positive consequence of this
2705is that there cannot be a misunderstanding about what role the child element
2706plays, while in for instance \mmlelement {power} you need to know that the second
2707child element denotes the degree.
2708
2709\stopsection
2710
2711\startsection[title={sin, cos, tan, cot, scs, sec, \unknown}]
2712
2713All members of the family of goniometric functions are available as empty
2714element. When needed, their argument is surrounded by braces. They all behave the
2715same.
2716
2717\starttabulate[|||||]
2718\HL
2719\NC sin \NC arcsin \NC sinh \NC arcsinh \NC \NR
2720\NC cos \NC arccos \NC cosh \NC arccosh \NC \NR
2721\NC tan \NC arctan \NC tanh \NC arctanh \NC \NR
2722\NC cot \NC arccot \NC coth \NC arccoth \NC \NR
2723\NC csc \NC arccsc \NC csch \NC arccsch \NC \NR
2724\NC sec \NC arcsec \NC sech \NC arcsech \NC \NR
2725\HL
2726\stoptabulate
2727
2728These functions are normally typeset in a non italic (often roman) font shape.
2729
2730\processxmlfile{wh-g-001.xml}
2731
2732By default the typesetting engine will minimize the number of braces that
2733surrounds the argument of a function.
2734
2735\typefile{wh-g-001.xml}
2736
2737You can specify $\pi$ as an entity \type {&pi;} or as empty element \mmlelement
2738{pi}. In many cases it is up to your taste which one you use. There are many
2739symbols that are only available as entity, so in some respect there is no real
2740reason to treat $\pi$ different.
2741
2742\startbuffer
2743<math xmlns="http://www.w3c.org/mathml" version="2.0">
2744  <apply> <eq/>
2745    <apply> <cos/>
2746      <pi/>
2747    </apply>
2748    <apply> <minus/>
2749      <cn> 1 </cn>
2750    </apply>
2751  </apply>
2752</math>
2753\stopbuffer
2754
2755\processxmlbuffer \typebuffer
2756
2757\stopsection
2758
2759\startsection[title={log, ln, exp}]
2760
2761The \mmlelement {log} and \mmlelement {ln} are typeset similar to the previously
2762discussed goniometric functions. The \mmlelement {exp} element is a special case
2763of \mmlelement {power}. The constant $e$ can be specified with \mmlelement
2764{exponentiale}.
2765
2766\startbuffer
2767<math xmlns="http://www.w3c.org/mathml" version="2.0">
2768  <apply> <approx/>
2769    <apply> <ln/>
2770      <apply> <plus/>
2771        <exponentiale/>
2772        <cn> 2 </cn>
2773      </apply>
2774    </apply>
2775    <cn> 1.55 </cn>
2776  </apply>
2777</math>
2778\stopbuffer
2779
2780\processxmlbuffer \typebuffer
2781
2782\startbuffer
2783<math xmlns="http://www.w3c.org/mathml" version="2.0">
2784  <apply> <eq/>
2785    <apply> <exp/>
2786      <cn> 2 </cn>
2787    </apply>
2788    <cn> 7.3890560989307 </cn>
2789  </apply>
2790</math>
2791\stopbuffer
2792
2793\processxmlbuffer \typebuffer
2794
2795\stopsection
2796
2797\startsection[title={quotient, rem}]
2798
2799The result of a division can be a rational number, so $\frac{5}{4}$ is equivalent
2800to $1.25$ and $1.25 \times 4$ gives~$5$. An integer division will give~$1$ with a
2801remainder~$2$. Many computer languages provide a \type {div} and \type {mod}
2802function, and since \MATHML\ is also meant for computation, it provides similar
2803concepts, represented by the elements \mmlelement {quotient} and \mmlelement
2804{rem}. The representation of \mmlelement {quotient} is rather undefined, but the
2805next one is among the recommended alternatives.
2806
2807\startbuffer
2808<math xmlns="http://www.w3c.org/mathml" version="2.0">
2809  <apply> <quotient/>
2810    <ci> a </ci>
2811    <ci> b </ci>
2812  </apply>
2813</math>
2814\stopbuffer
2815
2816\processxmlbuffer \typebuffer
2817
2818\stopsection
2819
2820\startsection[title={factorial}]
2821
2822Showing the representation of a factorial is rather dull, so we will use a few
2823more elements as well as a processing instruction to illustrate the usage of
2824\mmlelement {factorial}.
2825
2826\startbuffer
2827<math xmlns="http://www.w3c.org/mathml" version="2.0">
2828  <?context-mathml-directive times symbol yes ?>
2829  <apply> <eq/>
2830    <apply> <factorial/>
2831      <ci> n </ci>
2832    </apply>
2833    <apply> <times/>
2834      <ci> n </ci>
2835      <apply> <minus/> <ci> n </ci> <cn> 1 </cn> </apply>
2836      <apply> <minus/> <ci> n </ci> <cn> 2 </cn> </apply>
2837      <csymbol definitionUrl="cdots"/>
2838      <cn> 1 </cn>
2839    </apply>
2840  </apply>
2841</math>
2842\stopbuffer
2843
2844\processxmlbuffer \typebuffer
2845
2846The processing instruction is responsible for the placement of the $\times$
2847symbols.
2848
2849\stopsection
2850
2851\startsection[title={min, max, gcd, lcm}]
2852
2853These functions can handle more than two arguments. When typeset, these are
2854separated by commas.
2855
2856\startbuffer
2857<math xmlns="http://www.w3c.org/mathml" version="2.0">
2858  <apply> <eq/>
2859    <ci> z </ci>
2860    <apply> <min/>
2861      <apply> <plus/>   <ci> x </ci> <ci> y </ci> </apply>
2862      <apply> <times/>  <cn> 2 </cn> <ci> x </ci> </apply>
2863      <apply> <divide/> <cn> 1 </cn> <ci> y </ci> </apply>
2864    </apply>
2865  </apply>
2866</math>
2867\stopbuffer
2868
2869\processxmlbuffer \typebuffer
2870
2871\stopsection
2872
2873\startsection[title={and, or, xor, not}]
2874
2875Logical expressions can be defined using these elements. The operations are
2876represented by symbols and braces are applied when needed.
2877
2878\startbuffer
2879<math xmlns="http://www.w3c.org/mathml" version="2.0">
2880  <apply> <eq/>
2881    <apply> <and/>
2882      <cn type="integer" base="2"> 1001 </cn>
2883      <cn type="integer" base="2"> 0101 </cn>
2884    </apply>
2885    <cn type="integer" base="2"> 0001 </cn>
2886  </apply>
2887</math>
2888\stopbuffer
2889
2890\processxmlbuffer \typebuffer
2891
2892\stopsection
2893
2894\startsection[title={set, bvar}]
2895
2896The appearance of a \mmlelement {set} depends on the presence of the child
2897element \mmlelement {bvar}. In its simplest form, a set is represented as a list.
2898
2899\startbuffer
2900<math xmlns="http://www.w3c.org/mathml" version="2.0">
2901  <apply> <neq/>
2902    <set>
2903      <cn> 1 </cn>
2904      <cn> 4 </cn>
2905      <cn> 8 </cn>
2906    </set>
2907    <emptyset/>
2908  </apply>
2909</math>
2910\stopbuffer
2911
2912\processxmlbuffer \typebuffer
2913
2914A set can be distinguished from a vector by its curly braces. The simplest case
2915is just a comma separated list. The next example demonstrates the declarative
2916case. Without doubt, there will be other alternatives.
2917
2918\startbuffer
2919<math xmlns="http://www.w3c.org/mathml" version="2.0">
2920  <set>
2921    <bvar><ci> x </ci></bvar>
2922    <condition>
2923      <apply> <lt/>
2924        <cn> 2 </cn>
2925        <ci> x </ci>
2926        <cn> 8 </cn>
2927      </apply>
2928    </condition>
2929  </set>
2930</math>
2931\stopbuffer
2932
2933\processxmlbuffer \typebuffer
2934
2935\stopsection
2936
2937\startsection[title={list}]
2938
2939This element is used in different contexts. When used as a top level element, a
2940list is typeset as follows.
2941
2942\startbuffer
2943<math xmlns="http://www.w3c.org/mathml" version="2.0">
2944  <list>
2945    <cn> 1 </cn>
2946    <cn> 1 </cn>
2947    <cn> 3 </cn>
2948  </list>
2949</math>
2950\stopbuffer
2951
2952\processxmlbuffer \typebuffer
2953
2954When used in a context like \mmlelement {partialdiff}, the list specification
2955becomes a subscript.
2956
2957\startbuffer
2958<math xmlns="http://www.w3c.org/mathml" version="2.0">
2959  <apply> <partialdiff/>
2960    <list>
2961      <cn> 1 </cn>
2962      <cn> 1 </cn>
2963      <cn> 3 </cn>
2964    </list>
2965    <ci type="fn"> f </ci>
2966  </apply>
2967</math>
2968\stopbuffer
2969
2970\processxmlbuffer \typebuffer
2971
2972The function specification in this formula (which is taken from the specs) can
2973also be specified as \typ {<fn> <ci> f </ci> </fn>} (which is more clear).
2974
2975\stopsection
2976
2977\startsection[title={union, intersect, \unknown}]
2978
2979There is a large number of set operators, each represented by a distinctive
2980symbol.
2981
2982\starttabulate[||c||c|] % we want in line math
2983\HL
2984\NC union       \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><union/>      <ci>U</ci><ci>V</ci></apply></math>} \NC
2985                \NC \NC \NR
2986\NC intersect   \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><intersect/>  <ci>U</ci><ci>V</ci></apply></math>} \NC
2987                \NC \NC \NR
2988\NC in          \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><in/>         <ci>U</ci><ci>V</ci></apply></math>} \NC
2989    notin       \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><notin/>      <ci>U</ci><ci>V</ci></apply></math>} \NC \NR
2990\NC subset      \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><subset/>     <ci>U</ci><ci>V</ci></apply></math>} \NC
2991    notsubset   \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><notsubset/>  <ci>U</ci><ci>V</ci></apply></math>} \NC \NR
2992\NC prsubset    \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><prsubset/>   <ci>U</ci><ci>V</ci></apply></math>} \NC
2993    notprsubset \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><notprsubset/><ci>U</ci><ci>V</ci></apply></math>} \NC \NR
2994\NC setdiff     \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><apply><setdiff/>    <ci>U</ci><ci>V</ci></apply></math>} \NC
2995                \NC \NC \NR
2996\HL
2997\stoptabulate
2998
2999These operators are applied as follows:
3000
3001\startbuffer
3002<math xmlns="http://www.w3c.org/mathml" version="2.0">
3003  <apply> <union/>
3004    <ci> U </ci>
3005    <ci> V </ci>
3006  </apply>
3007</math>
3008\stopbuffer
3009
3010\processxmlbuffer \typebuffer
3011
3012\stopsection
3013
3014\startsection[title={conjugate, arg, real, imaginary}]
3015
3016The visual representation of \mmlelement {conjugate} is a horizontal bar with a
3017width matching the width of the expression.
3018
3019\startbuffer
3020<math xmlns="http://www.w3c.org/mathml" version="2.0">
3021  <apply> <conjugate/>
3022    <apply> <plus/>
3023      <ci> x </ci>
3024      <apply> <times/>
3025        <cn> &ImaginaryI; </cn>
3026        <ci> y </ci>
3027      </apply>
3028    </apply>
3029  </apply>
3030</math>
3031\stopbuffer
3032
3033\processxmlbuffer \typebuffer
3034
3035The \mmlelement {arg}, \mmlelement {real} and \mmlelement {imaginary} elements
3036trigger the following appearance.
3037
3038\startbuffer
3039<math xmlns="http://www.w3c.org/mathml" version="2.0">
3040  <apply> <arg/>
3041    <apply> <plus/>
3042      <ci> x </ci>
3043      <apply> <times/>
3044        <cn> &ImaginaryI; </cn>
3045        <ci> y </ci>
3046      </apply>
3047    </apply>
3048  </apply>
3049</math>
3050\stopbuffer
3051
3052\processxmlbuffer
3053
3054\startbuffer
3055<math xmlns="http://www.w3c.org/mathml" version="2.0">
3056  <apply> <real/>
3057    <apply> <plus/>
3058      <ci> x </ci>
3059      <apply> <times/>
3060        <cn> &ImaginaryI; </cn>
3061        <ci> y </ci>
3062      </apply>
3063    </apply>
3064  </apply>
3065</math>
3066\stopbuffer
3067
3068\processxmlbuffer
3069
3070\startbuffer
3071<math xmlns="http://www.w3c.org/mathml" version="2.0">
3072  <apply> <imaginaryi/>
3073    <apply> <plus/>
3074      <ci> x </ci>
3075      <apply> <times/>
3076        <cn> &ImaginaryI; </cn>
3077        <ci> y </ci>
3078      </apply>
3079    </apply>
3080  </apply>
3081</math>
3082\stopbuffer
3083
3084\processxmlbuffer
3085
3086\stopsection
3087
3088\startsection[title={abs, floor, ceiling}]
3089
3090There are a couple of functions that turn numbers into positive or rounded ones.
3091In computer languages names are used, but in math we use special boundary
3092characters.
3093
3094\startbuffer
3095<math xmlns="http://www.w3c.org/mathml" version="2.0">
3096  <apply> <eq/>
3097    <apply> <abs/> <cn> -5 </cn> </apply>
3098    <cn> 5 </cn>
3099  </apply>
3100</math>
3101\stopbuffer
3102
3103\processxmlbuffer \typebuffer
3104
3105\startbuffer
3106<math xmlns="http://www.w3c.org/mathml" version="2.0">
3107  <apply> <eq/>
3108    <apply> <floor/> <cn> 5.5 </cn> </apply>
3109    <cn> 5 </cn>
3110  </apply>
3111</math>
3112\stopbuffer
3113
3114\processxmlbuffer \typebuffer
3115
3116\startbuffer
3117<math xmlns="http://www.w3c.org/mathml" version="2.0">
3118  <apply> <eq/>
3119    <apply> <ceiling/> <cn> 5.5 </cn> </apply>
3120    <cn> 6 </cn>
3121  </apply>
3122</math>
3123\stopbuffer
3124
3125\processxmlbuffer \typebuffer
3126
3127\stopsection
3128
3129\startsection[title={interval}]
3130
3131An interval is visualized as: \xmldata {<math xmlns="http://www.w3c.org/mathml"
3132version="2.0"> <interval> <cn> 1 </cn> <cn> 10 </cn> </interval> </math>}. The
3133\mmlelement {interval} element is a container element and has a begin and endtag.
3134You can specify the closure as attribute:
3135
3136\startbuffer
3137<math xmlns="http://www.w3c.org/mathml" version="2.0">
3138  <interval closure="open-closed">
3139    <ci> a </ci>
3140    <ci> b </ci>
3141  </interval>
3142</math>
3143\stopbuffer
3144
3145\processxmlbuffer \typebuffer
3146
3147The following closures are supported:
3148
3149\starttabulate[|||]
3150\HL
3151\NC open        \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <interval closure="open"> <ci>
3152                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
3153\NC closed      \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <interval closure="closed"> <ci>
3154                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
3155\NC open-closed \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <interval closure="open-closed"> <ci>
3156                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
3157\NC closed-open \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <interval closure="closed-open"> <ci>
3158                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
3159\HL
3160\stoptabulate
3161
3162In strict \MATHML\ we use symbols instead of attributes to define the openess:
3163
3164\startbuffer
3165<math xmlns="http://www.w3c.org/mathml" version="3.0">
3166    <apply> <csymbol cd="interval1">interval_oo</csymbol>
3167        <ci>a</ci>
3168        <ci>x</ci>
3169    </apply>
3170</math>
3171\stopbuffer
3172
3173\processxmlbuffer \typebuffer
3174
3175\startbuffer
3176<math xmlns="http://www.w3c.org/mathml" version="3.0">
3177    <apply> <csymbol cd="interval1">interval_cc</csymbol>
3178        <ci>a</ci>
3179        <ci>x</ci>
3180    </apply>
3181</math>
3182\stopbuffer
3183
3184\processxmlbuffer \typebuffer
3185
3186\stopsection
3187
3188\startsection[title={inverse}]
3189
3190This operator is applied to a function. The following example demonstrates that
3191this is one of the few cases (if not the only one) where the first element
3192following an \mmlelement {apply} begintag is an \mmlelement {apply} itself.
3193
3194\startbuffer
3195<math xmlns="http://www.w3c.org/mathml" version="2.0">
3196  <apply>
3197    <apply> <inverse/> <sin/> </apply>
3198    <ci> x </ci>
3199  </apply>
3200</math>
3201\stopbuffer
3202
3203\processxmlbuffer \typebuffer
3204
3205\stopsection
3206
3207\startsection[title={reln}]
3208
3209This element is a left||over from the first \MATHML\ specification and its usage
3210is no longer advocated. Its current functionality matches the functionality of
3211\mmlelement {apply}.
3212
3213\stopsection
3214
3215\startsection[title={cartesianproduct, vectorproduct, scalarproduct, outerproduct}]
3216
3217The context of the formula will often provide information of what kind of
3218multiplication is meant, but using different symbols to represent the kind of
3219product certainly helps.
3220
3221\startbuffer
3222<math xmlns="http://www.w3c.org/mathml" version="2.0">
3223  <apply> <cartesianproduct/>
3224    <ci> a </ci>
3225    <ci> b </ci>
3226  </apply>
3227</math>
3228\stopbuffer
3229
3230\processxmlbuffer \typebuffer
3231
3232We have:
3233
3234\starttabulate[|||]
3235\HL
3236\NC cartesian \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <apply> <cartesianproduct/> <ci>
3237                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
3238\NC vector    \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <apply> <vectorproduct/> <ci>
3239                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
3240\NC scalar    \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <apply> <scalarproduct/> <ci>
3241                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
3242\NC outer     \NC \xmldata {<math xmlns="http://www.w3c.org/mathml" version="2.0"> <apply> <outerproduct/> <ci>
3243                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
3244\HL
3245\stoptabulate
3246
3247\stopsection
3248
3249\startsection[title={sum, product, limit, lowlimit, uplimit, bvar}]
3250
3251Sums, products and limits have a distinctive look, especially when they have
3252upper and lower limits attached. Unfortunately there is no way to specify the
3253$x_i$ in content \MATHML. In the next chapter we will see how we can handle that.
3254
3255\startbuffer
3256<math xmlns="http://www.w3c.org/mathml" version="2.0">
3257  <apply> <sum/>
3258    <bvar> <ci> i </ci> </bvar>
3259    <lowlimit> <cn> 1 </cn> </lowlimit>
3260    <uplimit> <ci> n </ci> </uplimit>
3261    <apply> <divide/>
3262      <cn> 1 </cn>
3263      <ci> x </ci>
3264    </apply>
3265  </apply>
3266</math>
3267\stopbuffer
3268
3269\processxmlbuffer \typebuffer
3270
3271When we omit the limits, the \mmlelement {bvar} is still typeset.
3272
3273\startbuffer
3274<math xmlns="http://www.w3c.org/mathml" version="2.0">
3275  <apply> <product/>
3276    <bvar>
3277      <ci> i </ci>
3278    </bvar>
3279    <apply> <divide/>
3280      <cn> 1 </cn>
3281      <ci> x </ci>
3282    </apply>
3283  </apply>
3284</math>
3285\stopbuffer
3286
3287\processxmlbuffer \typebuffer
3288
3289You can specify the condition under which the function is applied.
3290
3291\startbuffer
3292<math xmlns="http://www.w3c.org/mathml" version="2.0">
3293  <apply> <product/>
3294    <bvar>
3295      <ci> x </ci>
3296    </bvar>
3297    <condition>
3298      <apply> <in/>
3299        <ci> x </ci>
3300        <ci type="set"> R </ci>
3301      </apply>
3302    </condition>
3303    <apply> <ci type="fn"> f </ci>
3304      <ci> x </ci>
3305    </apply>
3306  </apply>
3307</math>
3308\stopbuffer
3309
3310\processxmlbuffer \typebuffer
3311
3312\startbuffer
3313<math xmlns="http://www.w3c.org/mathml" version="2.0">
3314  <apply> <limit/>
3315    <bvar>
3316      <ci> x </ci>
3317    </bvar>
3318    <lowlimit>
3319      <cn> 0 </cn>
3320    </lowlimit>
3321    <apply> <sin/>
3322      <ci> x </ci>
3323    </apply>
3324  </apply>
3325</math>
3326\stopbuffer
3327
3328\processxmlbuffer \typebuffer
3329
3330\stopsection
3331
3332\startsection[title={int, diff, partialdiff, bvar, degree}]
3333
3334These elements reach a high level of abstraction. The best way to learn how to
3335use them is to carefully study some examples.
3336
3337\startbuffer
3338<math xmlns="http://www.w3c.org/mathml" version="2.0">
3339  <apply> <diff/>
3340    <bvar> <ci> a </ci> </bvar>
3341    <apply> <int/>
3342      <lowlimit> <ci> p </ci> </lowlimit>
3343      <uplimit>  <ci> q </ci> </uplimit>
3344      <bvar> <ci> x </ci> </bvar>
3345      <apply>
3346        <fn> <ci> f </ci> </fn>
3347        <ci> x </ci>
3348        <ci> a </ci>
3349      </apply>
3350    </apply>
3351  </apply>
3352</math>
3353\stopbuffer
3354
3355\processxmlbuffer \typebuffer
3356
3357The \mmlelement {bvar} element is essential, since it is used to automatically
3358generate some of the components that make up the visual appearance of the
3359formula. If you look at the formal specification of these elements, you will
3360notice that the appearance may depend on your definition. How the formula shows
3361up, depends not only on the \mmlelement {bvar} element, but also on the optional
3362\mmlelement {degree} element within.
3363
3364\startbuffer
3365<math xmlns="http://www.w3c.org/mathml" version="2.0">
3366  <apply> <diff/>
3367    <ci> f </ci>
3368  </apply>
3369</math>
3370\stopbuffer
3371
3372\processxmlbuffer \typebuffer
3373
3374\startbuffer
3375<math xmlns="http://www.w3c.org/mathml" version="2.0">
3376  <apply> <diff/>
3377    <bvar>
3378      <ci> x </ci>
3379      <degree> <cn> 2 </cn> </degree>
3380    </bvar>
3381    <apply> <fn> <ci> f </ci> </fn>
3382      <ci> x </ci>
3383    </apply>
3384  </apply>
3385</math>
3386\stopbuffer
3387
3388\processxmlbuffer \typebuffer
3389
3390\startbuffer
3391<math xmlns="http://www.w3c.org/mathml" version="2.0">
3392  <apply> <partialdiff/>
3393    <bvar>
3394      <degree> <cn> 2 </cn> </degree>
3395      <ci> x </ci>
3396    </bvar>
3397    <bvar> <ci> y </ci> </bvar>
3398    <bvar> <ci> x </ci> </bvar>
3399    <degree> <cn> 4 </cn> </degree>
3400    <ci type="fn"> f </ci>
3401  </apply>
3402</math>
3403\stopbuffer
3404
3405\processxmlbuffer \typebuffer
3406
3407\startbuffer
3408<math xmlns="http://www.w3c.org/mathml" version="2.0">
3409  <apply> <partialdiff/>
3410    <bvar>
3411      <ci> x </ci> <degree> <ci> m </ci> </degree>
3412    </bvar>
3413    <bvar>
3414      <ci> y </ci> <degree> <ci> n </ci> </degree>
3415    </bvar>
3416    <degree> <ci> k </ci> </degree>
3417    <apply> <ci type="fn"> f </ci>
3418      <ci> x </ci>
3419      <ci> y </ci>
3420    </apply>
3421  </apply>
3422</math>
3423\stopbuffer
3424
3425\processxmlbuffer \typebuffer
3426
3427\startbuffer
3428<math xmlns="http://www.w3c.org/mathml" version="2.0">
3429  <apply> <partialdiff/>
3430    <bvar>
3431      <ci> x </ci> <degree> <ci> m </ci> </degree>
3432    </bvar>
3433    <bvar>
3434      <ci> y </ci> <degree> <ci> n </ci> </degree>
3435    </bvar>
3436    <apply> <ci type="fn"> f </ci>
3437      <ci> x </ci>
3438      <ci> y </ci>
3439    </apply>
3440  </apply>
3441</math>
3442\stopbuffer
3443
3444\processxmlbuffer \typebuffer
3445
3446When a degree is not specified, it is deduced from the context, but since this is
3447not 100\% robust, you can best be complete in your specification.
3448
3449These examples are taken from the \MATHML\ specification. In the example document
3450that comes with this manual you can find a couple more.
3451
3452\stopsection
3453
3454\startsection[title={fn}]
3455
3456There are a lot of predefined functions and operators. If you want to introduce a
3457new one, the \mmlelement {fn} element can be used. In the following example we
3458have turned the $\pm$ and $\mp$ symbols into (coupled) operators.
3459
3460\startbuffer
3461<math xmlns="http://www.w3c.org/mathml" version="2.0">
3462  <apply> <eq/>
3463    <apply> <times/>
3464      <apply> <fn> <ci> &plusminus; </ci> </fn>
3465        <ci> x </ci>
3466        <cn> 1 </cn>
3467      </apply>
3468      <apply> <fn> <ci> &minusplus; </ci> </fn>
3469        <ci> x </ci>
3470        <cn> 1 </cn>
3471      </apply>
3472    </apply>
3473    <apply> <minus/>
3474      <apply> <power/>
3475        <ci> x </ci>
3476        <cn> 2 </cn>
3477      </apply>
3478      <cn> 1 </cn>
3479    </apply>
3480  </apply>
3481</math>
3482\stopbuffer
3483
3484\processxmlbuffer \typebuffer
3485
3486The typeset result depends on the presence of a handler, which in this case
3487happens to be true.
3488
3489\stopsection
3490
3491\startsection[title={matrix, matrixrow}]
3492
3493A matrix is one of the building blocks of linear algebra and therefore both
3494presentational and content \MATHML\ have dedicated elements for defining it.
3495
3496\startbuffer
3497<math xmlns="http://www.w3c.org/mathml" version="2.0">
3498  <matrix>
3499    <matrixrow> <cn> 23 </cn> <cn> 87 </cn> <ci>  c </ci> </matrixrow>
3500    <matrixrow> <cn> 41 </cn> <ci>  b </ci> <cn> 33 </cn> </matrixrow>
3501    <matrixrow> <ci>  a </ci> <cn> 65 </cn> <cn> 16 </cn> </matrixrow>
3502  </matrix>
3503</math>
3504\stopbuffer
3505
3506\processxmlbuffer \typebuffer
3507
3508\stopsection
3509
3510\startsection[title={vector}]
3511
3512We make a difference between a vector specification and a vector variable. A
3513specification is presented as a list:
3514
3515\startbuffer
3516<math xmlns="http://www.w3c.org/mathml" version="2.0">
3517  <vector>
3518    <ci> x </ci>
3519    <ci> y </ci>
3520  </vector>
3521</math>
3522\stopbuffer
3523
3524\processxmlbuffer \typebuffer
3525
3526When the \mmlelement {vector} element has one child element, we use a right arrow
3527to identify the variable as vector.
3528
3529\startbuffer
3530<math xmlns="http://www.w3c.org/mathml" version="2.0">
3531  <apply> <vectorproduct/>
3532    <vector> <ci> A </ci> </vector>
3533    <vector> <ci> B </ci> </vector>
3534  </apply>
3535</math>
3536\stopbuffer
3537
3538\processxmlbuffer \typebuffer
3539
3540\stopsection
3541
3542\startsection[title={grad, curl, ident, divergence}]
3543
3544These elements expand into named functions, but we can imagine that in the future
3545a more appropriate visualization will be provided as an option.
3546
3547\startbuffer
3548<math xmlns="http://www.w3c.org/mathml" version="2.0">
3549  <apply> <neq/>
3550    <apply> <grad/>       <ci> A </ci> </apply>
3551    <apply> <curl/>       <ci> B </ci> </apply>
3552    <apply> <ident/>      <ci> C </ci> </apply>
3553    <apply> <divergence/> <ci> D </ci> </apply>
3554  </apply>
3555</math>
3556\stopbuffer
3557
3558\processxmlbuffer \typebuffer
3559
3560\stopsection
3561
3562\startsection[title={lambda, bvar}]
3563
3564The lambda specification of a function needs a \mmlelement {bvar} element. The
3565visualization can be influenced with processing instructions as described in a
3566later chapter.
3567
3568\startbuffer
3569<math xmlns="http://www.w3c.org/mathml" version="2.0">
3570  <lambda>
3571    <bvar> <ci> x </ci> </bvar>
3572    <apply> <sin/>
3573      <apply> <minus/>
3574        <ci> x </ci>
3575        <apply> <divide/>
3576          <ci> x </ci>
3577          <cn> 2 </cn>
3578        </apply>
3579      </apply>
3580    </apply>
3581  </lambda>
3582</math>
3583\stopbuffer
3584
3585\processxmlbuffer \typebuffer
3586
3587\stopsection
3588
3589\startsection[title={piecewise, piece, otherwise}]
3590
3591There are not so many elements that deal with combinations of formulas or
3592conditions. The \mmlelement {piecewise} is the only real selector available. The
3593following example defines how the state of~$n$ depends on the state of~$x$.
3594
3595\startbuffer
3596<math xmlns="http://www.w3c.org/mathml" version="2.0">
3597  <apply> <eq/>
3598    <ci> n </ci>
3599    <piecewise>
3600      <piece>
3601        <apply> <minus/>
3602          <cn> 1 </cn>
3603        </apply>
3604        <apply> <lt/>
3605          <ci> x </ci>
3606          <cn> 0 </cn>
3607        </apply>
3608      </piece>
3609      <piece>
3610        <cn> 1 </cn>
3611        <apply> <gt/>
3612          <ci> x </ci>
3613          <cn> 0 </cn>
3614        </apply>
3615      </piece>
3616      <otherwise>
3617        <cn> 0 </cn>
3618      </otherwise>
3619    </piecewise>
3620  </apply>
3621</math>
3622\stopbuffer
3623
3624\processxmlbuffer \typebuffer
3625
3626We could have used a third \mmlelement {piece} instead of (optional) \mmlelement
3627{otherwise}.
3628
3629\stopsection
3630
3631\startsection[title={forall, exists, condition}]
3632
3633Conditions are often used in combination with elements like \mmlelement {forall}.
3634There are several ways to convert and combine them in formulas and environments,
3635so you may expect more alternatives in the future.
3636
3637\startbuffer
3638<math xmlns="http://www.w3c.org/mathml" version="2.0">
3639  <apply> <forall/>
3640    <bvar> <ci> x </ci> </bvar>
3641    <condition>
3642      <apply> <lt/>
3643        <ci> x </ci>
3644        <cn> 9 </cn>
3645      </apply>
3646    </condition>
3647    <apply> <lt/>
3648      <ci> x </ci>
3649      <cn> 10 </cn>
3650    </apply>
3651  </apply>
3652</math>
3653\stopbuffer
3654
3655\processxmlbuffer \typebuffer
3656
3657The next example is taken from the specifications with a few small changes.
3658
3659\startbuffer
3660<math xmlns="http://www.w3c.org/mathml" version="2.0">
3661  <apply> <forall/>
3662    <bvar> <ci> x </ci> </bvar>
3663    <condition>
3664      <apply> <in/>
3665        <ci> x </ci>
3666        <ci type="set"> N </ci>
3667      </apply>
3668    </condition>
3669    <apply> <exists/>
3670      <bvar> <ci> p </ci> </bvar>
3671      <bvar> <ci> q </ci> </bvar>
3672      <condition>
3673        <apply> <and/>
3674          <apply> <in/>
3675            <ci> p </ci>
3676            <ci type="set"> P </ci>
3677          </apply>
3678          <apply> <in/>
3679            <ci> q </ci>
3680            <ci type="set"> P </ci>
3681          </apply>
3682          <apply> <eq/>
3683            <apply> <plus/> <ci> p </ci> <ci> q </ci> </apply>
3684            <apply> <times/> <cn> 2 </cn> <ci> x </ci> </apply>
3685          </apply>
3686        </apply>
3687      </condition>
3688    </apply>
3689  </apply>
3690</math>
3691\stopbuffer
3692
3693\processxmlbuffer \typebuffer
3694
3695\stopsection
3696
3697\startsection[title={factorof, tendsto}]
3698
3699The \mmlelement {factorof} element is applied to its two child elements and
3700contrary to most functions, the symbol is placed between the elements instead of
3701in front.
3702
3703\startbuffer
3704<math xmlns="http://www.w3c.org/mathml" version="2.0">
3705  <apply> <factorof/>
3706    <ci> a </ci>
3707    <ci> b </ci>
3708  </apply>
3709</math>
3710\stopbuffer
3711
3712\processxmlbuffer \typebuffer
3713
3714The same is true for the \mmlelement {tendsto} element.
3715
3716\startbuffer
3717<math xmlns="http://www.w3c.org/mathml" version="2.0">
3718  <apply> <tendsto/>
3719    <ci> a </ci>
3720    <ci> b </ci>
3721  </apply>
3722</math>
3723\stopbuffer
3724
3725\processxmlbuffer \typebuffer
3726
3727\stopsection
3728
3729\startsection[title={compose}]
3730
3731This is a nasty element since it has to take care of braces in special ways and
3732therefore has to analyse its child elements.
3733
3734\startbuffer
3735<math xmlns="http://www.w3c.org/mathml" version="2.0">
3736  <apply> <compose/>
3737    <ci type="fn"> f </ci>
3738    <ci type="fn"> g </ci>
3739    <ci type="fn"> h </ci>
3740  </apply>
3741</math>
3742\stopbuffer
3743
3744\processxmlbuffer \typebuffer
3745
3746\startbuffer
3747<math xmlns="http://www.w3c.org/mathml" version="2.0">
3748  <apply>
3749    <apply> <compose/>
3750      <fn> <ci> f </ci> </fn>
3751      <fn> <ci> g </ci> </fn>
3752    </apply>
3753    <ci> x </ci>
3754  </apply>
3755</math>
3756\stopbuffer
3757
3758\processxmlbuffer \typebuffer
3759
3760\stopsection
3761
3762\startsection[title={laplacian}]
3763
3764A laplacian function is typeset using a $\nabla$ (nabla) symbol.
3765
3766\startbuffer
3767<math xmlns="http://www.w3c.org/mathml" version="2.0">
3768  <apply> <laplacian/>
3769    <ci> x </ci>
3770  </apply>
3771</math>
3772\stopbuffer
3773
3774\processxmlbuffer \typebuffer
3775
3776\stopsection
3777
3778\startsection[title={mean, sdev, variance, median, mode}]
3779
3780When statistics shows up in math text books, the \mmlelement {sum} element is
3781likely to show up, probably in combination with the for statistics meaningful
3782symbolic representation of variables. The mean value of a series of observations
3783is defined as:
3784
3785\startbuffer
3786<math xmlns="http://www.w3c.org/mathml" version="2.0">
3787  <apply> <eq/>
3788    <apply> <mean/>
3789      <ci> x </ci>
3790    </apply>
3791    <apply> <divide/>
3792      <apply> <sum/>
3793        <ci> x </ci>
3794      </apply>
3795      <ci> n </ci>
3796    </apply>
3797  </apply>
3798</math>
3799\stopbuffer
3800
3801\processxmlbuffer \typebuffer
3802
3803or more beautiful:
3804
3805\startbuffer
3806<math xmlns="http://www.w3c.org/mathml" version="2.0">
3807  <apply> <eq/>
3808    <apply> <mean/>
3809      <ci> x </ci>
3810    </apply>
3811    <apply> <times/>
3812      <apply> <divide/>
3813        <cn> 1 </cn>
3814        <ci> n </ci>
3815      </apply>
3816      <apply> <sum/>
3817        <ci> x </ci>
3818      </apply>
3819    </apply>
3820  </apply>
3821</math>
3822\stopbuffer
3823
3824\processxmlbuffer \typebuffer
3825
3826Of course this definition is not that perfect, but we will present a better
3827alternative in the chapter on combined markup. The definition of the standard
3828deviation is more complicated:
3829
3830\startbuffer
3831<math xmlns="http://www.w3c.org/mathml" version="2.0">
3832  <apply> <approx/>
3833    <apply> <sdev/>
3834      <ci> x </ci>
3835    </apply>
3836    <apply> <root/>
3837      <apply> <divide/>
3838        <apply> <sum/>
3839          <apply> <power/>
3840            <apply> <minus/>
3841              <ci> x </ci>
3842              <apply> <mean/>
3843                <ci> x </ci>
3844              </apply>
3845            </apply>
3846            <cn> 2 </cn>
3847          </apply>
3848        </apply>
3849        <apply> <minus/>
3850          <ci> n </ci>
3851          <cn> 1 </cn>
3852        </apply>
3853      </apply>
3854    </apply>
3855  </apply>
3856</math>
3857\stopbuffer
3858
3859\processxmlbuffer \typebuffer
3860
3861The next example demonstrates the usage of the \mmlelement {variance} in its own
3862definition.
3863
3864\startbuffer
3865<math xmlns="http://www.w3c.org/mathml" version="2.0">
3866  <apply> <eq/>
3867    <apply> <variance/>
3868      <ci> x </ci>
3869    </apply>
3870    <apply> <approx/>
3871      <apply> <mean/>
3872        <apply> <power/>
3873          <apply> <minus/>
3874            <ci> x </ci>
3875            <apply> <mean/>
3876              <ci> x </ci>
3877            </apply>
3878          </apply>
3879          <cn> 2 </cn>
3880        </apply>
3881      </apply>
3882      <apply> <times/>
3883        <apply> <divide/>
3884          <cn> 1 </cn>
3885          <apply> <minus/>
3886            <ci> n </ci>
3887            <cn> 1 </cn>
3888          </apply>
3889        </apply>
3890        <apply> <sum/>
3891          <apply> <power/>
3892            <apply> <minus/>
3893              <ci> x </ci>
3894              <apply> <mean/>
3895                <ci> x </ci>
3896              </apply>
3897            </apply>
3898            <cn> 2 </cn>
3899          </apply>
3900        </apply>
3901      </apply>
3902    </apply>
3903  </apply>
3904</math>
3905\stopbuffer
3906
3907\processxmlbuffer \typebuffer
3908
3909The \mmlelement {median} and \mmlelement {mode} of a series of observations have
3910no special symbols and are presented as is.
3911
3912\stopsection
3913
3914\startsection[title={moment, momentabout, degree}]
3915
3916Because \MATHML\ is used for a wide range of applications, there can be
3917information in a definition that does not end up in print but is only used in
3918some cases. This is illustrated in the next example.
3919
3920\startbuffer
3921<math xmlns="http://www.w3c.org/mathml" version="2.0">
3922  <apply> <moment/>
3923    <degree>
3924      <cn> 3 </cn>
3925    </degree>
3926    <momentabout>
3927      <ci> p </ci>
3928    </momentabout>
3929    <ci> X </ci>
3930  </apply>
3931</math>
3932\stopbuffer
3933
3934\processxmlbuffer \typebuffer
3935
3936\stopsection
3937
3938\startsection[title={determinant, transpose}]
3939
3940These two (and the following) are used to manipulate matrices, either or not in a
3941symbolic way. A simple determinant or transpose looks like:
3942
3943\startbuffer
3944<math xmlns="http://www.w3c.org/mathml" version="2.0">
3945  <apply> <determinant/>
3946    <ci type="matrix"> A </ci>
3947  </apply>
3948</math>
3949\stopbuffer
3950
3951\processxmlbuffer \typebuffer
3952
3953\startbuffer
3954<math xmlns="http://www.w3c.org/mathml" version="2.0">
3955  <apply> <transpose/>
3956    <ci type="matrix"> A </ci>
3957  </apply>
3958</math>
3959\stopbuffer
3960
3961\processxmlbuffer \typebuffer
3962
3963When the \mmlelement {determinant} element is applied to a full blown matrix, the
3964braces are omitted and replaced by the vertical bars.
3965
3966\processxmlfile{wh-m-002.xml} \typefile{wh-m-002.xml}
3967
3968\stopsection
3969
3970\startsection[title={selector}]
3971
3972The \mmlelement {selector} element can be used to index a matrix cell or
3973variable. This element honors the braces.
3974
3975\startbuffer
3976<math xmlns="http://www.w3c.org/mathml" version="2.0">
3977  <apply> <selector/>
3978    <matrix>
3979      <matrixrow> <cn> 1 </cn> <cn> 2 </cn> </matrixrow>
3980      <matrixrow> <cn> 3 </cn> <cn> 4 </cn> </matrixrow>
3981    </matrix>
3982    <cn> 1 </cn>
3983  </apply>
3984</math>
3985\stopbuffer
3986
3987\processxmlbuffer \typebuffer
3988
3989A more common usage of the selector is the following:
3990
3991\startbuffer
3992<math xmlns="http://www.w3c.org/mathml" version="2.0">
3993  <apply> <selector/>
3994    <ci> x </ci>
3995    <ci> i </ci>
3996  </apply>
3997</math>
3998\stopbuffer
3999
4000\processxmlbuffer \typebuffer
4001
4002It is possible to pass a comma separated list of indices:
4003
4004\startbuffer
4005<math xmlns="http://www.w3c.org/mathml" version="2.0">
4006  <apply> <selector/>
4007    <ci> x </ci> <cn> 1,2 </cn>
4008  </apply>
4009</math>
4010\stopbuffer
4011
4012\processxmlbuffer \typebuffer
4013
4014If you want to have a more verbose index, you can use the \mmlelement {csymbol}
4015element, flagged with text encoding.
4016
4017\startbuffer
4018<math xmlns="http://www.w3c.org/mathml" version="2.0">
4019  <apply> <selector/>
4020    <ci> x </ci>
4021    <csymbol encoding="text"> max </csymbol>
4022  </apply>
4023</math>
4024\stopbuffer
4025
4026\processxmlbuffer \typebuffer
4027
4028\stopsection
4029
4030\startsection[title={card}]
4031
4032A cardinality is visualized using vertical bars.
4033
4034\startbuffer
4035<math xmlns="http://www.w3c.org/mathml" version="2.0">
4036  <apply> <eq/>
4037    <apply> <card/>
4038      <ci> A </ci>
4039    </apply>
4040    <ci> 5 </ci>
4041  </apply>
4042</math>
4043\stopbuffer
4044
4045\processxmlbuffer \typebuffer
4046
4047\stopsection
4048
4049\startsection[title={domain, codomain, image}]
4050
4051The next couple of examples are taken from the \MATHML\ specification and
4052demonstrate the usage of the not that spectacular domain related elements.
4053
4054\startbuffer
4055<math xmlns="http://www.w3c.org/mathml" version="2.0">
4056  <apply> <eq/>
4057    <apply> <domain/>
4058      <fn> <ci> f </ci> </fn>
4059    </apply>
4060    <reals/>
4061  </apply>
4062</math>
4063\stopbuffer
4064
4065\processxmlbuffer \typebuffer
4066
4067These are typically situations where the \mmlelement {fn} element may show up.
4068
4069\startbuffer
4070<math xmlns="http://www.w3c.org/mathml" version="2.0">
4071  <apply> <eq/>
4072    <apply> <codomain/>
4073      <fn> <ci> f </ci> </fn>
4074    </apply>
4075    <rationals/>
4076  </apply>
4077</math>
4078\stopbuffer
4079
4080\processxmlbuffer \typebuffer
4081
4082This example from the \MATHML\ specification demonstrates a typical usage of the
4083\mmlelement {image} element. As with the previous two, it is applied to a
4084function, in this case the predefined \mmlelement {sin}.
4085
4086\startbuffer
4087<math xmlns="http://www.w3c.org/mathml" version="2.0">
4088  <apply> <eq/>
4089    <apply> <image/>
4090      <sin/>
4091    </apply>
4092    <interval>
4093      <cn> -1 </cn>
4094      <cn>  1 </cn>
4095    </interval>
4096  </apply>
4097</math>
4098\stopbuffer
4099
4100\processxmlbuffer \typebuffer
4101
4102\stopsection
4103
4104\startsection[title={domainofapplication}]
4105
4106This is another seldom used element. Actually, this element is a further
4107specification of the outer level applied function.
4108
4109\startbuffer
4110<math xmlns="http://www.w3c.org/mathml" version="2.0">
4111  <apply> <int/>
4112    <domainofapplication>
4113      <ci> C </ci>
4114    </domainofapplication>
4115    <ci> f </ci>
4116  </apply>
4117</math>
4118\stopbuffer
4119
4120\processxmlbuffer \typebuffer
4121
4122\stopsection
4123
4124\startsection[title={semantics, annotation, annotation-xml}]
4125
4126We will never know what Albert Einstein would have thought about \MATHML. But we
4127do know for sure that coding one of his famous findings in \XML\ takes much more
4128tokens that it takes in \TEX.
4129
4130\startbuffer
4131<math xmlns="http://www.w3c.org/mathml" version="2.0">
4132  <semantics>
4133    <apply> <eq/>
4134      <ci> e </ci>
4135      <apply> <times/>
4136        <ci> m </ci>
4137        <apply> <power/>
4138          <ci> c </ci>
4139          <cn> 2 </cn>
4140        </apply>
4141      </apply>
4142    </apply>
4143    <annotation encoding="tex">
4144      e = m c^2
4145    </annotation>
4146  </semantics>
4147</math>
4148\stopbuffer
4149
4150Within a \mmlelement {semantics} element there can be many \mmlelement
4151{annotation} elements. When using \CONTEXT, the elements that can be identified
4152as being encoded in \TEX\ will be treated as such. Currently, the related
4153\mmlelement {annotation-xml} element is ignored.
4154
4155\processxmlbuffer \typebuffer
4156
4157Another variant that we support is called \quote {calcmath} which is an efficient
4158way to enter school math. The syntax resembles the one used in advanced
4159calculators.
4160
4161\startbuffer
4162<math xmlns="http://www.w3c.org/mathml" version="2.0">
4163  <semantics>
4164    <annotation encoding="calcmath">
4165      x = sqrt(sin(x) + cos(c))
4166    </annotation>
4167  </semantics>
4168</math>
4169\stopbuffer
4170
4171\processxmlbuffer \typebuffer
4172
4173\stopsection
4174
4175\startsection[title={integers, reals, ...}]
4176
4177Sets of numbers are characterized with special (often blackboard) symbols. These
4178symbols are not always available.
4179
4180\starttabulate[|||] % we want in line math
4181\HL
4182\NC integers       \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><integers/>      </math>} \NC \NR
4183\NC reals          \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><reals/>         </math>} \NC \NR
4184\NC rationals      \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><rationals/>     </math>} \NC \NR
4185\NC naturalnumbers \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><naturalnumbers/></math>} \NC \NR
4186\NC complexes      \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><complexes/>     </math>} \NC \NR
4187\NC primes         \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><primes/>        </math>} \NC \NR
4188\HL
4189\stoptabulate
4190
4191\stopsection
4192
4193\startsection[title={pi, imaginaryi, exponentiale}]
4194
4195Being a greek character, $\pi$ is a distinctive character. In most math documents
4196the imaginary~$i$ and exponential~$e$ are typeset as any math identifier.
4197
4198\starttabulate[|||] % we want in line math
4199\HL
4200\NC pi           \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><pi/>          </math>} \NC \NR
4201\NC imaginaryi   \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><imaginaryi/>  </math>} \NC \NR
4202\NC exponentiale \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><exponentiale/></math>} \NC \NR
4203\HL
4204\stoptabulate
4205
4206\stopsection
4207
4208\startsection[title={eulergamma, infinity, emptyset}]
4209
4210There are a couple of more special tokens. As with the other ones, they can be
4211changed by reassigning the corresponding entities.
4212
4213\starttabulate[|||] % we want in line math
4214\HL
4215\NC eulergamma \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><eulergamma/></math>} \NC \NR
4216\NC infinity   \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><infinity/>  </math>} \NC \NR
4217\NC emptyset   \NC \xmldata{<math xmlns="http://www.w3c.org/mathml" version="2.0"><emptyset/>  </math>} \NC \NR
4218\HL
4219\stoptabulate
4220
4221\stopsection
4222
4223\startsection[title={notanumber}]
4224
4225Because \MATHML\ is used for more purposes than typesetting, there are a couple
4226of elements that do not make much sense in print. One of these is \mmlelement
4227{notanumber}, which is issued by programs as error code or string.
4228
4229\startbuffer
4230<math xmlns="http://www.w3c.org/mathml" version="2.0">
4231  <apply> <eq/>
4232    <apply> <divide/>
4233      <ci> x </ci>
4234      <cn> 0 </cn>
4235    </apply>
4236    <notanumber/>
4237  </apply>
4238</math>
4239\stopbuffer
4240
4241\processxmlbuffer \typebuffer
4242
4243\stopsection
4244
4245\startsection[title={true, false}]
4246
4247When assigning to a boolean variable, or in boolean expressions one can use~$0$
4248or~$1$ to identify the states, but if you want to be more verbose, you can use
4249these elements.
4250
4251\startbuffer
4252<math xmlns="http://www.w3c.org/mathml" version="2.0">
4253  <apply> <equivalent/>
4254    <cn type="integer" base="2"> 1 </cn>
4255    <true/>
4256  </apply>
4257</math>
4258\stopbuffer
4259
4260\processxmlbuffer \typebuffer
4261
4262\stopsection
4263
4264\startsection[title={declare}]
4265
4266Reusing definitions would be a nice feature, but for the moment the formal
4267specification of this element does not give us the freedom to use it the way we
4268want.
4269
4270\startbuffer
4271<math xmlns="http://www.w3c.org/mathml" version="2.0">
4272  <declare>
4273    <ci> A </ci>
4274    <vector>
4275      <ci> a </ci>
4276      <ci> b </ci>
4277      <ci> c </ci>
4278    </vector>
4279  </declare>
4280</math>
4281\stopbuffer
4282
4283\processxmlbuffer \typebuffer
4284
4285\stopsection
4286
4287\startsection[title={csymbol}]
4288
4289This element will be implemented as soon as we have an application for it.
4290
4291\stopsection
4292
4293\stopchapter
4294
4295\startchapter[title={Mixed markup}]
4296
4297\startsection[title={introduction}]
4298
4299The advantage of presentational markup is that you can build complicated formulas
4300using super- and subscripts and other elements. The drawback is that the look and
4301feel is rather fixed and cannot easily be adapted to the purpose that the
4302document serves. Take for instance the difference between
4303
4304\startbuffer
4305<math xmlns="http://www.w3c.org/mathml" version="2.0">
4306  <apply> <log/>
4307    <logbase> <cn> 2 </cn> </logbase>
4308    <ci> x </ci>
4309  </apply>
4310</math>
4311\stopbuffer
4312
4313\processxmlbuffer
4314
4315and
4316
4317\startbuffer
4318<math xmlns="http://www.w3c.org/mathml" version="2.0">
4319  <?context-mathml-directive log location left ?>
4320  <apply> <log/>
4321    <logbase> <cn> 2 </cn> </logbase>
4322    <ci> x </ci>
4323  </apply>
4324</math>
4325\stopbuffer
4326
4327\processxmlbuffer
4328
4329Both formulas were defined in content \MATHML, so no explicit super- and
4330subscripts were used. In the next chapter we will see how to achieve such
4331different appearances.
4332
4333There are situations where content \MATHML\ is not rich enough to achieve the
4334desired output. This omission in content \MATHML\ forces us to fall back on
4335presentational markup.
4336
4337\startbuffer
4338<math xmlns="http://www.w3c.org/mathml" version="2.0">
4339  <apply> <eq/>
4340    <ci> <msub> <mi> P </mi> <mi> 1 </mi> </msub> </ci>
4341    <ci> <msub> <mi> P </mi> <mi> 2 </mi> </msub> </ci>
4342    <apply> <approx/>
4343      <cn> 1.01 </cn>
4344      <cn> 1 </cn>
4345    </apply>
4346  </apply>
4347</math>
4348\stopbuffer
4349
4350\processxmlbuffer
4351
4352Here we used presentational elements inside a content \mmlelement {ci} element.
4353We could have omitted the outer \mmlelement {ci} element, but since the content
4354\MATHML\ parser may base its decisions on the content elements it finds, it is
4355best to keep the outer element there.
4356
4357\typebuffer
4358
4359The lack of an index element can be quite prominent. For instance, when in an
4360expose about rendering we want to explore the mapping from coordinates in user
4361space to those in device space, we use the following formula.
4362
4363\startbuffer
4364<math xmlns="http://www.w3c.org/mathml" version="2.0">
4365  <apply> <eq/>
4366    <vector>
4367      <ci> <msub> <mi> D </mi> <mi> x </mi> </msub> </ci>
4368      <ci> <msub> <mi> D </mi> <mi> y </mi> </msub> </ci>
4369      <cn> 1 </cn>
4370    </vector>
4371    <apply> <times/>
4372      <vector>
4373        <ci> <msub> <mi> U </mi> <mi> x </mi> </msub> </ci>
4374        <ci> <msub> <mi> U </mi> <mi> y </mi> </msub> </ci>
4375        <cn> 1 </cn>
4376      </vector>
4377      <matrix>
4378        <matrixrow>
4379          <ci> <msub> <mi> s </mi> <mi> x </mi> </msub> </ci>
4380          <ci> <msub> <mi> r </mi> <mi> x </mi> </msub> </ci>
4381          <cn> 0 </cn>
4382        </matrixrow>
4383        <matrixrow>
4384          <ci> <msub> <mi> r </mi> <mi> y </mi> </msub> </ci>
4385          <ci> <msub> <mi> s </mi> <mi> y </mi> </msub> </ci>
4386          <cn> 0 </cn>
4387        </matrixrow>
4388        <matrixrow>
4389          <ci> <msub> <mi> t </mi> <mi> x </mi> </msub> </ci>
4390          <ci> <msub> <mi> t </mi> <mi> y </mi> </msub> </ci>
4391          <cn> 1 </cn>
4392        </matrixrow>
4393      </matrix>
4394    </apply>
4395  </apply>
4396</math>
4397\stopbuffer
4398
4399\processxmlbuffer \typebuffer
4400
4401Again, the \mmlelement {msub} element provides a way out, as in the next
4402examples, which are adapted versions of formulas we used when demonstrating the
4403statistics related elements.
4404
4405\startbuffer
4406<math xmlns="http://www.w3c.org/mathml" version="2.0">
4407  <apply> <eq/>
4408    <apply> <mean/>
4409      <ci> x </ci>
4410    </apply>
4411    <apply> <times/>
4412      <apply> <divide/>
4413        <cn> 1 </cn>
4414        <ci> n </ci>
4415      </apply>
4416      <apply> <sum/>
4417        <bvar> <ci> i </ci> </bvar>
4418        <ci> x </ci>
4419      </apply>
4420    </apply>
4421  </apply>
4422</math>
4423\stopbuffer
4424
4425\processxmlbuffer \typebuffer
4426
4427\startbuffer
4428<math xmlns="http://www.w3c.org/mathml" version="2.0">
4429  <apply> <eq/>
4430    <apply> <mean/>
4431      <ci> x </ci>
4432    </apply>
4433    <apply> <times/>
4434      <apply> <divide/>
4435        <cn> 1 </cn>
4436        <ci> n </ci>
4437      </apply>
4438      <apply> <sum/>
4439        <bvar> <ci> i </ci> </bvar>
4440        <lowlimit> <cn> 1 </cn> </lowlimit>
4441        <uplimit> <cn> n </cn> </uplimit>
4442        <ci> x </ci>
4443      </apply>
4444    </apply>
4445  </apply>
4446</math>
4447\stopbuffer
4448
4449\processxmlbuffer \typebuffer
4450
4451\startbuffer
4452<math xmlns="http://www.w3c.org/mathml" version="2.0">
4453  <apply> <eq/>
4454    <apply> <mean/>
4455      <ci> x </ci>
4456    </apply>
4457    <apply> <times/>
4458      <apply> <divide/>
4459        <cn> 1 </cn>
4460        <ci> n </ci>
4461      </apply>
4462      <apply> <sum/>
4463        <bvar> <ci> i </ci> </bvar>
4464        <lowlimit> <cn> 1 </cn> </lowlimit>
4465        <uplimit> <cn> n </cn> </uplimit>
4466        <ci> <msub> <mi> x </mi> <mi> i </mi> </msub> </ci>
4467      </apply>
4468    </apply>
4469  </apply>
4470</math>
4471\stopbuffer
4472
4473\processxmlbuffer \typebuffer
4474
4475You can also use a selector for indexing, so in practice we can avoid the mixed
4476mode:
4477
4478\startbuffer
4479<math xmlns="http://www.w3c.org/mathml" version="2.0">
4480  <apply> <eq/>
4481    <vector>
4482      <apply> <selector/> <ci> D </ci> <ci> x </ci> </apply>
4483      <apply> <selector/> <ci> D </ci> <ci> y </ci> </apply>
4484      <cn> 1 </cn>
4485    </vector>
4486    <apply> <times/>
4487      <vector>
4488        <apply> <selector/> <ci> U </ci> <ci> x </ci> </apply>
4489        <apply> <selector/> <ci> U </ci> <ci> y </ci> </apply>
4490        <cn> 1 </cn>
4491      </vector>
4492      <matrix>
4493        <matrixrow>
4494          <apply> <selector/> <ci> s </ci> <ci> x </ci> </apply>
4495          <apply> <selector/> <ci> r </ci> <ci> x </ci> </apply>
4496          <cn> 0 </cn>
4497        </matrixrow>
4498        <matrixrow>
4499          <apply> <selector/> <ci> s </ci> <ci> y </ci> </apply>
4500          <apply> <selector/> <ci> r </ci> <ci> y </ci> </apply>
4501          <cn> 0 </cn>
4502        </matrixrow>
4503        <matrixrow>
4504          <apply> <selector/> <ci> t </ci> <ci> x </ci> </apply>
4505          <apply> <selector/> <ci> t </ci> <ci> y </ci> </apply>
4506          <cn> 1 </cn>
4507        </matrixrow>
4508      </matrix>
4509    </apply>
4510  </apply>
4511</math>
4512\stopbuffer
4513
4514\processxmlbuffer \typebuffer
4515
4516\stopsection
4517
4518\stopchapter
4519
4520\startchapter[title={Directives}]
4521
4522Some elements can be tuned by changing their attributes. Especially when formulas
4523are defined by a team of people or when they are taken from a repository, there
4524is a good chance that inconsistencies will show up.
4525
4526In \CONTEXT, you can influence the appearance by setting the typesetting
4527parameters of (classes of) elements. You can do this either by adding processing
4528instructions, or by using the \CONTEXT\ command \type {\setupMMLappearance}.
4529Although the first method is more in the spirit of \XML, the second method is
4530more efficient and consistent. As a processing instruction, a directive looks
4531like:
4532
4533\starttyping
4534<?context-mathml-directive element key value ?>
4535\stoptyping
4536
4537This is equivalent to the \CONTEXT\ command:
4538
4539\starttyping
4540\setupMMLappearance [element] [key=value]
4541\stoptyping
4542
4543Some settings concern a group of elements, in which case a group classification
4544(like \type {sign}) is used.
4545
4546\startsection[title={scripts}]
4547
4548By default, nested super- and subscripts are kind of isolated from each other. If
4549you want a combined script, there is the \mmlelement {msubsup}. You can however
4550force combinations with a directive.
4551
4552\startbuffer
4553<math xmlns="http://www.w3c.org/mathml" version="2.0">
4554  <msup>
4555    <msub> <mi> x </mi> <mn> 1 </mn> </msub>
4556    <mn> 2 </mn>
4557  </msup>
4558</math>
4559\stopbuffer
4560
4561\processxmlbuffer \typebuffer
4562
4563\startbuffer
4564<?context-mathml-directive scripts alternative b ?>
4565
4566<math xmlns="http://www.w3c.org/mathml" version="2.0">
4567  <msup>
4568    <msub> <mi> x </mi> <mn> 1 </mn> </msub>
4569    <mn> 2 </mn>
4570  </msup>
4571</math>
4572\stopbuffer
4573
4574\processxmlbuffer \typebuffer
4575
4576\stopsection
4577
4578\startsection[title={sign}]
4579
4580The core element of \MATHML\ is \mmlelement {apply}. Even simple formulas will
4581often have more than one (nested) \mmlelement {apply}. The most robust way to
4582handle nested formulas is to use braces around each sub formula. No matter how
4583robust this is, when presented in print we want to use as less braces as
4584possible. The next example shows addition as well as subtraction.
4585
4586\startbuffer
4587<math xmlns="http://www.w3c.org/mathml" version="2.0">
4588  <apply> <plus/>
4589    <cn> 7 </cn>
4590    <cn> 5 </cn>
4591    <apply> <minus/>
4592      <cn> 3 </cn>
4593    </apply>
4594  </apply>
4595</math>
4596\stopbuffer
4597
4598\processxmlbuffer \typebuffer
4599
4600In principle subtraction is adding negated numbers, so it would have been natural
4601to have just an addition (\mmlelement {plus}) and negation operator. However,
4602\MATHML\ provides both a \mmlelement {plus} and \mmlelement {minus} operator,
4603where the latter can be used as a negation. So in fact we have:
4604
4605\startbuffer
4606<math xmlns="http://www.w3c.org/mathml" version="2.0">
4607  <?context-mathml-directive sign reduction no ?>
4608  <apply> <plus/>
4609    <cn> 7 </cn>
4610    <cn> 5 </cn>
4611    <apply> <minus/>
4612      <cn> 3 </cn>
4613    </apply>
4614  </apply>
4615</math>
4616\stopbuffer
4617
4618\processxmlbuffer
4619
4620Now imagine that a teacher wants to stress this negation in the way presented
4621here, using parentheses. Since all the examples shown here are typeset directly
4622from the \MATHML\ source, you may expect a solution, so here it is:
4623
4624\typebuffer
4625
4626By default signs are reduced, but one can disable that at the document and|/|or
4627formula level using a processing instruction at the top of the formula. There are
4628of course circumstances where the parentheses cannot be left out.
4629
4630\startbuffer
4631<math xmlns="http://www.w3c.org/mathml" version="2.0">
4632  <apply> <plus/>
4633    <ci> a </ci>
4634    <apply> <plus/> <ci> b </ci> <ci> c </ci> </apply>
4635    <ci> d </ci>
4636  </apply>
4637</math>
4638\stopbuffer
4639
4640\processxmlbuffer \typebuffer
4641
4642\startbuffer
4643<math xmlns="http://www.w3c.org/mathml" version="2.0">
4644  <apply> <minus/>
4645    <ci> a </ci>
4646    <apply> <minus/> <ci> b </ci> <ci> c </ci> </apply>
4647    <ci> d </ci>
4648  </apply>
4649</math>
4650\stopbuffer
4651
4652\processxmlbuffer \typebuffer
4653
4654\startbuffer
4655<math xmlns="http://www.w3c.org/mathml" version="2.0">
4656  <apply> <plus/>
4657    <ci> a </ci>
4658    <apply> <minus/> <ci> b </ci> <ci> c </ci> </apply>
4659    <ci> d </ci>
4660  </apply>
4661</math>
4662\stopbuffer
4663
4664\processxmlbuffer \typebuffer
4665
4666\startbuffer
4667<math xmlns="http://www.w3c.org/mathml" version="2.0">
4668  <apply> <minus/>
4669    <ci> a </ci>
4670    <apply> <plus/> <ci> b </ci> <ci> c </ci> </apply>
4671    <ci> d </ci>
4672  </apply>
4673</math>
4674\stopbuffer
4675
4676\processxmlbuffer \typebuffer
4677
4678Another place where parentheses are not needed is the following:
4679
4680\startbuffer
4681<math xmlns="http://www.w3c.org/mathml" version="2.0">
4682  <apply> <minus/>
4683    <apply> <exp/>
4684      <cn> 3 </cn>
4685    </apply>
4686  </apply>
4687</math>
4688\stopbuffer
4689
4690\typebuffer
4691
4692This means that the interpreter of this kind of \MATHML\ has to analyze child
4693elements in order to choose the right way to typeset the formula. The output will
4694look like:
4695
4696\processxmlbuffer
4697
4698By default, as less braces as possible are used. As demonstrated, a special case
4699is when \mmlelement {plus} and \mmlelement {minus} have one sub element to deal
4700with. If you really want many braces there, you can turn off sign reduction.
4701
4702\startdirectives
4703\HL
4704\NC sign \NC reduction \NC yes \NC use as less braces as possible \NC \NR
4705\NC      \NC           \NC no  \NC always use braces \NC \NR
4706\HL
4707\stopdirectives
4708
4709We will demonstrate these alternatives with an example.
4710
4711\startbuffer[a]
4712<math xmlns="http://www.w3c.org/mathml" version="2.0">
4713  <apply> <plus/>
4714    <ci> a </ci>
4715    <apply> <sin/>
4716      <ci> b </ci>
4717    </apply>
4718    <apply> <power/>
4719      <ci> c </ci>
4720      <cn> 5 </cn>
4721    </apply>
4722    <apply> <power/>
4723      <apply> <sin/>
4724        <ci> d </ci>
4725      </apply>
4726      <cn> 2 </cn>
4727    </apply>
4728    <ci> e </ci>
4729  </apply>
4730</math>
4731\stopbuffer
4732
4733\processxmlbuffer[a]
4734
4735We need quite some code to encode this formula.
4736
4737\typebuffer[a]
4738
4739\startbuffer[b]
4740<?context-mathml-directive power reduction no ?>
4741\stopbuffer
4742
4743With power reduction turned off, we get:
4744
4745\processxmlbuffer[b,a]
4746
4747As directive we used:
4748
4749\typebuffer[b]
4750
4751The following example illustrates that we should be careful in coding such
4752formulas; here the \mmlelement {power} is applied to the argument of \mmlelement
4753{sin}.
4754
4755\startbuffer
4756<math xmlns="http://www.w3c.org/mathml" version="2.0">
4757  <apply> <plus/>
4758    <ci> a </ci>
4759    <apply> <sin/>
4760      <ci> b </ci>
4761    </apply>
4762    <apply> <power/>
4763      <ci> c </ci>
4764      <cn> 5 </cn>
4765    </apply>
4766    <apply> <sin/>
4767      <apply> <power/>
4768        <ci> d </ci>
4769        <cn> 2 </cn>
4770      </apply>
4771    </apply>
4772    <ci> e </ci>
4773  </apply>
4774</math>
4775\stopbuffer
4776
4777\processxmlbuffer \typebuffer
4778
4779\stopsection
4780
4781\startsection[title={divide}]
4782
4783Divisions can be very space consuming but there is a way out: using a forward
4784slash symbol. You can set the level at which this will take place. By default,
4785fractions are typeset in the traditional way.
4786
4787\startbuffer[a]
4788<math xmlns="http://www.w3c.org/mathml" version="2.0">
4789  <apply> <divide/>
4790    <cn> 1 </cn>
4791    <apply> <plus/>
4792      <cn> 1 </cn>
4793      <apply> <divide/>
4794        <cn> 1 </cn>
4795        <ci> x </ci>
4796      </apply>
4797    </apply>
4798  </apply>
4799</math>
4800\stopbuffer
4801
4802\startbuffer[b]
4803<math xmlns="http://www.w3c.org/mathml" version="2.0">
4804  <apply> <divide/>
4805    <cn> 1 </cn>
4806    <apply> <plus/>
4807      <cn> 1 </cn>
4808      <apply> <divide/>
4809        <cn> 1 </cn>
4810        <apply> <plus/>
4811          <cn> 1 </cn>
4812          <apply> <divide/>
4813            <cn> 1 </cn>
4814            <ci> x </ci>
4815          </apply>
4816        </apply>
4817      </apply>
4818    </apply>
4819  </apply>
4820</math>
4821\stopbuffer
4822
4823\processxmlbuffer[a] \typebuffer[a]
4824\processxmlbuffer[b] \typebuffer[b]
4825
4826\startbuffer[c]
4827<?context-mathml-directive divide level 1 ?>
4828\stopbuffer
4829
4830\processxmlbuffer[c,a] \processxmlbuffer[c,b] \typebuffer[c]
4831
4832\startbuffer[c]
4833<?context-mathml-directive divide level 2 ?>
4834\stopbuffer
4835
4836\processxmlbuffer[c,a] \processxmlbuffer[c,b] \typebuffer[c]
4837
4838\stopsection
4839
4840\startsection[title={relation}]
4841
4842You should keep in mind that (at least level 2) content \MATHML\ is not that rich
4843in terms of presenting your ideas in a visually attractive way. On the other
4844hand, because the content is highly structured, some intelligence can be applied
4845when typesetting them. By default, a relation is not vertically aligned but
4846typeset horizontally.
4847
4848If an application just needs raw formulas, definitions like the following are all
4849right.
4850
4851\startbuffer[a]
4852<math xmlns="http://www.w3c.org/mathml" version="2.0">
4853  <apply> <eq/>
4854    <apply> <plus/>
4855      <ci> a </ci>
4856      <ci> b </ci>
4857      <ci> c </ci>
4858    </apply>
4859    <apply> <plus/>
4860      <ci> d </ci>
4861      <ci> e </ci>
4862    </apply>
4863    <apply> <plus/>
4864      <ci> f </ci>
4865      <ci> g </ci>
4866      <ci> h </ci>
4867      <ci> i </ci>
4868    </apply>
4869    <cn> 123 </cn>
4870  </apply>
4871</math>
4872\stopbuffer
4873
4874\typebuffer[a]
4875
4876The typeset result will bring no surprises:
4877
4878\processxmlbuffer[a]
4879
4880But, do we want to show a formula that way? And what happens with much longer
4881formulas? You can influence the appearance with processing instructions.
4882
4883\startdirectives
4884\HL
4885\NC relation \NC align \NC no    \NC don't align relations \NC \NR
4886\NC          \NC       \NC left  \NC align all relations left \NC \NR
4887\NC          \NC       \NC right \NC align all relations right \NC \NR
4888\NC          \NC       \NC first \NC place the leftmost relation left \NC \NR
4889\NC          \NC       \NC last  \NC place the rightmost relation right \NC \NR
4890\HL
4891\stopdirectives
4892
4893The next couple of formulas demonstrate in what way the previously defined
4894formula is influenced by the processing instructions.
4895
4896\startbuffer[b]
4897<?context-mathml-directive relation align left ?>
4898\stopbuffer
4899
4900\processxmlbuffer[b,a] \typebuffer[b]
4901
4902\startbuffer[b]
4903<?context-mathml-directive relation align right ?>
4904\stopbuffer
4905
4906\processxmlbuffer[b,a] \typebuffer[b]
4907
4908\startbuffer[b]
4909<?context-mathml-directive relation align first ?>
4910\stopbuffer
4911
4912\processxmlbuffer[b,a] \typebuffer[b]
4913
4914\startbuffer[b]
4915<?context-mathml-directive relation align last ?>
4916\stopbuffer
4917
4918\processxmlbuffer[b,a] \typebuffer[b]
4919
4920\stopsection
4921
4922\startsection[title={base}]
4923
4924When in a document several number systems are used, it can make sense to mention
4925the base of the number. There are several ways to identify the base.
4926
4927\startdirectives
4928\HL
4929\NC base \NC symbol \NC numbers    \NC a (decimal) number \NC \NR
4930\NC      \NC        \NC characters \NC one character      \NC \NR
4931\NC      \NC        \NC text       \NC a mnemonic         \NC \NR
4932\NC      \NC        \NC no         \NC no symbol          \NC \NR
4933\HL
4934\stopdirectives
4935
4936By default, when specified, a base is identified as number.
4937
4938\startbuffer[a]
4939<math xmlns="http://www.w3c.org/mathml" version="2.0">
4940  <cn type="integer" base="8"> 1427 </cn>
4941</math>
4942\stopbuffer
4943
4944\typebuffer[a]
4945
4946\startbuffer[b]
4947<?context-mathml-directive base symbol numbers ?>
4948\stopbuffer
4949
4950\processxmlbuffer[b,a] \typebuffer[b]
4951
4952\startbuffer[b]
4953<?context-mathml-directive base symbol characters ?>
4954\stopbuffer
4955
4956\processxmlbuffer[b,a] \typebuffer[b]
4957
4958\startbuffer[b]
4959<?context-mathml-directive base symbol text ?>
4960\stopbuffer
4961
4962\processxmlbuffer[b,a] \typebuffer[b]
4963
4964\stopsection
4965
4966\startsection[title={function}]
4967
4968There is a whole bunch of functions available as empty element, like \mmlelement
4969{sin} and \mmlelement {log}. When a function is applied to a function, braces
4970make not much sense and placement is therefore disabled.
4971
4972\startdirectives
4973\HL
4974\NC function \NC reduction \NC yes \NC chain functions without braces \NC \NR
4975\NC          \NC           \NC no  \NC put braces around nested functions \NC \NR
4976\HL
4977\stopdirectives
4978
4979\startbuffer[a]
4980<math xmlns="http://www.w3c.org/mathml" version="2.0">
4981  <apply> <sin/> <ci> x </ci> </apply>
4982</math>
4983\stopbuffer
4984
4985\typebuffer[a]
4986
4987\startbuffer[b]
4988<?context-mathml-directive function reduction yes ?>
4989\stopbuffer
4990
4991\processxmlbuffer[b,a] \typebuffer[b]
4992
4993\startbuffer[b]
4994<?context-mathml-directive function reduction no ?>
4995\stopbuffer
4996
4997\processxmlbuffer[b,a] \typebuffer[b]
4998
4999\stopsection
5000
5001\startsection[title={limits}]
5002
5003When limits are placed on top of the limitation symbol, this generally looks
5004better than when they are placed alongside. You can also influence limit
5005placement per element. This feature is available for \mmlelement{int},
5006\mmlelement {sum}, \mmlelement {product} and \mmlelement {limit}.
5007
5008\startdirectives
5009\HL
5010\NC limit \NC location \NC top   \NC place limits on top of the symbols \NC \NR
5011\NC       \NC          \NC right \NC attached limits as super/subscripts \NC \NR
5012\HL
5013\stopdirectives
5014
5015\startbuffer[a]
5016<math xmlns="http://www.w3c.org/mathml" version="2.0">
5017  <apply> <int/>
5018    <bvar> <ci> x </ci> </bvar>
5019    <lowlimit> <cn> 0 </cn> </lowlimit>
5020    <uplimit> <cn> 1 </cn> </uplimit>
5021  </apply>
5022</math>
5023\stopbuffer
5024
5025\typebuffer[a]
5026
5027\startbuffer[b]
5028<?context-mathml-directive int location top ?>
5029\stopbuffer
5030
5031\processxmlbuffer[b,a] \typebuffer[b]
5032
5033\startbuffer[b]
5034<?context-mathml-directive int location right ?>
5035\stopbuffer
5036
5037\processxmlbuffer[b,a] \typebuffer[b]
5038
5039\stopsection
5040
5041\startsection[title={declare}]
5042
5043Currently declarations are not supposed to end up in print. By default we typeset
5044a message, but you can as well completely hide declarations.
5045
5046\startdirectives
5047\HL
5048\NC declare \NC state \NC start \NC show declarations \NC \NR
5049\NC         \NC       \NC stop  \NC ignore (hide) declarations \NC \NR
5050\HL
5051\stopdirectives
5052
5053\stopsection
5054
5055\startsection[title={lambda}]
5056
5057There is more than one way to visualize a lambda function. As with some other
5058settings, changing the appearance can best take place at the document level.
5059
5060\startdirectives
5061\HL
5062\NC lambda \NC alternative \NC b \NC show lambda as arrow \NC \NR
5063\NC        \NC             \NC a \NC show lambda as set \NC \NR
5064\HL
5065\stopdirectives
5066
5067\startbuffer[a]
5068<math xmlns="http://www.w3c.org/mathml" version="2.0">
5069  <lambda>
5070    <bvar> <ci> x </ci> </bvar>
5071    <apply> <log/>
5072      <ci> x </ci>
5073    </apply>
5074  </lambda>
5075</math>
5076\stopbuffer
5077
5078\typebuffer[a]
5079
5080\startbuffer[b]
5081<?context-mathml-directive lambda alternative a ?>
5082\stopbuffer
5083
5084\processxmlbuffer[b,a] \typebuffer[b]
5085
5086\startbuffer[b]
5087<?context-mathml-directive lambda alternative b ?>
5088\stopbuffer
5089
5090\processxmlbuffer[b,a] \typebuffer[b]
5091
5092\stopsection
5093
5094\startsection[title={power}]
5095
5096Taking the power of a function looks clumsy when braces are put around the
5097function. Therefore, by default, the power is applied to the function symbol
5098instead of the whole function.
5099
5100\startdirectives
5101\HL
5102\NC power \NC reduction \NC yes \NC attach symbol to function symbol \NC \NR
5103\NC       \NC           \NC no  \NC attach symbol to function argument \NC \NR
5104\HL
5105\stopdirectives
5106
5107\startbuffer[a]
5108<math xmlns="http://www.w3c.org/mathml" version="2.0">
5109  <apply> <power/>
5110    <apply> <ln/>
5111      <ci> x </ci>
5112    </apply>
5113    <cn> 3 </cn>
5114  </apply>
5115</math>
5116\stopbuffer
5117
5118\typebuffer[a]
5119
5120\startbuffer[b]
5121<?context-mathml-directive power reduction yes ?>
5122\stopbuffer
5123
5124\processxmlbuffer[b,a] \typebuffer[b]
5125
5126\startbuffer[b]
5127<?context-mathml-directive power reduction no ?>
5128\stopbuffer
5129
5130\processxmlbuffer[b,a] \typebuffer[b]
5131
5132\stopsection
5133
5134\startsection[title={diff}]
5135
5136Covering all kind of differential formulas is not trivial. Currently we support
5137two locations for the operand (function). By default the operand is placed above
5138the division line.
5139
5140\startdirectives
5141\HL
5142\NC diff \NC location \NC top   \NC put the operand in the fraction \NC \NR
5143\NC      \NC          \NC right \NC put the operand after the fraction \NC \NR
5144\HL
5145\stopdirectives
5146
5147\startbuffer[a]
5148<math xmlns="http://www.w3c.org/mathml" version="2.0">
5149  <apply> <diff/>
5150    <bvar>
5151      <ci> x </ci>
5152      <degree> <cn> 2 </cn> </degree>
5153    </bvar>
5154    <apply> <fn> <ci> f </ci> </fn>
5155      <apply> <plus/>
5156        <apply> <times/>
5157          <cn> 2 </cn>
5158          <ci> x </ci>
5159        </apply>
5160        <cn> 1 </cn>
5161      </apply>
5162    </apply>
5163  </apply>
5164</math>
5165\stopbuffer
5166
5167\typebuffer[a]
5168
5169\startbuffer[b]
5170<?context-mathml-directive diff location top ?>
5171\stopbuffer
5172
5173\processxmlbuffer[b,a] \typebuffer[b]
5174
5175\startbuffer[b]
5176<?context-mathml-directive diff location right ?>
5177\stopbuffer
5178
5179\processxmlbuffer[b,a] \typebuffer[b]
5180
5181\stopsection
5182
5183\startsection[title={vector}]
5184
5185Depending on the complication of a vector or on the available space, you may wish
5186to typeset a vector horizontally or vertically. By default a vector is typeset
5187horizontally.
5188
5189\startdirectives
5190\HL
5191\NC vector \NC direction \NC horizontal \NC put vector elements alongside \NC \NR
5192\NC        \NC           \NC vertical   \NC stack vector elements \NC \NR
5193\HL
5194\stopdirectives
5195
5196\startbuffer[a]
5197<math xmlns="http://www.w3c.org/mathml" version="2.0">
5198  <apply> <eq/>
5199    <vector>
5200      <ci> x </ci>
5201      <ci> y </ci>
5202      <ci> z </ci>
5203    </vector>
5204    <vector>
5205      <cn> 1 </cn>
5206      <cn> 0 </cn>
5207      <cn> 1 </cn>
5208    </vector>
5209  </apply>
5210</math>
5211\stopbuffer
5212
5213\typebuffer[a]
5214
5215\startbuffer[b]
5216<?context-mathml-directive vector direction horizontal ?>
5217\stopbuffer
5218
5219\processxmlbuffer[b,a] \typebuffer[b]
5220
5221\startbuffer[b]
5222<?context-mathml-directive vector direction vertical ?>
5223\stopbuffer
5224
5225\processxmlbuffer[b,a] \typebuffer[b]
5226
5227\stopsection
5228
5229\startsection[title={times}]
5230
5231Depending on the audience, a multiplication sign is implicit (absent) or
5232represented by a regular times symbol or a dot.
5233
5234\startdirectives
5235\HL
5236\NC times \NC symbol \NC no  \NC don't add a symbol \NC \NR
5237\NC       \NC        \NC yes \NC separate operands by a times ($\times$) \NC \NR
5238\NC       \NC        \NC dot \NC separate operands by a dot ($\cdot$)\NC \NR
5239\NC auto  \NC symbol \NC no  \NC don't check for succesive numbers \NC \NR
5240\NC       \NC        \NC yes \NC separate succesive numbers by a times ($\times$) \NC \NR
5241\NC       \NC        \NC dot \NC separate succesive numbers by a dot ($\cdot$)\NC \NR
5242\HL
5243\stopdirectives
5244
5245\startbuffer[a]
5246<math xmlns="http://www.w3c.org/mathml" version="2.0">
5247  <apply> <plus/>
5248    <ci> x </ci>
5249    <apply> <times/>
5250      <cn> 2 </cn>
5251      <ci> x </ci>
5252    </apply>
5253  </apply>
5254</math>
5255\stopbuffer
5256
5257\typebuffer[a]
5258
5259\startbuffer[b]
5260<?context-mathml-directive times symbol no ?>
5261\stopbuffer
5262
5263\processxmlbuffer[b,a] \typebuffer[b]
5264
5265\startbuffer[b]
5266<?context-mathml-directive times symbol yes ?>
5267\stopbuffer
5268
5269\processxmlbuffer[b,a] \typebuffer[b]
5270
5271\startbuffer[b]
5272<?context-mathml-directive times symbol dot ?>
5273\stopbuffer
5274
5275\processxmlbuffer[b,a] \typebuffer[b]
5276
5277\stopsection
5278
5279\startsection[title={log}]
5280
5281The location of a logbase depends on tradition and|/|or preference, which is why
5282we offer a few alternatives: as pre superscript (in the right top corner before
5283the symbol) or as post subscript (in the lower left corner after the symbol).
5284
5285\startdirectives
5286\HL
5287\NC log \NC location \NC right \NC place logbase at the right top \NC \NR
5288\NC     \NC          \NC left  \NC place logbase at the lower left \NC \NR
5289\HL
5290\stopdirectives
5291
5292\startbuffer[a]
5293<math xmlns="http://www.w3c.org/mathml" version="2.0">
5294  <apply> <log/>
5295    <logbase>
5296      <ci> 3 </ci>
5297    </logbase>
5298    <apply> <plus/>
5299      <ci> x </ci>
5300      <cn> 1 </cn>
5301    </apply>
5302  </apply>
5303</math>
5304\stopbuffer
5305
5306\typebuffer[a]
5307
5308\startbuffer[b]
5309<?context-mathml-directive log location right ?>
5310\stopbuffer
5311
5312\processxmlbuffer[b,a] \typebuffer[b]
5313
5314\startbuffer[b]
5315<?context-mathml-directive log location left ?>
5316\stopbuffer
5317
5318\processxmlbuffer[b,a] \typebuffer[b]
5319
5320\stopsection
5321
5322\startsection[title={polar}]
5323
5324For polar notation we provide several renderings:
5325
5326\startdirectives
5327\HL
5328\NC polar \NC alternative \NC a \NC explicit polar notation       \NC \NR
5329\NC       \NC             \NC b \NC exponential power notation    \NC \NR
5330\NC       \NC             \NC c \NC exponential function notation \NC \NR
5331\HL
5332\stopdirectives
5333
5334\startbuffer[a]
5335<math xmlns="http://www.w3c.org/mathml" version="2.0">
5336  <cn type="polar"> 2 <sep/> <pi/> </cn>
5337</math>
5338\stopbuffer
5339
5340\typebuffer[a]
5341
5342\startbuffer[b]
5343<?context-mathml-directive polar alternative a ?>
5344\stopbuffer
5345
5346\processxmlbuffer[b,a] \typebuffer[b]
5347
5348\startbuffer[b]
5349<?context-mathml-directive polar alternative b ?>
5350\stopbuffer
5351
5352\processxmlbuffer[b,a] \typebuffer[b]
5353
5354\startbuffer[b]
5355<?context-mathml-directive polar alternative c ?>
5356\stopbuffer
5357
5358\processxmlbuffer[b,a] \typebuffer[b]
5359
5360\stopsection
5361
5362\startsection[title={e-notation}]
5363
5364Depending on the context, you may want to typeset the number \type {1.23e4} not
5365as this sequence, but using a multiplier construct. As with the \mmlelement
5366{times}, we support both multiplication symbols.
5367
5368\startdirectives
5369\HL
5370\NC enotation \NC symbol \NC no  \NC no interpretation              \NC \NR
5371\NC           \NC        \NC yes \NC split exponent, using $\times$ \NC \NR
5372\NC           \NC        \NC dot \NC split exponent, using $\cdot$  \NC \NR
5373\HL
5374\stopdirectives
5375
5376\startbuffer[a]
5377<math xmlns="http://www.w3c.org/mathml" version="2.0">
5378  <cn type="e-notation">10<sep/>23</cn>
5379</math>
5380\stopbuffer
5381
5382\typebuffer[a]
5383
5384\startbuffer[b]
5385<?context-mathml-directive enotation symbol no ?>
5386\stopbuffer
5387
5388\processxmlbuffer[b,a] \typebuffer[b]
5389
5390\startbuffer[b]
5391<?context-mathml-directive enotation symbol yes ?>
5392\stopbuffer
5393
5394\processxmlbuffer[b,a] \typebuffer[b]
5395
5396\startbuffer[b]
5397<?context-mathml-directive enotation symbol dot ?>
5398\stopbuffer
5399
5400\processxmlbuffer[b,a] \typebuffer[b]
5401
5402\stopsection
5403
5404\stopchapter
5405
5406\startchapter[title={Typesetting modes}]
5407
5408Math can be typeset inline or display. In order not to widen up the text of a
5409paragraph too much, inline math is typeset more cramped. Since \MATHML\ does
5410provide just a general purpose \mmlelement {math} element we have to provide the
5411information needed using other elements. Consider the following text.
5412
5413\startbuffer
5414<document>
5415To what extent is math supposed to reflect the truth and nothing but
5416the truth? Consider the simple expression
5417    <math xmlns="http://www.w3c.org/mathml" version="2.0">
5418        <apply> <eq/>
5419            <cn> 10 </cn>
5420            <apply> <plus/>
5421                <cn> 3 </cn>
5422                <cn> 7 </cn>
5423            </apply>
5424        </apply>
5425    </math>. Many readers will consider this the truth, but then,
5426can we assume that the decimal notation is used?
5427
5428<formula>
5429  <math xmlns="http://www.w3c.org/mathml" version="2.0">
5430    <apply> <eq/>
5431      <cn> 10 </cn>
5432      <apply> <plus/>
5433        <cn> 3 </cn>
5434        <ci> x </ci>
5435      </apply>
5436    </apply>
5437  </math>
5438</formula>
5439
5440In many elementary math books, you can find expressions like the
5441previous. Because in our daily life we use the decimal numbering system,
5442we can safely assume that
5443    <math xmlns="http://www.w3c.org/mathml" version="2.0">
5444        <apply> <eq/>
5445            <ci> x </ci>
5446            <cn> 7 </cn>
5447        </apply>
5448    </math>. But, without explicitly mentioning this boundary condition,
5449more solutions are correct.
5450
5451<formula label="octal" sublabel="a">
5452  <math xmlns="http://www.w3c.org/mathml" version="2.0">
5453    <apply> <eq/>
5454      <cn> 10 </cn>
5455      <apply> <plus/>
5456        <cn> 3 </cn>
5457        <cn> 5 </cn>
5458      </apply>
5459    </apply>
5460  </math>
5461</formula>
5462
5463In <textref label="octal">formula</textref> we see an at first sight
5464wrong formula. But, if we tell you that octal numbers are used, your
5465opinion may change instantly. A rather clean way out of this confusion
5466is to extend the notation of numbers by explicitly mentioning the base.
5467
5468<subformula label="octal base" sublabel="b">
5469  <math xmlns="http://www.w3c.org/mathml" version="2.0">
5470    <apply> <eq/>
5471      <cn type="integer" base="8"> 10 </cn>
5472      <apply> <plus/>
5473        <cn type="integer" base="8"> 3 </cn>
5474        <cn type="integer" base="8"> 5 </cn>
5475      </apply>
5476    </apply>
5477  </math>
5478</subformula>
5479
5480Of course, when a whole document is in octal notation, a proper
5481introduction is better than annotated numbers as used in <textref
5482label="octal base">formula</textref>.
5483</document>
5484\stopbuffer
5485
5486\blank \startnarrower \processxmlbuffer \stopnarrower \blank
5487
5488In terms of \XML\ this can look like:
5489
5490\typebuffer
5491
5492Math that is part of the text flow is automatically handled as inline math. If
5493needed you can encapsulate the code in an \mmlelement {imath} environment.
5494Display math is recognized as such when it is a separate paragraph, but since
5495this is more a \TEX\ feature than an \XML\ one, you should encapsulate display
5496math either in a \mmlelement {dmath} element or in a \mmlelement {formula} or
5497\mmlelement {subformula} element.
5498
5499For a while you can use attribute \type {mode} with values \type {display} or
5500\type {inline}. Recent \MATHML\ specifications provide the \type {display}
5501attribute with values \type {block} or \type {inline}. We support both.
5502
5503\stopchapter
5504
5505\startchapter[title={Getting started}]
5506
5507A comfortable way to get accustomed to \MATHML\ is to make small documents of the
5508following form:
5509
5510\starttyping
5511\usemodule[mathml]
5512
5513\starttext
5514
5515\startbuffer
5516<math xmlns="http://www.w3c.org/mathml" version="2.0">
5517  <apply> <cos/>
5518    <ci> x </ci>
5519  </apply>
5520</math>
5521\stopbuffer
5522
5523\processxmlbuffer
5524
5525\stoptext
5526\stoptyping
5527
5528As you see, we can mix \MATHML\ with normal \TEX\ code. A document like this is
5529processed in the normal way using the \type {context} command. If you also want
5530to see the original code, you can say:
5531
5532\starttyping
5533\usemodule[mathml]
5534
5535\starttext
5536
5537\startbuffer
5538<math xmlns="http://www.w3c.org/mathml" version="2.0">
5539  <apply> <cos/>
5540    <ci> x </ci>
5541  </apply>
5542</math>
5543\stopbuffer
5544
5545\processxmlbuffer
5546
5547\typebuffer
5548
5549\stoptext
5550\stoptyping
5551
5552Like \TEX\ and \METAPOST\ code, buffers can contain \MATHML\ code. The advantage
5553of this method is that we only have to key in the data once. It also permits you
5554to experiment with processing instructions.
5555
5556\starttyping
5557\startbuffer[mml]
5558<math xmlns="http://www.w3c.org/mathml" version="2.0">
5559  <apply> <log/>
5560    <logbase> <cn> 3.5 </cn> </logbase>
5561    <ci> x </ci>
5562  </apply>
5563</math>
5564\stopbuffer
5565
5566\startbuffer[pi]
5567 <?context-mathml-directive log location right ?>
5568\stopbuffer
5569
5570\processxmlbuffer[pi,mml]
5571
5572\startbuffer[pi]
5573 <?context-mathml-directive log location left ?>
5574\stopbuffer
5575
5576\processxmlbuffer[pi,mml]
5577\stoptyping
5578
5579If you like coding your documents in \TEX\ but want to experiment with \MATHML,
5580combining both languages in the way demonstrated here may be an option. When you
5581provide enough structure in your \TEX\ code, converting a document to \XML\ is
5582then not that hard to do. Where coding directly in \XML\ is kind of annoying,
5583coding \MATHML\ is less cumbersome, because you can structure your formulas
5584pretty well, especially since the fragments are small so that proper indentation
5585is possible.
5586
5587\stopchapter
5588
5589\startchapter[title={Bidi}]
5590
5591Support for bidirectional math is not entirely trivial as it demands a font that
5592supports it. When they were released, the stix fonts were not that useable and
5593Khaled Hosny turned them into the xits fonts that are now quite complete and
5594useable in an \OPENTYPE\ and \UNICODE\ environment. He also added support for
5595right to left math.
5596
5597Normally you will only use that in a right to left typeset document, in which
5598case you have a setup like this:
5599
5600\starttyping
5601\setuptobodyfont
5602  [xitsbidi]
5603
5604\setupalign
5605  [r2l]
5606
5607\setupmathematics
5608  [align=r2l]
5609
5610\starttext
5611
5612Some text.
5613
5614\startformula \sqrt{ف^2\over 4ب} \stopformula
5615
5616Some more text
5617
5618\stoptext
5619\stoptyping
5620
5621As \MATHML\ has no global settings you need to control it specifically. At some
5622point we might decide to provide some global flags but that depends on how the
5623general bidi layout machinery evolves. Here we just stick to an example:
5624
5625\startbuffer[test]
5626<math xmlns="http://www.w3.org/1998/Math/MathML" dir="rtl">
5627    <msqrt>
5628        <mfrac>
5629            <msup><mi>ف</mi><mn>2</mn></sup>
5630            <mrow><mn>4</mn><mi>ب</mi></mrow>
5631        </mfrac>
5632    </msqrt>
5633</math>
5634\stopbuffer
5635
5636\typebuffer[test]
5637
5638\start
5639    \switchtobodyfont[xitsbidi]
5640    \xmlprocessbuffer{main}{test}{}
5641    \par
5642\stop
5643
5644The order of input is still rather left to right which makes sense as we're sort
5645of structuring the math input.
5646
5647\stopchapter
5648
5649\startchapter[title={OpenMath}]
5650
5651Because \OPENMATH\ is now a subset of \MATHML\ we can to some extend also support
5652this coding. We do a straightforward remapping to content \MATHML\ so any
5653rendering that is supported there is also supported in the equivalent \OPENMATH\
5654code.
5655
5656\startbuffer
5657<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
5658  <OMA> <OMS cd="relation1" name="eq"/>
5659    <OMV name="y"/>
5660    <OMA> <OMS cd="arith1" name="minus"/>
5661      <OMA> <OMV name="f"/>
5662        <OMV name="x"/>
5663      </OMA>
5664      <OMA> <OMV name="f"/>
5665        <OMA> <OMS cd="arith1" name="minus"/>
5666          <OMV name="x"/>
5667          <OMI>1</OMI>
5668        </OMA>
5669      </OMA>
5670    </OMA>
5671  </OMA>
5672</OMOBJ>
5673\stopbuffer
5674
5675\processxmlbuffer \typebuffer
5676
5677Because in practice we may use a mixture of math encodings this can come in handy
5678because it saves conversion of the \XML\ source.
5679
5680\stopchapter
5681
5682\startchapter[title={CalcMath}]
5683
5684We support two types of annotation markup: \TEX\ (\type {tex}) and what we call
5685\quote {calculator math} (\type {calcmath}). The second type is also available
5686directly. Inline calcmath is coded using the \mmlelement{icm} element.
5687
5688\startbuffer
5689<document>
5690  This is an inline formula <icm>sin(x^2+1/x)</icm> just to demonstrate
5691  the idea of calculator math.
5692</document>
5693\stopbuffer
5694
5695\blank \noindentation \processxmlbuffer \typebuffer
5696
5697If one edits the \XML\ file directly this can type quite some coding. For more
5698complex formulas one can revert to content \MATHML, or when interactivity is
5699needed to \OPENMATH.
5700
5701The argument that one should use a dedicated editor for math instead is not that
5702convincing for authors who have to key on lots of small snippets of math. And one
5703can always transform this code in its more bloated variant. The calcmath
5704converter is dedicated to Frits Spijkers, author of Dutch math schoolbooks and
5705fluent in all those math encodings methods we force upon him. The code resembles
5706that used in the calculators at schools and we used it in projects with computer
5707aided feedback where students had to key in math. When there is demand for this
5708input method we will provide more details.
5709
5710\stopchapter
5711
5712\startchapter[title={AsciiMath}]
5713
5714A few years back we included some basic support for \ASCIIMATH\ as a proof of
5715concept not knowing that one day we were forced to fully support it in a project.
5716In one of our projects \CONTEXT\ is the backend for generating math books for
5717high school math. Input is \XML\ and math is coded in presentational \MATHML. We
5718should say \quotation {was coded}, because in the Spring of 2014 another party in
5719the project (the one responsible for the web part) converted the \MATHML\ into
5720\ASCIIMATH\ on behalve of their web authoring tool.
5721
5722Where we would have chosen to use the \MATHML\ annotation attribute, they had
5723chosen to flatten the structured \MATHML\ into less structured \ASCIIMATH. And
5724there was no way back. We're talking of tens of thousands of files here.
5725\footnote {Around the same time Google decided to drop native \MATHML\ support
5726from Chrome so one might wonder why \MATHML\ was developed in the first place.}
5727
5728On the web \ASCIIMATH\ is mostly interpreted by MathJax's \JAVASCRIPT\ in
5729combination with \CSS. Since we didn't want to depend on a \JAVASCRIPT\
5730conversion in \CONTEXT\ we started to completely rewrite our \ASCIIMATH\ module.
5731We also needed a bit more control in order to meet specific demands of the
5732publisher, like formatting numbers, support for characters not in the normal
5733repertoire, checking and tracing, and the speed of rendering had not to be
5734affected.
5735
5736If you invoke the \ASCIIMATH\ module with \typ {\usemodule [asciimath]} the
5737command \type {\asciimath{...}} is available for testing purposes. Within the
5738curly brackets you can type an \ASCIIMATH\ expression.
5739
5740Normally an \ASCIIMATH\ expression in \XML|/|\HTML\ is enclosed by back-quotes:
5741
5742\startbuffer
5743`x^2`
5744\stopbuffer
5745
5746\typebuffer
5747
5748But we rather stick to the \XML\ like coding:
5749
5750\startbuffer
5751<am>x^2</am>
5752\stopbuffer
5753
5754\typebuffer
5755
5756This is equivalent to the \TEX\ command:
5757
5758\asciimath{x^2}
5759
5760The interpretation of such a formula is no problem. But let's give a few examples
5761where \ASCIIMATH\ lacks structure or needs a (sometimes bizar) interpretation to
5762obtain adequate rendering:
5763
5764\noindentation Behaviour of superscripts and subscripts depends on operator that
5765preceeds a number or variable:
5766
5767\starttabulate
5768\FL
5769\NC \type{`sin^-1(x)`}          \NC \asciimath{sin^-1(x)}             \NC \NR
5770\NC \type{`sin^+1(x)`}          \NC \asciimath{sin^+1(x)}             \NC \NR
5771\LL
5772\stoptabulate
5773
5774\noindentation A script can be either one character or a number made from more
5775characters:
5776
5777\starttabulate
5778\FL
5779\NC \type{`int_a^b f(x)`}       \NC \asciimath{int_a^b f(x)}          \NC \NR
5780\NC \type{`int_aa^bb f(x)`}     \NC \asciimath{int_aa^bb f(x)}        \NC \NR
5781\NC \type{`int_1000^2000 f(x)`} \NC \asciimath{int_1000^2000 f(x)}    \NC \NR
5782\LL
5783\stoptabulate
5784
5785\noindentation Behaviour of operator depends on character, where some characters
5786have special meaning:
5787
5788\starttabulate
5789\FL
5790\NC \type{`d/dx`}               \NC \asciimath{d/dx}                  \NC \NR
5791\NC \type{`q/qx`}               \NC \asciimath{q/qx}                  \NC \NR
5792\LL
5793\stoptabulate
5794
5795\noindentation Behaviour of the curly brackets is somewhat peculiar because at
5796times they are not used for grouping anymore:
5797
5798\starttabulate
5799\FL
5800\NC \type{`{a/b}/{d/c}`}        \NC \asciimath{{a/b}/{d/c}}           \NC \NR
5801\NC \type{`{a/b}//{d/c}`}       \NC \asciimath{{a/b}//{d/c}}          \NC \NR
5802\LL
5803\stoptabulate
5804
5805\noindentation Behaviour depends on sequence of scripts (solved in \CONTEXT):
5806
5807\starttabulate
5808\FL
5809\NC \type{`int_0^1 f(x)dx`}     \NC \asciimath{int_0^1 f(x)dx}        \NC \NR
5810\NC \type{`int^1_0 f(x)dx`}     \NC \asciimath{int^1 text(_)0 f(x)dx} \NC \NR
5811\LL
5812\stoptabulate
5813
5814During the development of the \ASCIIMATH\ support we used the MathJax interpretor
5815as a reference since that is available on the web. At the time of writing
5816documentation was limited so some trial and error was involved in writing the
5817parser. As usual we started from examples. Below we give a number of those
5818examples so you can familiarize yourself with \ASCIIMATH. Note that you can use
5819\TEX||like math coding and even use the backslash, but be warned for unexpected
5820behaviour. In a webpage backticks are used to indicate \ASCIIMATH.
5821
5822\startlines
5823\ExampleLine{sqrt-3ax}
5824\ExampleLine{sqrt(-3ax)}
5825\ExampleLine{root(3)(ax)}
5826\ExampleLine{x^2+y_1+z_12^3}
5827\ExampleLine{sin^-1(x)}
5828\ExampleLine{d/dx f(x)=lim_(h->0) (f(x+h)-f(x))/h}
5829\ExampleLine{f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n}
5830\ExampleLine{int_0^1 f(x)dx}
5831\ExampleLine{int^1_0 f(x)dx}
5832\ExampleLine{a//b}
5833\ExampleLine{a//\alpha}
5834\ExampleLine{(a/b)/(d/c)}
5835\ExampleLine{((a*b))/(d/c)}
5836\ExampleLine{(a/b)/(c/d)={:(ad)/(bd):}/{:(bc)/(bd):}=(ad)/(bc)=(ad)/(bc)}
5837\ExampleLine{a/b//c/d=(ad)/(bd)//(bc)/(bd)=ad//bc=(ad)/(bc)}
5838\ExampleLine{[[a,b],[c,d]]((n),(k))}
5839\ExampleLine{1/x={(1,text{if } x!=0),(text(undefined), text(if ) x=0):}}
5840\ExampleLine{<<a,b>> text{ and } [ (x,y),(u,v) ] }
5841\ExampleLine{(a,b] = {x in RR | a < x <= b}}
5842\ExampleLine{langle larr ; 0,4]}
5843\ExampleLine{〈← ; 0,4]}
5844\ExampleLine{[0 , rarr rangle}
5845\ExampleLine{[0 , →〉}
5846\ExampleLine{5/|CD|=8/5}
5847\ExampleLine{|MD|/|CD|=|AD|/|MD|}
5848\ExampleLine{x lt 4 vv x gt 1}
5849\ExampleLine{x \lt 4 vv x \gt 1}
5850\ExampleLine{x &lt; 4 vv x &gt; 1}     % Hans: werkt niet goed; wel op http://www.wjagray.co.uk/maths/ASCIIMathTutorial.html
5851\ExampleLine{lim_(x→∞)1/x=0}
5852\ExampleLine{text(D)_(f)}
5853\ExampleLine{p _|_ q}
5854\ExampleLine{g·g· stackrel (text(n times) ) (...·g)}
5855\ExampleLine{stackrel(+)(\rightarrow)}
5856\ExampleLine{stackrel(+)(rightarrow)}  % Hans: werkt niet goed; wel op http://www.wjagray.co.uk/maths/ASCIIMathTutorial.html
5857\ExampleLine{((a_(11),cdots,a_(1n)),(vdots,ddots,vdots),(a_(m1),cdots,a_(mn)))}
5858\stoplines
5859
5860Unfortunately \ASCIIMATH\ can be unpredictable which is a side effect of the fact that a
5861high degree of tolerance is built in. We strongly advice to use spaces to make your
5862results predictable.
5863
5864\startlines
5865\ExampleLine{o ox x = xo}
5866\ExampleLine{a ax x = xa}
5867\ExampleLine{ooxx=xo}
5868\ExampleLine{aaxx=xa}
5869\stoplines
5870
5871One of the properties is that \TEX\ commands are supported, that is,. with a few
5872exceptions: \type {P} and \type {S} don't produce $\P$ and $\S$. Also, don't
5873confuse these symbols with the entities supported by \MATHML: in \ASCIIMATH\
5874\type{circ} is circle and not a circumflex. Also, \type {&lt;}, \type {&gt;} are
5875converted into \asciimath {&lt;} and \asciimath {&gt;} while \type {&amp;}
5876becomes \asciimath{&amp;}. As usual with input formats that start out simple, in
5877the end they become so complex that one can wonder why to use them. It is the
5878usual problem of using one system for everything.
5879
5880The following examples are similar to the once shown elsewhere in this document.
5881
5882\startsubsubject[title=derivatives]
5883
5884\ExampleLine{(da)/(dx) = 0}
5885\ExampleLine{dx/dx = 0}
5886\ExampleLine{(d(au))/(dx) = a (du)/(dx)}
5887\ExampleLine{(d(u+v+w))/(dx) = (du)/(dx) + (dv)/(dx) + (dw)/(dx)}
5888\ExampleLine{(d(uv))/(dx) = u (du)/(dx) + v (dv)/(dx)}
5889\ExampleLine{(d(uvw))/(dx) = vw(du)/(dx) + uw(dv)/(dx) + uv(dw)/(dx)}
5890\ExampleLine{(d(u/v))/(dx) = (v(du)/(dx) - u(dv)/(dx) ) / (v^2) = 1/v (du)/(dx) - u/v^2 (dv)/(dx)}
5891\ExampleLine{(d(u^n))/(dx) = n(u)^(n-1) (dv)/(dx)}
5892\ExampleLine{(d sqrt(u))/(dx) = 1/(2 sqrt(u)) (du)/(dx) }
5893\ExampleLine{(d(1/u))/(dx) = - 1/u^2 (du)/(dx)}
5894\ExampleLine{(d(1/(u^n)))/(dx) = - n/u^(n+1) (du)/(dx)}
5895\ExampleLine{(d log (u + sqrt(u^2+1)))/(dx) = 1/(sqrt(u^2 + 1)) (du)/(dx) }
5896
5897\stopsubsubject
5898
5899\startsubsubject[title=integral]
5900
5901\ExampleLine{int (1 / (x sqrt(a^2 +- x^2) ) ) dx = - 1/a log (a + sqrt(a^2 +- x^2)) / x}
5902\ExampleLine{int (1 / ( a + bx^2) ) = 1 / (2 sqrt(-ab)) log (a + x sqrt(-ab) ) / (a - x sqrt(-ab) ) vv 1 / sqrt(-ab) tanh^(-1) (x sqrt (-ab)) / a}
5903\ExampleLine{int ( 1 / (cos(ax) (1 +- sin(ax)) ) ) dx = ( 1 / (2a( 1 +- sin(ax) )) ) + 1 / (2a) log tan(pi/4 + (ax)/2)}
5904
5905\stopsubsubject
5906
5907\startsubsubject[title=series]
5908
5909\ExampleLine{1 - 1/3 + 1/5 - 1/7 + cdots = pi/4}
5910\ExampleLine{1 + 1/2^2 + 1/3^2 + 1/4^2 + cdots = pi^2/6}
5911\ExampleLine{1 - 1/2^2 + 1/3^2 - 1/4^2 + cdots = pi^2/12}
5912\ExampleLine{AA x in RR | e^x = 1 + x + x^2/(2!) + x^3/(3!) + cdots + x^n/(n!)}
5913\ExampleLine{AA x in RR | e^(text(-)x) = 1 - x + x^2/(2!) - x^3/(3!) + cdots + (text(-)1^n)x^n/(n!)}
5914
5915\stopsubsubject
5916
5917\startsubsubject[title=logs]
5918
5919\ExampleLine{AA a > 0 ^^ b > 0 | {:log_g:} a + {:log_g:} b}
5920\ExampleLine{AA a > 0 ^^ b > 0 | {:log_g:} a/b = {:log_g:} a - {:log_g:} b}
5921\ExampleLine{AA b in RR ^^ a > 0 | {:log_g:} a^b = b {:log_g:} a}
5922\ExampleLine{AA a > 0 | {:log_g:} a = ({:log_p:} a) / ({:log_p:} g)}
5923
5924\stopsubsubject
5925
5926\startsubsubject[title=goniometrics]
5927
5928\ExampleLine{sin(x+y) = sinx cosy + cosx siny}
5929\ExampleLine{sin(x-y) = sinx cosy - cosx siny}
5930\ExampleLine{sin(x+y) = cosx cosy - sinx siny}
5931\ExampleLine{sin(x-y) = cosx cosy + sinx siny}
5932\ExampleLine{tan(x+y) = (tanx + tany) / (1 - tanx tany)}
5933\ExampleLine{tan(x-y) = (tanx - tany) / (1 + tanx tany)}
5934\ExampleLine{sinp + sinq = 2 sin (p+q)/2 cos (p-q)/2}
5935\ExampleLine{sinp - sinq = 2 cos (p+q)/2 sin (p-q)/2}
5936\ExampleLine{cosp + cosq = 2 cos (p+q)/2 cos (p-q)/2}
5937\ExampleLine{2 cos alpha cos beta = cos(alpha + beta) + cos(alpha - beta)}
5938\ExampleLine{-2 sin alpha cos beta = sin(alpha + beta) - sin(alpha - beta)}
5939\ExampleLine{AA  ABC | a / (sin alpha) + b / (sin beta) + c / (sin gamma)}
5940\ExampleLine{AA  ABC | {:(a^2 = b^2 + c^2 - 2bc cos alpha),(b^2 = a^2 + c^2 - 2ac cos beta),(c^2 = a^2 + b^2 - 2ab cos gamma):}}
5941
5942\stopsubsubject
5943
5944\startsubsubject[title=statistics]
5945
5946\ExampleLine{bar x = 1/n sum x_i}
5947\ExampleLine{sigma (x) ~~ sqrt ((x_i - (bar x)^2) / (n-1) )}
5948\ExampleLine{sigma (x)^2 ~~ bar ((x_i - bar x)^2) = 1/(n-1) sum (x_i - bar x)^2}
5949
5950\stopsubsubject
5951
5952\startsubsubject[title=matrices]
5953
5954\ExampleLine{|{:(sin alpha,cos alpha),(sin beta,cos beta):}| = sin (alpha - beta)}
5955\ExampleLine{|I| = | {: (1,0),(0,1):}| = 1}
5956
5957\stopsubsubject
5958
5959\stopchapter
5960
5961\startchapter[title={A few examples}]
5962
5963\setups[showexamples]
5964
5965\startsection[title={derivatives}]  \getbuffer[derivates]    \stopsection
5966\startsection[title={integrals}]    \getbuffer[integrals]    \stopsection
5967\startsection[title={series}]       \getbuffer[series]       \stopsection
5968\startsection[title={logs}]         \getbuffer[logs]         \stopsection
5969\startsection[title={goniometrics}] \getbuffer[goniometrics] \stopsection
5970\startsection[title={statistics}]   \getbuffer[statistics]   \stopsection
5971\startsection[title={matrices}]     \getbuffer[matrices]     \stopsection
5972
5973\stopchapter
5974
5975\startchapter[title={Unicode Math}]
5976
5977\startsection[title={entities}]
5978
5979Support for \MATHML\ showed up in \CONTEXT\ by the end of second millenium. The
5980first more or less complete version of this manual dates from the end of 1999. At
5981that time \UNICODE\ math was no fact yet and entities were the way to get special
5982symbols done. Mapping the names of symbols onto something that could be rendered
5983was up to the \XML\ processors and typesetting engine.
5984
5985Nowadays we can use \UNICODE\ directly although it has the drawback that not all
5986editing applications show the corresponding shapes. It is for this reason that
5987entities will have their use for a while. In the next table we see the official
5988ones. The table is actually larger, but we only show the shapes that have a math
5989property in the \CONTEXT\ character database. The full list is supported and can
5990be found in the following documents:
5991
5992\starttyping
5993http://www.w3.org/2003/entities/2007/w3centities-f.ent
5994http://www.w3.org/2003/entities/2007/htmlmathml-f.ent
5995\stoptyping
5996
5997\blank \showmathentities
5998
5999\stopsection
6000
6001\startsection[title={properties}]
6002
6003\noindentation A different way to look at this is \UNICODE\ itself. Here's the
6004list of characters that have a math related property in \CONTEXT.
6005
6006\blank \showmathcharacters
6007
6008\stopsection
6009
6010\startsection[title={alphabets}]
6011
6012Traditionally (in \TEX) one enters \ASCII\ characters to represent identifiers
6013and use a font switch to get for instance a bold rendering. In \UNICODE\ it is
6014more natural to use code points that represent the meaning. So, instead if
6015enterinf
6016
6017So instead of keying in byte \type {U+0058} for a bold \type {x} one will use an
6018\UTF\ sequence representing \type {U+1D431}. Because there are not than many
6019editors that show all those \UNICODE\ characters it still makes sense to use
6020regular latin and greek alphabets combined with directives that tell what real
6021alphabet is used. For \CONTEXT\ it does not matter what approach is chosen: both
6022work ok and internally characters are mapped onto the right slot. When a font
6023does not provide a shape a fallback is chosen. Technically one can construct a
6024complete math font by combining all kind of fonts, but this is normally not
6025needed.
6026
6027Here we show the combinations of styles and alternatives. Not all combinations
6028are present in \UNICODE. Actually, as \UNICODE\ math is rather agnostic of
6029cultural determined math rendering, at some point \CONTEXT\ could provide more.
6030\footnote {An example is the German handwriting style Suetterlin that is still
6031used for vectors.} Also, modern \OPENTYPE\ fonts can have alternatives, for
6032instance variants of script, blackboard or fraktur. This is not related to
6033\UNICODE\ and it makes no sense to encode that in \MATHML, but a setup of the
6034rendering.
6035
6036\blank \showmathalphabets
6037
6038\stopsection
6039
6040\startsection[title={scripts}]
6041
6042Glyphs (traditionally) come in three sizes. The script and scriptscript sizes can
6043be downscaled from text size but most math fonts have additional glyphs tuned for
6044smaller sizes. The next table shows some of this.
6045
6046\blank \showmathscripts
6047
6048\stopsection
6049
6050\startsection[title={bold}]
6051
6052There are two ways to look at bold math. First there are bold alphabets and bold
6053symbols and these have some meaning. Then there is what we can best call boldened
6054math that is used in section titles and such. The normal bold then becomes heavy.
6055The next table shows (for the font used here) what bold shapes are available.
6056
6057\blank \showmathbold
6058
6059\stopsection
6060
6061\stopchapter
6062
6063\stopbodymatter
6064
6065\stoptext
6066