This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Add-ons & Links / XML Capabilities / Working with MathML /

Generating MathML

Mathematica 5.0 includes several functions for generating MathML from the boxes and expressions used internally by Mathematica to represent equations. You can enter an equation in a notebook using palettes, menus, or keyboard shortcuts and then convert it into MathML using one of these conversion functions. All the MathML conversion functions are located in the XML`MathML` context.

You can use BoxesToMathML to generate MathML from a box structure. By default, this generates presentation markup only.



Alternatively, you can use ExpressionToMathML to convert a typeset equation in a notebook into MathML. By default, this generates combined markup with both the presentation markup and content markup for the equation enclosed in a semantics element.



The annotation-xml element is used to provide additional information of a type specified by its encoding attribute. Here, the encoding attribute has the value "MathML-Content" indicating that the annotation-xml element contains content MathML.

You can use the option "Formats" to generate either presentation MathML or content MathML only. You can also set the option "Annotations" Rule{} to suppress the header information. For more details, see MathML Conversion Options.



It is important to note that ExpressionToMathML evaluates its first argument before converting it to MathML. Hence, if you supply an expression that can be simplified on evaluation, you may get unexpected results. For example, suppose you want to generate the presentation markup for the following definite integral.



Since the integral evaluates to give the result 1, the following command generates the MathML representation of 1 instead of the integral.



To get the MathML representation of the integral, you must force the integral to remain unevaluated by wrapping the Unevaluated function around it.



Setting Options

These are all the functions that generate MathML as output.

  • BoxesToMathML

  • ExpressionToMathML

  • BoxesToSymbolicMathML

  • ExpressionToSymbolicMathML

  • Import

These functions all accept the following options.

  • "Annotations"

  • "Formats"

  • "NamespacePrefixes"

Using these options, you can control various features of the generated MathML, such as including an XML declaration or DTD declaration, generating presentation markup, content markup, or both, and using an explicit namespace declaration and namespace prefix.

You can specify the options explicitly each time you evaluate one of the MathML functions. Alternatively, you can use the SetOptions command to change the default values of the options for a particular function. The option values you set are then used for all subsequent evaluations of that function.

For example, evaluating the following command ensures that the output for all subsequent evaluations of ExpressionToMathML will by default generate presentation MathML only and omit the header information in the output.