mathjax не может получить объект перед набираемым div - PullRequest
0 голосов
/ 11 октября 2018

Я пишу формальный HTML с mathjax, теперь у меня есть вопрос, вот мои фрагменты кода:

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+"}"]);
}

когда я вызываю метод UpdateMath после загрузки страницы, объект "математика""равно нулю, js выдает ошибку: невозможно выполнить обратный вызов из заданных данных.так что есть предложения? спасибо.

вот официальная демонстрация mathjax, после изменения кодов для вызова UpdateMath после одновременного запуска страницы возникает ошибка

    <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="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_CHTML-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>
...