MathML code examples

From Wiki
Revision as of 13:16, 9 August 2020 by Taco (talk | contribs) (Text replacement - "<cmd>" to "{{cmd|")
Jump to navigation Jump to search

< 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.

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

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

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>