gpt4 book ai didi

javascript - 如何从 Mathquill Matheditor 输出为 LaTeX?

转载 作者:行者123 更新时间:2023-11-29 23:27:24 29 4
gpt4 key购买 nike

当我尝试将 Mathquill 方程翻译成 LaTeX 语言时,我的数学字段卡住(无法在其中输入)。

<span id="math-field" class="mathquill-textbox" />
<textarea id="latex" name="content" />

这是我当前使用的 mathquill 脚本:https://github.com/jipsen/matheditor/blob/master/mathquill.js

这是 Mathquill.com 主页上什么都不做的原始脚本:

<p>Type math here: <span id="math-field"></span></p>
<p>LaTeX of what you typed: <span id="latex"></span></p>

<script>
var mathFieldSpan = document.getElementById('math-field');
var latexSpan = document.getElementById('latex');

var MQ = MathQuill.getInterface(2); // for backcompat
var mathField = MQ.MathField(mathFieldSpan, {
spaceBehavesLikeTab: true, // configurable
handlers: {
edit: function() { // useful event handlers
latexSpan.textContent = mathField.latex(); // simple API
}
}
});
</script>

最佳答案

我在下面提供 HTML 和脚本。

HTML:

<p>Type math here:
<span id="math-field" maxlength="20"></span>
</p>
<p>LaTeX of what you typed:
<span id="latex"></span>
</p>

JavaScript:

var mathField;
let mathFieldSpan = document.getElementById('math-field');
let latexSpan = document.getElementById('latex');
let MQ = MathQuill.getInterface(2);

let config = {
spaceBehavesLikeTab: true,
restrictMismatchedBrackets: true,
supSubsRequireOperand: true,
handlers: {
edit: function () { // useful event handlers
var enteredMath = mathField.latex(); // Get entered math in LaTeX format
latexSpan.textContent = enteredMath; // simple API
}
}
};
mathField = MQ.MathField(mathFieldSpan, config);

关于javascript - 如何从 Mathquill Matheditor 输出为 LaTeX?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48615734/

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