如何从Mathquill Matheditor输出LaTeX?

时间:2018-02-05 04:04:30

标签: javascript mathquill

当我尝试将Mathquill方程转换为LaTeX语言时,使用Mathquill Matheditor冻结我的数学字段(无法在其中键入)。

$("#button1").on("click", function() {

  var radio1 = $("input[name='option1']:checked").val();
  var radio2 = $("input[name='option2']:checked").val();
  var radio3 = $("input[name='option3']:checked").val();
  var radio4 = $("input[name='option4']:checked").val();
  var qstring = "1. " + radio1 + "<br /> " + "2. " + radio2 + "<br />" + "3. " + radio3 + "<br />" + "4. " + radio4;
  var result2 = qstring.fontsize(3);
  document.getElementById("Center").innerHTML = result2;
  result2.select();
  document.execCommand("Copy");
});

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

这是Mathquill.com首页的原始脚本,它什么都不做:

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

1 个答案:

答案 0 :(得分:1)

我在下面提供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);