This page is currently a draft. Edit it. |
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:
The presentation elements are meant to express the syntactic structure of mathematical notation
A token in MathML is an individual symbol, name or number. Tokens are grouped together to form MathML expressions.
Tokens can be:
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> </math>
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> </math>
Token elements are needed for representing tokens: the smallest units of mathematical notation that convey some meaning.
There are several token elements:
mi
identifiermn
numbermo
operator, fence, or separatormtext
textmspace
spacems
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 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 horizontallymfrac
form sa fraction from two sub-expressionsmsqrt
forms a square root (radical without an index)Some layout elements are used to add subscripts and superscripts:
msub
attach a subscript to a basemsup
attach a superscript to a basemsubsup
attach a subscript-superscript pair to a baseAnd special kinds of scripts (TODO: describe in more details)
munder
attach an underscript to a basemover
attach an overscript to a basemunderover
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> </math>
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> </math>
There are more complex elements such as mtable
.
MathML presentation elements only suggest specific ways of rendering
Certain characters are used to name identifiers or operators that in traditional notation render the same as other symbols or usually rendered invisibly.
entities ⁢
→
The complete list of MathML entities is described in Entities.