【发布时间】:2015-08-28 19:34:43
【问题描述】:
我已经构建了一个表单来编写 LaTeX 表达式并使用 MathJax 呈现它们。为了加速 MathML 代码的复制,我编写了一个脚本,在另一个文本区域中显示 MathML 代码,就像你 can see here。
这是我的代码:
<!doctype html>
<html>
<head>
<title>LaTeX para Word</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
tex2jax: {
inlineMath: [
['$','$'],
[ '\\(', '\\)' ]
]
},
extensions: ['toMathML.js']
});
var math = null;
MathJax.Hub.queue.Push(function () {
math = MathJax.Hub.getAllJax('MathOutput') [0];
});
window.UpdateMath = function (TeX) {
MathJax.Hub.queue.Push(['Text', math, '\\displaystyle{' + TeX + '}']);
document.getElementById('output').value = '<?xml version="1.0"?>' + math.root.toMathML("");
};
function selectTextarea(element) {
var text = document.getElementById(element).select();
}
</script>
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&locale=pt-br"></script>
</head>
<body>
<textarea id="MathInput" cols="60" rows="10" onkeyup="UpdateMath(this.value)"></textarea>
<div id="MathOutput">
$${}$$
</div>
<hr>
<br>
<textarea id="output" cols="60" rows="10" readonly="readonly"></textarea>
<br>
<button onclick="selectTextarea('output')">Selecionar código</button>
<script src="main.js"></script>
</body>
</html>
问题是当我更快地键入公式时,MathML 代码上不显示最后一个字符。有时,我必须在公式末尾添加一个空格才能获得正确的 MathML 代码。谁能给我一些提示来解决这个问题?
【问题讨论】:
-
未来注意事项:cdn.mathjax.org 即将结束生命周期,请查看 mathjax.org/cdn-shutting-down 以了解迁移提示。
标签: javascript mathjax