Javascript MathML呈现中名称空间的使用

Javascript MathML呈现中名称空间的使用,javascript,html,namespaces,mathjax,Javascript,Html,Namespaces,Mathjax,现在,没有名称空间的MathML呈现良好,但如果我添加名称空间,如m:或mml:则呈现不起作用。任何帮助,请提前感谢 下面是我使用的代码 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML

现在,没有名称空间的MathML呈现良好,但如果我添加名称空间,如m:或mml:则呈现不起作用。任何帮助,请提前感谢

下面是我使用的代码

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<head>
    <script type="text/javascript" src="file:/P:/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
        <h3>MathML Previewer</h3>

        Paste your MathML:<br/>
            <textarea id="myMath" style="resize: none; height:250px; width:850px">
        </textarea>

            <button type="button" onclick="myclear()">Reset</button>
            <p>Click the button to get output</p>
            <button type="button" onclick="myFunction()">Output</button>
            <div id="demo">
            </div>

            <script>
                function myFunction() {

                var x = document.getElementById("myMath").value;
                document.getElementById("demo").innerHTML = x;
                MathJax.Hub.Typeset("demo");
                }
            </script>
            <script>
                function myclear() {
                var x = document.getElementById("myMath").value =' ';
                //document.getElementById("demo").innerHTML = x;

                }
            </script>

    </body>
</html>

MathML预览器
粘贴您的MathML:
重置 单击按钮以获取输出

输出 函数myFunction(){ var x=document.getElementById(“myMath”).value; document.getElementById(“demo”).innerHTML=x; Typeset(“demo”); } 函数myclear(){ var x=document.getElementById(“myMath”).value=''; //document.getElementById(“demo”).innerHTML=x; }
MathML:

名称空间不呈现

 <m:math display="block" xmlns:m="http://www.w3.org/1998/Math/MathML"><m:mrow><m:mi>r</m:mi><m:mo>=</m:mo><m:mfrac><m:mrow><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mrow><m:mi>x</m:mi><m:mi>y</m:mi><m:mo>-</m:mo><m:mfrac><m:mrow><m:mo stretchy='false'>(</m:mo><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mi>x</m:mi></m:mstyle><m:mo stretchy='false'>)</m:mo><m:mo stretchy='false'>(</m:mo><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mi>y</m:mi></m:mstyle><m:mo stretchy='false'>)</m:mo></m:mrow><m:mi>n</m:mi></m:mfrac></m:mrow></m:mstyle></m:mrow><m:mrow><m:msqrt><m:mrow><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mrow><m:msup><m:mi>x</m:mi><m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mfrac><m:mrow><m:msup><m:mrow><m:mo stretchy='false'>(</m:mo><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mi>x</m:mi></m:mstyle><m:mo stretchy='false'>)</m:mo></m:mrow><m:mn>2</m:mn></m:msup></m:mrow><m:mi>n</m:mi></m:mfrac></m:mrow></m:mstyle></m:mrow></m:msqrt></m:mrow></m:mfrac></m:mrow></m:math>
r=&x03A3;xy-(Σ;x)(Σ;y)nΣ;x2-(Σ;x)2n
没有按要求呈现名称空间

 <math display="block" xmlns:m="http://www.w3.org/1998/Math/MathML"><mrow><mi>r</mi><mo>=</mo><mfrac><mrow><mstyle displaystyle='true'><mo>&#x03A3;</mo><mrow><mi>x</mi><mi>y</mi><mo>-</mo><mfrac><mrow><mo stretchy='false'>(</mo><mstyle displaystyle='true'><mo>&#x03A3;</mo><mi>x</mi></mstyle><mo stretchy='false'>)</mo><mo stretchy='false'>(</mo><mstyle displaystyle='true'><mo>&#x03A3;</mo><mi>y</mi></mstyle><mo stretchy='false'>)</mo></mrow><mi>n</mi></mfrac></mrow></mstyle></mrow><mrow><msqrt><mrow><mstyle displaystyle='true'><mo>&#x03A3;</mo><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>-</mo><mfrac><mrow><msup><mrow><mo stretchy='false'>(</mo><mstyle displaystyle='true'><mo>&#x03A3;</mo><mi>x</mi></mstyle><mo stretchy='false'>)</mo></mrow><mn>2</mn></msup></mrow><mi>n</mi></mfrac></mrow></mstyle></mrow></msqrt></mrow></mfrac></mrow></math>
r=&x03A3;xy-(Σ;x)(Σ;y)nΣ;x2-(Σ;x)2n

为了正确处理名称空间,您需要在
标记中声明它们。例如:

<html xmlns:m="http://www.w3.org/1998/Math/MathML">

如果要同时处理m:和mml:,请将两者添加为NamSeparaces

<html xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:mml="http://www.w3.org/1998/Math/MathML">


这对于XHTML文档是必需的,但对于HTML5则不是。

我今天遇到了同样的问题。如前所述,在使用名称空间之前,必须先声明名称空间。向math标记添加名称空间在html中不起作用,只有在xhtml中才起作用-在html标记中声明名称空间。确保文件具有.xhtml扩展名

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:m="http://www.w3.org/1998/Math/MathML">
<head>
<script type="text/javascript" async="async"
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_CHTML">
</script>
</head>
<body>
<h3>Quadratic Equation</h3>
  <math>
  <m:mi>x</m:mi> <m:mo>=</m:mo>
  <m:mrow>
    <m:mfrac>
      <m:mrow>
        <m:mo>&#x2212;</m:mo>
        <m:mi>b</m:mi>
        <m:mo>&#x00B1;</m:mo>
        <m:msqrt>
          <m:msup><m:mi>b</m:mi><mn>2</mn></m:msup>
          <m:mo>&#x2212;</m:mo>
          <mn>4</mn><m:mi>a</m:mi><m:mi>c</m:mi>
        </m:msqrt>
      </m:mrow>
      <m:mrow> <mn>2</mn><m:mi>a</m:mi> </m:mrow>
    </m:mfrac>
  </m:mrow>
</math>
</body>
</html>

二次方程
x=
−;
B
±;
b2
−;
4ac
2a

亲爱的先生,虽然我已经添加了两个名称空间,但呈现输出与不带名称空间的不同。您能更具体地说明什么是不一样的吗。该页面适合我(一旦我删除额外的
并将

转换为

以使其成为有效的XHTML)。另外,看起来您是通过
文件://
URL使用此文件,但您没有说明是使用名称以
.xhtml
结尾的文件,还是仅使用
.html
。他们都像我期望的那样工作。如果您仍然有问题,您可能需要发布没有为您呈现的MathML以及上面的代码。我已经在上面的问题中添加了MathML代码。是的,它对我有效。如果它不适合你,你需要更清楚地解释什么不适合你。这应该包括您正在键入的MathML,以及您正在使用的浏览器和操作系统。当您说“呈现输出与没有名称空间的呈现输出不同”时,这是什么意思?输出有什么特别的问题吗?亲爱的先生,我使用的是firefox浏览器14.0.1。MathML的命名空间呈现在一行中,这是不正确的。不带命名空间的MathML呈现实际视图。