Digitally Displaying Math Formulas with MathML

MathML 3.0In an earlier post I gave a primer on MusicXML as a way to create XML sheet music. Another way that XML can be used to structure and display specialized character types is MathML. One of the challenges of displaying mathematical formulas is that there are many different line heights, superscripts, subscripts, positions of fractions and special characters. Recently adopted by EPUB 3, MathML is a format first recommended by the WC3 in 1998 with version 3.0 finalized in 2010.

Presentation MathML vs. Content MathML

There are two different types of MathML:

  1. Presentation MathML
  2. Content MathML

Sometimes called P-MathML, Presentation MathML is used when the presentation of mathematical expressions, perhaps in the case of printing the formulas in a textbook.  Content MathML, sometimes know as C-MathML, is better used when the functionality of the formula is needed within the XML to perform a task. C-MathML keeps the semantics of the formula.

Here is the code used to write the quadratic equation*:

<math mode="display" xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mi>x</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo form="prefix">−</mo>
<mi>b</mi>
<mo>±</mo>
<msqrt>
<msup>
<mi>b</mi>
<mn>2</mn>
</msup>
<mo>−</mo>
<mn>4</mn>
<mo>⁢</mo>
<mi>a</mi>
<mo>⁢</mo>
<mi>c</mi>
</msqrt>
</mrow>
<mrow>
<mn>2</mn>
<mo>⁢</mo>
<mi>a</mi>
</mrow>
</mfrac>
</mrow>
</math>

MathML is better than using .gif images of formulas, because MathML is searchable whereas the content of a .gif is not. Notice how the following code is selectable with your mouse, meaning they are actual values read by your computer: (NOTE: Only displays correctly in Safari or Firefox who have been the first to adopt MathML natively in the browser https://developer.mozilla.org/en/Mozilla_MathML_Project)

x=−b±b2−4ac2a

The +/- found in the above quadratic equation must be written in P-MathML because it is not an actual operator but a theoretical concept. If you were to write the quadratic formula in C-MathML you would have to write out two separate equations.

One thought on “Digitally Displaying Math Formulas with MathML

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>