MathML code examples

From ConTeXt wiki

< Math | MathML | XML >


Here is a complete and simple example of a ConTeXt file including MathML for MKII:

  <msup> <mi>x</mi><mn>2</mn> </msup>

That gives:

MathML support in ConTeXt is very extensive, but some features are rather hidden for now.

\setupMMLappearance allows you to adjust various things. For example, the layout of presentational markup which uses mtables for alignment can be changed via \setupMMLappearance[mtable][alternative=a|b|c]. Experiment with the different alternatives to see the effects.

When embedding XML inside normal ConTeXt code, remember that \stopXMLdata gobbles up any following white-space. You'll need to explicitly put it back in if you want it (with \space).

Current bugs and workarounds

To use UTF inside MathML currently requires this workaround:


   % enable unknown elements (should be macro)
   \pushmacro\doXMLentity % needed ?
   % this will change, proper split in element itself
     % here we need to get rid of the namespace; we also
     % have to preserve the leaqding / if present
     % ##2 removes leading spaces
   \let\parseXMLescape \remapXMLescape
   \let\doXMLentity    \remapXMLentity
   \enableXML % sets entities
   \popmacro\doXMLentity % needed ?



Additional space appears in front of an inline equation (tagged as an imath element). The fix (from Hans) is made in xtag-ini.tex: locate the line


and add a * immediately following it, to produce


The * (comment token) prevents the spurious space.


Support with MKIV is not as complete as MKII and under construction. The example above for MKIV:

<math xmlns=''>
  <msup> <mi>x</mi><mn>2</mn> </msup>