MathML superscript is created with the <msup> tag. You have to place the base inside the <msup> tag, followed by the superscript.
Example
If you want to write x2, use the following MathML code:
Equivalent MathML code:
- <math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
- <msup>
- <mi>x</mi>
- <mn>2</mn>
- </msup>
- </math>
MathML element <msup> acts more like a function than a normal HTML markup tag. In the above MathML code, the base and the superscript can be thought of as two “arguments” passed to the <msup> “function.” Both arguments need to be a single MathML element (e.g., <mi> or <mn>). It is fine for working with atomic values like x and 2, but things get more complicated once we start working with compound expressions.
Grouping Sub-Expressions
Group of sub expression is used to include more than one element. It cannot be passed directly into <msup>. Instead, you will have to use <mrow> tag to group the expression, as shown below.
For example: If you want to write e2x+1, use the following MathML code:
Equivalent MathML code:
- <math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
- <msup>
- <mi>e</mi>
- <mrow>
- <mn>2</mn>
- <mi>x</mi>
- <mo>+</mo>
- <mn>1</mn>
- </mrow>
- </msup>
- </math>
It will display the expression like this:
To create a complex base expression, you have to wrap the superscript argument in an <mrow> element.
For example: If you want to write an expression (5x ? 3y)2, use the following MathML code:
Equivalent MathMl code:
- <math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
- <msup>
- <mrow>
- <mo>(</mo>
- <mrow>
- <mrow><mn>5</mn><mi>x</mi></mrow>
- <mo>–</mo>
- <mrow><mn>3</mn><mi>y</mi></mrow>
- </mrow>
- <mo>)</mo>
- </mrow>
- <mn>2</mn>
- </msup>
- </math>
Supporting Browsers:
Element | Chrome | IE | Firefox (Gecko) | Opera | Safari |
<msup> | Not Supported | Not Supported | Supported | Not Supported | Only Basic Support |
Leave a Reply