Converting expressions to MathML

(Excerpt from "The MathML Handbook" by Pavi Sandhu)

As we saw under Using MathML for computations: Mathematica, Mathematica includes many commands for working with MathML. In particular, you can convert expressions in Mathematica syntax into MathML and vice versa. The following example shows an MSP script that displays the MathML representation for any expression in Mathematica syntax. The following figure shows how this script looks when viewed in IE.

Example: An HTML document for converting an expression into MathML.

  <head><title>Conversion to MathML</title></head>
  <body bgcolor="white"> 
    <h1>Conversion to MathML</h1>
    <form method="post">Enter an expression: <input type="text" name="input" align="left" size="50" value="<%Mathlet MSPValue[ $$input, "Sqrt[x+1]"] %>" /> 
      <p><input type="submit" name="inputButton" value="Convert"> </p>
      <p><%Mathlet  MSPBlock[{$$input}, MSPFormat[XML`MathML`ExpressionToMathML[$$input]]] %></p>

webMathematica: Translating mathematical expressions into MathML

Figure: Translating mathematical expressions into MathML.

This script is similar to the previous ones in that it uses Mathlet tags along with the standard functions: MSPValue, MSPBlock, and MSPFormat. The Mathematica function XML`MathML`ExpressionToMathML is used to translate the expression entered by the user into MathML.

You can use the conversion options discussed under MathML conversion functions to control various aspects of the MathML produced, such as the type of markup or the declarations added to it. For example, by default, XML`MathML`ExpressionToMathML yields both presentation markup and content markup encodings of its argument, enclosed in a semantics tag. However, you can modify the function to get either presentation markup or content markup alone by setting the option "Formats" to "PresentationMathML" or "ContentMathML", respectively. Other conversion options for customizing the form of the output include, for example:

  • Adding a namespace declaration and prefix to all the element and attribute names.
  • Adding an XML declaration or DOCTYPE declaration at the start of the MathML expression.
  • Changing the format of the output to be a continuous string without any additional indentation and linebreaking.


<< back next >>





Copyright © CHARLES RIVER MEDIA, INC., Massachusetts (USA) 2003
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "The MathML Handbook" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

CHARLES RIVER MEDIA, INC., 20 Downer Avenue, Suite 3, Hingham, Massachusetts 02043, United States of America