In the previous post we have discussed how to create mathematical expressions in the web pages by using MathML. The basics are discussed and some examples are given. In this post we want to create more complicated cases and try to make expressions in subscript and superscript forms . . .
Like other MathML elements subscripts and superscripts have their especial tags. The structure for subscript is given below, in an example:
<math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
<msub>
<mi>x</mi>
<mn>i</mn>
</msub>
</math>
Do not forget to load the MathJax script discussed in previous post. And for superscript:
<math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
<msup>
<mi>x</mi>
<mi>2</mi>
</msup>
</math>
Two tags must be inputted within ‘<msub>‘ and ‘<msup>‘ tags; the first is the main expression and the second would be subscript/superscript. The results of the above MathML codes are:
Another useful tag is also used to have subscript and superscript at the same time:
<math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
<msubsup>
<mi>x</mi>
<mn>i</mn>
<mn>2</mn>
</msubsup>
</math>
The first inside tag is the main expression, the second is for subscript and the last used for superscript. The result is:
You can also use multi-scripts in both left and right sides, by ‘<mmultiscripts>‘:
<math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
<mmultiscripts>
<mi>x</mi>
<none/>
<mi>j</mi>
<mprescripts/>
<mi>k</mi>
<mn>2</mn>
</mmultiscripts>
</math>
The first three tags are the same with ‘<msubsup>‘; they are the main expression, the subscript and the superscript respectively. In the above example we have removed the subscript (second input); to do this use ‘<none/>‘ tag instead of a real input. The ‘<mprescripts/>‘ changes the place from right to left, i. e. the prescript part. Here, two inputs are for the pre-subscript and pre-superscript, respectively. The result is:
The problem here is that you cannot used more than one inside-tag for each part; so if you have an expression which contains more than one symbol, you must group it before inserting. ‘<mrow>‘ tag does the grouping:
<math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
<mo>,</mo>
<mi>j</mi>
</mrow>
</msub>
</math>
Here, the subscript symbol is replaced by a group (‘i,j‘). So the whole group is shown as the subscript:
And in our last and most complex example, we have made groups for all parts:
<math xmlns=’http://www.w3.org/1998/Math/MathML’ display=’block’>
<msubsup>
<mrow>
<mn>2</mn>
<mi>x</mi>
</mrow>
<mrow>
<mi>i</mi>
<mo>,</mo>
<mi>j</mi>
</mrow>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>+</mo>
<mi>y</mi>
<mo>)</mo>
</mrow>
</msubsup>
</math>
This would be:
As you see the subscript and superscripts is near to each other. So we use ‘ subscriptshift’ and ‘subscriptshift’ attributes for shifting them from the base. The value, here, is in pixel format. Replace the ‘<msubsup>‘ with:
<msubsup subscriptshift =”10px” superscriptshift =”20px”>
So we have:
Continue in the next post . . .

