% engine=luatex language=uk

% \lesspdfcompression

\usemodule[abr-02,mathml]

% \setupxml[method=mkiv]
% \remapXMLtoMKIV

\def\processXMLbuffer{\dosingleempty\processXMLbuffer}
\def\doprocessXMLbuffer[#1]{\xmlprocessbuffer{test}{#1}{}}

\setupindenting
  [medium,next,yes]

\setupinteraction
  [state=start,
   color=,
   style=]

\placebookmarks
  [chapter,section]

\setupcolors
  [state=start]

\startmode[atpragma]
    \usetypescriptfile[type-buy]
    \usetypescript[lucida][texnansi]
    \setupbodyfont[lucida,11pt]
    \definefont[ChapterFont][Handwriting at 32pt]
    \definefont[SectionFont][Handwriting sa 1.2]
    \definefont[FormulaFont][Handwriting sa 1.0]
\stopmode

\startnotmode[atpragma]
    \usetypescript[palatino][texnansi]
    \setupbodyfont[palatino,11pt]
    \definefont[ChapterFont][SerifBold at 32pt]
    \definefont[SectionFont][SerifBold sa 1.2]
    \definefont[FormulaFont][SerifBold sa 1.0]
\stopnotmode

\setuplayout
  [topspace=2cm,
   backspace=2cm,
   width=middle,
   height=middle]

\setuppagenumbering
  [alternative=doublesided]

\setuphead
  [chapter]
  [alternative=middle,
   number=no,
   style=ChapterFont,
   color=darkred,
   after={\blank[3*big]},
   header=high,
   footer=startofchapter]

\setuphead
  [section]
  [alternative=text,
   textcommand=\SectionCommand,
   number=no,
   style=SectionFont,
   color=darkred,
   after={\blank[big]}]

\def\SectionCommand#1%
  {\inleftmargin{\darkblue\string<\string>}#1}

\setuplayout
  [style=\hw]

\setuppagenumbering
  [color=darkblue]

\setupheader
  [color=darkblue]

\setupfooter
  [color=darkblue]

\setuplinewidth
  [1pt]

\setuptabulate
  [rulecolor=darkblue]

\setuptables
  [rulecolor=darkblue]

\setupfootertexts
  [chapter]

\definetext
  [startofchapter]
  [footer][pagenumber]

\definestartstop
  [element]
  [style=\it]

% \definestartstop
%   [attribute]
%   [style=\it]

\definestartstop
  [attvalue]
  [style=\it]

\definestartstop
  [entity]
  [style=\it,
   left=\string&,
   right=\string;]

\setuplist
  [chapter]
  [interaction=all,
   alternative=b,
   aligntitle=yes,
   style=bold,
   after=\blank]

\setuplist
  [section]
  [interaction=all,
   alternative=b,
   maxwidth=.8\hsize,
   aligntitle=yes]

\definetabulate[directives][|Tl|Tl|Tl|l|]
\definetabulate[attributes][|Tl|Tl|l|l|]

\setupformulas
  [way=bytext]

% some helpers

\startxmlsetups xml:mmlprime
    \xmlsetsetup {\xmldocument} {document} {xml:mmlprime:document}
    \xmlsetsetup {\xmldocument} {textref}  {xml:mmlprime:textref}
\stopxmlsetups

\xmlregistersetup{xml:mmlprime}

\startxmlsetups xml:mmlprime:document
    \blank \start
    \xmlflush{#1}
    \stop \blank
\stopxmlsetups
\startxmlsetups xml:mmlprime:textref
    \in {\xmlflush{#1}} [\xmlatt{#1}{label}]
\stopxmlsetups

% redefine to use lua and mkiv xml instead of slower mkii

\startluacode
    local mapping = {
        [';'] = "{{\\blue\\string;}}",
        ['&'] = "{{\\ttsl\\blue\\string&}}", -- otherwise "et"
        ['/'] = "{{\\blue\\string/}}",
        ['<'] = "{{\\blue\\string<}}",
        ['>'] = "{{\\blue\\string>}}",
    }
    function document.filterxmltitlestuff(name)
        local data = io.loaddata(name)
        data = data:gsub("<math[^>]*>","<math>")
        data = data:gsub("[%s ]+"," ")
        data = data:gsub("(.)",mapping)
        tex.sprint(tex.ctxcatcodes,data)
    end
\stopluacode

\startsetups TitlePageBackground
    \setbox\scratchbox=\vbox to \paperheight {
        \hsize\paperwidth
        \switchtobodyfont[lucida,8pt,hw]
        \let\section\gobbleoneargument
        \def\showXMLfile##1 ##2 ##3 {
            \ignorespaces\ctxlua{document.filterxmltitlestuff("##2##3.xml")}
            \removeunwantedspaces\space\ignorespaces
        }
        \baselineskip=1\baselineskip plus 1pt
        \input mmlfiles\relax
    }
    \setbox\scratchbox=\vsplit\scratchbox to \paperheight
    \vbox to \paperheight {
        \unvbox\scratchbox
        \vskip-.2ex
    }
\stopsetups

\defineoverlay
  [titlepage]
  [\directsetup{TitlePageBackground}]

\starttext

\setupbackgrounds
  [page]
  [background={foreground,titlepage}]

\startstandardmakeup[footerstate=none,doublesided=no,page=]
    \setupalign[left]
    \definefont[BigFont][RegularBold at 108pt]
    \definefont[MedFont][RegularBold at  48pt]
    \vfill
    \BigFont \darkred MathML     \par
    \vskip6pt
    \MedFont \darkred HANS HAGEN \par
\stopstandardmakeup

\setupbackgrounds
  [page]
  [background=]

\startstandardmakeup[footerstate=none,doublesided=no,page=]
    \startpacked
    Hans Hagen \par
    Hasselt, January 2001 / June 2008 \par
    \goto{www.pragma-ade.com}[url(http://www.pragma-ade.com)] \par
    \stoppacked
    \vfill
    More changes and additions can be expected when there is a definitive
    version of the \MATHML~3 specification and more correct testsuite. One
    thing we need to look into is the nesting model dealign with ()
    discussed in the spec.
    \blank
    \start
    \starttabulate
    \NC \color[darkblue]{copyright} \EQ PRAGMA ADE, Hasselt, NL \NC \NR
    \NC \color[darkblue]{version}   \EQ \currentdate \NC \NR
    \NC \color[darkblue]{renderer}  \EQ \doifmodeelse{mkiv}{version 1 / mkiv}{\doifsetupselse{mmc:apply:start}{version 2}{version 3} / mkii} \NC \NR
    \stoptabulate
    \stop
\stopstandardmakeup

\startfrontmatter

\title{Table of Contents}

\startcolumns[n=3,rule=on] % ,balance=no]
  \placelist[chapter,section]
\stopcolumns

\chapter{Introduction}

It is a well known fact that \TEX\ can do a pretty good job on typesetting
math. This is one reason why many scientific articles, papers and books are
typeset using \TEX. However, in these days of triumphing angle brackets,
coding in \TEX\ looks more and more out of place.

From the point of view of an author, coding in \TEX\ is quite natural, given
that some time is spent on reading the manuals. This is because
not only the natural flow of the definition suits the way mathematicians
think, but also because the author has quite some control over the way his
thoughts end up on paper. It will be no surprise that switching to a more
restricted way of coding, which also demands more keystrokes, is not on
forehand considered to be better.

There are however circumstances that one wants to share formulas (or
formula||like specifications) between several applications, one of which is a
typesetting engine. In that case, a bit more work now, later saves you some
headaches due to keeping the different source documents in sync.

As soon as coding math in \XML\ is discussed, those in favour stress
that coding can be eased by using appropriate editors. Here we encounter a
dilemma. For optimal usage, one should code in terms of content, that is, the
principles that are expressed in a formula. Editors are not that strong in
this area, and if they would be, editing would be not that much different
from traditionally editing formulas: just keying in ideas using code that at
first sight looks obscure. A more graphical oriented editor can help authors
to compose formulas, but the underlaying coding will mainly be in terms of
placing glyphs and boxes, and as a result the code will hardly be usable in
other applications.

So either we code in terms of concepts, which permits sharing code among
applications, and poses strong limitations on the influence of authors on the
visual appearance. Or we use an interactive editor to fine tune the
appearance of a formula and take for granted that reuse will be minimal or
suboptimal.

In the following chapters we will discuss the mathematical language \MATHML\
in the perspective of typography. As a typesetting vehicle, we have used
\CONTEXT. However, the principles introduced here and the examples that we
provide are independent of \CONTEXT. For a more formal exploration we
recommend the \MATHML\ specification.

This document is dedicated to all those \CONTEXT\ users who like typesetting
math. I'm sure that my father, who was a math teacher, would have liked
proofreading this document. His absence was compensated by Tobias Burnus,
Wang Lei, Ton Otten, and members of the \CONTEXT\ mailing list who carefully
read the text, corrected the errors in my math, tested the functionality, and
made suggestions. Any remaining errors are mine.

\stopfrontmatter

\startbodymatter

\chapter{What is \MATHML}

\section{Backgrounds}

\MATHML\ showed up in the evolving vacuum between structural \SGML\ markup
and presentational \HTML. Both \SGML\ and \HTML\ can be recognized by angle
brackets. The disadvantage of \SGML\ was that it was so open ended, that
general tools could hardly be developed. \HTML\ on the other hand was easy to
use and became extremely popular and users as well as software vendors
quickly spoiled the original ideas and created a mess. \SGML\ never became
really popular, but thanks to \HTML\ people became accustomed to that kind of
notation. So, when \XML\ came around as a more restricted cousin of \SGML,
the world was kind of ready for it. It cannot be denied that by some clever
marketing many of today's users think that they use something new and modern,
while we are actually dealing with something from the early days of
computing. A main benefit of \XML\ is that it brought the ideas behind \SGML\
(and medium neutral coding in general) to the users and at the same time made
a major cleanup of \HTML\ possible.

About the same time, \MATHML\ was defined, both to bring math to the \WWW,
and to provide a way of coding math that will stimulate sharing the same code
between different applications. At the end of 2000, the \MATHML\ version~2
draft became a recommendation. In the process of rewriting the interpreter
for \CONTEXT\ \MKIV\ mid 2008 a draft of \MATHML\ version~3 has been used.

Now, imagine that we want to present a document on the internet using a
format like \HTML, either for viewing or for being spoken. Converting
text and graphics is, given proper source coding, seldom a problem, but
converting formulas into some angle bracket representation is more tricky. A
way out of this is \MATHML's presentational markup.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> a </mi>
    <mo> + </mo>
    <mi> b </mi>
    <mo> = </mo>
    <mi> c </mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer

This simple formula, when coded in \TEX, looks like:

\starttyping
$$ a + b = c $$
\stoptyping

In presentational \MATHML\ we get:

\typebuffer

In presentational \MATHML, we use mostly begintags (\type {<mi>}) and end
tags (\type {</mi>}). The \element {row} element is the basic building block
of a formula. The \element {mi} element specifies a math identifier and
\element {mo} is used for operators. In the process of typesetting, both are
subjected to interpretation in order to get the best visualization.

Converting \TEX\ code directly or indirectly, using the \DVI\ output or even
in||memory produced math lists, has been one of the driving forces behind
presentational \MATHML\ and other math related \DTD's like \EUROMATH. One may
wonder if there are sound and valid reasons for going the opposite way. You
can imagine that a converter from \TEX\ to \MATHML\ produces \element
{menclose}, \element {mspace}, \element {mstyle} and other elements that can
have many spacing related attributes, but I wonder if any author is willing
to think in those quantities. Visual editors of course are good candidates
for producing presentational \MATHML.

But wouldn't it be more efficient if we could express ideas and concepts in
such a way that they could be handled by a broad range of applications,
including a typesetting engine? This is why, in addition to presentational
\MATHML, there is also content \MATHML. The previous formula, when coded in
such a way, looks like:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <plus/>
      <ci> a </ci>
      <ci> b </ci>
    </apply>
    <ci> c </ci>
  </apply>
</math>
\stopbuffer

\typebuffer

This way of defining a formula resembles the so called polish (or stackwise)
notation. Opposite to presentational markup, here a typesetting engine has to
find out in what order and what way the content has to be presented. This may
seem a disadvantage, but in practice implementing content markup is not that
complicated. The big advantage is that, once we know how to typeset a
concept, \TEX\ can do a good job, while in presentational markup much hard
coded spacing can spoil everything. One can of course ignore specific
elements, but it is more safe to start from less and enhance, than to leave
away something with unknown quantities.

Instead of using hard coded operators as in presentational \MATHML, content
markup uses empty elements like \type {<plus/>}. Many operators and functions
are predefined but one can also define his own; in \MATHML~3 this is further
extended by adopting \OPENMATH\ as variant.

Of course the main question to be answered now is to what extent the author
can influence the appearance of a formula defined in content markup. Content
markup has the advantage that the results can be more consistent, but taking
away all control is counterproductive. The \MATHML\ level~2 draft mentions
that this level covers most of the pre university math. If so, that is a
proper starting point, but especially educational math often has to be
typeset in such ways that it serves its purpose. Also, (re|)|using the
formulas in other applications (simulators and alike) is useful in an
educational setting, so content markup is quite suitable.

How do we combine the advantages of content markup with the wish of an author
to control the visual output and at the same time get an as high as possible
typeset result. There are several ways to accomplish this. One is to include
in the document source both the content markup and the \TEX\ specific code.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <semantics>
    <apply> <eq/>
      <apply> <plus/>
        <ci> a </ci>
        <ci> b </ci>
      </apply>
    </apply>
    <ci> c </ci>
    <annotation encoding="TeX">a+b=c</annotation>
  </semantics>
</math>
\stopbuffer

\typebuffer

The \element {annotation} element is one of the few that is permitted inside
the \element {math} element. In this example, we embed pure \TEX\ code,
which, when enabled is typeset in math mode. It will be clear that for a
simple formula like this one, such redundant coding is not needed, but one
can imagine more complicated formulas. Because we want to limit the amount of
work, we prefer just content markup.
\blank {\it Remark: Some characters, fillers or whatever may not
show up. This is due to the fact that the relevant tables for
\CONTEXT\ \MKIV\ are defined stepwise. In due time most relevant
symbols will be accessible.}

\section{Two methods}

The best way to learn \MATHML\ is to key in formulas, so that is what we did
as soon as we started adding \MATHML\ support to \CONTEXT. In some areas,
\MATHML\ provides much detail (many functions are represented by elements)
while in other areas one has to fall back on the more generic function
element or a full description. Compare the following definitions:

\startbuffer[a]
<document>
  <math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply> <sin/> <ci> x </ci> </apply>
  </math>
  <math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <mrow> <mo> sin </mo> <mi> x </mi> </mrow>
  </math>
</document>
\stopbuffer

\typebuffer[a]

We prefer the first definition because it is more structured and gives more
control over the result. There is only one \quote {unknown} quantity, $x$,
and from the encapsulating element \element {ci} we know that it is an
identifier.

\processXMLbuffer[a]

In the content example, from the \element {apply} \element {sin} we can
deduce that the following argument is an operand, either an \element {apply},
or a \element {ci} or \element {cn}. In the presentational alternative, the
following elements can be braces, a math identifier, a row, a sequence of
identifiers and operators, etc. There, the look and feel is hard coded.

\startbuffer[b]
<?context-mathml-directive function reduction no ?>
\stopbuffer

\typebuffer[b]

This directive, either issued in the \XML\ file, or set in the style file,
changes the appearance of the function, but only in content markup. It is
because of this feature, that we favour content markup.

\processXMLbuffer[b,a]

Does this mean that we can cover everything with content markup? The answer
to this is still unclear. Consider the following definition.

\processXMLfilegrouped {pc-i-380.xml}

Here we combine several cases in one formula by using $\pm$ and $\mp$
symbols. Because we only have \element {plus} and \element {minus} elements,
we have to revert to the generic function element \element {fn}. We show the
complete definition of this formula.

\typefile {pc-i-380.xml}

The \MATHML\ parser and typesetting engine have to know how to handle these
special cases, because the visualization depends on the function (or
operator). Here both composed signs are treated like the plus and minus
signs, but in other cases an embraced argument may be needed. Each special
case needs a specific handler.

\chapter{Presentational markup}

If a document contains presentational \MATHML, there is a good chance that
the code is output by an editor. Here we will discuss the presentation
elements that make sense for users when they want to manually code
presentational \MATHML. In this chapter we show the default rendering, later
we will discuss options.

Although much is permitted, we advise to keep the code as simple as possible,
because then \TEX\ can do a rather good job on interpreting and typesetting
it. Just let \TEX\ take care of the spacing.

\section {mi, mn, mo}

Presentational markup comes down to pasting boxes together in math specific
ways. The basic building blocks are these three character elements.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> x </mi> <mo> = </mo> <mn> 5 </mn>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\starttabulate[||||]
\HL
\NC \element {mi} \NC identifier \NC normally typeset in an italic font \NC \NR
\NC \element {mn} \NC number     \NC normally typeset in a normal font  \NC \NR
\NC \element {mo} \NC operator   \NC surrounded by specific spacing     \NC \NR
\HL
\stoptabulate

Because numbers are taken from an upright font, special numbers are taken
care of automatically. Here are some from the \MATHML\ specification:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mn> 2 </mn>
    <mn> 0.123 </mn>
    <mn> 0,000,000 </mn>
    <mn> 2.1e10 </mn>
    <mn> 0xFFeF </mn>
    <mn> MCMLXIX </mn>
    <mn> twenty one </mn>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Special characters can be accessed by their \UNICODE\ point or
by a corresponding entity. For some reason there is quite some
duplication in entities, but we don't bother too much about it
because after all \UNICODE\ math (which has its own peculiarities)
is the way to go. The specification has this somewhat strange
formula definition:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mn> 2 </mn>
    <mo> + </mo>
    <mrow>
      <mn> 3</mn>
      <mo> &InvisibleTimes; </mi>
      <mi> &ImaginaryI; </mi>
    </mrow>
  </mrow>
  <mfrac>
    <mn> 1 </mn>
    <mn> 2 </mn>
  </mfrac>
  <mi> &pi; </mi>
  <mi> &ExponentialE; </mi>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

And:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac>
    <mo> &DifferentialD; </mo>
    <mrow>
      <mo> &DifferentialD; </mo>
      <mi> x </mi>
    </mrow>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Visualizing the \element {mo} element involved some heuristics. For instance
the size of fences depends on what they fence. In the following case you see
how we can influence this. For practical pusposes we only support size~1.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mo> ( </mo> <mi> x </mi>  <mo> ) </mo>
  </mrow>
  <mtext> or </mtext>
  <mrow>
    <mo maxsize='1'> ( </mo>  <mi> x </mi>  <mo> ) </mo>
  </mrow>
  <mtext> or </mtext>
  <mrow>
    <mo maxsize='1'     > ( </mo>
        <mfrac> <mn> 1 </mn> <mn> 2 </mn> </mfrac>
    <mo stretchy='false'> ) </mo>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer


\section {mrow}

The previous example demonstrated the use of \element {mrow}, the element
that is used to communicate the larger building blocks. Although this element
from the perspective of typesetting is not always needed, by using it, the
structure of the formula in the document source is more clear. There is some
messy magic going on when we try to fake fenced expressions.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow> <mi> x </mi> <mo> &geq; </mo> <mn> 2 </mn> </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> y </mi> <mo> &gt; </mo> <mn> 4 </mn>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mo> &lt; </mo> <mi> x </mi> <mo> &gt; </mo>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> a </mi> <mo> &lt; </mo> <mi> b </mi> <mo> &lt; </mo> <mi> c </mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Spacing between a sign and the following token is taken care of automatically
by \TEX:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mo> - </m0>
    <mn> 1 </mn>
    <mo> - </m0>
    <mn> 1 </mn>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {msup, msub, msubsup}

Where in content markup super and subscript are absent and derived from the
context, in presentational markup they are quite present.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <msup>
    <msub> <mi> x </mi> <mn> 1 </mn> </msub>
    <mn> 2 </mn>
  </msup>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <msubsup>
    <mi> x </mi>
    <mn> 1 </mn>
    <mn> 2 </mn>
  </msubsup>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Watch the difference between both definitions and appearances. You can
influence the default behaviour with processing instructions.

\section {mfrac}

Addition, subtraction and multiplication is hard coded using the \element
{mo} element with $+$, $-$, and $\times$ (or nothing). You can use $/$ for
division, but for more complicated formulas you have to fall back on fraction
building. This is why \MATHML\ provides the \element {mfrac}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac>
    <mrow> <mi> x </mi> <mo> + </mo> <mn> 1 </mn> </mrow>
    <mrow> <mi> y </mi> <mo> + </mo> <mn> 1 </mn> </mrow>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

You can change the width of the rule, but this is generally a
bad idea. For special purposes you can set the line thickness
to zero.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac linethickness="0">
    <mrow> <mi> x </mi> <mo> &geq; </mo> <mn> 2 </mn> </mrow>
    <mrow> <mi> y </mi> <mo> &leq; </mo> <mn> 4 </mn> </mrow>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

A different kind of rendering is also possible, as shown in
the following example.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac bevelled='true'>
    <mfrac>
      <mi> x </mi> <mn> 2 </mn>
      <mi> y </mi> <mn> 4 </mn>
    </mfrac>
    <mfrac>
      <mi> x </mi> <mn> 2 </mn>
      <mi> y </mi> <mn> 4 </mn>
    </mfrac>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mfenced}

Braces are used to visually group sub||expressions. In presentational
\MATHML\ you can either hard code braces, or use the \element {mfenced}
element to generate delimiters automatically. In \CONTEXT, as much as
possible, the operators and identifiers are interpreted, and when
recognized treated according to their nature.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfenced> <mi> a </mi> <mi> b </mi> <mn> 1 </mn> </mfenced>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The fencing symbols adapt their size to the content. Their
dimensions also depend on the way math fonts are defined. The
standard \TEX\ fonts will give the same height of braces around
$x$ and $y$, but in other fonts the $y$ may invoke slightly larger
ones.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfenced open="[" close=")" separators=",">
    <mn> 0 </mn> <mn> 1 </mn>
  </mfenced>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The separators adapt their size to the fenced content too, just like
the fences.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfenced open="[" close="]" separators="|">
    <mfrac> <mn> 1 </mn> <mi> x </mi> </mfrac>
    <mfrac> <mn> 1 </mn> <mi> y </mi> </mfrac>
    <mfrac> <mn> 1 </mn> <mi> z </mi> </mfrac>
  </mfenced>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfenced>
    <mrow> <mn> 1 </mn> <mo> + </mo> <mi> x </mi> </mrow>
  </mfenced>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfenced open='{' close='' separators='|+-'>
    <mn> 1 </mn> <mn> 2 </mn> <mn> 3 </mn> <mn> 4 </mn>
  </mfenced>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfenced open='a' close='e' separators='bcd'>
    <mn> 1 </mn> <mn> 2 </mn> <mn> 3 </mn> <mn> 4 </mn>
  </mfenced>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {msqrt, mroot}

The shape and size of roots, integrals, sums and products can depend on the
size of the content.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <msqrt>
    <mi> b </mi>
  </msqrt>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mroot>
    <mi> b </mi>
    <mn> 2 </mn>
  </mroot>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mroot>
    <mfrac> <mn> 1 </mn> <mi> b </mi> </mfrac>
    <mn> 2 </mn>
  </mroot>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mroot>
    <mfrac>
      <mn> 1 </mn>
      <mrow> <mi> a </mi> <mo> + </mo> <mi> b </mi> </mrow>
    </mfrac>
    <mn> 3 </mn>
  </mroot>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mtext}

If you put text in a \element {mi} element, it will come out rather ugly.
This is due to the fact that identifiers are (at least in \TEX) not subjected
to the kerning that is normally used in text. Therefore, when you want to add
some text to a formula, you should use the \element {mtext} element.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac>
    <mi> Some Text </mi>
    <mtext> Some Text </mtext>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

As with all elements, leading and trailing spaces are ignored. If you really
want a space in front or at the end, you should use one of the space tokens
other than the ascii spacing tokens. You can also use entities like \type
{&nbsp;}.

\section {mover, munder, munderover}

Not all formulas are math and spacing and font rules may differ per
discipline. The following formula reflects a chemical reaction.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mrow>
      <mn> 2 </mn>
      <msub> <mtext> H </mtext> <mn> 2 </mn> </msub>
    </mrow>
    <mo> + </mo>
    <msub> <mtext> O </mtext> <mn> 2 </mn> </msub>
    <munder>
      <mo> &RightArrow; </mo>
      <mtext> explosion </mtext>
    </munder>
    <mrow>
      <mn> 2 </mn>
      <msub> <mtext> H </mtext> <mn> 2 </mn> </msub>
      <mtext> O </mtext>
    </mrow>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \element {munder}, \element {mover} and \element {munderover} elements
can be used to put symbols and text or formulas on top of each other. When
applicable, the symbols will stretch themselves to span the natural size of
the text or formula.

The following examples demonstrate how the relevant components of
this threesome are defined.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> x </mi>
    <munder>
      <mo> &RightArrow; </mo>
      <mtext> maps to </mtext>
    </munder>
    <mi> y </mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> x </mi>
    <munder>
      <mtext> maps to </mtext>
      <mo> &RightArrow; </mo>
    </munder>
    <mi> y </mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> x </mi>
    <mover>
      <mtext> maps to </mtext>
      <mo> &RightArrow; </mo>
    </mover>
    <mi> y </mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> x </mi>
    <mover>
      <mo> &RightArrow; </mo>
      <mtext> maps to </mtext>
    </mover>
    <mi> y </mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <munderover>
      <mi> &int; </mi>
      <mn> 1 </mn>
      <mi> &infin; </mi>
    </munderover>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <mover>
        <mi> x </mi>
        <mo> &Hat; </mo>
    </mover>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {ms}

This is a bit weird element. It behaves like \element {mtext} but puts quotes
around the text.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac>
    <ms> Some Text </ms>
    <mtext> Some Text </mtext>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

You can specify the left and right boundary characters, either directly or
(preferably) using entities like \type {&quot;}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <ms lquote="+" rquote="+"> A Famous Quotation </ms>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {menclose}

This element is implemented but it is such a weird element that it's
probably seldom used.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation='longdiv'><mn>123</mn></menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation='actuarial'><mn>123</mn></menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation='radical'><mn>123</mn></menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

A bit more complex example (taken from the specification) demonstrates
where those somewhat strange rendering options are good for:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mtable columnspacing='0pt' rowspacing='0pt'>
    <mtr>
      <mtd></mtd>
      <mtd columnalign='right'><mn>10</mn></mtd>
    </mtr>
    <mtr>
      <mtd columnalign='right'><mn>131</mn></mtd>
      <mtd columnalign='right'>
        <menclose notation='longdiv'><mn>1413</mn></menclose>
      </mtd>
    </mtr>
    <mtr>
      <mtd></mtd>
      <mtd columnalign='right'>
        <mrow>
          <munder>
            <mn>131</mn>
            <mo>&UnderBar;</mo>
          </munder>
          <mphantom><mn>3</mn></mphantom>
        </mrow>
      </mtd>
    </mtr>
    <mtr>
      <mtd></mtd>
      <mtd columnalign='right'><mn>103</mn></mtd>
    </mtr>
  </mtable>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

In \MATHML~3 a few more notations showed up and to some extend we support
them. We assume that the previously mentioned variants are always applied
to the content first.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="box downdiagonalstrike">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="roundedbox updiagonalstrike">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="circle verticalstrike horizontalstrike">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="left top verticalstrike">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="right bottom horizontalstrike">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="radical right bottom horizontalstrike">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <menclose notation="right bottom horizontalstrike radical">
    <mtext>whatever</mtext>
  </menclose>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The graphics are drawn at runtime by \METAPOST. Currently we don't
combine them into one which would be more efficient in terms of
output (not so much in runtime). You can define additional variants;
as an example we show one of the solutions:

\starttyping
\startuseMPgraphic{mml:enclose:box}
  draw OverlayBox withpen pencircle scaled (ExHeight/10) ;
\stopuseMPgraphic

\defineoverlay [mml:enclose:box] [\useMPgraphic{mml:enclose:box}]
\stoptyping

\section {merror}

There is not much chance that this element will end up in a math textbook,
unless the typeset output of programs is part of the story.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <merror>
    <mtext> Are you kidding? &ThickSpace; </mtext>
    <mfrac>
      <mrow> <mn> 1 </mn> <mo> + </mo> <mi> x </mi> </mrow>
      <mn> 0 </mn>
    </mfrac>
  </merror>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mmultiscripts, mprescripts}

This element is one of the less obvious ones. The next two examples are taken
from the specification. The \element {multiscripts} element takes an odd
number of arguments. The second and successive child elements alternate
between sub- and superscript. The empty element \element {none} |<|a
dedicated element \element {mnone} would have been a better choice|>| serves
as a placeholder.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mmultiscripts>
    <mi> R </mi>
    <mi> i </mi>
    <none/>
    <none/>
    <mi> j </mi>
    <mi> k </mi>
    <none/>
    <mi> l </mi>
    <none/>
  </mmultiscripts>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \element {mmultiscripts} element can also be used to attach prescripts to
a symbol. The next example demonstrates this. The empty \element {prescripts}
element signals the start of the prescripts section.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mmultiscripts>
    <mi> Qb </mi>
    <mn> 4 </mn>
    <none/>
    <mprescripts/>
    <mn> 427 </mn>
    <none/>
  </mmultiscripts>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mspace}

Currently not all functionality of the \element {mspace} element is
implemented. Over time we will see what support is needed and makes sense,
especially since this command can spoil things. We only support the units
that make sense, so units in terms of pixels |<|a rather persistent oversight
in drafts|>| are kindly ignored.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mtext> use  </mtext> <mspace width="1em" />
    <mtext> me   </mtext> <mspace width="1ex" />
    <mtext> with </mtext> <mspace width="10pt"/>
    <mtext> care </mtext>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

You can also pass a sample text:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mfrac>
     <mi> 44 </mi>
     <mfrac>
       <mrow>
         <mn> 11 </mn> <mn> 22 </mn> <mn> 33 </mn>
       </mrow>
       <mrow>
         <mn> 11 </mn> <mspace spacing="22"/> <mn> 33 </mn>
       </mrow>
     </mfrac>
  </mfrac>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mphantom}

A phantom element hides its content but still takes its space. A phantom
element can contain other elements.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mtext>    who is afraid of </mtext>    <mspace width=".5em" />
    <mphantom> phantom          </mphantom> <mspace width=".5em" />
    <mtext>    elements         </mtext>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mpadded}

As with a few other elements, we first have to see some practical usage for
this, before we could implement the functionality needed.

\section {mtable, mtr, mtd, mlabeledtr}

As soon as you want to represent a matrix or other more complicated composed
constructs, you end up with spacing problems. This is when tables come into
view. Because presentational elements have no deep knowledge about their
content, tables made with presentational \MATHML\ will in most cases look
worse than those that result from content markup.

We have implemented tables on top of the normal \XML\ (\HTML) based table
support in \CONTEXT, also known as natural tables. Depending on the needs,
support for the \element {mtable} element will be extended.

The \element {mtable} element takes a lot of attributes. When no attributes
are given, we assume that a matrix is wanted, and typeset the content
accordingly.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mo> ( </mo>
    <mtable>
      <mtr>
        <mtd> <msub> <mi> x </mi> <mn> 1,1 </mn> </msub> </mtd>
        <mtd> <mn> 1 </mn> </mtd>
        <mtd> <mn> 0 </mn> </mtd>
      </mtr>
      <mtr>
        <mtd> <mn> 0 </mn> </mtd>
        <mtd> <msub> <mi> x </mi> <mn> 2,2 </mn> </msub> </mtd>
        <mtd> <mn> 1 </mn> </mtd>
      </mtr>
      <mtr>
        <mtd> <mn> 0 </mn> </mtd>
        <mtd> <mn> 1 </mn> </mtd>
        <mtd> <msub> <mi> x </mi> <mn> 3,3 </mn> </msub> </mtd>
      </mtr>
    </mtable>
    <mo> ) </mo>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mtable columnalign="left center right">
    <mtr>
      <mtd frame="solid"> <mn> 100 </mn> </mtd>
      <mtd              > <mn> 100 </mn> </mtd>
      <mtd              > <mn> 100 </mn> </mtd>
    </mtr>
    <mtr>
      <mtd              > <mn> 10  </mn> </mtd>
      <mtd frame="solid"> <mn> 10  </mn> </mtd>
      <mtd              > <mn> 10  </mn> </mtd>
    </mtr>
    <mtr>
      <mtd              > <mn> 1   </mn> </mtd>
      <mtd              > <mn> 1   </mn> </mtd>
      <mtd frame="solid"> <mn> 1   </mn> </mtd>
    </mtr>
  </mtable>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

A special case is the labeled row \element {mlabeledtr}. This one is
meant for numbering equations. However, is a properly formatted
document there is probably some encapsulating structure that takes
care of this. Therefore we discard the first child element. We show
an example taken from the specification.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mtable>
    <mlabeledtr>
      <mtd>crap</mtd>
      <mtd>
        <mrow>
          <mi>E</mi>
          <mo>=</mo>
          <mrow>
            <mi>m</mi>
            <mi>&it;</mi>
            <msup>
              <mi>c</mi>
              <mn>2</mn>
            </msup>
          </mrow>
        </mrow>
      </mtd>
    </mlabeledtr>
  </mtable>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Although the underlying table mechanism can provide all the support needed
(and even more), not all attributes are yet implemented. We will make a
useful selection.

\starttabulate[|l|l|]
\HL
\NC columnalign   \NC keyword: left center (middle) right \NC \NR
\NC columnspacing \NC a meaningful dimension              \NC \NR
\NC rowspacing    \NC a meaningful dimension              \NC \NR
\NC frame         \NC keyword: none (off) solid (on)      \NC \NR
\NC color         \NC a named color identifier            \NC \NR
\NC background    \NC a named color identifier            \NC \NR
\HL
\stoptabulate

We only support properly named colors as back- and foreground colors. The
normal \CONTEXT\ color mapping mechanism can be used to remap colors. This
permits (read: forces) a consistent usage of colors. If you use named
backgrounds \unknown\ the sky is the limit.

\section {mcolumn}

This element is new in \MATHML~3 and is kind of special in the
sense that the content is analyzed. It would have made more sense
just to provide some proper structure instead since it's intended
use is rather well defined.

Because it is not much fun to implement such a messy element we
only support it partially and add what comes on our way. Here are
a few examples (more or less taken from the reference).

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mcolumn>
    <mn>12</mn>
    <mrow> <mo>&times;</mo> <mn>12</mn> </mrow>
    <mline spacing="000"/>
    <mn>24</mn>
    <mrow> <mn>12</mn> <mspace spacing="0"/> </mrow>
    <mline spacing="000"/>
    <mn>144</mn>
  </mcolumn>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mcolumn>
    <mn>123</mn>
    <mrow> <mn>456</mn> <mo>+</mo> </mrow>
    <mline spacing="000+"/>
    <mn>579</mn>
  </mcolumn>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mcolumn>
    <mn>1,23</mn>
    <mrow> <mn>4,56</mn> <mo>+</mo> </mrow>
    <mline spacing="0,00+"/>
    <mn>5,79</mn>
  </mcolumn>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mcolumn>
    <mstyle mathsize="71%">
        <menclose notation="bottom"> <mn>10</mn> </menclose>
    </mstyle>
    <mn>5&#x0338;2</mn>
    <mrow> <mo>&minus;</mo> <mn>7</mn> </mrow>
    <mline spacing="45"/>
    <mn>45</mn>
  </mcolumn>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Similar effects can be accomplished with the \element {mtable}
element.

\section {malignmark}

This element is used in tables and is not yet implemented, first because I
still have to unravel its exact usage, but second, because it is about the
ugliest piece of \MATHML\ markup you will encounter.

\section {mglyph}

This element is for those who want to violate the ideas of general markup by
popping in his or hers own glyphs. Of course one should use entities, even if
they have to be defined.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <mrow>
    <mi> <mglyph fontfamily="Serif" index="65" alt="The Letter A"/></mi>
    <mo> + </mo>
    <mi> <mglyph fontfamily="Serif" index="66" alt="The Letter B"/></mi>
    <mo> = </mo>
    <mi> <mglyph fontfamily="Serif" index="67" alt="The Letter C"/></mi>
  </mrow>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mstyle}

This element is implemented but not yet discussed since we want more control
over its misuse.

\section {afterword}

You may have noticed that we prefer content \MATHML\ over presentational
\MATHML. So, unless you're already tired of any math coded in angle brackets,
we invite you to read the next chapter too.

\chapter{Content markup}

In this chapter we will discuss the \MATHML\ elements from the point of view
of typesetting. We will not pay attention to other rendering techniques, like
speech generation. Some elements take attributes and those often make more
sense for other applications than for a typesetting engine like \TEX, which
has a strong math engine that knows how to handle math.

One of the most prominent changes in \MATHML~3 is support for an \OPENMATH\
like coding. Here the \element {csymbol} takes the place of the empty element
as first argument of an \element {apply}. There are more symbols in \OPENMATH\
then we supported in the interpreter, but in due time (depending on demand)
we will add more. At the time of writing this there quite some bugs and
inconcistencies in the draf and accompanying demo files which mad it hard
to grasp all the implications for rendering so we probably need to overhaul the
code sometime in the future.

Another change is the usage of \element {apply} has been delegated
to \element {bind}. One may wonder why this hadn't happen before.
For the moment we treat the \element {bind} as were it an \element
{apply}.

\section {apply}

If you are dealing with rather ordinary math, you will only need a subset of
content \MATHML. For this reason we will start with the most common elements.
When you key in \XML\ directly, you will encounter the \element {apply}
element quite often, even in a relatively short formula like the following.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply> <minus/>
        <cn> 1 </cn>
    </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

In most cases the \element {apply} element is followed by a specification
disguised as an empty element.

Later we will see more complex examples but here we already show the different
ways of encoding. First we show the traditional \MATHML~2 method:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply> <forall/>
        <bvar> <ci>x</ci> </bvar>
        <apply> <geq/>
            <ci>x</ci>
            <cn>4</cn>
        </apply>
    </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

This is now called pragmatic \MATHML. Using symbols this
and \element {bind} this becomes strict \MATHML:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='3.0'>
    <bind> <csymbol cd="quant1">forall</csymbol>
        <bvar> <ci>x</ci> </bvar>
        <apply> <csymbol cd="relation1">geq</csymbol>
            <ci>x</ci>
            <cn>4</cn>
        </apply>
    </bind>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {ci, cn, sep}

These elements are used to specify identifiers and numbers. Both elements can
be made more explicit by using attributes.

\startattributes
\HL
\NC type \NC set      \NC use a representation appropriate for sets \NC \NR
\NC      \NC vector   \NC mark this element as vector               \NC \NR
\NC      \NC function \NC consider this element to be a function    \NC \NR
\NC      \NC fn       \NC idem \NC \NR
\HL
\stopattributes

When \attvalue {set} is specified, a blackboard symbol is used when
available.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <in/>
    <ci> x </ci>
    <ci type="set"> N </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \attvalue {function} specification makes sense when the \element {ci}
element is used in for instance a differential equation.

\startattributes
\HL
\NC type \NC integer           \NC a whole number with an optional base \NC \NR
\NC      \NC logical           \NC a boolean constant \NC \NR
\NC      \NC rational          \NC a real number \NC \NR
\NC      \NC complex-cartesian \NC a complex number in $x+iy$ notation \NC \NR
\NC      \NC complex           \NC idem \NC \NR
\NC      \NC complex-polar     \NC a complex number in polar notation \unknown \NC \NR
\HL
\stopattributes

You're lucky when your document uses decimal notation, otherwise you will end
up with long specs if you want to be clear in what numbers are used.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <plus/>
      <cn type="integer" base="16"> 1A2C </cn>
      <cn type="integer" base="16"> 0101 </cn>
    </apply>
    <cn type="integer" base="16"> 1B2D </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Complex numbers have two components. These are separated by the \element
{sep} element. In the following example we see that instead of using a
\element {ci} with set specifier, the empty element \element {complexes} can
be used. We will see some more of those later.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <in/>
    <cn type="complex"> 2 <sep/> 5 </cn>
    <complexes/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {eq, neq, gt, lt, geq, leq}

Expressions, and especially those with \element {eq} are typical for math.
Because such expressions can be quite large, there are provisions for proper
alignment.

\starttabulate[||c||c|] % we want in line math
\HL
\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
    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
\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
    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
\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
    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
\HL
\stoptabulate

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <leq/>
    <ci> a </ci>
    <ci> b </ci>
    <ci> c </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {equivalent, approx, implies}

Equivalence, approximations, and implications are handled like \element {eq}
and alike and have their own symbols.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <equivalent/>
    <apply> <plus/> <ci> a </ci> <ci> b </ci> </apply>
    <apply> <plus/> <ci> b </ci> <ci> a </ci> </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

This document is typeset with \PDFTEX\ version $3.14159$, and given that
\TEX\ is written by a mathematician, it will be no surprise that:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <approx/>
    <cn> 3.14159 </cn>
    <pi/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <implies/>
    <apply> <eq/>
      <apply> <plus/>
        <ci> x </ci>
        <cn> 4 </cn>
      </apply>
      <cn> 9 </cn>
    </apply>
    <apply> <eq/>
      <ci> x </ci>
      <cn> 5 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {minus, plus}

Addition and subtraction are main building blocks of math so you will meet
them often.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <minus/>
    <cn> 37 </cn>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

In most cases there will be more than one argument to take care of, but
especially \element {minus} will be used with one argument too. Although \typ
{<cn> -37 </cn>} is valid, using \element {minus} is sometimes more clear.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <minus/>
    <cn> 37 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

You should pay attention to combinations of \element {plus} and \element
{minus}. Opposite to presentational \MATHML, in content markup you don't
think and code sequential.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <apply> <minus/>
      <ci> x </ci>
    </apply>
    <cn> 37 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

In \MATHML~3 we can also be more vebose:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='3.0'>
    <apply> <csymbol cd="arith1">plus</csymbol>
        <ci>a</ci>
        <ci>x</ci>
    </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {times}

Multiplication is another top ten element. Although \type {3p} as content of
the \element {ci} element would have rendered the next example as well, you
really should split off the number and mark it as \element {cn}. When this is
done consistently, we can comfortably change the font of numbers independent
of the font used for displaying identifiers.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <times/>
    <cn> 3 </cn>
    <ci> p </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

In a following chapter we will see how we can add multiplication signs
between variables and constants.

\section {divide}

When typeset, a division is characterized by a horizontal rule. Some
elements, like the differential element \element {diff}, generate their own
division.

\processXMLfilegrouped{pc-s-001.xml}

This example also demonstrates how to mix \element {plus} and \element
{minus}.

\typefile{pc-s-001.xml}

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply><divide/>
        <apply><minus/>
            <apply><minus/><ci>b</ci></apply>
            <apply><minus/><ci>b</ci></apply>
            <apply><root/> <ci>a</ci></apply>
        </apply>
        <apply><minus/>
            <apply><minus/><ci>b</ci><ci>b</ci></apply>
            <apply><minus/><ci>b</ci></apply>
            <apply><root/> <ci>a</ci></apply>
        </apply>
    </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {power}

In presentational \MATHML\ you think in super- and subscripts, but in content
\MATHML\ these elements are not available. There you need to think in terms
of \element {power}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <apply> <power/>
      <ci> x </ci>
      <cn> 2 </cn>
    </apply>
    <apply> <power/>
      <apply> <sin/>
        <ci> x </ci>
      </apply>
      <cn> 2 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \element {power} element is clever enough to determine where the
superscript should go. In the case of the sinus function, by default it will
go after the function identifier.

\section {root, degree}

If you study math related \DTD's |<|this are the formal descriptions for
\SGML\ or \XML\ element collections|>| you will notice that there are not
that many elements that demand a special kind of typography: differential
equations, limits, integrals and roots are the most distinctive ones.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <root/>
      <degree> 3 </degree>
      <ci> 64 </ci>
    </apply>
    <cn> 4 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Contrary to \element {power}, the \element {root} element uses a specialized
child element to denote the degree. The positive consequence of this is that
there cannot be a misunderstanding about what role the child element plays,
while in for instance \element {power} you need to know that the second child
element denotes the degree.

\section {sin, cos, tan, cot, scs, sec, \unknown}

All members of the family of goniometric functions are available as empty
element. When needed, their argument is surrounded by braces. They all behave
the same.

\starttabulate[|||||]
\HL
\NC sin \NC arcsin \NC sinh \NC arcsinh \NC \NR
\NC cos \NC arccos \NC cosh \NC arccosh \NC \NR
\NC tan \NC arctan \NC tanh \NC arctanh \NC \NR
\NC cot \NC arccot \NC coth \NC arccoth \NC \NR
\NC csc \NC arccsc \NC csch \NC arccsch \NC \NR
\NC sec \NC arcsec \NC sech \NC arcsech \NC \NR
\HL
\stoptabulate

These functions are normally typeset in a non italic (often roman) font
shape.

\processXMLfilegrouped{wh-g-001.xml}

By default the typesetting engine will minimize the number of braces that
surrounds the argument of a function.

\typefile{wh-g-001.xml}

You can specify $\pi$ as an entity \type {&pi;} or as empty element \element
{pi}. In many cases it is up to your taste which one you use. There are many
symbols that are only available as entity, so in some respect there is no
real reason to treat $\pi$ different.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <cos/>
      <pi/>
    </apply>
    <apply> <minus/>
      <cn> 1 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {log, ln, exp}

The \element {log} and \element {ln} are typeset similar to the previously
discussed goniometric functions. The \element {exp} element is a special case
of \element {power}. The constant $e$ can be specified with \element
{exponentiale}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <approx/>
    <apply> <ln/>
      <apply> <plus/>
        <exponentiale/>
        <cn> 2 </cn>
      </apply>
    </apply>
    <cn> 1.55 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <exp/>
      <cn> 2 </cn>
    </apply>
    <cn> 7.3890560989307 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {quotient, rem}

The result of a division can be a rational number, so $\frac{5}{4}$ is
equivalent to $1.25$ and $1.25 \times 4$ gives~$5$. An integer division will
give~$1$ with a remainder~$2$. Many computer languages provide a \type {div}
and \type {mod} function, and since \MATHML\ is also meant for computation,
it provides similar concepts, represented by the elements \element {quotient}
and \element {rem}. The representation of \element {quotient} is rather
undefined, but the next one is among the recommended alternatives.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <quotient/>
    <ci> a </ci>
    <ci> b </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {factorial}

Showing the representation of a factorial is rather dull, so we will use a
few more elements as well as a processing instruction to illustrate the usage
of \element {factorial}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <?context-mathml-directive times symbol yes ?>
  <apply> <eq/>
    <apply> <factorial/>
      <ci> n </ci>
    </apply>
    <apply> <times/>
      <ci> n </ci>
      <apply> <minus/> <ci> n </ci> <cn> 1 </cn> </apply>
      <apply> <minus/> <ci> n </ci> <cn> 2 </cn> </apply>
      <csymbol definitionUrl="cdots"/>
      <cn> 1 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The processing instruction is responsible for the placement of the $\times$
symbols.

\section {min, max, gcd, lcm}

These functions can handle more than two arguments. When typeset, these are
separated by commas.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <ci> z </ci>
    <apply> <min/>
      <apply> <plus/>   <ci> x </ci> <ci> y </ci> </apply>
      <apply> <times/>  <cn> 2 </cn> <ci> x </ci> </apply>
      <apply> <divide/> <cn> 1 </cn> <ci> y </ci> </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {and, or, xor, not}

Logical expressions can be defined using these elements. The operations are
represented by symbols and braces are applied when needed.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <and/>
      <cn type="integer" base="2"> 1001 </cn>
      <cn type="integer" base="2"> 0101 </cn>
    </apply>
    <cn type="integer" base="2"> 0001 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {set, bvar}

The appearance of a \element {set} depends on the presence of the child
element \element {bvar}. In its simplest form, a set is represented as a
list.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <neq/>
    <set>
      <cn> 1 </cn>
      <cn> 4 </cn>
      <cn> 8 </cn>
    </set>
    <emptyset/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

A set can be distinguished from a vector by its curly braces. The simplest
case is just a comma separated list. The next example demonstrates the
declarative case. Without doubt, there will be other alternatives.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <set>
    <bvar><ci> x </ci></bvar>
    <condition>
      <apply> <lt/>
        <cn> 2 </cn>
        <ci> x </ci>
        <cn> 8 </cn>
      </apply>
    </condition>
  </set>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {list}

This element is used in different contexts. When used as a top level element,
a list is typeset as follows.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <list>
    <cn> 1 </cn>
    <cn> 1 </cn>
    <cn> 3 </cn>
  </list>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

When used in a context like \element {partialdiff}, the list specification
becomes a subscript.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <partialdiff/>
    <list>
      <cn> 1 </cn>
      <cn> 1 </cn>
      <cn> 3 </cn>
    </list>
    <ci type="fn"> f </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The function specification in this formula (which is taken from the specs)
can also be specified as \typ {<fn> <ci> f </ci> </fn>} (which is more
clear).

\section {union, intersect, \unknown}

There is a large number of set operators, each represented by a distinctive
symbol.

\starttabulate[||c||c|] % we want in line math
\HL
\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
                \NC \NC \NR
\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
                \NC \NC \NR
\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
    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
\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
    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
\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
    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
\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
                \NC \NC \NR
\HL
\stoptabulate

These operators are applied as follows:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <union/>
    <ci> U </ci>
    <ci> V </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {conjugate, arg, real, imaginary}

The visual representation of \element {conjugate} is a horizontal bar with a
width matching the width of the expression.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <conjugate/>
    <apply> <plus/>
      <ci> x </ci>
      <apply> <times/>
        <cn> &ImaginaryI; </cn>
        <ci> y </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \element {arg}, \element {real} and \element {imaginary} elements trigger
the following appearance.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <arg/>
    <apply> <plus/>
      <ci> x </ci>
      <apply> <times/>
        <cn> &ImaginaryI; </cn>
        <ci> y </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <real/>
    <apply> <plus/>
      <ci> x </ci>
      <apply> <times/>
        <cn> &ImaginaryI; </cn>
        <ci> y </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <imaginaryi/>
    <apply> <plus/>
      <ci> x </ci>
      <apply> <times/>
        <cn> &ImaginaryI; </cn>
        <ci> y </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

\section {abs, floor, ceiling}

There are a couple of functions that turn numbers into positive or rounded
ones. In computer languages names are used, but in math we use special
boundary characters.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <abs/> <cn> -5 </cn> </apply>
    <cn> 5 </cn>
  </apply>
</math>
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <floor/> <cn> 5.5 </cn> </apply>
    <cn> 5 </cn>
  </apply>
</math>
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <ceiling/> <cn> 5.5 </cn> </apply>
    <cn> 6 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {interval}

An interval is visualized as: \startXMLdata <math xmlns='http://www.w3c.org/mathml'
version='2.0'> <interval> <cn> 1 </cn> <cn> 10 </cn> </interval> </math> \stopXMLdata .
The \element {interval} element is a container element and has a begin and endtag.
You can specify the closure as attribute:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <interval closure="open-closed">
    <ci> a </ci>
    <ci> b </ci>
  </interval>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The following closures are supported:

\starttabulate[|||]
\HL
\NC open        \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <interval closure="open"> <ci>
                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
\NC closed      \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <interval closure="closed"> <ci>
                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
\NC open-closed \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <interval closure="open-closed"> <ci>
                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
\NC closed-open \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <interval closure="closed-open"> <ci>
                    a </ci> <ci> b </ci> </interval> </math>} \NC \NR
\HL
\stoptabulate

In strict \MATHML\ we use symbols instead of attributes to
define the openess:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='3.0'>
    <apply> <csymbol cd="interval1">interval_oo</csymbol>
        <ci>a</ci>
        <ci>x</ci>
    </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='3.0'>
    <apply> <csymbol cd="interval1">interval_cc</csymbol>
        <ci>a</ci>
        <ci>x</ci>
    </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {inverse}

This operator is applied to a function. The following example demonstrates
that this is one of the few cases (if not the only one) where the first
element following an \element {apply} begintag is an \element {apply} itself.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply>
    <apply> <inverse/> <sin/> </apply>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {reln} This element is a left||over from the first \MATHML\
specification and its usage is no longer advocated. Its current functionality
matches the functionality of \element {apply}.

\section {cartesianproduct, vectorproduct, scalarproduct, outerproduct}

The context of the formula will often provide information of what kind of
multiplication is meant, but using different symbols to represent the kind of
product certainly helps.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <cartesianproduct/>
    <ci> a </ci>
    <ci> b </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

We have:

\starttabulate[|||]
\HL
\NC cartesian \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <apply> <cartesianproduct/> <ci>
                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
\NC vector    \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <apply> <vectorproduct/> <ci>
                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
\NC scalar    \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <apply> <scalarproduct/> <ci>
                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
\NC outer     \NC \XMLdata {<math xmlns='http://www.w3c.org/mathml' version='2.0'> <apply> <outerproduct/> <ci>
                  a </ci> <ci> b </ci> </apply> </math>} \NC \NR
\HL
\stoptabulate

\section {sum, product, limit, lowlimit, uplimit, bvar}

Sums, products and limits have a distinctive look, especially when they have
upper and lower limits attached. Unfortunately there is no way to specify the
$x_i$ in content \MATHML. In the next chapter we will see how we can handle
that.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <sum/>
    <bvar> <ci> i </ci> </bvar>
    <lowlimit> <cn> 1 </cn> </lowlimit>
    <uplimit> <ci> n </ci> </uplimit>
    <apply> <divide/>
      <cn> 1 </cn>
      <ci> x </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

When we omit the limits, the \element {bvar} is still typeset.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <product/>
    <bvar>
      <ci> i </ci>
    </bvar>
    <apply> <divide/>
      <cn> 1 </cn>
      <ci> x </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

You can specify the condition under which the function is applied.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <product/>
    <bvar>
      <ci> x </ci>
    </bvar>
    <condition>
      <apply> <in/>
        <ci> x </ci>
        <ci type="set"> R </ci>
      </apply>
    </condition>
    <apply> <ci type="fn"> f </ci>
      <ci> x </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <limit/>
    <bvar>
      <ci> x </ci>
    </bvar>
    <lowlimit>
      <cn> 0 </cn>
    </lowlimit>
    <apply> <sin/>
      <ci> x </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {int, diff, partialdiff, bvar, degree}

These elements reach a high level of abstraction. The best way to learn how
to use them is to carefully study some examples.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <diff/>
    <bvar> <ci> a </ci> </bvar>
    <apply> <int/>
      <lowlimit> <ci> p </ci> </lowlimit>
      <uplimit>  <ci> q </ci> </uplimit>
      <bvar> <ci> x </ci> </bvar>
      <apply>
        <fn> <ci> f </ci> </fn>
        <ci> x </ci>
        <ci> a </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \element {bvar} element is essential, since it is used to automatically
generate some of the components that make up the visual appearance of the
formula. If you look at the formal specification of these elements, you will
notice that the appearance may depend on your definition. How the formula
shows up, depends not only on the \element {bvar} element, but also on the
optional \element {degree} element within.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <diff/>
    <ci> f </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <diff/>
    <bvar>
      <ci> x </ci>
      <degree> <cn> 2 </cn> </degree>
    </bvar>
    <apply> <fn> <ci> f </ci> </fn>
      <ci> x </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <partialdiff/>
    <bvar>
      <degree> <cn> 2 </cn> </degree>
      <ci> x </ci>
    </bvar>
    <bvar> <ci> y </ci> </bvar>
    <bvar> <ci> x </ci> </bvar>
    <degree> <cn> 4 </cn> </degree>
    <ci type="fn"> f </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <partialdiff/>
    <bvar>
      <ci> x </ci> <degree> <ci> m </ci> </degree>
    </bvar>
    <bvar>
      <ci> y </ci> <degree> <ci> n </ci> </degree>
    </bvar>
    <degree> <ci> k </ci> </degree>
    <apply> <ci type="fn"> f </ci>
      <ci> x </ci>
      <ci> y </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <partialdiff/>
    <bvar>
      <ci> x </ci> <degree> <ci> m </ci> </degree>
    </bvar>
    <bvar>
      <ci> y </ci> <degree> <ci> n </ci> </degree>
    </bvar>
    <apply> <ci type="fn"> f </ci>
      <ci> x </ci>
      <ci> y </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

When a degree is not specified, it is deduced from the context, but since
this is not 100\% watertight, you can best be complete in your specification.

These examples are taken from the \MATHML\ specification. In the example
document that comes with this manual you can find a couple more.

\section {fn}

There are a lot of predefined functions and operators. If you want to
introduce a new one, the \element {fn} element can be used. In the following
example we have turned the $\pm$ and $\mp$ symbols into (coupled) operators.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <times/>
      <apply> <fn> <ci> &plusminus; </ci> </fn>
        <ci> x </ci>
        <cn> 1 </cn>
      </apply>
      <apply> <fn> <ci> &minusplus; </ci> </fn>
        <ci> x </ci>
        <cn> 1 </cn>
      </apply>
    </apply>
    <apply> <minus/>
      <apply> <power/>
        <ci> x </ci>
        <cn> 2 </cn>
      </apply>
      <cn> 1 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The typeset result depends on the presence of a handler, which in this case
happens to be true.

\section {matrix, matrixrow}

A matrix is one of the building blocks of linear algebra and therefore both
presentational and content \MATHML\ have dedicated elements for defining
it.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <matrix>
    <matrixrow> <cn> 23 </cn> <cn> 87 </cn> <ci>  c </ci> </matrixrow>
    <matrixrow> <cn> 41 </cn> <ci>  b </ci> <cn> 33 </cn> </matrixrow>
    <matrixrow> <ci>  a </ci> <cn> 65 </cn> <cn> 16 </cn> </matrixrow>
  </matrix>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {vector}

We make a difference between a vector specification and a vector variable. A
specification is presented as a list:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <vector>
    <ci> x </ci>
    <ci> y </ci>
  </vector>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

When the \element {vector} element has one child element, we use a right
arrow to identify the variable as vector.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <vectorproduct/>
    <vector> <ci> A </ci> </vector>
    <vector> <ci> B </ci> </vector>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {grad, curl, ident, divergence}

These elements expand into named functions, but we can imagine that in the
future a more appropriate visualization will be provided as an option.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <neq/>
    <apply> <grad/>       <ci> A </ci> </apply>
    <apply> <curl/>       <ci> B </ci> </apply>
    <apply> <ident/>      <ci> C </ci> </apply>
    <apply> <divergence/> <ci> D </ci> </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {lambda, bvar}

The lambda specification of a function needs a \element {bvar} element. The
visualization can be influenced with processing instructions as described in
a later chapter.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <lambda>
    <bvar> <ci> x </ci> </bvar>
    <apply> <sin/>
      <apply> <minus/>
        <ci> x </ci>
        <apply> <divide/>
          <ci> x </ci>
          <cn> 2 </cn>
        </apply>
      </apply>
    </apply>
  </lambda>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {piecewise, piece, otherwise}

There are not so many elements that deal with combinations of formulas or
conditions. The \element {piecewise} is the only real selector available. The
following example defines how the state of~$n$ depends on the state of~$x$.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <ci> n </ci>
    <piecewise>
      <piece>
        <apply> <minus/>
          <cn> 1 </cn>
        </apply>
        <apply> <lt/>
          <ci> x </ci>
          <cn> 0 </cn>
        </apply>
      </piece>
      <piece>
        <cn> 1 </cn>
        <apply> <gt/>
          <ci> x </ci>
          <cn> 0 </cn>
        </apply>
      </piece>
      <otherwise>
        <cn> 0 </cn>
      </otherwise>
    </piecewise>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

We could have used a third \element {piece} instead of (optional) \element {otherwise}.

\section {forall, exists, condition}

Conditions are often used in combination with elements like \element
{forall}. There are several ways to convert and combine them in formulas and
environments, so you may expect more alternatives in the future.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <forall/>
    <bvar> <ci> x </ci> </bvar>
    <condition>
      <apply> <lt/>
        <ci> x </ci>
        <cn> 9 </cn>
      </apply>
    </condition>
    <apply> <lt/>
      <ci> x </ci>
      <cn> 10 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The next example is taken from the specifications with a few small changes.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <forall/>
    <bvar> <ci> x </ci> </bvar>
    <condition>
      <apply> <in/>
        <ci> x </ci>
        <ci type="set"> N </ci>
      </apply>
    </condition>
    <apply> <exists/>
      <bvar> <ci> p </ci> </bvar>
      <bvar> <ci> q </ci> </bvar>
      <condition>
        <apply> <and/>
          <apply> <in/>
            <ci> p </ci>
            <ci type="set"> P </ci>
          </apply>
          <apply> <in/>
            <ci> q </ci>
            <ci type="set"> P </ci>
          </apply>
          <apply> <eq/>
            <apply> <plus/> <ci> p </ci> <ci> q </ci> </apply>
            <apply> <times/> <cn> 2 </cn> <ci> x </ci> </apply>
          </apply>
        </apply>
      </condition>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {factorof, tendsto}

The \element {factorof} element is applied to its two child elements and
contrary to most functions, the symbol is placed between the elements instead
of in front.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <factorof/>
    <ci> a </ci>
    <ci> b </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The same is true for the \element {tendsto} element.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <tendsto/>
    <ci> a </ci>
    <ci> b </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {compose}

This is a nasty element since it has to take care of braces in special ways
and therefore has to analyse its child elements.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <compose/>
    <ci type="fn"> f </ci>
    <ci type="fn"> g </ci>
    <ci type="fn"> h </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply>
    <apply> <compose/>
      <fn> <ci> f </ci> </fn>
      <fn> <ci> g </ci> </fn>
    </apply>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {laplacian}

A laplacian function is typeset using a $\nabla$ (nabla) symbol.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <laplacian/>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {mean, sdev, variance, median, mode}

When statistics shows up in math text books, the \element {sum} element is
likely to show up, probably in combination with the for statistics meaningful
symbolic representation of variables. The mean value of a series of
observations is defined as:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <mean/>
      <ci> x </ci>
    </apply>
    <apply> <divide/>
      <apply> <sum/>
        <ci> x </ci>
      </apply>
      <ci> n </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

or more beautiful:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <mean/>
      <ci> x </ci>
    </apply>
    <apply> <times/>
      <apply> <divide/>
        <cn> 1 </cn>
        <ci> n </ci>
      </apply>
      <apply> <sum/>
        <ci> x </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Of course this definition is not that perfect, but we will present a better
alternative in the chapter on combined markup. The definition of the
standard deviation is more complicated:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <approx/>
    <apply> <sdev/>
      <ci> x </ci>
    </apply>
    <apply> <root/>
      <apply> <divide/>
        <apply> <sum/>
          <apply> <power/>
            <apply> <minus/>
              <ci> x </ci>
              <apply> <mean/>
                <ci> x </ci>
              </apply>
            </apply>
            <cn> 2 </cn>
          </apply>
        </apply>
        <apply> <minus/>
          <ci> n </ci>
          <cn> 1 </cn>
        </apply>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The next example demonstrates the usage of the \element {variance} in its own
definition.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <variance/>
      <ci> x </ci>
    </apply>
    <apply> <approx/>
      <apply> <mean/>
        <apply> <power/>
          <apply> <minus/>
            <ci> x </ci>
            <apply> <mean/>
              <ci> x </ci>
            </apply>
          </apply>
          <cn> 2 </cn>
        </apply>
      </apply>
      <apply> <times/>
        <apply> <divide/>
          <cn> 1 </cn>
          <apply> <minus/>
            <ci> n </ci>
            <cn> 1 </cn>
          </apply>
        </apply>
        <apply> <sum/>
          <apply> <power/>
            <apply> <minus/>
              <ci> x </ci>
              <apply> <mean/>
                <ci> x </ci>
              </apply>
            </apply>
            <cn> 2 </cn>
          </apply>
        </apply>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

The \element {median} and \element {mode} of a series of observations have no
special symbols and are presented as is.

\section {moment, momentabout, degree}

Because \MATHML\ is used for a wide range of applications, there can be
information in a definition that does not end up in print but is only used in
some cases. This is illustrated in the next example.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <moment/>
    <degree>
      <cn> 3 </cn>
    </degree>
    <momentabout>
      <ci> p </ci>
    </momentabout>
    <ci> X </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {determinant, transpose}

These two (and the following) are used to manipulate matrices, either or
not in a symbolic way. A simple determinant or transpose looks like:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <determinant/>
    <ci type="matrix"> A </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <transpose/>
    <ci type="matrix"> A </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

When the \element {determinant} element is applied to a full blown matrix, the
braces are omitted and replaced by the vertical bars.

\processXMLfilegrouped{wh-m-002.xml} \typefile{wh-m-002.xml}

\section {selector}

The \element {selector} element can be used to index a
matrix cell or variable. This element honors the braces.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <selector/>
    <matrix>
      <matrixrow> <cn> 1 </cn> <cn> 2 </cn> </matrixrow>
      <matrixrow> <cn> 3 </cn> <cn> 4 </cn> </matrixrow>
    </matrix>
    <cn> 1 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

A more common usage of the selector is the following:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <selector/>
    <ci> x </ci>
    <ci> i </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

It is possible to pass a comma separated list of indices:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <selector/>
    <ci> x </ci> <cn> 1,2 </cn>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

If you want to have a more verbose index, you can use the \element
{csymbol} element, flagged with text encoding.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <selector/>
    <ci> x </ci>
    <csymbol encoding="text"> max </csymbol>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {card}

A cardinality is visualized using vertical bars.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <card/>
      <ci> A </ci>
    </apply>
    <ci> 5 </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {domain, codomain, image}

The next couple of examples are taken from the \MATHML\ specification and
demonstrate the usage of the not that spectacular domain related elements.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <domain/>
      <fn> <ci> f </ci> </fn>
    </apply>
    <reals/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

These are typically situations where the \element {fn} element may show up.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <codomain/>
      <fn> <ci> f </ci> </fn>
    </apply>
    <rationals/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

This example from the \MATHML\ specification demonstrates a typical usage of
the \element {image} element. As with the previous two, it is applied to a
function, in this case the predefined \element {sin}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <image/>
      <sin/>
    </apply>
    <interval>
      <cn> -1 </cn>
      <cn>  1 </cn>
    </interval>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {domainofapplication}

This is another seldom used element. Actually, this element is a further
specification of the outer level applied function.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <int/>
    <domainofapplication>
      <ci> C </ci>
    </domainofapplication>
    <ci> f </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {semantics, annotation, annotation-xml}

We will never know what Albert Einstein would have thought about \MATHML. But
we do know for sure that coding one of his famous findings in \XML\ takes
much more tokens that it takes in \TEX.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <semantics>
    <apply> <eq/>
      <ci> e </ci>
      <apply> <times/>
        <ci> m </ci>
        <apply> <power/>
          <ci> c </ci>
          <cn> 2 </cn>
        </apply>
      </apply>
    </apply>
    <annotation encoding="tex">
      e = m c^2
    </annotation>
  </semantics>
</math>
\stopbuffer

Within a \element {semantics} element there can be many \element {annotation}
elements. When using \CONTEXT, the elements that can be identified as being
encoded in \TEX\ will be treated as such. Currently, the related \element
{annotation-xml} element is ignored.

\processXMLbuffer \typebuffer

Another variant that we support is called \quote {calcmath} which is an
efficient way to enter school math. The syntax resembles the one used in
advanced calculators.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <semantics>
    <annotation encoding="calcmath">
      x = sqrt(sin(x) + cos(c))
    </annotation>
  </semantics>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {integers, reals, ...}

Sets are characterized with special (often blackboard) symbols. These symbols
are not always available.

\starttabulate[|||] % we want in line math
\HL
\NC integers       \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><integers/>      </math>} \NC \NR
\NC reals          \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><reals/>         </math>} \NC \NR
\NC rationals      \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><rationals/>     </math>} \NC \NR
\NC naturalnumbers \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><naturalnumbers/></math>} \NC \NR
\NC complexes      \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><complexes/>     </math>} \NC \NR
\NC primes         \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><primes/>        </math>} \NC \NR
\HL
\stoptabulate

\section {pi, imaginaryi, exponentiale}

Being a greek character, $\pi$ is a distinctive character. In most math
documents the imaginary~$i$ and exponential~$e$ are typeset as any math
identifier.

\starttabulate[|||] % we want in line math
\HL
\NC pi           \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><pi/>          </math>} \NC \NR
\NC imaginaryi   \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><imaginaryi/>  </math>} \NC \NR
\NC exponentiale \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><exponentiale/></math>} \NC \NR
\HL
\stoptabulate

\section {eulergamma, infinity, emptyset}

There are a couple of more special tokens. As with the other ones, they can
be changed by reassigning the corresponding entities.

\starttabulate[|||] % we want in line math
\HL
\NC eulergamma \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><eulergamma/></math>} \NC \NR
\NC infinity   \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><infinity/>  </math>} \NC \NR
\NC emptyset   \NC \XMLdata{<math xmlns='http://www.w3c.org/mathml' version='2.0'><emptyset/>  </math>} \NC \NR
\HL
\stoptabulate

\section {notanumber}

Because \MATHML\ is used for more purposes than typesetting, there are a
couple of elements that do not make much sense in print. One of these is
\element {notanumber}, which is issued by programs as error code or string.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <divide/>
      <ci> x </ci>
      <cn> 0 </cn>
    </apply>
    <notanumber/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {true, false}

When assigning to a boolean variable, or in boolean expressions one can
use~$0$ or~$1$ to identify the states, but if you want to be more verbose,
you can use these elements.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <equivalent/>
    <cn type="integer" base="2"> 1 </cn>
    <true/>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {declare}

Reusing definitions would be a nice feature, but for the moment the formal
specification of this element currently does not give us the freedom to use
it the way we want.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <declare>
    <ci> A </ci>
    <vector>
      <ci> a </ci>
      <ci> b </ci>
      <ci> c </ci>
    </vector>
  </declare>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section {csymbol}

This element will be implemented as soon as we have an application for it.

\blank {\it is implemented, examples need to be added here}

\chapter{Mixed markup}

The advantage of presentational markup is that you can build complicated
formulas using super- and subscripts and other elements. The drawback is that
the look and feel is rather fixed and cannot easily be adapted to the
purpose that the document serves. Take for instance the difference between

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <log/>
    <logbase> <cn> 2 </cn> </logbase>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

and

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <?context-mathml-directive log location left ?>
  <apply> <log/>
    <logbase> <cn> 2 </cn> </logbase>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

Both formulas were defined in content \MATHML, so no explicit super- and
subscripts were used. In the next chapter we will see how to achieve such
different appearances.

There are situations where content \MATHML\ is not rich enough to achieve the
desired output. This omission in content \MATHML\ forces us to fall back on
presentational markup.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <ci> <msub> <mi> P </mi> <mi> 1 </mi> </msub> </ci>
    <ci> <msub> <mi> P </mi> <mi> 2 </mi> </msub> </ci>
    <apply> <approx/>
      <cn> 1.01 </cn>
      <cn> 1 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

Here we used presentational elements inside a content \element {ci} element.
We could have omitted the outer \element {ci} element, but since the content
\MATHML\ parser may base its decisions on the content elements it finds, it
is best to keep the outer element there.

\typebuffer

The lack of an index element can be quite prominent. For instance, when in an
expose about rendering we want to explore the mapping from coordinates in
user space to those in device space, we use the following formula.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <vector>
      <ci> <msub> <mi> D </mi> <mi> x </mi> </msub> </ci>
      <ci> <msub> <mi> D </mi> <mi> y </mi> </msub> </ci>
      <cn> 1 </cn>
    </vector>
    <apply> <times/>
      <vector>
        <ci> <msub> <mi> U </mi> <mi> x </mi> </msub> </ci>
        <ci> <msub> <mi> U </mi> <mi> y </mi> </msub> </ci>
        <cn> 1 </cn>
      </vector>
      <matrix>
        <matrixrow>
          <ci> <msub> <mi> s </mi> <mi> x </mi> </msub> </ci>
          <ci> <msub> <mi> r </mi> <mi> x </mi> </msub> </ci>
          <cn> 0 </cn>
        </matrixrow>
        <matrixrow>
          <ci> <msub> <mi> r </mi> <mi> y </mi> </msub> </ci>
          <ci> <msub> <mi> s </mi> <mi> y </mi> </msub> </ci>
          <cn> 0 </cn>
        </matrixrow>
        <matrixrow>
          <ci> <msub> <mi> t </mi> <mi> x </mi> </msub> </ci>
          <ci> <msub> <mi> t </mi> <mi> y </mi> </msub> </ci>
          <cn> 1 </cn>
        </matrixrow>
      </matrix>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Again, the \element {msub} element provides a way out, as in the next
examples, which are adapted versions of formulas we used when demonstrating
the statistics related elements.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <mean/>
      <ci> x </ci>
    </apply>
    <apply> <times/>
      <apply> <divide/>
        <cn> 1 </cn>
        <ci> n </ci>
      </apply>
      <apply> <sum/>
        <bvar> <ci> i </ci> </bvar>
        <ci> x </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <mean/>
      <ci> x </ci>
    </apply>
    <apply> <times/>
      <apply> <divide/>
        <cn> 1 </cn>
        <ci> n </ci>
      </apply>
      <apply> <sum/>
        <bvar> <ci> i </ci> </bvar>
        <lowlimit> <cn> 1 </cn> </lowlimit>
        <uplimit> <cn> n </cn> </uplimit>
        <ci> x </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <mean/>
      <ci> x </ci>
    </apply>
    <apply> <times/>
      <apply> <divide/>
        <cn> 1 </cn>
        <ci> n </ci>
      </apply>
      <apply> <sum/>
        <bvar> <ci> i </ci> </bvar>
        <lowlimit> <cn> 1 </cn> </lowlimit>
        <uplimit> <cn> n </cn> </uplimit>
        <ci> <msub> <mi> x </mi> <mi> i </mi> </msub> </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

You can also use a selector for indexing, so in practice we
can avoid the mixed mode:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <vector>
      <apply> <selector/> <ci> D </ci> <ci> x </ci> </apply>
      <apply> <selector/> <ci> D </ci> <ci> y </ci> </apply>
      <cn> 1 </cn>
    </vector>
    <apply> <times/>
      <vector>
        <apply> <selector/> <ci> U </ci> <ci> x </ci> </apply>
        <apply> <selector/> <ci> U </ci> <ci> y </ci> </apply>
        <cn> 1 </cn>
      </vector>
      <matrix>
        <matrixrow>
          <apply> <selector/> <ci> s </ci> <ci> x </ci> </apply>
          <apply> <selector/> <ci> r </ci> <ci> x </ci> </apply>
          <cn> 0 </cn>
        </matrixrow>
        <matrixrow>
          <apply> <selector/> <ci> s </ci> <ci> y </ci> </apply>
          <apply> <selector/> <ci> r </ci> <ci> y </ci> </apply>
          <cn> 0 </cn>
        </matrixrow>
        <matrixrow>
          <apply> <selector/> <ci> t </ci> <ci> x </ci> </apply>
          <apply> <selector/> <ci> t </ci> <ci> y </ci> </apply>
          <cn> 1 </cn>
        </matrixrow>
      </matrix>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\chapter{Directives}

Some elements can be tuned by changing their attributes. Especially when
formulas are defined by a team of people or when they are taken from a
repository, there is a good chance that inconsistencies will show up.

In \CONTEXT, you can influence the appearance by setting the typesetting
parameters of (classes of) elements. You can do this either by adding
processing instructions, or by using the \CONTEXT\ command \type
{\setupMMLappearance}. Although the first method is more in the spirit of
\XML, the second method is more efficient and consistent. As a processing
instruction, a directive looks like:

\starttyping
<?context-mathml-directive element key value ?>
\stoptyping

This is equivalent to the \CONTEXT\ command:

\starttyping
\setupMMLappearance [element] [key=value]
\stoptyping

Some settings concern a group of elements, in which case a group
classification (like \type {sign}) is used.

\section{scripts}

By default, nested super- and subscripts are kind of isolated from each
other. If you want a combined script, there is the \element {msubsup}. You can
however force combinations with a directive.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <msup>
    <msub> <mi> x </mi> <mn> 1 </mn> </msub>
    <mn> 2 </mn>
  </msup>
</math>
<?context-mathml-directive scripts alternative b ?>
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <msup>
    <msub> <mi> x </mi> <mn> 1 </mn> </msub>
    <mn> 2 </mn>
  </msup>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section{sign}

The core element of \MATHML\ is \element {apply}. Even simple formulas will
often have more than one (nested) \element {apply}. The most robust way to
handle nested formulas is to use braces around each sub formula. No matter
how robust this is, when presented in print we want to use as less braces as
possible. The next example shows addition as well as subtraction.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <cn> 7 </cn>
    <cn> 5 </cn>
    <apply> <minus/>
      <cn> 3 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

In principle subtraction is adding negated numbers, so it would have been
natural to have just an addition (\element {plus}) and negation operator.
However, \MATHML\ provides both a \element {plus} and \element {minus}
operator, where the latter can be used as a negation. So in fact we have:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <?context-mathml-directive sign reduction no ?>
  <apply> <plus/>
    <cn> 7 </cn>
    <cn> 5 </cn>
    <apply> <minus/>
      <cn> 3 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

Now imagine that a teacher wants to stress this negation in the way presented
here, using parentheses. Since all the examples shown here are typeset
directly from the \MATHML\ source, you may expect a solution, so here it is:

\typebuffer

By default signs are reduced, but one can disable that at the document
and|/|or formula level using a processing instruction at the top of the
formula. There are of course circumstances where the parentheses cannot be
left out.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <ci> a </ci>
    <apply> <plus/> <ci> b </ci> <ci> c </ci> </apply>
    <ci> d </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <minus/>
    <ci> a </ci>
    <apply> <minus/> <ci> b </ci> <ci> c </ci> </apply>
    <ci> d </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <ci> a </ci>
    <apply> <minus/> <ci> b </ci> <ci> c </ci> </apply>
    <ci> d </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <minus/>
    <ci> a </ci>
    <apply> <plus/> <ci> b </ci> <ci> c </ci> </apply>
    <ci> d </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

Another place where parentheses are not needed is the following:

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <minus/>
    <apply> <exp/>
      <cn> 3 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\typebuffer

This means that the interpreter of this kind of \MATHML\ has to analyze child
elements in order to choose the right way to typeset the formula. The output
will look like:

\processXMLbuffer

By default, as less braces as possible are used. As demonstrated, a special
case is when \element {plus} and \element {minus} have one sub element to
deal with. If you really want many braces there, you can turn off sign
reduction.

\startdirectives
\HL
\NC sign \NC reduction \NC yes \NC use as less braces as possible \NC \NR
\NC      \NC           \NC no  \NC always use braces \NC \NR
\HL
\stopdirectives

We will demonstrate these alternatives with an example.

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <ci> a </ci>
    <apply> <sin/>
      <ci> b </ci>
    </apply>
    <apply> <power/>
      <ci> c </ci>
      <cn> 5 </cn>
    </apply>
    <apply> <power/>
      <apply> <sin/>
        <ci> d </ci>
      </apply>
      <cn> 2 </cn>
    </apply>
    <ci> e </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer[a]

We need quite some code to encode this formula.

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive power reduction no ?>
\stopbuffer

With power reduction turned off, we get:

\processXMLbuffer[b,a]

As directive we used:

\typebuffer[b]

The following example illustrates that we should be careful in coding such
formulas; here the \element {power} is applied to the argument of \element
{sin}.

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <ci> a </ci>
    <apply> <sin/>
      <ci> b </ci>
    </apply>
    <apply> <power/>
      <ci> c </ci>
      <cn> 5 </cn>
    </apply>
    <apply> <sin/>
      <apply> <power/>
        <ci> d </ci>
        <cn> 2 </cn>
      </apply>
    </apply>
    <ci> e </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer \typebuffer

\section{divide}

Divisions can be very space consuming but there is a way out: using a forward
slash symbol. You can set the level at which this will take place. By
default, fractions are typeset in the traditional way.

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <divide/>
    <cn> 1 </cn>
    <apply> <plus/>
      <cn> 1 </cn>
      <apply> <divide/>
        <cn> 1 </cn>
        <ci> x </ci>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\startbuffer[b]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <divide/>
    <cn> 1 </cn>
    <apply> <plus/>
      <cn> 1 </cn>
      <apply> <divide/>
        <cn> 1 </cn>
        <apply> <plus/>
          <cn> 1 </cn>
          <apply> <divide/>
            <cn> 1 </cn>
            <ci> x </ci>
          </apply>
        </apply>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\processXMLbuffer[a] \typebuffer[a]
\processXMLbuffer[b] \typebuffer[b]

\startbuffer[c]
<?context-mathml-directive divide level 1 ?>
\stopbuffer

\processXMLbuffer[c,a] \processXMLbuffer[c,b] \typebuffer[c]

\startbuffer[c]
<?context-mathml-directive divide level 2 ?>
\stopbuffer

\processXMLbuffer[c,a] \processXMLbuffer[c,b] \typebuffer[c]

\section{relation}

You should keep in mind that (at least level 2) content \MATHML\ is not that
rich in terms of presenting your ideas in a visually attractive way. On the
other hand, because the content is highly structured, some intelligence can
be applied when typesetting them. By default, a relation is not vertically
aligned but typeset horizontally.

If an application just needs raw formulas, definitions like the following are
all right.

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <apply> <plus/>
      <ci> a </ci>
      <ci> b </ci>
      <ci> c </ci>
    </apply>
    <apply> <plus/>
      <ci> d </ci>
      <ci> e </ci>
    </apply>
    <apply> <plus/>
      <ci> f </ci>
      <ci> g </ci>
      <ci> h </ci>
      <ci> i </ci>
    </apply>
    <cn> 123 </cn>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

The typeset result will bring no surprises:

\processXMLbuffer[a]

But, do we want to show a formula that way? And what happens with much longer
formulas? You can influence the appearance with processing instructions.

\startdirectives
\HL
\NC relation \NC align \NC no    \NC don't align relations \NC \NR
\NC          \NC       \NC left  \NC align all relations left \NC \NR
\NC          \NC       \NC right \NC align all relations right \NC \NR
\NC          \NC       \NC first \NC place the leftmost relation left \NC \NR
\NC          \NC       \NC last  \NC place the rightmost relation right \NC \NR
\HL
\stopdirectives

The next couple of formulas demonstrate in what way the previously defined
formula is influenced by the processing instructions.

\startbuffer[b]
<?context-mathml-directive relation align left ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive relation align right ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive relation align first ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive relation align last ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{base}

When in a document several number systems are used, it can make sense to
mention the base of the number. There are several ways to identify the base.

\startdirectives
\HL
\NC base \NC symbol \NC numbers    \NC a (decimal) number \NC \NR
\NC      \NC        \NC characters \NC one character      \NC \NR
\NC      \NC        \NC text       \NC a mnemonic         \NC \NR
\NC      \NC        \NC no         \NC no symbol          \NC \NR
\HL
\stopdirectives

By default, when specified, a base is identified as number.

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <cn type="integer" base="8"> 1427 </cn>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive base symbol numbers ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive base symbol characters ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive base symbol text ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{function}

There is a whole bunch of functions available as empty element, like \element
{sin} and \element {log}. When a function is applied to a function, braces
make not much sense and placement is therefore disabled.

\startdirectives
\HL
\NC function \NC reduction \NC yes \NC chain functions without braces \NC \NR
\NC          \NC           \NC no  \NC put braces around nested functions \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <sin/> <ci> x </ci> </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive function reduction yes ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive function reduction no ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{limits}

When limits are placed on top of the limitation symbol, this generally looks
better than when they are placed alongside. You can also influence limit
placement per element. This feature is available for \element{int}, \element
{sum}, \element {product} and \element {limit}.

\startdirectives
\HL
\NC limit \NC location \NC top   \NC place limits on top of the symbols \NC \NR
\NC       \NC          \NC right \NC attached limits as super/subscripts \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <int/>
    <bvar> <ci> x </ci> </bvar>
    <lowlimit> <cn> 0 </cn> </lowlimit>
    <uplimit> <cn> 1 </cn> </uplimit>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive int location top ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive int location right ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{declare}

Currently declarations are not supposed to end up in print. By default we
typeset a message, but you can as well completely hide declarations.

\startdirectives
\HL
\NC declare \NC state \NC start \NC show declarations \NC \NR
\NC         \NC       \NC stop  \NC ignore (hide) declarations \NC \NR
\HL
\stopdirectives

\section{lambda}

There is more than one way to visualize a lambda function. As with some other
settings, changing the appearance can best take place at the document level.

\startdirectives
\HL
\NC lambda \NC alternative \NC b \NC show lambda as arrow \NC \NR
\NC        \NC             \NC a \NC show lambda as set \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <lambda>
    <bvar> <ci> x </ci> </bvar>
    <apply> <log/>
      <ci> x </ci>
    </apply>
  </lambda>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive lambda alternative a ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive lambda alternative b ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{power}

Taking the power of a function looks clumsy when braces are put around the
function. Therefore, by default, the power is applied to the function symbol
instead of the whole function.

\startdirectives
\HL
\NC power \NC reduction \NC yes \NC attach symbol to function symbol \NC \NR
\NC       \NC           \NC no  \NC attach symbol to function argument \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <power/>
    <apply> <ln/>
      <ci> x </ci>
    </apply>
    <cn> 3 </cn>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive power reduction yes ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive power reduction no ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{diff}

Covering all kind of differential formulas is not trivial. Currently we
support two locations for the operand (function). By default the operand is
placed above the division line.

\startdirectives
\HL
\NC diff \NC location \NC top   \NC put the operand in the fraction \NC \NR
\NC      \NC          \NC right \NC put the operand after the fraction \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <diff/>
    <bvar>
      <ci> x </ci>
      <degree> <cn> 2 </cn> </degree>
    </bvar>
    <apply> <fn> <ci> f </ci> </fn>
      <apply> <plus/>
        <apply> <times/>
          <cn> 2 </cn>
          <ci> x </ci>
        </apply>
        <cn> 1 </cn>
      </apply>
    </apply>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive diff location top ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive diff location right ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{vector}

Depending on the complication of a vector or on the available space, you may
wish to typeset a vector horizontally or vertically. By default a vector is
typeset horizontally.

\startdirectives
\HL
\NC vector \NC direction \NC horizontal \NC put vector elements alongside \NC \NR
\NC        \NC           \NC vertical   \NC stack vector elements \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <eq/>
    <vector>
      <ci> x </ci>
      <ci> y </ci>
      <ci> z </ci>
    </vector>
    <vector>
      <cn> 1 </cn>
      <cn> 0 </cn>
      <cn> 1 </cn>
    </vector>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive vector direction horizontal ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive vector direction vertical ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{times}

Depending on the audience, a multiplication sign is implicit (absent) or
represented by a regular times symbol or a dot.

\startdirectives
\HL
\NC times \NC symbol \NC no  \NC don't add a symbol \NC \NR
\NC       \NC        \NC yes \NC separate operands by a times ($\times$) \NC \NR
\NC       \NC        \NC dot \NC separate operands by a dot ($\cdot$)\NC \NR
\NC auto  \NC symbol \NC no  \NC don't check for succesive numbers \NC \NR
\NC       \NC        \NC yes \NC separate succesive numbers by a times ($\times$) \NC \NR
\NC       \NC        \NC dot \NC separate succesive numbers by a dot ($\cdot$)\NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <plus/>
    <ci> x </ci>
    <apply> <times/>
      <cn> 2 </cn>
      <ci> x </ci>
    </apply>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive times symbol no ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive times symbol yes ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive times symbol dot ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{log}

The location of a logbase depends on tradition and|/|or preference, which is
why we offer a few alternatives: as pre superscript (in the right top corner
before the symbol) or as post subscript (in the lower left corner after the
symbol).

\startdirectives
\HL
\NC log \NC location \NC right \NC place logbase at the right top \NC \NR
\NC     \NC          \NC left  \NC place logbase at the lower left \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <log/>
    <logbase>
      <ci> 3 </ci>
    </logbase>
    <apply> <plus/>
      <ci> x </ci>
      <cn> 1 </cn>
    </apply>
  </apply>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive log location right ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive log location left ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{polar}

For polar notation we provide several renderings:

\startdirectives
\HL
\NC polar \NC alternative \NC a \NC explicit polar notation       \NC \NR
\NC       \NC             \NC b \NC exponential power notation    \NC \NR
\NC       \NC             \NC c \NC exponential function notation \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <cn type="polar"> 2 <sep/> <pi/> </cn>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive polar alternative a ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive polar alternative b ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive polar alternative c ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\section{e-notation}

Depending on the context, you may want to typeset the number \type {1.23e4}
not as this sequence, but using a multiplier construct. As with the \element
{times}, we support both multiplication symbols.

\startdirectives
\HL
\NC enotation \NC symbol \NC no  \NC no interpretation              \NC \NR
\NC           \NC        \NC yes \NC split exponent, using $\times$ \NC \NR
\NC           \NC        \NC dot \NC split exponent, using $\cdot$  \NC \NR
\HL
\stopdirectives

\startbuffer[a]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <cn type="e-notation">10<sep/>23</cn>
</math>
\stopbuffer

\typebuffer[a]

\startbuffer[b]
<?context-mathml-directive enotation symbol no ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive enotation symbol yes ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\startbuffer[b]
<?context-mathml-directive enotation symbol dot ?>
\stopbuffer

\processXMLbuffer[b,a] \typebuffer[b]

\chapter{Features}

In this chapter we will introduce some additional elements that are not part
of \MATHML, but can be used to organize your math in such a way that it can
be part of elementary math books.

\chapter{Typesetting modes}

Math can be typeset in line or in display. In order not to widen up the text
of a paragraph too much, inline math is typeset more cramped. Since \MATHML\
does provide just a general purpose \element {math} element we have to
provide the information needed using other elements. Consider the following
text.

\blank {\it todo: define the extra elements}

\startbuffer
<document>
To what extent is math supposed to reflect the truth and nothing but
the truth? Consider the simple expression
    <math xmlns='http://www.w3c.org/mathml' version='2.0'>
        <apply> <eq/>
            <cn> 10 </cn>
            <apply> <plus/>
                <cn> 3 </cn>
                <cn> 7 </cn>
            </apply>
        </apply>
    </math>. Many readers will consider this the truth, but then,
can we assume that the decimal notation is used?

<formula>
  <math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply> <eq/>
      <cn> 10 </cn>
      <apply> <plus/>
        <cn> 3 </cn>
        <ci> x </ci>
      </apply>
    </apply>
  </math>
</formula>

In many elementary math books, you can find expressions like the
previous. Because in our daily life we use the decimal numbering system,
we can safely assume that
    <math xmlns='http://www.w3c.org/mathml' version='2.0'>
        <apply> <eq/>
            <ci> x </ci>
            <cn> 7 </cn>
        </apply>
    </math>. But, without explicitly mentioning this boundary condition,
more solutions are correct.

<formula label="octal" sublabel="a">
  <math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply> <eq/>
      <cn> 10 </cn>
      <apply> <plus/>
        <cn> 3 </cn>
        <cn> 5 </cn>
      </apply>
    </apply>
  </math>
</formula>

In <textref label="octal">formula</textref> we see an at first sight
wrong formula. But, if we tell you that octal numbers are used, your
opinion may change instantly. A rather clean way out of this confusion
is to extend the notation of numbers by explicitly mentioning the base.

<subformula label="octal base" sublabel="b">
  <math xmlns='http://www.w3c.org/mathml' version='2.0'>
    <apply> <eq/>
      <cn type="integer" base="8"> 10 </cn>
      <apply> <plus/>
        <cn type="integer" base="8"> 3 </cn>
        <cn type="integer" base="8"> 5 </cn>
      </apply>
    </apply>
  </math>
</subformula>

Of course, when a whole document is in octal notation, a proper
introduction is better than annotated numbers as used in <textref
label="octal base">formula</textref>.
</document>
\stopbuffer

\blank \startnarrower \processXMLbuffer \stopnarrower \blank

In terms of \XML\ this can look like:

\typebuffer

Math that is part of the text flow is automatically handled as in line math.
If needed you can encapsulate the code in an \element {imath} environment.
Display math is recognized as such when it is a separate paragraph, but since
this is more a \TEX\ feature than an \XML\ one, you should encapsulate
display math either in a \element {dmath} element or in a \element {formula}
or \element {subformula} element.

\chapter {Getting started}

A comfortable way to get accustomed to \MATHML\ is to make small documents of
the following form:

\starttyping
\usemodule[mathml]

\starttext

\startXMLdata
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <cos/>
    <ci> x </ci>
  </apply>
</math>
\stopXMLdata

\stoptext
\stoptyping

As you see, we can mix \MATHML\ with normal \TEX\ code. A document like this
is processed in the normal way using \TEXEXEC. If you also want to see the
original code, you can say:

\starttyping
\usemodule[mathml]

\starttext

\startbuffer
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <cos/>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\processXMLbuffer

\typebuffer

\stoptext
\stoptyping

Like \TEX\ and \METAPOST\ code, buffers can contain \MATHML\ code.  The
advantage of this method is that we only have to key in the data once. It
also permits you to experiment with processing instructions.

\starttyping
\startbuffer[mml]
<math xmlns='http://www.w3c.org/mathml' version='2.0'>
  <apply> <log/>
    <logbase> <cn> 3.5 </cn> </logbase>
    <ci> x </ci>
  </apply>
</math>
\stopbuffer

\startbuffer[pi]
 <?context-mathml-directive log location right ?>
\stopbuffer

\processXMLbuffer[pi,mml]

\startbuffer[pi]
 <?context-mathml-directive log location left ?>
\stopbuffer

\processXMLbuffer[pi,mml]
\stoptyping

If you like coding your documents in \TEX\ but want to experiment with
\MATHML, combining both languages in the way demonstrated here may be an
option. When you provide enough structure in your \TEX\ code, converting a
document to \XML\ is then not that hard to do. Where coding directly in \XML\
is kind of annoying, coding \MATHML\ is less cumbersome, because you can
structure your formulas pretty well, especially since the fragments are small
so that proper indentation is possible.

\chapter{OpenMath}

Because \OPENMATH\ is now a subset of \MATHML\ we can to some extend also
support this coding. We do a straightforward remapping to content \MATHML\
so any rendering that is supported there is also supported in the
equivalent \OPENMATH\ code.

\startbuffer
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
  <OMA> <OMS cd="relation1" name="eq"/>
    <OMV name="y"/>
    <OMA> <OMS cd="arith1" name="minus"/>
      <OMA> <OMV name="f"/>
        <OMV name="x"/>
      </OMA>
      <OMA> <OMV name="f"/>
        <OMA> <OMS cd="arith1" name="minus"/>
          <OMV name="x"/>
          <OMI>1</OMI>
        </OMA>
      </OMA>
    </OMA>
  </OMA>
</OMOBJ>
\stopbuffer

\processXMLbuffer \typebuffer

Because in practice we may use a mixture of math encodings this can come
in handy because it saves conversion of the \XML\ source.

\chapter{CalcMath}

We support two types of annotation markup: \TEX\ (\type {tex}) and what we
call \quote {calculator math} (\type {calcmath}). The second type is also
available directly. Inline calcmath is coded using the \element{icm} element.

\startbuffer
<document>
  This is an inline formula <icm>sin(x^2+1/x)</icm> just to demonstrate
  the idea of calculator math.
</document>
\stopbuffer

\blank \noindentation \processXMLbuffer \typebuffer

If one edits the \XML\ file directly this can type quite some
coding. For more complex formulas one can revert to content \MATHML,
or when interactivity is needed to \OPENMATH.

The argument that one should use a dedicated editor for math
instead is not that convincing for authors who have to key on lots
of small snippets of math. And one can always transform this code
in its more bloated variant. The calcmath converter is dedicated
to Frits Spijkers, author of Dutch math schoolbooks and fluent in
all those math encodings methods we force upon him. The code
resembles that used in calculators at schools and we used it in
projects with computer aided feedback where students had to key in
math.

\chapter{A few examples}

\setupformulas
  [left=,
   right=,
   location=left,
   numberstyle=FormulaFont,
   numbercolor=darkblue]

\reset[formula]

\def\showXMLfile #1 #2 #3
  {\bgroup
   \setuplabeltext[formula=#1 ]
   \setnumber[formula]{#3}
   \decrementnumber[formula]
   \placeformula\startformula
     \processXMLfilegrouped{#2#3.xml}
   \stopformula
   \egroup
   \typefile{#2#3.xml}
   \page[bigpreference]}

\input mmlfiles

% In due time we will move these xtag things to x-newmme.tex.

\def\doMMLfiles#1%
  {\doMMLshow{Arrow relations}  {xtag-m#1a}{0}
   \doMMLshow{Binary operators} {xtag-m#1b}{1}
   \doMMLshow{Delimiters}       {xtag-m#1c}{1}
   \doMMLshow{General Technical}{xtag-m#1h}{1}
   \doMMLshow{Negated Relations}{xtag-m#1n}{1}
   \doMMLshow{Ordinary Symbols} {xtag-m#1r}{1}
   \doMMLshow{Ordinary}         {xtag-m#1o}{1}}

\def\doMMLshow#1#2#3%
  {\ifcase#3\else\NC\NR\NC\NR\fi
   \NC\switchtobodyfont[big]%
      \writetolist[section]{}{#1}%
      \rlap{\hwa\SectionCommand\darkred#1}\NC\NR
   \NC\NR
   \doifmodeelse{complete}
     {\readfile{#2}{}{}}
     {{\em Remark: list skipped in this version.}}}

\chapter{Primary entities}

This chapter is one big table of entities. This list is derived from the
lists posted on the \WWW\ by Patrick Ion from the American Mathematics
Society.

\def\showMMLentities
  {\bgroup
   \switchtobodyfont[small]
   \def\dodefineMMLentity##1##2##3##4%
     {\NC\ConvertConstantAfter\doifnot{##3}{unknown}{\defineXMLentity[##1]{##3}}%
         \showMMLentity{##1}\NC\tttf##1\NC\tttf##2\NC##4\NC\NR}%
   \starttabulate[|l|l|l|l|]
     \doMMLfiles{e}%
   \stoptabulate
   \egroup}

\showMMLentities

\chapter{Synonym entities}

If, after reading the previous chapter, you still think that entities form
a well defined clean language, this chapter will destroy your dreams.

\def\showMMLsynonyms
  {\bgroup
   \switchtobodyfont[small]
   \def\dodefineMMLsynonym##1##2%
     {\NC\showMMLentity{##1}\NC\tttf##1\NC\tttf##2\NC\NR}%
   \starttabulate[|l|l|l|]
     \doMMLfiles{x}
   \stoptabulate
   \egroup}

\showMMLsynonyms

\stopmode

\chapter{Further reading}

\section {The MathML spec} You can fetch the latest version of this document,
which is written by the \MATHML\ committee from \hyphenatedurl {www.w3c.org}
web||site. Depending on the state of development, you can grab the draft,
recommendation or standard.

\section {The \TeX book} Once you have read this book, you will see why
\MATHML\ is not embraced by those who love to optimize the look and feel of
their math formulas. Although your documents will be more consistent when you
code in (content) \MATHML, you also loose many fine points of math
typesetting. Of course you can always fall back on the \element {annotation}
element. This book is written by Donald Knuth and published by Addison
Wesley.

\section {The XML Companion} Written by Neil Bradley and published by
Addison Wesley, this book is a good introduction to \XML\ and its relatives.
More compact but not less useful, is Robert Eckstein's {\em XML Pocket
Reference}, published by O'Reilly.

\section {XML in \ConTeXt} This document describes how you can use \CONTEXT\
for processing your \XML\ documents. You may also want to take a look at the
beginners manual, the reference manual, guides and examples that can be
fetched from \hyphenatedurl {www.pragma-ade.com}.

\section {MathML in \ConTeXt} We have keyed in a lot of realistic \MATHML\
examples and turned them into a document suitable for viewing on your
computer display. Over time, this collection will grow.

\section {MathML} This is a short manual explaining how to load and use the
\MATHML\ module.

\stopbodymatter

\stoptext
