Search code examples
xmlxhtmlmathml

Declaring XML namespaces for MathML


On this page of my site: http://docs.gl/gl4/glBlendEquation

I have some code that looks like:

        <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">

            <mml:mfenced open="(" close=")">
                <mml:msub><mml:mi mathvariant="italic">R</mml:mi>
                <mml:mi mathvariant="italic">s</mml:mi>
                </mml:msub>
                <mml:msub><mml:mi mathvariant="italic">G</mml:mi>
                <mml:mi mathvariant="italic">s</mml:mi>
                </mml:msub>
                <mml:msub><mml:mi mathvariant="italic">B</mml:mi>
                <mml:mi mathvariant="italic">s</mml:mi>
                </mml:msub>
                <mml:msub><mml:mi mathvariant="italic">A</mml:mi>
                <mml:mi mathvariant="italic">s</mml:mi>
                </mml:msub>
            </mml:mfenced>
        </mml:math>

and in other places it looks like:

                    <math overflow="scroll">

                        <mrow>
                            <mi mathvariant="italic">Rr</mi>
                            <mo>=</mo>
                            <mrow>
                                <msub><mi mathvariant="italic">R</mi>
                                <mi mathvariant="italic">s</mi>
                                </msub>
                                <mo>⁢</mo>
                                <msub><mi mathvariant="italic">s</mi>
                                <mi mathvariant="italic">R</mi>
                                </msub>
                                <mo>+</mo>
                                <msub><mi mathvariant="italic">R</mi>
                                <mi mathvariant="italic">d</mi>
                                </msub>
                                <mo>⁢</mo>
                                <msub><mi mathvariant="italic">d</mi>
                                <mi mathvariant="italic">R</mi>
                                </msub>
                            </mrow>
                        </mrow>
                    </math>

The MathML markup in the places with the namespace prefix don't work, but the ones without the prefix seem to work just fine.

I could do a find and replace and remove the mml in all of my files, but I have hundreds of files and I would prefer to fix it if I can by editing my single shared header file. Is this possible?


Solution

  • If you want to use namespace prefixed elements in HTML, you must use XHTML, including serving your page with an application/xhtml+xml media type. Note that your page markup is, despite your doctype, not well-formed XML, so you would need to fix that.

    Otherwise, browsers will use an HTML parser. The HTML parser doesn't know about namespace prefixes, it just knows that <math>, <mrow>, <mi> etc are MathML elements. So in that case, you must convert your MathML to not use prefixes.