Home

Daniel I. Scully

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.

  1. <mrow>
  2. <mi>x</mi>
  3. <mo>+</mo>
  4. <mn>2</mn>
  5. </mrow>
x + 2

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
  • normal
  • bold
  • italic
  • bold-italic
  • script
mathsize Sets the base font size
  • small
  • normal
  • big
  • number (a numerical font-size, eg: 12px)
mathcolor Sets the font colour
  • #rrggbb (a hex RGB colour, eg: #0022dd)
  • #rgb (a short hex RGB colour, eg: #02d)
  • css color name (one of the named CSS colours)
mathbackground Sets the font colour
  • #rrggbb (a hex RGB colour, eg: #0022dd)
  • #rgb (a short hex RGB colour, eg: #02d)
  • css color name (one of the named CSS colours)

These are applied as attributes either directly to individual token elements, or collectively to a group of elements via the <mstyle> element:

  1. <mi>y</mi>
  2. <mo>=</mo>
  3. <mi mathbackground="red">m</mi><mi>x</mi>
  4. <mo>+</mo>
  5. <mi mathcolor="blue">c</mi>
  6. <mo>=</mo>
  7. <mstyle mathbackground="red">
  8. <mn>3</mn><mo>t</mo>
  9. </mstyle>
  10. <mi>x</mi>
  11. <mo>+</mo>
  12. <mn mathcolor="blue" mathvariant="bold">4</mn>
y = m x + c = 3t x + 4

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.