gpt4 book ai didi

javascript - 实时显示 mathjax 输出

转载 作者:数据小太阳 更新时间:2023-10-29 04:16:16 25 4
gpt4 key购买 nike

如何在输入时修改此 mathjax 示例以进行实时预览?现在它只在我按下回车键后显示结果。我想对其进行调整,使其工作方式类似于 stackoverflow/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>

Type some TeX code:
<input id="MathInput" size="50" onchange="UpdateMath(this.value)" />
<p>

<div id="MathOutput">
You typed: ${}$
</div>

</body>
</html>

最佳答案

不要使用 onchange 尝试使用 onkeypressonkeyup

onchange 仅在您离开字段时触发,但其他事件(显然)在每次击键时发生。

关于javascript - 实时显示 mathjax 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7925622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com