# ML Wiki

## MathML

MathML Mathematical Markup Language - is a standard for mathematical expressions defined by W3C that browsers should support to render math formulas

There are two types of MathML:

• presentation - how browsers show draw a mathematical expression
• meaning - what is the meaning of this expression?

## Presentation Elements

The presentation elements are meant to express the syntactic structure of mathematical notation

• MathML expressions trees with nested layout.

A token in MathML is an individual symbol, name or number. Tokens are grouped together to form MathML expressions.

Tokens can be:

• identifier, variable or function names
• numbers
• operators (including brackets - so called "fences")
• text and whitespaces

A "symbol" is not necessarily one character: it could be a string such as <mi>sin</mi> or <mn>24</mn>. In MathML they are treated as single tokens.

As in mathematics, MathML expressions are constructed recursively from smaller expressions or single tokens. Complex expressions are created with so-called "layout" constructor elements, while tokens are created with token elements.

Let us consider an example. A mathematical expression $(a + b)^2$ can be represented in MathML as follows:

<math xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
<mrow>
<mo>)</mo>
</mrow>
<mn>2</mn>
</msup>
[/itex]


It has the tree structure and recursive. If we take another mathematical expression $\cfrac{3}{(a + b)^2}$. It is a fraction and we see that its denominator is the same as the previous expression. This is also true for the MathML representation:

<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac>
<mn>3</mn>
<msup>
<mrow>
<mo>(</mo>
<mrow>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
<mrow>
<mo>)</mo>
</mrow>
<mn>2</mn>
</msup>
</mfrac>
[/itex]


### Token Elements

Token elements are needed for representing tokens: the smallest units of mathematical notation that convey some meaning.

There are several token elements:

• mi identifier
• mn number
• mo operator, fence, or separator
• mtext text
• mspace space
• ms string literal

Often tokens are just single characters, like <mi>E</mi> or <mn>5</mn>, but there are cases when tokes are multi-character, e.g. <mi>sin</mi> or <mi>span</mi>.

In MathML mi elements represent some symbolic name or text that should be rendered as identifiers. Identifiers could be variables, function names, and symbolic constants.

Transitional mathematical notation often involve some special typographical properties of fonts, e.g. using bold symbols e.g. $\mathbf x$ to denote vectors or capital script symbols e.g. $\mathcal G$ to denote groups and sets. To address this, there is a special attribute "mathvariant" that can take values such as "bold", "script" and others.

Numerical literals are represented with mn elements. Typically they are sequences of digits, sometimes with a decimal point, representing an unsigned integer or real number, e.g. <mn>50</mn> or <mn>50.00</mn>.

Finally, operators are represented with mo elements. Operators are ...

### Layout Elements

Layout elements are needed to form complex mathematical expressions from simple ones. They group elements in some particular way. For example:

• mrow groups any number of sub-expressions horizontally
• mfrac form sa fraction from two sub-expressions
• msqrt forms a square root (radical without an index)

Some layout elements are used to add subscripts and superscripts:

• msub attach a subscript to a base
• msup attach a superscript to a base
• msubsup attach a subscript-superscript pair to a base

And special kinds of scripts (TODO: describe in more details)

• munder attach an underscript to a base
• mover attach an overscript to a base
• munderover attach an underscript-overscript pair to a base

For example, $\vec v$ will be rendered as

<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mover>
<mi>v</mi>
<mo>→</mo>
</mover>
[/itex]


This is how we would represent $\hat{ \mathbf x}$ (a bold x with a hat) in MathML:

<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mover>
<mrow>
<mi mathvariant="bold">x</mi>
</mrow>
<mo>^<!-- ^ --></mo>
</mover>
</mrow>
[/itex]


There are more complex elements such as mtable.

MathML presentation elements only suggest specific ways of rendering

### Math Entities

Certain characters are used to name identifiers or operators that in traditional notation render the same as other symbols or usually rendered invisibly.

entities &InvisibleTimes; →

The complete list of MathML entities is described in Entities.