Daniel I. Scully

A Beginner's Guide to MathML


Brackets are an essential part of maths which while serving a functional purpose also significantly improve readability. In MathML they are included with the <mfenced> tag:

  1. <mfenced>
  2. <mfrac>
  3. <mrow>
  4. <mi>x</mi>
  5. <mo>+</mo>
  6. <mn>2</mn>
  7. </mrow>
  8. <mn>3</mn>
  9. </mfrac>
  10. </mfenced>
x+2 3

It is important (and somewhat irritating) to note that <mfenced> must contain exactly one child tag if it is simply to enclose the contents in brackets. If it contains more than one child tag, separators are inserted between them:

  1. <mfenced>
  2. <mn>3</mn>
  3. <mn>5</mn>
  4. <mn>4</mn>
  5. </mfenced>
3 5 4

Using the 'open', 'close' and 'separator' attributes we can specify the paretheses and separators used:

  1. <mfenced open="[" close="}" separators=":">
  2. <mi>a</mi>
  3. <mi>b</mi>
  4. <mi>c</mi>
  5. <mi>d</mi>
  6. </mfenced>
a b c d

The separator attribute can also accept a list if more than one type is required (eg: separators=":~*").

As an aside targeted at my other main interest: the physicists among you will notice that this is ideally suited to the 'bra-ket' notation of quantum mechanics:

  1. <mfenced open="〈" close="〉" separators="|">
  2. <mi>p</mi>
  3. <mo>a</mo>
  4. <mi>p`</mi>
  5. </mfenced>
p a p`