MathQuill: How to capture pasted latex if the latex is wrong?

267 views Asked by At

I am using mathquill library to convert the latex to equation. If the latex is valid it will call the edit handler. But if the pasted latex is invalid, then show the alert message. How to capture the pasted latex if it is wrong.

mathtext.js

var valid = false;
var mathFieldSpan = document.getElementById('math-field');
latexSpan = document.getElementById('latex');
hiddenSpanArea = document.getElementById('hiddenSpan');
mathField = MQ.MathField(mathFieldSpan, {
  spaceBehavesLikeTab: true,
  handlers: {
    edit: function () {
      latexSpan.textContent = mathField.latex();
      valid = true;
    }
  }
});
window.mathField = mathField;

$(mathFieldSpan).keydown(function (e) {
  if (e.keyCode == 86) { //keycode value for "v"
      if (!valid) { // checks if the pasted value is not valid
        alert("error")
      }
      valid = false;
  }
});

mathtext.html

<span id="math-field"></span>
<span id="latex"></span>
0

There are 0 answers