【问题标题】:MathML is not rendered and displayed below the textareaMathML 未呈现并显示在文本区域下方
【发布时间】:2014-11-23 01:00:10
【问题描述】:

我有一个包含文本区域的页面。用户将在其中输入 mathML,当用户单击输出按钮时,MathML 应该被渲染并显示在文本区域下方。但是渲染没有发生。 Textarea 可能包含多个用于渲染的 mathml 代码。

下面是我使用的代码。

<html xmlns="http://www.w3.org/1999/xhtml">
<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>

            </div>
            <script>
                function myFunction() {

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

                }
            </script>

    </body>
</html>

【问题讨论】:

  • 您是否使用file 方案运行该页面?
  • 是的,我已经运行但渲染没有发生,正如我提到的那样。
  • 您在寻找什么输出?当我测试您的代码时,它似乎工作正常。不过,通过搜索,只有 Firefox 和 Safari 支持正确渲染 MathML,这就是我在计算机上看到的在 IE、Firefox 和 Chrome 上测试您的代码,只有 Firefox 正确渲染了它。

标签: javascript html mathjax mathml


【解决方案1】:

当页面被客户端脚本更改时,不应期望 MathJax 处理该页面。要请求此类处理,请在执行更改的代码后添加以下内容,在函数 myFunction 的末尾:

MathJax.Hub.Typeset();

更经济的是,使用只处理单个元素的代码:

MathJax.Hub.Typeset("demo");

请参阅 MathJax 文档,第 Modifying Math on the Page 页。

【讨论】:

  • 对于没有命名空间的情况下它工作正常,但如果我包含像 m: 和/或 mml: 这样的命名空间,那么渲染不会发生。
  • 为了正确处理命名空间,您需要在&lt;html&gt; 标记中声明它们。例如,&lt;html xmlns:m="http://www.w3.org/1998/Math/MathML"&gt;。如果您想同时处理 m:mml:,请将两者都添加为命名空间。
  • 虽然我已经在 标签中添加了命名空间声明,但仍然没有出现。
猜你喜欢
  • 2012-09-17
  • 2020-04-29
  • 2011-04-18
  • 2021-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
相关资源
最近更新 更多