Mar*_*ark 9 javascript mathjax
我一直在调整以下示例代码.MathJax的文档不是很完整.有人可以更多经验告诉我应该如何修改下面的代码,这样当我指定了像$\alpha $这样的分隔符时,Tex才会解析.我想让它像math.stackexchange一样工作.
<html>
<head>
<title>MathJax Dynamic Math Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [["$","$"],["\\(","\\)"]]
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full">
</script>
</head>
<body>
<script>
//
// Use a closure to hide the local variables from the
// global namespace
//
(function () {
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
var math = null; // the element jax for the math output.
//
// Get the element jax when MathJax has produced it.
//
QUEUE.Push(function () {
math = MathJax.Hub.getAllJax("MathOutput")[0];
});
//
// The onchange event handler that typesets the
// math entered by the user
//
window.UpdateMath = function (TeX) {
QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]);
}
})();
</script>
<textarea id="MathInput" size="50" onkeyup="UpdateMath(this.value)"></textarea>
<div id="MathOutput">
You typed: ${}$
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Phi*_*ick 20
您发布的示例代码获取MathInput的内容,并使用MathInput中的新"math"替换第一个MathJax元素.你想要的是排版MathInput并为分隔文本创建新的MathJax元素.我在这里设置了一个jsFiddle示例:http: //jsfiddle.net/Zky72/2/
主要的变化是在UpdateMath函数中:
window.UpdateMath = function (TeX) {
//set the MathOutput HTML
document.getElementById("MathOutput").innerHTML = TeX;
//reprocess the MathOutput Element
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"MathOutput"]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5691 次 |
| 最近记录: |