webMathematica >

MathML

One resource for learning more about MathML is the Wolfram Research sponsored website, http://www.mathmlcentral.com. A section describing the evolution of MathML and some of the issues involved in developing a mathematical language suitable for a computation system such as Mathematica is found at http://www.mathmlcentral.com/history.html.

Embedding MathML in Web Documents

XHTML

XHTML is an XML compliant form of HTML, available as an official W3C recommendation, http://www.w3.org/MarkUp. It is very similar to HTML, except that for a document to be valid it must follow the rules of XML. (Some of these were described in the previous section.) To use documents that mix mathematics and text, XHTML is required. Use of XHTML is needed anyway, since the W3C intends that HTML will not be developed further.
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Basic XHTML Document</title>
</head>
<body>
<h1>XHTML</h1>
<p>This is a basic XHTML document.</p>
</body>
</html>

XHTML and MathML

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Basic XHTML+MathML Document</title>
</head>
<body>
<h1>XHTML+MathML</h1>
<p>Here is a math expression.</p>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup></math>
</body>
</html>

Rendering XHTML and MathML Documents

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/mathml.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Basic XHTML+MathML Document</title>
</head>
<body>
<h1>XHTML+MathML</h1>
<p>Here is a math expression.</p>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
</math>
</body>
</html>
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/webMathematica/Resources/XSL/mathml.xsl"?>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mi>sin</mi>
<mo>&af;</mo>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mi>sin</mi>
<mo>&#8289;</mo>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
In[1]:=
Out[1]//BaseForm=

Generating MathML from webMathematica

<msp:evaluate>
MSPFormat[ expr, MathMLForm]
</msp:evaluate>
<msp:evaluate>
MSPFormat[ expr, TraditionalForm, PresentationMathML]
</msp:evaluate>
<msp:evaluate>
MSPFormat[ expr, TraditionalForm, ContentMathML]
</msp:evaluate>

MathML Integrate Example

This example JSP uses the MathML stylesheet. The page is actually a combination of two JSPs, IntegrateForm.jsp and IntegrateXSLT.jsp, that use JavaScript. They are closely modeled on the standard webMathematica examples PlotScript.jsp and PlotScript1.jsp. The source for these MathML examples is available in webMathematica/Examples/MathML. If you installed webMathematica as described above, you should be able to connect to this JSP via http://localhost:8080/webMathematica/Examples/MathML/IntegrateForm.jsp. (You may have some other URL for accessing your server.)
<%@ taglib uri="http://www.wolfram.com/msp" prefix="msp" %>

<html>

<head>
<title>MathML Example: Integrate a Function</title>
<script>
function integrate(f, page)
{
if ( page == 1)
pageToLoad = "IntegrateXSLT.jsp"
else if ( page == 2)
pageToLoad = "IntegrateXML.jsp"
else
pageToLoad = "IntegrateMathPlayer.jsp"
win = window.open( pageToLoad + "?fun=" + URLescape(f.fun.value), "integrate",
"toolbar=none,resizeable=yes,width=450,height=350");
}
</script>
</head>

<body>

<h1>MathML Example: Integrate a Function</h1>

<form action="IntegrateForm.jsp" method="post">
Enter a function to be integrated: <br/>
<input type="text" name="fun" size="24" value="<msp:evaluate>MSPValue[$$fun, "Sin[x]^2"]</msp:evaluate>"/>
The following uses the MathML XSLT style sheet.
<input type="image" name="btnSubmit" src="../../Resources/Images/Buttons/xslt.gif" onclick="integrate(this.form, 1)"/> <br/>
<i>Uses the general MathML XSLT style sheet, this is the most general solution.</i>
The following are alternatives for rendering MathML. They are not
general solutions, but are included for demonstration purposes.
<input type="image" name="btnSubmit" src="../../Resources/Images/Buttons/xml.gif" onclick="integrate(this.form, 2)"/> <br/>
<i>Returns XHTML+MathML, suitable for a browser with native MathML support.</i>
<input type="image" name="btnSubmit" src="../../Resources/Images/Buttons/mathplayer.gif" onclick="integrate(this.form, 3)"/> <br/>
<i>Uses MathPlayer specific markup, suitable if you have MathPlayer installed.</i>
</form>

This example shows how MathML can be generated from webMathematica.
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/webMathematica/Resources/XSL/mathml.xsl"?>

<%@ taglib uri="http://www.wolfram.com/msp" prefix="msp" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Integrate Result</title>
</head>

<body>

<msp:evaluate>
MSPPageOptions[ "ContentType" -> "text/xml"];
fun = Unspecified;
int = Unspecified;
If[ MSPValueQ[ $$fun],
fun = MSPToExpression[ $$fun];
int = Integrate[ fun, x];
If[ Head[int ] === Integrate, int = Unknown]] ;
</msp:evaluate>

Integration of a function, formatting into MathML.

<table border="2" rules="all">
<thead>
<tr>
<th>Function</th><th>Integral</th>
</tr>
</thead>
<tr>
<td align="center"><msp:evaluate> MSPFormat[ fun, MathMLForm]</msp:evaluate></td>
<td align="center"><msp:evaluate> MSPFormat[ int, MathMLForm]</msp:evaluate></td>
</tr>
</table>

</body>
</html>