Mathematical Markup Language (MathML)

MohammadTaghi Hajiaghayi,
Department of Computer Science,
University of Waterloo,
mhajiaghayi@math.uwateroo.ca
Available On-line at:
http://www.cs.uwaterloo.ca/~mhajiaghayi/mathml/mathml1.html
Slides of this presentation

Abstract
 

This presentation is a brief description of  Mathematical Markup Language, or MathML. MathML is an XML application for describing mathematical notation  and  it is mainly supported by W3C. The goal of  MathML is to enable mathematics to be served, received, and  processed on the World Wide Web, just as HTML has enabled this functionality for text. This paper begins with an introduction to MathML. Then, it considers the two ways of encoding of mathematics in the MathML.  Additional sections discuss about the overall structure and some elements of MathML and finally it contains a conclusion. The main references for this summery  in order are [3] , [1, 2]. Other references are used for some sections.
 
1. Introduction

Mathematical Markup Language (MathML)  is an application for defining and expressing mathematical documents on the WEB, just like HTML which provides this functionality for text documents. Its final goal is to provide a standard notation that other WEB softwares and application are be capable of reading and expressing mathematical formulas very easily.

Because of lack of  standard notaitons for representing of mathematics on the web, the current method for defining the mathematical expressions is using the GIF or other types of images. However they are not appropriate at all. Suppose that you want to copy and paste a GIF formula. There would be a lot of problems, because you must copy and paste the actual image file. Also, the problem arises in the case that you want to change the formula somewhat. However, using the MathML you are be able to copy and paste or change the mathematical formula like the other HTML text. Another property of MathML is that, people with visual disabilities can also  understand the mathematical formula, because the MathML documents can be easily converted into alternative media such as speech or Braille. Also MathML provides a  more  efficient method for transferring the mathematics formulas on the web, since sending the Image files instead of formulas  is not efficient mainly because of the large size of them.

At present,  W3C  which is the main sponsor of MathML has released three recommendation of MathML. One is W3C MathML 1.0 Recommendation  released on 7th April 1998. Another  is MathML 1.01 Recommendation  which was release on 7 July 1999 [1] and the other is Proposed Recommendation 2.0 published on 8 January 2001.

Now, several vendors  offer plug-ins appletes which can  render the MathML encoding. However still there are a few translators and equation editors which are capable of generating HTML pages with embedded MathML codes. So far, W3C's Amaya browser supports MathML as does E-Lite by ICEsoft. Netscape's new unreleased browser, titled Gecko,  is planning on fully  supporting MathML, and maybe including a WYSIWYG editor for mathematical equations [3]. It is hoped that MathML will be also available through  the use of plug-ins for browsers that can't fully implement it yet.

However, many organizations  have expressed support for MathML.  Some of them are as follow: IBM, makers of the Techexplorer Scientific Browser; Wolfram Research, makers of Mathematica 3.0; Waterloo Maple, makers of Maple V; Hewlett-Packard, makers of the EzMath plug-in; the American Mathematical Society,  developers of a LaTeX to MathML translator; Design Science, makers of the MathType equation editor; and yours truly, Design Science, makers of the WebEQ suite of MathML tools [3]. Also there are some conferences and workshops e.g. MathML International Conference 2000 [4] and some discussion sites e.g [7] concerning MathML. Also, there are so many brief papers about introduction or features of MathML such as [5, 6, 8]

2. MathML Overview

2. 1. Presentation and Content

 
There are two different ways for expressing the mathematical formulas. Let us consider an example. Suppose that you want to express the formula f'(g(x)) g'(x). You have two options either you can say "chain rule of  the derivative of f composed with g" or you can say  "f prime, open paren, g of x, close paren and g prime of x". Both of them can convey the meaning of the above expression, but the first say the content meaning and the second say the presentation meaning of this expression.  You can also find another example by comparing of Microsoft Word and Latex in the sense of writing a  mathematical formula.  In Microsoft Word you usally have to  make attention to the presentation of the  formula, however in  Latex you can easily express the formula and then Latex itself responsible for appropriate representing of it.

MathML supports both of these content encoding and presentation encoding and you can easily chose each of them in different situation depending upon which of them is easier and more appropriate for the expressing the formula. Even you can mix this two encoding and use the hybrid of both of them.

In MathML, there are about 28 MathML elements, with about 50 attributes which are used for presentation encoding [1]. Most of these elements are used for  representing templates or patterns for laying out subexpressions. For an example mfrac is an element for expressing a fraction of two subexpressions by putting one over the other with a line in between. When you use elements like this, renderer or other MathML softwares generate or print it in an appropriate form without mentioning any futher information concerning the special software or hardware media, however, still you have to mention the tickness of the line or the length of the line by adding some attributes (the default value will be used if you don't mention them explicitly). So the presentation encoding provide a middle level for expressing the mathematical formulas.

For content encoding there are about 75 elements with about only 12  attributes [1]. As you can see the number of attributes here is so smaller than the number of  presentation attributes.  The main reason is that in content encoding we rarely deal with attributes concerning representation. Most of these elements are used for representing the mathematical operations and functions, such as plus and sin or other mathematical concepts like  set and vector. These elements provide a high level way for expressing  formulas.

In MathML,  presentation and content elements provide a rich set of means for representing the mathematical expressions without dealing with very low level attributes such as media-dependent attributes.


Now, let us consider an example. Suppose you want to show this expression:

(a * b)^2

The presentation encoding for this formula  is as follows:

 
   <mfenced>
      <mi>a</mi>
      <mo>*</mo>
       <mi>b</mi>
   </mfenced>
   <mo>^</mo>
   <mn>2</mn>
 
In this examle we represent the open  and close parenteces with <mfenced> and </mfenced>. Also we  indicate  identifiers  with  <mi>, operators with  <mo> and finally numbers with <mn> tags. The overall encoding is very simple and so there is no need for futher explanation.

Now, let us show the same expression using content encoding:
 

<apply>
    <power/>
    <apply>
        <times/>
        <ci>a</ci>
        <ci>b</ci>
    </apply>
    <cn>2</cn>
</apply>


As you see the  structure of this example is very similar to the structure of presentation encoding, however the elements used are content elements instead of presentation elements.  Each subexpression is enclosed between <apply> and  </apply> tags and also it is represented in prefix form. This form of representation is common in Content encoding, because MathML content encoding considers all  operations as function with some operands. Also, we have used <ci> and <cn> tags instead of <mi> and <mn> tags.

In addition, we can mix the content and presention encoding and get a hybrid encoding like below example for above experssion.
 

<apply>
    <power/>
    <apply>
      <mi>a</mi>
      <mo>*</mo>
       <mi>b</mi>
    </apply>
    <cn>2</cn>
</apply>
 
2. 2. Expression Trees and Layout Boxes


Most of  expressions in MathML are nested and the best way for expressing these nested formula and having a good idea in our mind specially when the formula is complicated is expression trees. In these expression trees each node represents an operation or a particular layout schema, and its children represent the subexpression. This description is not only used for bettter understing of expressions but also used for knowing how  the MathML tags should be nested on the screen or on the printer. We discuss more about this issue after introducing the layout boxes.

You can see one mathematical notation and its tree structure cited from [3] in figure below:
 


 
 

Layout boxes are main structure of MathML presentation encoding and it can be thought as a bounding box of a particular kind of object. There are two kinds of boxes in MathML: simple boxes which contain only individual characters and their size only depend upon the font of those  characters and  complicated boxes which  contain  nested "child boxes" and their  size depend upon the the size of their children recursively.

 In fact, layout boxes are corresponded to nodes of expression tree, and these two models i.e. expression tree and layout boxes provide an abstract model for representing, evaluating and rendering the mathematical formulas. This abstract model is not only used for people to better understanding the expressions, but also used for renderer to find the size and dimensions of these boxes and provides an abstract model for evaluating of a expression especially in system algebra softwares.

It is worth mentioning that in spite of that simple layout boxes are the smallest  substructures of MathML presentation encoding, however they are still media independent and they are middle level models.

You can see the layout boxes and it's corresponding nodes in the above figure. For an example, if you want to evaluate the dimension of the root of this tree first, you must compute the dimension of the simple layout box 3, then you must compute the size of the complicated layout box (x+ 2) recursively and finally consider  an attribute of "thickness" or "length" of  the fraction line. Using all these information you can compute the size of the whole box of 3/(x+ 2).
 

3. Elements and Characters


The style of mark-up elements in MathML is very similar to  that of HTML, however, because the number of notation in the mathematical formula is  more than the number of notation in regular text, naturally the number of start tag/end tag is very high in MathML. The syntax of using attributes for tags  is also similar to  HTML.
 

 In addition, actual text and symbol characters can also be represented in mathematical formulas. To do that we use special MathML elements called token elements. Consider this example:


<mfenced>

  <mn>3</mn>
   <mo>+</mo>
   <mi>b</mi>
</mfenced>
 
Most of  the MathML elements, like  mfenced element, expect to only find other MathML elements in their content however token elements like mi and mo elements  can contain symbols, characters,  numbers or even plain text which display as themselves or especial entities called references Entity references are used for  representing  extended characters. For example &alpha; and &cup are stand for a lower case Greek alpha, and the union sign, respectively. MathML renderers after accessing  to symbol fonts,  display the actual extended character glyph instead of the entity reference. The style of using references is as follows:
&entity_name;
 
The name of the most of the entity references in MathML is identical to the name of that symbol in the Latex; for example, we use &alpha; in MathML which is corresponded to \alpha in Latex. So people which is familiar with Latex can easily use the same name of symbol with only some differences of its style in MathML.
 
Because Mathematical glyphs are very important in representing the mathematical notations and without them, it is difficult to read the mathematical notations fluently, MathML references  provide access to Unicode characters legal in XML documents or glyph elements.  The latter represent the characters which do not have any special Unicode representation, however because the Unicode provide a reach set of element e.g. there are over 900 special symbols in Unicode 3.2, the need for glyph should be rare. These two kind of reference entity  together provide over 1800 symbols and you may find the whole list in references [1, 2, 3].
 
4. Containers and Functions
 
4. 1. Containers
Token elements represent identifier, numbers and plain text and naturally plain text  can contain any  other mathematical objects, however some mathematical objects like vectors and sets need special consideration. Since if we decide to show them using tokens, they can not be easily used for rendering or evaluating the expressions. So we need some special elements for representing mathematical objects and data types which are called  container elements. In most of the cases,  containers elements are used for representing elements which are constructed from other kinds of data. The main container elements are as follows [3]:

1: Sets  (Generic form: <set> [<elt1> <elt2> ... | <condition>] </set>)
A set represent a set of data which all must be from the same type. There are two ways for showing a set: specify the elements of a set explicitly or only say some conditions like "all real y such that 1< y < 2". This condition can be represented by interval container elements introduced below.

2: Intervals  (Generic form: <interval> <pt1> <pt2> </interval>)

Interval is mostly used for representing conditions on real numbers. It contains two children pt1 and pt2 which show the end points. It has also  the closure attribute determines which of the end points lie in the interval, and can accept the values "open", "closed", "open closed" and "closed open".
3: Vectors  (Generic form: <vector> <elt1> <elt2> ... </vector>)
A vector element shows a vector whose components are given in order by its children. By convention, in MathML vectors are column vectors for matrix multiplication. It's worth mentioning that this special consideration is mostly used for evaluating because the final goal of MathML is that it can be used for real time computation.
4: Matrices (Generic form: <matrix> <matrixrow1> <matrixrow2> ... </matrix>)
Matrices are naturally constructed from some  rows where each row represented by one matrixrow element. Actually the representation of a matrixrow element is very similar to  vector element.  The children of  a matrixrow element represent the individual elements of the whole matrix and  similar to sets, elements of a matrix must have the same type.

These  elements were the the main container elements of MathML, however still there are other kinds of container elements such as list which are introduced in [1, 2].

Let us consider an example cited from [3].

 
  • Expression:
  • Markup:
  • <reln> <eq/>
        <apply><times/>
             <vector> <cn>1 </cn> <cn>2 </cn>
             </vector>
     
             <matrix>
             <matrixrow> <cn>0 </cn> <cn>1 </cn> </matrixrow>
             <matrixrow> <cn>1 </cn> <cn>0 </cn> </matrixrow>
             </matrix>
       </apply>
        <apply> <transpose/>
             <vector> <cn>2 </cn> <cn>1 </cn>
             </vector>
        </apply>
    </reln>
     
    In the above example, you can see how the matrix and vector elements were represented in MathML. You can find a lot of example concerning these container elements and others in [3].

    4.2. Operators and Functions

     
    As we have mentioned before there are so many empty elements in  MathML. Most of this elements are operators or functions like sin x or cos x. However there is another operator named fn which is used for user-defined functions. Essentially there is no differences between operators and functions, however, historically we consider notation '+' as an operator because it is used in between two operand (infix form) and notation 'sin' as a function because it has some operands like x (prefix form).

    For an  example consider the expression below:
     

  • Expression:
  • (sin + cos)(x)
  • Markup:
  • <apply>
        <fn>
             <mfenced>
                 <apply><plus/>
                       <sin/>
                       <cos/>
                 </apply>
             </mfenced>
        </fn>
        <ci>x</ci>
    </apply>
     
    All the tags used in this formula is clear except fn which needs more consideration. As we have mentioned before fn used for user defined functions. However it also has other usages, for example if we use an computer algebra system it would recognize the tangent and cosine functions, and treat the result of adding them together as a function again.

    You may find a wide variety of  examples of this kind in references [1, 2, 3].

     
    5. Conclusion


    In this presentation we have introduced the MathML and briefly discuss about main points of it. We said that MathML is very good standard for using and showing mathematics in the WEB. But, the problem is that MathML codes are not so readable, and so we must use other software's and  interfaces to create, manipulate and show them. Now there is a question:   It wouldn't be better if we use an alternative already exists in some software's such as Mathematical or Maple, for example we  use only a  start tag like <mathematics use=Mathematica> and an end tag</mathematics>  in HTML (with  possible other values, like Maple). This may be expensive in the short run (because of copyright), but maybe much cheaper and beneficial in the longer term. The problem of  copyright is also not so important, because, after developing some other interfaces for MathML, they will be not necessarily free and so this problem will be appeared again. In addition, using of this software's will increase the portability of mathematics in the web and in the computing software area.  In the mean time, the MathML proposal as in the draft paper can be published, but not as a new standard but as a contribution to the discussion.

    I believe that the answer of the above question is 'no',  and my reasons are mainly those which I have mentioned in the Introduction section, but I think this question must be answered deeper. You can also find futher discussion about this issue in [7].

    6. References:

    [1]: Mathematical Markup Language (MathML[tm]) 1.01 Specification WIC Recommendation, revision of 7 July 1999

    [2]: Mathematical Markup Language (MathML) Version 2.0 W3C Proposed Recommendation 08 January 2001

    [3]: Gentle Introduction to MathML

    [4]: MathML International Conference 2000

    [5]: The Interchange of Mathematics in XML: MathML, OpenMath and their Application

    [6]: MathML - What's in it for us?

    [7]: The Disappointment and Embarrassment of MathML - update: Including Reactions and Answers

    [8]: Putting Mathematical Notation on the Web