The Universal MathML stylesheet

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

The Universal MathML stylesheet specifies how to transform a document that contains MathML into a form suitable for the browser or MathML add-on available on the client machine. This stylesheet can be used with modern browsers that include support for CSS and XSLT (such as IE 5.0 and later or Netscape 6.1 and later). The stylesheet can also be used with Mozilla. However, you can’t use the stylesheet with since Amaya does not support XSLT transformations.

The Universal MathML stylesheet works as follows:

  1. When a document that contains MathML content is downloaded, the stylesheet checks to see what browser is being used on the client machine and if a suitable add-on to render the MathML is available.
  2. If the browser can render MathML natively, the browser’s native rendering capabilities are used.
  3. If the browser cannot render MathML directly but an add-on for rendering MathML is present on the machine, the stylesheet adds the appropriate markup needed in the document to render it with that add-on.
  4. If more than one add-on is present, the stylesheet chooses one based on a set of preferences that the author can specify.
  5. Finally, if none of the required add-ons are installed, at least on IE, the stylesheet can still render the MathML using a combination of CSS and JavaScript. The quality of this rendering is not as good as with a dedicated plug-in. However, since the rendering uses standard built-in features of the browser, the equations can be rendered quickly and with acceptable quality, both for viewing and printing.

The Universal MathML stylesheet resolves the problem of IE and Mozilla/Netscape having conflicting MIME type and DOCTYPE requirements for an XHTML+MathML document.

The beauty of the Universal MathML stylesheet is that all these transformations are performed automatically; the person viewing the document doesn’t have to do anything other than including a reference to the stylesheet, as explained later in this chapter. Using this stylesheet, an author can create a MathML document that will be viewable on any browser, with or without a special plug-in. This eliminates the need to author documents tailored to specific rendering environments and goes a long way towards achieving the goal of "write once, read everywhere," which is essential for MathML documents to be accessible to a broad audience.

Another important feature of the stylesheet is that it allows content MathML to be displayed even on browsers that support only the display of presentation MathML. Most add-on software for rendering MathML, including MathPlayer and techexplorer, support the display of content markup as well as presentation markup. However, browsers like Mozilla and Amaya can only render presentation markup. To allow content markup to be displayed on such browsers, the Universal MathML stylesheet includes code for transforming all content markup in the input document into a corresponding presentation markup expression. The resulting document contains only presentation markup and can therefore be displayed in Mozilla or Amaya using their native rendering capabilities.

Using the stylesheet

To display MathML in a browser using the Universal MathML stylesheet, you need to do two things. First, embed the MathML markup in an XHTML document, with each instance of MathML enclosed in a math tag. The MathML namespace must be specified for each MathML element, either using a namespace prefix or via a declaration on the outer math tag.

Note:
Note that the requirements for an XHTML document are more stringent than those for an HTML one. Some guidelines on creating valid XHTML documents are given in the discussion of Mozilla.

After embedding the MathML markup in an XHTML document, you must include the following processing instruction at the start of the XHTML document, before the opening html tag but after the XML declaration:

<?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/mathml.xsl"?>

This statement tells the browser to download an XSLT stylesheet called mathml.xsl from the specified URL and apply it to the document. The stylesheet contains transformation rules that provide a proper rendering for presentation elements. As explained earlier in this chapter, any content MathML present in the document is first converted into presentation MathML. Hence, the transformation rules appropriate to presentation markup can be used for rendering content elements as well.

The following example shows a template for a typical document that observes these guidelines.

Example: A template document that contains a reference to the Universal MathML stylesheet.

<?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> ... </title></head>
  <body>
    <math xmlns="http://www.w3.org/1998/Math/MathML">
      <mrow>
        <msqrt><mi>x</mi></msqrt>
      </mrow>
    </math>
  </body>
</html>

If the XHTML document contains only presentation markup, the mathml.xsl stylesheet can be replaced by a simpler version called pmathml.xsl. In other words, the processing instruction to be inserted in the document should be the following:

<?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/pmathml.xsl"?>

The pmathml.xsl stylesheet is much smaller than the mathml.xsl stylesheet because it contains only the transformation rules needed for presentation elements. Hence, the document can be displayed faster.

IE security issues

The method of referencing a stylesheet at its public location on the W3C Web site, as shown in the example "A template document that contains a reference to the Universal MathML stylesheet", will not work for IE when you use the default security settings. This is because, with its default settings, IE will not accept a stylesheet that is on a different server from the one that contains the document to be viewed. One solution to this problem would be to change IE 's security settings. However, this requires some customization on each individual client machine, which is not a practical option.

A better solution is to place a local copy of the stylesheet on the server. The stylesheet-processing instruction should then specify the location of the stylesheet on your server using a relative URL, as in the example below:

<?xml-stylesheet type="text/xsl" href="styles/mathml.xsl"?>

As discussed earlier, if the document contains only presentation markup, the mathml.xsl stylesheet can be replaced by pmathml.xsl instead.

If you specify a local URL, the stylesheet is downloaded from the server along with the XHTML+MathML document. This ensures that your document is viewable on IE as well as on Netscape/Mozilla. Hence, to make your documents accessible to the widest possible audience, it is advisable to use a local copy of the stylesheet instead of the public copy.

The Universal MathML stylesheet consists of the following four files, which can be accessed from the URL "www.w3.org/Math/XSL":

  • pmathml.xsl: is the main stylesheet for presentation MathML. It detects the browser and add-on available on the client machine and sets up an appropriate transformation.
  • mathml.xsl: is identical to pmathml.xsl except that it first uses ctop.xsl to transform content MathML to presentation MathML on Mozilla/Netscape.
  • ctop.xsl: transforms content MathML to presentation MathML.
  • pmathmlcss.xsl: transforms presentation MathML to XHTML using CSS and JavaScript, so MathML can be rendered using the browser’s native capabilities.

If you are going to make the stylesheet accessible locally, you must copy all four files to your server.

Specifying preferences

If the browser on the local machine has more than one way of displaying MathML, you can use the pref:renderer attribute to specify which method should be used. This attribute belongs to a private namespace and must be specified in the html tag, as shown here:

<?xml-stylesheet type="text/xsl" href="pmathml.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:pref="http://www.w3.org/2002/Math/preference" pref:renderer="css">
  <head>...</head>
  <body>...</body>
</html>

The renderer attribute can take the following values, each corresponding to a specific method of rendering MathML:

  • css: uses the browser's native CSS capabilities.
  • mathplayer: uses MathPlayer.
  • mathplayer-dl: uses MathPlayer if it is installed, or prompts the user to install it.
  • techexplorer-plugin: uses the techexplorer plug-in.
  • techexplorer: uses the techexplorer Behavior (see IBM techexplorer for details).

Supported browsers

The following table provides a partial list of the different browsers and add-ons that can be used to render MathML, with the help of the Universal MathML stylesheet, on different platforms. For a more detailed and up-to-date listing, see XSLT Stylesheets for MathML on the Web.

Table: Browsers that can render MathML.

Platform Browser
Windows IE 5.0 with techexplorer
  IE 5.5 with either MathPlayer or techexplorer
  IE 6.0 either directly or with MathPlayer or techexplorer
  Netscape 6.1 with techexplorer
  Netscape 7.0 either directly or with techexplorer
  Mozilla 1.0 or later
  Amaya
Macintosh IE 5.0 or later with techexplorer
  Netscape 6.1 or later with techexplorer
  Mozilla 1.1 or later
Linux/Unix Netscape 6.1 with techexplorer
  Netscape 7.0 either directly or with techexplorer
  Mozilla 1.0 or later
  Amaya

   

<< 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