Authoring MathML

As indicated in the introduction of the MathML Recommendation, authors are supposed to use equation editors, conversion programs, and other specialized software tools to generate MathML. This page first describes how to incorporate the code generated in a document readable by Mozilla. In the remainder of the page, some tools are briefly described. Of course, the list is by no means exhaustive and you are invited to check the W3C MathML software list where you can find various other tools. If for some reason you need to know more on how to write MathML code, have a look to Roger B. Sidje's authoring guidelines or the MathML element reference.

Essentials

Example in HTML5 (text/html) Requires Gecko 2.0

Starting with Gecko 2.0 (Firefox 4.0) you can use MathML inline in HTML5 documents. The new HTML5 parser liberates MathML and SVG from XML, which makes well-formed XML markup unessential. In addition, prefixes for elements (like math:math) and name space settings like xmlns="http://www.w3.org/1998/Math/MathML" aren't necessary anymore.

<!DOCTYPE html>
<html>
<head>
 <title>MathML in HTML5</title>
</head>
<body>

<h1>MathML in HTML5</h1>

<math display="block">
  <mrow>
    <munderover>
      <mo>&Sum;</mo>
      <mrow>
        <mi>i</mi>
        <mo>=</mo>
        <mn>1</mn>
      </mrow>
      <mi>N</mi>
    </munderover>
    <msub>
      <mi>a</mi>
      <mi>i</mi>
    </msub>
  </mrow>
</math>

</body>
</html>

Example in XHTML (application/xhtml+xml)

In prior versions (before Gecko 2.0/Firefox 4.0) it is essential to serve MathML as application/xhtml+xml. Basically you need to follow these requirements:

  1. Mozilla must be asked to parse the document as XML.
  2. The document must be a well-formed XML document.

To satisfy the first requirement, it is enough to use local files with the extension .xhtml. More generally, your document must be served as application/xhtml+xml. For example, you can use a .htaccess to configure Apache servers and map an extension to a given Mime type.

To satisfy the second requirement, the natural choice of XML format is XHTML. By default, formulas are treated as inline math. If you prefer to use display math, attach the attribute display="block" to the <math/> element.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
  "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>XHTML+MathML Example</title>
</head>
<body>

<h1>XHTML+MathML Example</h1>

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <munderover>
      <mo>&Sum;</mo>
      <mrow>
        <mi>i</mi>
        <mo>=</mo>
        <mn>1</mn>
      </mrow>
      <mi>N</mi>
    </munderover>
    <msub>
      <mi>a</mi>
      <mi>i</mi>
    </msub>
  </mrow>
</math>

</body>
</html>

Note that some workarounds exist to use MathML inside HTML 4 document such as using <object> , <iframe> or JavaScript, but they are not as convenient/standard as direct embedding of MathML.

Editors & converters

Amaya

homepage - screenshot - output example

Amaya is the W3C's web editor, which is able to handle MathML inside XHTML documents. Use the Elements and the Special Chars panels to create various advanced mathematical constructs. Simple text such that a+2 is automatically parsed and the appropriate MathML markup is generated. Once you are done, you can directly save your XHTML page and open it in Mozilla.

Blahtex

homepage - output example

Blahtex is a TeX-to-MathML converter intended for use with MediaWiki. Here is a simple command:

echo '\sqrt{x^2+\alpha-\frac{z}{a_0}}' | blahtex --mathml > blahtex.xml

Blahtex supports alternative output formats and is planned to replace the current TeX-to-PNG converter of Wikipedia.

Bluegriffon

homepage - screenshot

Bluegriffon is a mozilla-based Wysiwyg HTML editor. An add-on is available to insert MathML formulas in your document, using ASCII/LaTeX-like syntax.

ctop.xsl

XSL source - example

Content MathML is generated by tools, such that computer algebra systems. Use this stylesheet if you want to convert from Content to Presentation MathML.

Firemath

homepage - screenshot - output example

Firemath is an extension for Firefox that provides a WYSIWYG MathML editor. A preview of the formula is displayed using the rendering engine of Mozilla. The generated MathML code is available at the bottom. Use the text field for token elements and buttons to build advanced constructions. Once you are done, you can save your document as a XHTML page.

GELLMU

homepage - input example - output example

Generalized Extensible LaTeX-Like Markup (GELLMU) is a system using a LaTeX-like syntax and is able to produce XHTML+MathML documents.

itex2MML

homepage - input example - output example

itex2MML is a stream filter that converts from a LaTeX-like syntax to MathML. As an example, here is a simple command to convert itex fragments contained in an input file into MathML:

cat input.xhtml | itex2MML > output.xhtml

itex2MML has been successfully used by Jacques Distler to create a blog and a wiki with MathML.

Frédéric Wang has also written Mozilla MathML Add-ons based on the source code of itex2MML. They add features such that a itex2MML parser or conversion of PNG images into MathML.

LaTeXML

homepage - documentation - output example

LaTeXML is a Perl program that mimics TeX's behavior, but produces XML instead of dvi. It has successfully been used in the arXMLiv Project to convert 95% of the research papers from arXiv.org, including 65% without any warning.

MathEL

homepage 

MathEL is (another) stream filter that converts from the MathEL mathematics authoring language to MathML.

MathEL features a concise, highly readable and hence easy-to-learn, pure ASCII presentational mathematics authoring language that has been designed to enable a technical author to easily integrate mathematical formulas into any web site.

MathEL has been successfully used to create a MathML-enabled Wiki.

Mathjax

homepage - MathML samples

MathJax is an open source JavaScript display engine for mathematics, which is able to convert TeX notation into MathML.

Open Office

homepage - screenshot - output example

The famous open source office suite has an equation editor (File → New → Formula). It is semi-WYSIWYG: you enter the source of the formula using the equation panel/keyboard and a preview of the formula is regularly refreshed. The editor uses its own syntax "StarMath" for the source but MathML is also generated when the document is saved. To get the MathML code, save the document as mml and open it with any text editor. Alternatively, you can extract the odf file (which is actually a zip archive) and open an xml file called content.xml.

Tex4ht

homepage - input example - output example

Tex4ht is TeX-based authoring system which is able to generate XHTML+MathML pages. You input a classical LaTeX source file and get an output that can directly be read in Mozilla.

Original Document Information

  • Author(s): Frédéric Wang
  • Other Contributors: Florian Scholz
  • Last Updated Date: April 2, 2011
  • Copyright Information: Portions of this content are © 2010 by individual mozilla.org contributors; content available under a Creative Commons license | Details.

Tags (2)

Edit tags

Attachments (10)

Attach file