MathJax.HTML.Element()不起作用

时间:2014-04-02 21:14:43

标签: mathjax

MathJax.HTML.Element()不会转换提供的代码。执行

后只附加源
 .appendChild(MathJax.HTML.Element("div",{id: "MathDiv",
style:{border:"1px solid", padding:"5px"}},
["Here is math: \\(x+1\\)",["br"],"and a display $$x+1\\over x-1$$"] ));

也没有

MathJax.HTML.addElement((document.getElementsByClassName("equations")[0]),"div",
{id: "MathDiv", 
style:{border:"1px solid", padding:"5px"}},
["Here is math: \\(x+1\\)",["br"],"and a display $$x+1\\over x-1$$"])

的工作。使用了不同的浏览器。

1 个答案:

答案 0 :(得分:3)

您是否正在使用MathJax。您是否在$$标签之间的页面文本中有一个正常的等式来工作? MathJax通常在页面加载后处理方程式。通过动态添加元素,您可能需要在添加后调用MathJax.Hub.Queue(["Typeset",MathJax.Hub,'outputDiv']);以强制渲染数学。

<html>
<head>
<title>Jep: Creating mathml from expressions</title>
<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/javascript">
    MathJax.Hub.Config({
        jax : [ "input/TeX", "output/HTML-CSS" ],
        extensions : [ "tex2jax.js" ],
        "HTML-CSS" : {
            scale : 150
        },
        styles : {
            ".MathJax_Display" : {
                "text-align" : "left !important",
                margin : "1em 0em"
            }
        },
        tex2jax : {
            inlineMath : [ [ '$', '$' ], [ '\\(', '\\)' ] ]
        }
    });

    function render()
    {
      var res = "$e^{i\\pi}=-1$";
      var target = document.getElementById('outputDiv');
      target.innerHTML=res;
      MathJax.Hub.Queue(["Typeset",MathJax.Hub,'outputDiv']);
    }
</script>
</head>
<body>

<form>
<input type="button" value="Render" onClick="render();"/>
</form>

<div id="outputDiv" style="border:1px; font-size:x-large;">

</body>
</html>
相关问题