]> Introduction to Presentation MathML

Introduction to Presentation MathML

Mathematicians usually have good knowledge of LaTeX. Because this is probably not true for MathML and because I want mathematicians to be able to use Gemse, I give here a very short introduction to Presentation MathML. This introdcution however, scratches only the surface of Presentation MathML, so you want to look into the MathML specification afterwards. Additionally, there is always the :help element command to open the specification for a specific element.

While it is quite practical to write LaTeX with a text editor, to write MathML is not. This is the reason why there is Gemse.

Tree concepts

We will often use the words child, descendant, parent, ancestor and sibling. You should know what they mean.

A mathematical formula is basically a tree structure. This immediately yields the idea to encode it with XML. What the heck is XML you may ask. You will see. Usually, one learns the basics of XML by learning something else. In this case, the something else is MathML.

Unicode

To represent text in a computer, you have to use a mapping between numbers and characters. Unicode is an approach to do that. It is a mapping between numbers and characters of many scripts used on earth. Unicode includes a huge amount of mathematical signs. A text file is basically a sequence of such characters. LaTeX files are also text files, but they use traditionally ASCII instead of Unicode. ASCII maps characters to exactly one byte, which can obviously not be enough. This means that in a LaTeX file you have to write \phi instead of writing φ directly. In MathML, we will write every Character directly. (One has to add, that LaTeX is able to handle Unicode files, but it needs an additional effort.)

Tags and Elements

If you know XML, you can skip this section.

Let us directly look at an example:

(a+b) n = k=1 n ( nk ) a k b n-k

This formulated in MathML looks like the following:



    
        (a+b)
        n
    
    =
    
        
        k=1
        n
    
    
        (
        nk
        )
    
    
        a
        k
    
    
        b
        n-k
    


]]>

Those parts that begin with a < and end with the next > are called tags. There are two sorts of tags: Opening tags and closing tags. Those that begin with </ are the closing ones, the others are opening tags. For example, <mrow> is an opening tag and </mrow> is a closing one. (There is also a sort of tags which are of both kinds at the same time, opening and closing. Such a tag is for example <mrow />.)

Every opening tag must have a corresponging end tag. Together with the text between them, they form an element. The text between the tags is called the content of the element. The content can consist of other elements or plain text. The name of the element is given by the tags. Consider k=1]]>. This is an element with the name mrow. It contains three elements which have the names mi, mo and mi. We will call an element with the a name A an A element.

I hope you see now that the elements form a tree structure. Indeed, in the case of k=1]]>, We have an mrow element with 3 children. Please be aware that the order of the children does matter. Changing their order does change the meaning. This is important for MathML as we will later see.

But there is more: Every element can have attributes. Attributes are just key/value pairs. A key must not turn up in more than one attribute. Unlike for children of an element, the order of the attributes does not matter. An attribute has the form key="value" and is placed in the starting tag of the element. In the example you can spot an mfrac element wich has a linethickness attribute with value 0.

Identifiers, operators and numbers

In LaTeX, if we want to have a φ, we can write a φ, without a special containment. In MathML this is not possible. We have to put the φ into an mi element, like this: <mi>φ</mi>. For an identifier we use an mi element. For an operator we have to use an mo element. The mn element is for literal numbers. (With literal, I want to stress that an mn element is not suited for a even if a. In this case, you must use mi.)

The mo element is very powerful. It is not only used for operators like +, · and the like, but it is also used for fences, arrows, separators and more. It is even used for accents like a hat over a variable. The mo element has a huge amount of attributes which control the behaviour of the operators. However, these attributes have default values depending on the content of the mo element. Every MathML renderer has an operator dictionary which tells it the default values if it encounters an mo element containing a known operator. But it can be that you wish to change these defaults or that you have to set them because you use an operator that is not found in the dictionary. You can look up the operator dictionary in the MathML specification. You can read about the attributes in the section about mo in the MathML specification. It is quite a big section, you may want to read it after you have gone through the rest of this introduction.

Superscripts and subscripts

Look at the following part of our example:

b n-k

    
        b
        n-k
    

]]>

The first child of the msup element is the base, the second is the superscript. In this case, the superscript does not only consist of an identifier or a number but is a whole expression consisting of more than one element, so we have to put it in an mrow. Subscripts are done with msub:

a ik

    
        a
        ik
    

]]>

msub and msup can be combined:

x 1 2

    
        
            x
            1
        
        2
    

]]>

But that's perhaps not what you want. In order to put subscript and superscript tight to the base, use msubsup. This element has three children.

x 1 2

    
        x
        1
        2
    

]]>

But the full power you can get with the mmultipscripts element. It can not only place multiple subscripts and superstcripts behind a base but also before it:

A 1 2 a c b d

    
        A
        1
        2
        
        
        a
        c
        b
        d
        
    

]]>

munder and mover

For integrals, sums, products and so on, you want to put the limits above and below the sign. This is done by munder, mover and munderover.

i 1 i


    
        
        i
    
    
        1
        i
    


]]>
a b


    
        
        a
        b
    


]]>

Look how munder, mover and munderover change their behaviour when you change the value of the display attribute of the MathML element to inline:

a b , a b , lim n


    
        
        a
        b
    
    ,
    
        
        a
        b
    
    ,
    
        lim
        
            n
            
            
        
    


]]>

Actually, inline is the default. So omitting this attribute has the same effect as setting it to inline. You use inline if your formula flows inside the text. If you want to set it apart from the text of the paragraph on its own line, you use block.

Fractions

For this there is the mfrac element.

1 2


    
        1
        2
    


]]>

You can use fractions to write biniomial coefficients:

( n k )

  
    (
    
      n
      k
    
    )
  

]]>

The linethickness attribute suppresses the horizontal bar of the fraction.

Roots

The elements msqrt and root do the obvious thing:

x 2 + y 2

  
    
      
        x
        2
      
      +
      
        y
        2
      
    
  

]]>
x 2 + y 2 3

  
    
      
        
          x
          2
        
        +
        
          y
          2
        
      
      3
    
  

]]>

Tables

Tables in MathML are a little bit like tables in HTML. There are the elements mtable, mtr and mtd.

( 1 0 0 0 1 0 0 0 1 )


   ( 
  
    
       1 
       0 
       0 
    
    
       0 
       1 
       0 
    
    
       0 
       0 
       1 
    
  
   ) 


]]>

Note that the fences are not part of the table, you have to put them with mo elements. Like this you can also use other brackets or none at all.

Instead of mtr you can also use mlabeledtr, which interprets its first child as a label for this row. Otherwise, it works just like mtr.

mfenced

The mfenced element is a shorter notation for its equivalent using mo elements. For example

xyz

  xyz

]]>

is equivalent to



  (
    
      x
      ,
      y
      ,
      z
    
  )


]]>

I hope you get the idea. The mfenced element has three attributes which control what operators are used: The attribute open declares which operator is used at the beginning. It is ( by default. close is for the operator at the end, ) by default. The attribute separators provides the operators put between the children of the mfenced element. It is , by default.

Examples

I will here give you a waterfall of examples. They are mainly transcribed from The Not So Short Introduction To LateX2e using Gemse.

lim n k = 1 n 1 k 2 = π 2 6


    
        lim
        
            n
            
            
        
    
    
        
        
            k
            =
            1
        
        n
    
    
        1
        
            k
            2
        
    
    =
    
        
            π
            2
        
        6
    


]]>
x : x 2 0

  
    
    
      x
      
      
    
    :
    
      
        x
        2
      
      
      0
    
  

]]>
x 2 x 2

  
    
      
      
        x
        2
      
    
    
    
      
        
        x
      
      2
    
  

]]>
m + n ¯



  
    m
    +
    n
  
  ¯



]]>

In the above I am not shure whether one should use ‾ (OVERLINE U+203E) or as above ¯ (MACRON U+00AF). Firefox stretches only the latter. Also, the operator dictionary found in the specification does not contain the overline, but declares the macron to be stretchy. So it is best to use the macron.

a + b + + z

  
    
      
        a
        +
        b
        +
        
        +
        z
      
      
    
  

]]>
A B

  
    
      
        A
        B
      
      
    
  

]]>
( n k )

  
    (
    
      n
      k
    
    )
  

]]>
f N ( x ) = ! 1

  
    
    
      
        f
        N
      
      (
      x
      )
    
    
      =
      !
    
    1
  

]]>

Look what happens when we do not use an mrow element:

f N ( x ) = ! 1

  
    
      
        f
        N
      
      (
      x
      )
    
      =
      !
    
    1
  

]]>
X = ( x 1 1 x 1 2 x 2 1 x 2 2 )

  
    X
    =
    (
    
      
        
          
            x
            
              1
              1
            
          
        
        
          
            x
            
              1
              2
            
          
        
        
          
        
      
      
        
          
            x
            
              2
              1
            
          
        
        
          
            x
            
              2
              2
            
          
        
        
          
        
      
      
        
          
        
        
          
        
        
          
        
      
    
    )
  

]]>
i = 1 n ( x i - x ¯ ) ( y i - y ¯ ) [ i = 1 n ( x i - x ¯ ) 2 i = 1 n ( y i - y ¯ ) 2 ] 1 2

  
    
      
        
          
          
            i
            =
            1
          
          n
        
        
          (
          
            
              x
              i
            
            -
            
              x
              ¯
            
          
          )
          (
          
            
              y
              i
            
            -
            
              y
              ¯
            
          
          )
        
      
      
        
          
            [
            
              
                
                
                  i
                  =
                  1
                
                n
              
              
                
                  (
                  
                    x
                    i
                  
                  -
                  
                    x
                    ¯
                  
                  )
                
                2
              
            
            
              
                
                
                  i
                  =
                  1
                
                n
              
              
                
                  (
                  
                    y
                    i
                  
                  -
                  
                    y
                    ¯
                  
                  )
                
                2
              
            
            ]
          
          
            1
            2
          
        
      
    
  

]]>