A Beginner's Guide to MathML
Grouping
mrow
Another of the most commonly used tags is the <mrow> element. It's sole purpose is to group elements together in a horizontal row.
<mrow>
<mi>x</mi>
<mo>+</mo>
<mn>2</mn>
</mrow>
It's usage is quite simple but it is still particularly useful in MathML since, as we will discuss later, some elements require a specific number of child elements. When you need to contain a complicated expression within one of these elements, we do so by grouping it within an <mrow>.
Styling
Here are some of the most useful style attributes with their allowed values:
Attribute | Description | Allowed Values |
---|---|---|
mathvariant | Sets the font style |
|
mathsize | Sets the base font size |
|
mathcolor | Sets the font colour |
|
mathbackground | Sets the font colour |
|
These are applied as attributes either directly to individual token elements, or collectively to a group of elements via the <mstyle> element:
<mi>y</mi>
<mo>=</mo>
<mi mathbackground="red">m</mi><mi>x</mi>
<mo>+</mo>
<mi mathcolor="blue">c</mi>
<mo>=</mo>
<mstyle mathbackground="red">
<mn>3</mn><mo>t</mo>
</mstyle>
<mi>x</mi>
<mo>+</mo>
<mn mathcolor="blue" mathvariant="bold">4</mn>
Some web developers may, at first glance, feel uneasy about specifying style information with attributes. We have, after all, spent years driving this out of HTML. But you shouldn't worry.
This is "presentational" MathML and the semantics of this language is the styling. The situation is analagous to SVG, where, for example, the colours are also specified by attributes. It is entirely appropriate to place style information directly into a document whose purpose is to describe how something should be displayed.