A Beginner's Guide to MathML
Fractions
To write a fraction, or any thing which should be displayed in a similar way (e.g.: binomial coefficients), we can use the <mfrac> element.
<mfrac>
<mrow> <mi>x</mi><mo>+</mo><mn>2</mn> </mrow>
<mn>3</mn>
</mfrac>
The fraction is our first example of a feature which is strange to XML but common to MathML: the importance of order. Within an <mfrac> the first child is defined as the numerator and the second child the denominator. This also means that it must have exactly two children, no more, no less. When either the numerator or denominator are expressions in their own right, they must be grouped together in some other tag such as the <mrow> in the example above.
There are also four fraction-specific attributes which can be set to describe the layout of the fraction:
Attribute | Description | Allowed Values |
---|---|---|
linethickness | Sets the thickness of the line which separates the numerator and the denominator |
|
numalign | Sets the alignment of the numerator |
|
denomalign | Sets the alignment of the numerator |
|
bevelled | Determines whether the fraction is displayed with the separating line horizontal (false) or at an angle (true) |
|
Here are some examples of their use:
Example: Binomial coefficients
As we said earlier, <mfrac> is not just for fractions. By setting linethickness="0" we can use <mfrac> to display binomial coefficients:
<mfenced>
<mfrac linethickness="0">
<mn>2</mn>
<mn>3</mn>
</mfrac>
</mfenced>
Example: Alignment
Using the 'denomalign' attribute, we can align the denominator in this expression to the right of the fraction.
<mfrac denomalign="right">
<mrow> <mi>x</mi><mo>+</mo><mn>2</mn> </mrow>
<mn>3</mn>
</mfrac>
The same can be done with the numerator using 'numalign'.
Example: Bevelled fractions
When the 'bevelled' attribute is set to 'true', the fraction is displayed with a diagonal separator, instead of the horizontal one in the other examples above.
<mfrac bevelled="true">
<mrow> <mi>x</mi><mo>+</mo><mn>2</mn> </mrow>
<mn>3</mn>
</mfrac>