Part 0. Why there are two kinds of MathML and what is the difference?
Presentation markup captures notational structure. It encodes the notational structure of an expression in a sufficiently abstract way to facilitate rendering to various media. Thus, the same presentation markup can be rendered with relative ease on screen in either wide and narrow windows, in ASCII or graphics, in print, or it can be enunciated in a sensible way when spoken. It does this by providing information such as structured grouping of expression parts, classification of symbols, etc.
Presentation markup does not directly concern itself with the mathematical structure or meaning of an expression. In many situations, notational structure and mathematical structure are closely related, so a sophisticated processing application may be able to heuristically infer mathematical meaning from notational structure, provided sufficient context is known. However, in practice, the inference of mathematical meaning from mathematical notation must often be left to the reader.
Employing presentation tags alone may limit the ability to re-use a MathML object in another context, especially evaluation by external applications.
Content markup captures mathematical structure. It encodes mathematical structure in a sufficiently regular way in order to facilitate the assignment of mathematical meaning to an expression by application programs. Though the details of mapping from mathematical expression structure to mathematical meaning can be extremely complex, in practice, there is wide agreement about the conventional meaning of many basic mathematical constructions. Consequently, much of the meaning of a content expression is easily accessible to a processing application, independently of where or how it is displayed to the reader. In many cases, content markup could be cut from a Web browser and pasted into a mathematical software tool with the confidence that sensible values will be computed.
Since content markup is not directly concerned with how an expression is displayed, a renderer must infer how an expression should be presented to a reader. While a sufficiently sophisticated renderer and style sheet mechanism could in principle allow a user to read mathematical documents using personalized notational preferences, in practice, rendering content expressions with notational nuances may still require the intervention of some sort.
Employing content tags alone may limit the ability of the author to precisely control how an expression is rendered.
Both content and presentation tags are necessary in order to provide the full expressive capability one would expect in a mathematical markup language. Often the same mathematical notation is used to represent several completely different concepts. For example, the notation x^i may be intended (in polynomial algebra) as the i-th power of the variable x, or as the i-th component of a vector x (in tensor calculus). In other cases, the same mathematical concept may be displayed in one of the various notations. For instance, the factorial of a number might be expressed with an exclamation mark, a Gamma function, or a Pochhammer symbol.
Thus, the same notation may represent several mathematical ideas, and, conversely, the same mathematical idea often has several notations. In order to provide authors with the ability to precisely control notation while at the same time encoding meanings in a machine-readable way, both content and presentation markup are needed.
In general, if it is important to control exactly how an expression is rendered, presentation markup will generally be more satisfactory. If it is important that the meaning of an expression can be interpreted dependably and automatically, then content markup will generally be more satisfactory.
Part 1. Presentational-MathML elements
Top-level element
<math>
Top-level MathML element used to write a single mathematical formula.Attributes
display
: its default value is inline
-
display
=block
: this element will be displayed in its own block outside the current span of text. -
display
=inline
: this element will be displayed inside the current span of text.
Example
The infinite sumis equal to the real number
Token elements
<mi>
Indicates that the content should be rendered as an identifier such as function names, variables, or symbolic constants.Attributes
-
mi
accepts global attributes. - For
mi
elements that contain a single character, the default value of themathvariant
attribute isitalic
. Otherwise, themathvariant
attribute isnormal
.
Example
<mn>
Represents a numeric literal which is normally a sequence of digits with a possible separator (a dot or a comma). It is also allowed to have arbitrary text in it which is actually a numeric quantityAttributes
mn
: accepts global attributes.
Example
<mo>
Represents an operator in a broad sense. Besides operators in strict mathematical meaning, this element also includes "operators" like parentheses, separators like commas and semicolons, or "absolute value" bars.Attributes
mo
: accepts global attributes.
accent
: A boolean
indicating whether the operator should be treated as an accent when used as an under or overscript (i.e. drawn bigger and closer to the base expression).
-
accent
=True
: does draw bigger and closer to the base expression. -
accent
=False
: does not draw bigger and closer to the base expression.
fence
: A boolean
indicating whether the operator is a fence (such as parentheses).
-
fence
=True
: the operator is a fence. -
fence
=False
: the operator is not a fence.
separator
: A boolean
indicating whether the operator is a separator (such as commas).
-
separator
=True
: the operator is a separator. -
separator
=False
: the operator is not a separator.
stretchy
: A boolean
indicating whether the operator stretches to the size of the adjacent element.
-
stretchy
=True
: stretches to the size of adjacent element. -
stretchy
=False
: does not stretches to the size of adjacent element.
symmetric
: A boolean
indicating whether a stretchy operator should be vertically symmetric around the imaginary math axis (centered fraction line).
-
symmetric
=True
: a stretchy operator should be vertically symmetric around the imaginary math axis. -
symmetric
=False
: a stretchy operator does not have to be vertically symmetric around the imaginary math axis.
movablelimits
: A boolean
indicating whether attached under- and overscripts move to sub- and superscript positions when math-style
is set to compact
.
-
movablelimits
=True
: allow to perform the movement. -
movablelimits
=False
: do not allow to perform the movement.
lspace
: indicates the amount of space before the operator.
-
lspace
=<length>
: set the space to a specific thickness given the unit. -
lspace
=<percentage>
: set the space relative to its parent object.
rspace
: indicates the amount of space after the operator.
-
rspace
=<length>
: set the space to a specific thickness given the unit. -
rspace
=<percentage>
: set the space relative to its parent object.
maxsize
: indicates the maximum size of the operator when it is stretchy.
-
maxsize
=<length>
: set the size to a specific thickness given the unit. -
maxsize
=<percentage>
: set the size relative to its parent object.
minsize
: indicates the minimum size of the operator when it is stretchy.
-
minsize
=<length>
: set the size to a specific thickness given the unit. -
minsize
=<percentage>
: set the size relative to its parent object.
Example
<ms>
Represents a string literal meant to be interpreted by programming languages and computer algebra systems.Attributes
ms
: accepts global attributes.
Example
<mspace>
Used to display a blank space, whose size is set by its attributes.Attributes
depth
: desired depth (below the baseline) of the space.
-
depth
=<length>
: set the depth to a specific thickness given the unit. -
depth
=<percentage>
: set the depth relative to its parent object.
height
: desired height (above the baseline) of the space.
-
height
=<length>
: set the height to a specific thickness given the unit. -
height
=<percentage>
: set the height relative to its parent object.
width
: desired width of the space.
-
width
=<length>
: set the width to a specific thickness given the unit. -
width
=<percentage>
: set the width relative to its parent object.
Example
<mtext>
Used to render arbitrary text with no notational meaning, such as comments or annotations.Attributes
mtext
: accepts global attributes.
Example
General Layout
<menclose>
Renders its content inside an enclosing notation specified by thenotation
attribute.
Attributes
menclose
: accepts global attributes.
notation
: layout element that encompasses expression. Multiple options.
-
notation
=longdiv
: enclose in long division symbol. -
notation
=actuarial
: enclose in actuarial symbol. -
notation
=box
: enclose in an enclosed box. -
notation
=roundedbox
: enclose in a rounded box. -
notation
=circle
: enclose in a circle. -
notation
=left
: line to the left of the content. -
notation
=right
: line to the right of the content. -
notation
=top
: line to above content. -
notation
=bottom
: line to bottom content. -
notation
=updiagonalstrike
: - strikeout line through contents from lower left to upper right. -
notation
=downdiagonalstrike
: - strikeout line through contents from upper left to lower right. -
notation
=verticalstrike
: - vertical strikeout line through contents. -
notation
=horizontalstrike
: - horizontal strikeout line through contents. -
notation
=madruwb
: - Arabic factorial symbol. -
notation
=phasorangle
: - phasor angle.
Example
<merror>
Used to display contents as error messages. The intent of this element is to provide a standard way for programs that generate MathML from other inputs to report syntax errors.Attributes
merror
: accepts global attributes.
Example
<mfrac>
Used to display fractions and fraction-like objects such as binomial coefficients and Legendre symbols.Attributes
mfrac
: accepts global attributes.
denomalign
: The alignment of the denominator under the fraction (not standard, only accepted by Safari).
-
denomalign
=center
: (default) place the denominator on center. -
denomalign
=left
: place the denominator on left. -
denomalign
=right
: place the denominator on right.
numalign
: The alignment of the numerator under the fraction (not standard, only accepted by Safari).
-
numalign
=center
: (default) place the numerator on center. -
numalign
=left
: place the numerator on left. -
numalign
=right
: place the numerator on right.
linethickness
: indicates the thickness of the horizontal fraction line.
-
linethickness
=<length>
: set the line to a specific thickness given the unit. -
linethickness
=<percentage>
: set the line to a size relative to its parent.
Example
<mpadded>
Used to add extra padding and to set the general adjustment of position and size of enclosed contents.Attributes
mpadded
: accepts global attributes.
depth
: desired depth (below the baseline) of the mpadded
element.
-
depth
=<length>
: set the depth to a specific thickness given the unit. -
depth
=<percentage>
: set the depth relative to its parent object.
height
: desired height (above the baseline) of the mpadded
element.
-
height
=<length>
: set the height to a specific thickness given the unit. -
height
=<percentage>
: set the height relative to its parent object.
width
: desired width of the mpadded
element.
-
width
=<length>
: set the width to a specific thickness given the unit. -
width
=<percentage>
: set the width relative to its parent object.
lspace
: indicating the horizontal location of the positioning point of the child content with respect to the positioning point of the mpadded
element.
-
lspace
=<length>
: set the horizontal line to a specific thickness given the unit. -
lspace
=<percentage>
: set the horizontal line relative to its parent object.
voffset
: indicating the vertical location of the positioning point of the child content with respect to the positioning point of the mpadded
element.
-
voffset
=<length>
: set the vertical line to a specific thickness given the unit. -
voffset
=<percentage>
: set the vertical line relative to its parent object.
Example
<mphamtom>
Renders the element invisibly, but dimensions (such as height, width, and baseline position) are still kept.Attributes
mphamtom
: accepts global attributes.
Example
<mroot>
Used to display roots with an explicit index. Two arguments are accepted, the first element is the base, and the second element is the index.Attributes
mroot
: accepts global attributes.
Example
<mrow> important
Used to group sub-expressions, which usually contain one or more operators with their respective operands (such as <mi> and <mn>).
Attributes
mrow
: accepts global attributes.
Example
<msqrt>
Display square root symbol (no index is displayed).Attributes
msqrt
: accepts global attributes.
Example
Script and limit elements
<mmultiscripts>
Used to attach an arbitrary number of subscripts and superscripts to an expression at once, generalizing themsubsup
element. Scripts can be either prescripts (placed before the expression) or postscripts (placed after it).
Attributes
mmultiscripts
: accepts global attributes.
subscriptshift
: indicating the minimum amount to shift the baseline of the subscript down for both pre and post subscripts (not standard).
-
subscriptshift
=<length>
: indicate shift by length. -
subscriptshift
=<percentage>
: indicate shift by percentage.
superscriptshift
: indicating the minimum amount to shift the baseline of the superscript up for both pre and post subscripts (not standard).
-
superscriptshift
=<length>
: indicate shift by length. -
superscriptshift
=<percentage>
: indicate shift by percentage.
Example 1
By default, children are sub- and super-scripts tot eh right of the base expression. You can add sub- and super-scripts to the left of the expression using the<mprescripts/>
element:
Example 2
You can use the<mrow>
tag to not include a sub-/super-script (or just use a blank <mi>
child, though that may cause problems with certain parsers).
Example 3
Children alternate between the sub- and super- script<msub>
Used to attach a subscript to an expression.Attributes
msub
: accepts global attributes.
subscriptshift
: indicating the minimum amount to shift the baseline of the subscript down for both pre and post subscripts (not standard).
-
subscriptshift
=<length>
: indicate shift by length. -
subscriptshift
=<percentage>
: indicate shift by percentage.
Example
<msup>
Used to attach a superscript to an expression.Attributes
msup
: accepts global attributes.
superscriptshift
: indicating the minimum amount to shift the baseline of the superscript up for both pre and post subscripts (not standard).
-
superscriptshift
=<length>
: indicate shift by length. -
superscriptshift
=<percentage>
: indicate shift by percentage.
Example
<msubsup>
Used to attach a superscript to an expression.Attributes
msubsup
: accepts global attributes.
subscriptshift
: indicating the minimum amount to shift the baseline of the subscript down for both pre and post subscripts (not standard).
-
subscriptshift
=<length>
: indicate shift by length. -
subscriptshift
=<percentage>
: indicate shift by percentage.
superscriptshift
: indicating the minimum amount to shift the baseline of the superscript up for both pre and post subscripts (not standard).
-
superscriptshift
=<length>
: indicate shift by length. -
superscriptshift
=<percentage>
: indicate shift by percentage.
Example
<mover>
Used to attach an accent or a limit over an expression.Attributes
mover
: accepts global attributes.
accent
: indicating whether the over script should be treated as an accent (i.e. drawn bigger and closer to the base expression).
-
accent
=True
: the overscript should be treated as an accent. -
accent
=False
: the overscript should not be treated as an accent.
Example
<munder>
Used to attach an accent or a limit under an expression.Attributes
munder
: accepts global attributes.
accentunder
: indicating whether the over script should be treated as an accent (i.e. drawn bigger and closer to the base expression).
-
accentunder
=True
: the underscript should be treated as an accent. -
accentunder
=False
: the underscript should not be treated as an accent.
Example
<munderover>
Used to attach an accent or a limit to both under and over an expression.Attributes
munderover
: accepts global attributes.
accent
: indicating whether the over script should be treated as an accent (i.e. drawn bigger and closer to the base expression).
-
accent
=True
: the overscript should be treated as an accent. -
accent
=False
: the overscript should not be treated as an accent.
accentunder
: indicating whether the over script should be treated as an accent (i.e. drawn bigger and closer to the base expression).
-
accentunder
=True
: the underscript should be treated as an accent. -
accentunder
=False
: the underscript should not be treated as an accent.
Example
Tabular Math
<mtable>
Allows the creation of tables or matrices. Its children are<mtr>
elements (representing rows), each of them having <mtd>
elements as its children (representing cells).
Attributes
mtable
: accepts global attributes.
width
: indicating the width of the entire table.
-
width
=<length>
: set the width to a specific thickness (must provide unit). -
width
=<percentage>
: set the width to a size relative to its parent object.
align
: specify the table's vertical alignment with respect to its environment.
-
align
=axis
: (default) the vertical center of the table aligns on the environment's axis (typically the minus sign). -
align
=baseline
: the vertical center of the table aligns with the environment's baseline. -
align
=bottom
: the bottom of the table aligns with the environment's baseline. -
align
=center
: same asbaseline
. -
align
=top
: the top of the table aligns on the environment's baseline.
columnalign
: specifies the horizontal alignment of the cells.
-
columnalign
=left
: align the column to left. -
columnalign
=center
: center text in column. -
columnalign
=right
: align the column to right.
columnspacing
: specifies the horizontal alignment of the cells.
-
columnspacing
=<length>
: set the spacing to a specific thickness given the unit. -
columnspacing
=<percentage>
: set the spacing to a size relative to its parent object.
rowalign
: specifies the vertical alignment of the cells.
-
rowalign
=baseline
: (default) the vertical center of the cell aligns with the environment's baseline. -
rowalign
=axis
: the vertical center of the cell aligns on the environment's axis (typically the minus sign). -
rowalign
=bottom
: the bottom of the cell aligns with the environment's baseline. -
rowalign
=center
: same asbaseline
. -
rowalign
=top
: the top of the cell aligns on the environment's baseline.
rowlines
: specifies row borders.
-
rowlines
=none
: no lines between rows. -
rowlines
=solid
: solid border. -
rowlines
=dashed
: dashed border.
rowspacing
: specifies space between table rows.
-
rowspacing
=<length>
: set the spacing to a specific thickness given the unit. -
rowspacing
=<percentage>
: set the spacing to a size relative to its parent object.
frame
: specifies border around the entire table.
-
frame
=none
: no border. -
frame
=solid
: solid border. -
frame
=dashed
: dashed border.
framespacing
: specifies additional space added between the table and frame. The first value specifies the spacing on the right and left; the second value specifies the spacing above and below.
-
framespacing
=<length>
: set the spacing to a specific thickness given the unit. -
framespacing
=<percentage>
: set the spacing to a size relative to its parent object.
Example
<mtr>
Represents a row in a table or a matrix.Attributes
mtr
: accepts global attributes.
columnalign
: specifies the horizontal alignment of the cells (overrides setting in parent environment).
-
columnalign
=left
: align the column to left. -
columnalign
=center
: center text in column. -
columnalign
=right
: align the column to right.
rowalign
: specifies the vertical alignment of the cells (overrides setting in parent environment).
-
rowalign
=baseline
: (default) the vertical center of the cell aligns with the environment's baseline. -
rowalign
=axis
: the vertical center of the cell aligns on the environment's axis (typically the minus sign). -
rowalign
=bottom
: the bottom of the cell aligns with the environment's baseline. -
rowalign
=center
: same asbaseline
. -
rowalign
=top
: the top of the cell aligns on the environment's baseline.
Example
Check example in<mtable>
<mtd>
Represents a cell in a table or a matrix.Attributes
mtd
: accepts global attributes.
columnspan
: use to setup a multi-column cell. A non-negative integer value that indicates on how many columns does the cell extend.
-
columnspan
=num
: indicates the number of columns the cell extends.
rowspan
: use to setup a multi-row cell. A non-negative integer value that indicates on how many columns does the cell extend.
-
rowspan
=num
: indicates the number of rows the cell extends.
columnalign
: specifies the horizontal alignment of the cells (overrides setting in parent environment).
-
columnalign
=left
: align the column to left. -
columnalign
=center
: center text in column. -
columnalign
=right
: align the column to right.
rowalign
: specifies the vertical alignment of the cells (overrides setting in parent environment).
-
rowalign
=baseline
: (default) the vertical center of the cell aligns with the environment's baseline. -
rowalign
=axis
: the vertical center of the cell aligns on the environment's axis (typically the minus sign). -
rowalign
=bottom
: the bottom of the cell aligns with the environment's baseline. -
rowalign
=center
: same asbaseline
. -
rowalign
=top
: the top of the cell aligns on the environment's baseline.
Example
Check example in<mtable>
Semantic annotations
<semantics>
A tag used to define alternate formats of the expression.- Must be a first child in the
<math>
environment and must contain a MathML expression to be annotated. - By default, only the first child is rendered, which is supposed to be Presentation MathML.
- Subsequent
<annotation>
or<annotation-xml>
elements are reserved for XML formats such as OpenMath.
Attributes
encoding
: the encoding of the semantic information in the annotation.
-
encoding
=MathML-Content
: a dedicated XML dialect to express the meaning of mathematical formulas. Typically used to store data for parsing and analysis. -
encoding
=MathML-Presentation
: the presentation of the formula that most browsers render. Typically this isn't needed since the presentation version is in thesemantics
environment by default but it is included for certain data processing tasks. -
encoding
=image/png
: annotate with a PNG image of the formula. Some browsers may choose to load the image if the equation markup throws an error. -
encoding
=<custom>
: can define a custom environment to be used with data processing tasks.
src
: the location of an external source for semantic information.
-
src
=“some/path/formula.png”
Example
Part 2. (Strict) Content-MathML elements
Just like HTML at-large, there are many different flavors of content-markup. We’ll focus on strict content-MathML typically used by parsers such as LateXML.
<cn>
Used to represent integers, real numbers, and double-precision floating point numbers.Attributes
cn
: accepts global attributes.
type
: Defines integer format.
-
type
=integer
: an integer is represented by an optional sign followed by a string of one or more decimal "digits". -
type
=real
: a real number is presented in radix notation. -
type
=double
: used to mark up those double-precision floating point numbers that can be represented in theIEEE 754 standard format. -
type
=hexdouble
: used to directly represent the 64 bits of an IEEE 754 double-precision floating point number as a 16-digit hexadecimal number.
Example
<ci>
Represent "mathematical variables" which have properties, but no fixed value.Attributes
ci
: accepts global attributes.
type
: Defines integer format.
-
type
=integer
: used as the argument of the type symbol to convey the type of an integer. -
type
=rational
: used as the argument of the type symbol to convey the type of a rational number. -
type
=real
: a real number is presented in radix notation. -
type
=complex
: used as the argument of the type symbol to convey the type for a complex number. -
type
=complex-polar
: used as the argument of the type symbol to convey the type of a complex number specified in terms of its modulus and argument. -
type
=complex-cartesian
: used as the argument of the type symbol to convey the type of a complex number specified in terms of its real and imaginary parts. -
type
=constant
: used as the argument of the type symbol to convey a type for the common constants, pi ~= 3.1415, e ~= 2.718, i = square root of -1, gamma ~= .5772, NaN, infinity (all in the nums cd), true and false (in the logic cd). Also for MathML variables declared to have type constant, as in "x=2." -
type
=function
: used as the argument of the type symbol to convey the type for a function name. -
type
=vector
: used as the argument of the type symbol to convey the type for a vector. -
type
=list
: used as the argument of the type symbol to convey the type for a list. -
type
=set
: used as the argument of the type symbol to convey the type for a set. -
type
=matrix
: used as the argument of the type symbol to convey the type for a matrix (n tuple of rows, where each row is an m tuple for some m, it should be noted that each row must be the same length).
Example
<csymbol>
Used to refer to a specific, mathematically-defined concept with an external definition. In the expression "x+y", the plus sign is a symbol since it has a specific, external definition, namely the addition function.Attributes
csymbol
: accepts global attributes.
cd
: directly referring to OpenMath CD(Content Dictionaries), an extensive, open, and active repository of mathematical definitions.
-
cd
= the name of the Content Dictionary
cdgroup
: specifies a URL to an OpenMath CD Group file.
-
cdgroup
= URI, the URI is used to look up for the name in the CD Group File.
definitionURL
: reference CDs or any other source of definitions that can be identified by a URL.
-
definitionURL
= URI/URL.
Example
<cs>
Encodes "string literals" which may be used in Content MathML expressions.Attributes
cs
: accepts global attributes.
Example
<apply>
Used to build an expression tree that represents the application of a function or operator to its arguments. Roughly speaking, this means a piece of mathematics that could be surrounded by parentheses or "logical brackets" without changing its meaning.Attributes
apply
: accepts global attributes.
Example
The expression "(F+G)X" can be ambiguous but with the content markup, the intent is clear:<bind> and <bvar>
Used to represent bound variables. Informally, they can be thought of as the "dummy variables" in expressions such as integrals, sums, products, and the logical quantifiers "for all" and "there exists". Binding expressions are represented as MathML expression trees using thebind
element. Its first child is a MathML expression that represents a binding operator, for example integral operator. This is followed by a non-empty list of bvar
elements denoting the bound variables, and then the final child which is a general Content MathML expression, known as the body
Attributes
bind
: accepts global attributes.
bvar
: accepts global attributes.
Example
<share>
Used to conserve space in the XML encoding, MathML expression trees can make use of structure sharing.Attributes
share
: accepts global attributes.
href
: a URI specifying the id
attribute of the root node of the expression tree.
-
href
= URI of the structure.
Example
Original form:share
form:
<cerror>
It has no direct mathematical meaning. Errors occur as the result of some action performed on an expression tree. Errors may occur inside other objects and also inside other errors.Attributes
cerror
: accepts global attributes.
Example
Divide by zero error:<cbytes>
Represents a stream of bytes as a sequence of characters in Base64 encoding. It is mainly used for OpenMath compatibility, but may be used, as in OpenMath, to encapsulate output from a system that may be hard to encode in MathML, such as binary data relating to the internal state of a system, or image data.Attributes
cbytes
: accepts global attributes.
References
- List of global attributes
- Mozilla’s MathML developer notes
- W3C MathML notes (lot of good examples)
- Variable types (OpenMath)