You must log in to edit PetroWiki. Help with editing

Content of PetroWiki is intended for personal use only and to supplement, not replace, engineering judgment. SPE disclaims any and all liability for your use of such content. More information

Message: PetroWiki content is moving to OnePetro! Please note that all projects need to be complete by November 1, 2024, to ensure a smooth transition. Online editing will be turned off on this date.


Help:MathML guide

PetroWiki
Jump to navigation Jump to search

MathML is an XML based system that uses tags to help a website correctly format complicated equations. This page is a guide to the basic elements of MathML for writing equations. Equations in PetroWiki can also be rendered as images (most currently are shown as images).

Tags

A tag is used to help the website correctly format an equation. Tags are surrounded by angle brackets <> to denote the fact that they will not appear in the website text. An example of a simple MathML tag is <mi>, which denotes that the next letter in the sequence will be an identifier, generally a variable like “x.” Tags almost always come in pairs and surround each element of the equation. For example, a simple variable, x, would be written as <mi>x</mi>. The end tag has a forward slash to denote that it is the end of the expression.

Nesting

Tags are often stacked inside each other, for example <mrow><mi>x</mi></mrow> . This is known as nesting. Nesting is used when multiple tags apply to a single number or variable, or if a tag applies to a large number of numbers or variables. Every equation will have some elements of nesting in it.

Commonly Used Tags

Beginning Ending Used For
<code> </code> This tag begins and ends every equation.
<math> </math> This tag is nested inside the <code> tag. It is required in every equation.
<mrow> </mrow> This tag groups elements in a horizontal row.
<mi> </mi> This tag denotes an indicator, such as a variable.
<mn> </mn> This tag denotes a number.
<mo> </mo> This tag denotes an operator, such as a +, -, =, etc.
<mtext> </mtext> This tag denotes text within an equation.
<msub> </msub> This tag attaches a subscript to a base.
<msup> </msup> This tag attaches a superscript to a base.
<msubsup> </msubsup> This tag attaches a subscript and superscript to a base.
<msqrt> </msqrt> This tag forms a square root around an element or elements.
<mspace/> This tag is used as a spacer between elements


Examples of MathML Code and Explanations

Basic Equation:

<code><math><mn>2</mn><mi>x</mi><mspace/><mo>+</mo><mspace/><mn>4</mn><mspace/><mo>=</mo><mspace/><mn>0</mn></math></code>

As with all equations, this one begins and ends with the <code> and <math> tags. Each element of the equation is correctly tagged as a number <mn>, indicator <mi>, or operator <mo>. A space tag <mspace/> has been included between each element and the operators to help spread out the equation a little, so it is easier to read.


Equations with Superscripts:

<code><math><msup><mi>x</mi><mn>2</mn></msup><mspace/><mo>-</mo><mspace/><mn>4</mn><mspace/><mo>=</mo><mspace/><mn>0</mn></math></code>

Superscripts use the <msup> tag to identify both a base and an exponent. The base is listed first, the exponent second, and both use the appropriate tags, nested inside the <msup> tag.


Equations with Square Roots: </nowiki>

The square root tag <msqrt> puts any element of an equation that is nested inside it under the square root symbol.


More Complicated Equations

This page gives a very basic overview of how to use MathML, but MathML is a powerful tool that can produce very complex equations. The internet is full of guides and tutorials to help produce more complicated equations using MathML.

Helpful Links

The following links are a few tutorials and guides that might be helpful to you when working with MathML.