junep
junep

Reputation: 2164

how to use MathML in HTML

I'm trying to displaying math formula on a web page. But when I write html code like following

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>Binomial Theorem</title>
</head>
<body>
<p>Binomial Theorem:</p>
<math xmlns="http://www.w3.org/1998/Math/MathML">
    <mrow>
        <msup>
            <mfenced>
                <mrow>
                    <mi>a</mi>
                    <mo>+</mo>
                    <mi>b</mi>
                </mrow>
            </mfenced>
            <mn>2</mn>
        </msup>
        <mo>=</mo>
        <msup>
            <mrow>
                <mi>a</mi>
            </mrow>
            <mn>2</mn>
        </msup>
        <mo>+</mo>
        <msup>
            <mrow>
                <mi>b</mi>
            </mrow>
            <mn>2</mn>
        </msup>
        <mo>+</mo>
        <mrow>
            <mn>2</mn>
            <mi>a</mi>
            <mi>b</mi>
        </mrow>
    </mrow>
</math>
</body>
</html>

And the result is just

Binomial Theorem:

a + b 2 = a 2 + b 2 + 2 a b

It is not like a formula

help me to use MathML in HTML Thanks,

Upvotes: 5

Views: 5464

Answers (3)

S M
S M

Reputation: 3233

MathML isn't supported by all popular user agents. Firefox 3.5 or later releases, for example, do support it:

The MathML snippet rendered by Firefox 3.5

Upvotes: 4

afwings
afwings

Reputation: 461

I would make 3 changes to your page:

  1. Include a DOCTYPE declaration as the first line of code. <!DOCTYPE html> identifies this page to the browser as an HTML5 page.
  2. I'd omit the namespace declaration from the html element. It doesn't hurt anything to have it there, but it's not necessary. You're probably going to include it on each math element anyway.
  3. If you add this as the last line above </head>, the math will be visible in all browsers, not just Firefox:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

Upvotes: 4

Jeyenth
Jeyenth

Reputation: 492

MathML is currently supported only on Firefox browsers. Try on Firefox browser.

Upvotes: 1

Related Questions