gpt4 book ai didi

javascript - 使用 AsciiMath 输入更新 MathJax

转载 作者:行者123 更新时间:2023-11-28 00:04:27 30 4
gpt4 key购买 nike

我有以下 div:

<div id="math-display">``</div>

页面加载时运行 MathJax.Hub.Queue(['Typeset', MathJax.Hub, 'math-display'])` 是 AsciiMath 输入的分隔符。

如果我使用 latex 输入方程,并且想要刷新数学显示,我可以运行以下代码:

MathJax.Hub.Queue(['Text', MathJax.Hub.getAllJax('math-display')[0], 'new latex here'])

但是,如果我使用 AsciiMath 输入而不是 Latex,结果仍然会使用 Latex 呈现(即使在 'new Latex here' 字符串中使用 AsciiMath 分隔符)。如何使用 AsciiMath 输入而不是 Latex 更新显示的 MathJax?

如果可能的话,我宁愿不调用 Typeset 进行更新。

最佳答案

Text() 方法仅更新对象实例的文本,并且该对象已经将输入类型作为属性。这种类型的输入是在创建对象时由分隔符定义的。

当您使用 text() 时,您会修改 delimiters 之间的字符串,因此您不需要 delimiters,但您可以无法更改输入类型。

但是您可以排版单个元素。它将使用分隔符定义的输入创建一个新对象。请参阅片段示例:

document.querySelector('#switch').onclick = function() {
//inputJax property defines type of input
alert('input type of math-display is: ' + MathJax.Hub.getAllJax('math-display')[0].inputJax);

//To change type of input, you can modifiy content of math-display, not of the math object that was generated
document.querySelector('#math-display').textContent = "$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$";

//You typeset only element that has id math-display.
MathJax.Hub.Queue(['Typeset', MathJax.Hub, 'math-display']);

}
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
<div id="math-display">`sum_(i=1)^n i^3=((n(n+1))/2)^2`</div>
<button id="switch">Change content</button>

关于javascript - 使用 AsciiMath 输入更新 MathJax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31490588/

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