Displaying Mathml equations

☆樱花仙子☆ 提交于 2019-12-06 01:37:02

问题


My browser, Firefox 3.6, seems to display the Mathml equations in the W3C test suite just fine. But if I copy the code into my webpage, like from here, all Firefox produces is something like x y x y instead of how it correctly rendered the W3C page. What am I missing here>

EDIT: I just tried it in Chrome and Chrome failed the test itself by rendering it as x y x y. Needless to say, it rendered the math in my own webpage the same.

EDIT 2: I tried it on a new html document. Doesn't work:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
  </head>
  <body>
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" mode="display">
  <mfrac>
    <mi>x</mi>
    <mi>y</mi>
  </mfrac>
    </math>
    <math display="block" xmlns="http://www.w3.org/1998/Math/MathML" mode="inline">
  <mfrac>
    <mi>x</mi>
    <mi>y</mi>
      </mfrac>
    </math>
  </body>
</html>

I swear the W3C equations render just fine though...


回答1:


Putting your file in a filename named mml-prb.xhtml works. Note the extension.




回答2:


Including

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

and then using

    <math xmlns="http://www.w3.org/1998/Math/MathML">
        <mroot>
            <mrow>
                <mi>x</mi>
            </mrow>
            <mn>4</mn>
        </mroot>
    </math>

works in Chrome and Firefox

Update:

Since the mathjax cdn is shutting down, change

<script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...">
</script>

to

<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?...">
</script>



回答3:


as others have said you need to serve as xml for FF3, if you want to use mathml-in-html5 served as text/html you need firefox 4 (or webkit nightlies)




回答4:


You should use xml and serve it as such (i.e. use correct mimetype), which means you have to use xhtml and mathml tags with proper namespaces. Take how W3C serves the example as an example.

Note: HTML5 is NOT xml



来源:https://stackoverflow.com/questions/4174277/displaying-mathml-equations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!