Daniel I. Scully

A Beginner's Guide to MathML

Getting started

We're going to approach MathML one aspect at a time, but it's nice to know what we're aiming for in the end so we'll start by having a look at a simple example:

  1. <math xmlns="http://www.w3.org/1998/Math/MathML">
  2. <mi>a</mi>
  3. <msup>
  4. <mi>x</mi>
  5. <mn>2</mn>
  6. </msup>
  7. <mo>+</mo>
  8. <mi>b</mi>
  9. <mi>x</mi>
  10. <mo>+</mo>
  11. <mi>c</mi>
  12. </math>

Boxes such as the one below show what the MathML examples above should look like.

a x 2 + b x + c

There's not too much to say here except to note that the root element in MathML is the <math> element. It must always be present and enclose the entire MathML content. Whether you need to include the 'xmlns' definition depends on how you are using MathML (see the last section on Using MathML). I will neglect the <math> tag in examples for the sake of brevity.

If this is your first encounter with MathML, perhaps coming from a Latex background or similar, then the example may seem somewhat verbose for such a simple equation. This is primarily due to the fact that XML is designed to be absolutley unambiguous in its meaning. While giving you complete control over any expression, regardless of its rarity or complexity, this also makes simple expressions more cumbersome.

Using a text editor which auto-completes XML tags for you will definitely make life easier.