Example of MathML in HTML5


In the following article, we are going to learn about example of MathML in HTML5. HTML tags and MathML tags have a lot in common. Similar to how HTML tags are used to specify headings and paragraphs, MathML uses tags to describe the various components of a mathematical equation.

Mathematical Markup Language is referred to as MathML. It uses XML to describe mathematical notations and capture their structure as well as their content. It mostly functions to incorporate mathematical formulae into Web sites. MathML makes it feasible to publish scientific and mathematical knowledge online.

MathML Can Be Used

  • The MathML can serve as a substitute for the Matrix form.

  • The MathML enables the partial differential equation to be represented.

  • The MathML enables the Chemical Reaction Equation to be represented.

S.No Tags and Usage
1 <mi>
It is used for variables
2 <mn>
It is used for number values
3 <mo>
It is used for mathematical operators
4 <mrow>
It is used for grouping MathML elements to single unit

Let’s look into the following examples for better understanding of MathML

Example 1

In the following example we are printing a2= b2= c2

<!DOCTYPE html>
<html>
<body>
   <math>
      <mrow>
         <msup><mi>a</mi><mn>2</mn></msup>
         <mo>=</mo>
         <msup><mi>b</mi><mn>2</mn></msup>
      </mrow>
         <mo>=</mo>
         <msup><mi>c</mi><mn>2</mn></msup>
      </mrow>
   </math>
</body>
</html>

When the script gets executed, it will generate an output displaying the mathematical expression that we created in the above script on the webpage.

Example 2: Using MathML Characters

In the following example we are following markup which make use of characters and invisible times.

<!doctype html>
<html>
<body>
   <math>
      <mrow>
         <msup>
            <mi>x</mi>
            <mn>2</mn>
         </msup>
      <mo>+</mo>
      <mrow>
         <mn>4</mn>
         <mo>⁢</mo>
         <mi>x</mi>
      </mrow>
         <mo>+</mo>
         <mn>4</mn>
      </mrow>
         <mo>=</mo>
         <mn>0</mn>
      </mrow>
   </math>
</body>
</html>

On running the above script, it will generate an output consisting of the mathematical expression "x2 + 4x + 4 = 0" obtained by using MathML on the webpage.

Example 3

In the following example we are creating a mathematical expression Σ n = 1.

<!DOCTYPE html>
<html>
<body>
   <math>
      <mrow>
         <munderover>
         <mo>Σ</mo>
         <mrow>
         <mi>n</mi>
         <mo>=</mo>
         <mn>1</mn>
      </mrow>
   </math>
</body>
</html>

When the user tries to execute the script, it will display a mathematical expression Σ n = 1 generated by using MathML on the webpage.

Example 4

In the following we are generating a mathematical expression a2 + b2 = c2.

<!DOCTYPE html>
<html>
<body>
   <math>
      <mrow>
         <msup><mi>a</mi><mn>2</mn></msup>
         <mo>+</mo>

         <msup><mi>b</mi><mn>2</mn></msup>
         <mo> = </mo>

         <msup><mi>c</mi><mn>2</mn></msup>
      </mrow>
   </math>
</body>
</html>

When the script gets executed, it will generate an output consisting of the mathematical expression "a2 + b2 = c2" generated by using MathML on the webpage.

Updated on: 16-Dec-2022

242 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements