MathML is a language for expressing mathematical notations, both their presentation (how a notation looks on a page) and their semantics or content (what a notation means).
This page presents an overview of
what I have used from
presentation MathML version 3.0:
of the 39 elements,
and a few of their attributes.
For details,
additional elements,
and additional attributes for the elements presented here,
or for content MathML,
see the
W3C definition
[MathML 3.0].
Each discussion in this document
of an element m
ends with a link to m's section in the definition
(→W3C definition of m
).
MathML, like other recursively-defined languages, contains compound elements which contain other elements, and tokens which do not.
Group | Function | Element | Examples | |
---|---|---|---|---|
Token elements |
Identifier | mi | <mi>x</mi> | |
<mi>π</mi> | ||||
<mi>sin</mi> | ||||
Number | mn | <mn>123</mn> | ||
Operator, fence, separator |
mo | <mo>+</mo> | ||
<mo>(</mo> | ||||
<mo>,</mo> | ||||
Text | mtext | <mtext>Thus</mtext> | ||
Space | mspace | <mspace width='1em' /> | ||
Compound elements |
Horizontal expression | mrow |
<mrow> <mn>1</mn><mo>+</mo> <mn>2</mn> </mrow> |
|
Fenced and separated list | mfenced |
<mfenced> <mn>1</mn><mn>2</mn> </mfenced> |
||
Fraction | mfrac | <mfrac><mn>1</mn><mn>2</mn></mfrac> | ||
Sub-, superscript | msub | <msub><mi>a</mi><mn>1</mn></msub> | ||
msup | <msup><mi>b</mi><mn>2</mn></msup> | |||
msubsup |
<msubsup> <mi>c</mi><mn>3</mn><mn>4</mn> </msubsup> |
|||
Radical | msqrt | <msqrt><mn>3</mn></msqrt> | ||
mroot | <mroot><mn>4</mn><mn>3</mn></mroot> | |||
Tables and matrices | mtable | →examples | ||
mtr | ||||
mtd | ||||
Top-level element | math |
The following token elements are not discussed here: maction, maligngroup, malignmark, mglyph1, ms.
Token element mo is discussed here but not its use for mathematical accents.
The following compound elements are not discussed here: menclose, mlabeledtr, mlongdiv, mmultiscripts, mpadded, mphantom, mprescripts, mscarries, mscarry, msgroup, msline, mstack, mstyle, munder, mover, munderover, none.
Note that some of the elements not discussed here are not supported by most or in some cases any browsers at this writing (2019), or are poorly supported.
The namespace for MathML is http://www.w3.org/1998/Math/MathML.
All MathML must be within a <math> element. (To save space, many of this page's examples do not show it.)
A <math> element may not be contained within another <math> element.
The <math> element takes several attributes (see the W3C definition of math for specifics).
Attribute | Values | Effect | Default |
---|---|---|---|
display |
'block'
'inline' |
Displays its contents' presentation as a block or inline | 'inline' |
The <math> element does not take the ordinary HTML attributes such as class and style.
<mi>S</mi> presents identifier , which can be a single letter or other character or a sequence of them.
Function names like should be presented with mi. (See the function application operator.)
Symbolic constants should be presented with mi; here are some examples:
Sym. | UTF-8 for it | In MathML | |
---|---|---|---|
Oct &# | Hex &#x | ||
π | π | <mi> π </mi> | |
ⅇ | ⅇ | <mi> ⅇ<!--DOUBLE-STRUCK ITALIC SMALL E--> </mi> | |
ⅈ | ⅈ | <mi> ⅈ<!--DOUBLE-STRUCK ITALIC SMALL I--> </mi> | |
… | … | <mi> … </mi> |
A horizontal ellipsis as an element in a list should be presented with mi.
<mn>12</mn> presents the number .
According to the W3C specification, mo is used for so many kinds of things because operators required sophisticated rendering and it was too tempting to reuse mo for other things that needed similar sophistication, namely fences, separators, and (not discussed here) mathematical accents.
Operator | In MathML |
---|---|
<mo>-</mo> | |
<mo>></mo> | |
<mo>≥</mo> | |
<mo>=></mo> | |
<mo>∑</mo> | |
<mo>.NOT.</mo> |
<mo>o</mo> presents operator o, of one or more characters, with appropriate spacing, font size, etc.
<math> <mi>tan</mi><mo>⁡</mo><mi>x</mi> </math>
<math> <mi>a</mi><mo>⁢</mo><mi>a</mi> </math>
<math> <mn>1</mn> <mo>⁤<!--INVISIBLE PLUS--></mo> <mfrac><mn>2</mn><mn>3</mn></mfrac> </math>
Sym. | utf-8 for it | In MathML | |
---|---|---|---|
Oct &# | Hex &#x | ||
function application |
⁡ | ⁡ |
<mo>⁡</mo>
<mo>⁡</mo> |
invisible times |
⁢ | ⁢ |
<mo>⁢</mo>
<mo>⁢</mo> |
invisible plus |
⁤ | ⁤ | <mo>⁤<!--INVISIBLE PLUS--></mo> |
mo also presents fences such as ( and ).
<math> <mo>(</mo> <mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow> <mo>)</mo> </math>
Note that may be equivalently presented using mfenced:
The fence='true' attribute should be given for fences that are not single ‘ ’ or double “ ” quotes, parentheses ( ), square brackets [ ], curly braces { }, absolute value bars | |, or any of about four dozen more listed in MathML's operator dictionary.
mo also presents separators such as commas.
The separator='true' attribute should be given for any separator other than comma, semicolon, or the invisible separator (⁣); see MathML's operator dictionary.
Sym. | utf-8 for it | In MathML | |
---|---|---|---|
Oct &# | Hex &#x | ||
invisible separator
(invisible comma) |
⁣ | ⁣ |
<mo>⁣</mo>
<mo>⁣</mo> |
<math> <msub> <mi>a</mi> <mrow> <mn>1</mn> <mo>&InvisibleComma:</mo> <mn>2</mn> </mrow> </msub> </math>
<mtext>Commentary text</mtext> presents text .
<mspace width='1em' /> presents 1em of whitespace .
Widths may also be given in units of px, cm, mm, pt, and several others.
Compound elements group mathematical subexpressions in useful ways.
An mrow element groups its contents in a horizontal row, spaced appropriately as determined by what its contents are.
An mrow may contain other mrows (or other compound elements), and in fact often should. Each subexpression within an mrow should be contained in its own nested mrow. Each operator should be placed in its own mrow along with its operand(s), with the exception that a sequence of operators of the same precedence2 and their operands may be placed in a single mrow (for example, addition and subtraction may share an mrow, or multiplication and division, but not addition and multiplication).
Each of these is a subexpression and should be in its own mrow:
Several other MathML elements present their contents as if enclosed in an mrow:
and others not covered by this web page but described in the W3C definition §3.1.3.2.
An mfenced element groups its contents in a horizontal row, separated by commas and enclosed in parentheses.
Different separators (or none) and different fences (or none) may be specified using attributes. With no separators and no fences, mfenced has the same effect as mrow.
Attribute | Value type | Effect of its value | Default |
---|---|---|---|
open | String | The opening fence | ( |
close | String | The closing fence | ) |
separators | String | The separator character(s); if more than one is given, they are used in sequence | , |
<math><mfenced><mi>a</mi><mi>b</mi><mi>c</mi></mfenced></math>
<math>
<mfenced open='[' close=']' separators=':,'>
<mi>a</mi><mi>b</mi><mi>c</mi>
</mfenced>
</math>
<math> <mi>max</mi> <mo>⁡<!--function application--></mo> <mfenced> <mi>d</mi><mi>e</mi><mi>f</mi> </mfenced> </math>
<mfrac>N D</mfrac> presents the fraction with numerator N and denominator D.
The fraction is presented with a horizontal fraction bar, or with a slanted fraction bar if the attribute bevelled='true' is given.
<math><mfrac><mi>π<!--SMALL PI--></mi><mn>2</mn></mfrac></math>
<math> <mfrac> <mn>1</mn> <mrow><mi>b</mi><mo>+</mo><mn>2</mn></mrow> </mfrac> </math>
<math> <mfrac bevelled='true'> <mn>1</mn> <mrow><mi>b</mi><mo>+</mo><mn>2</mn></mrow> </mfrac> </math>
<msub>E B</msub> presents subexpression E with subscript B.
<msub>E P</msub> presents subexpression E with superscript P.
<math> <msup> <mi>b</mi> <mrow> <mn>2</mn> <mo>&InvisibleTimes#59</mo> <mi>d</mi> </mrow> </msup> </math>
<msubsup>E B P</msubsup> presents subexpression E with subscript B and superscript P.
<math> <msubsup> <mi>c</mi> <mn>3</mn> <mn>4</mn> </msubsup> </math>
<msqrt>E</msqrt> presents the square root of subexpression E.
<mroot>E N</mroot> presents the Nth root of subexpression E.
The mtable element presents a table, a matrix, or subexpressions whose layout can be specified in tabular form.
Analogous to an HTML table, an mtable element contains one or more mtr elements presenting the table's rows; each mtr element contains one or more mtd elements presenting the table's cells.
<math> <mfenced> <mtable> <mtr><mtd>2</mtd><mtd>-1</mtd></mtr> <mtr><mtd>1</mtd><mtd>0</mtd></mtr> </mtable> </mfenced> </math>
<math> <mtable side='right'> <mtr> <mtd><mtext>(1)</mtext></mtd> <mtd><mi>a</mi></mtd> <mtd><mo>=</mo></mtd> <mtd> <mrow> <mi>u</mi> <mo>&InvisibleTimes#59 </mo><mi>v</mi> </mrow> </mtd> </mtr> <mtr> <mtd><mi>b</mi></mtd> <mtd><mo>=</mo></mtd> <mtd> <mrow> <msup><mi>u</mi><mn>2</mn></msup> <mo>-</mo> <msup><mi>v</mi><mn>2</mn></msup> </mrow> </mtd> </mtr> </mtable> </math>
→W3C definition of mtable, mtr, mtd
Attribute | Value type | Effect of its value | Default |
---|---|---|---|
class | String | Associates the style class(es) with the element | none |
style | String | Associates the style information with the element | none |
href | URI | Makes the element a hyperlink | none |
See [MathML 3.0] Using CSS with MathML to use class or style intelligently.
Elements also accept the id and xref attributes (for cross-referencing presentation and content elements), not discussed here.
Attribute | Value type | Effect of its value | Default |
---|---|---|---|
mathcolor | color | Sets the element's color | inherited |
mathbackgroundcolor | color | Sets the element's background color | transparent |
Colors may be #RGB, #RRGGBB, or an HTML color name.
Attribute | Value type | Effect of its value | Default |
---|---|---|---|
mathvariant | normal, bold, italic, double-struck, script, sans-serif, twelve others | Sets the element's font type | normal (except for mi) |
mathsize | small normal big length | Sets the element's size | inherited |
Token elements also accept the dir attribute, not discussed here.
more tightlyand thus which one is performed first during evaluation of an expression containing them. For example, multiplication is said to bind more tightly than addition, so the expression
is evaluated in the sequence
multiplications then addition
rather than
addition then multiplications
In contrast, addition and subtraction are said to bind with equal tightness. In such cases the operations are typically performed left-to-right, so that
Precedence | Operators |
---|---|
20 | ( ) |
40 | , invisible comma |
190 | ∨ |
200 | ∧ |
230 | ∀, ∃ |
240 | ∈, ⊂, ⊃ |
241 | ≤ |
242 | ≥ |
243 | > |
245 | < |
255 | ≠ |
260 | = |
265 | ∙ / |
275 | − + |
390 | invisible times |
880 | invisible plus |
is evaluated
Operations may be listed in a total order by precedence, that is to say, for any two operators a and b, either a binds more tightly than b, b binds more tightly than a, or a and b bind equally tightly. Consequently the precedence of each in a set of operators is expressed as an integer. By custom, smaller integers mean tighter binding. and larger, less-tight.
The operator precedences for MathML
are listed in a
very, very long table,
from which a dozen or so common operators have been drawn
and appear in the brief table at right.
(I don't know why multiplication seems to have been given
two different precedences,
one for ∙ and the other for invisible times
.)
Mathematical Markup Language (MathML) Version 3.0 2nd Edition. W3C Recommendation 10 April 2014.