Ввод Mathjax, применяемый из сценария javascript, не работает?

У меня есть один простой код Mathjax:

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript"
     src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  </script>
<script>
var ok = function ()
{
   document.getElementById('demo').innerHTML="$$10\\x^2$$"
}
</script>

</head>
<body>
<button onclick="ok()">Click</button>
<p id="demo1">Within html $$10\\x^2$$</p>
  <p id="demo"></p>
</body>
</html>
I was applied from direct html the Tex was converting.But applied from javascript its not rendering.What should i do.I was search with google but not getting answer. I need to apply the latex code from javascript It will be rendered with Tex format.Anyone help me to solve my problem.Please give a code its more help full for me.

Спасибо.


person Community    schedule 03.10.2016    source источник


Ответы (1)


<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript"
     src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  </script>
<script>
var ok = function ()
{
   document.getElementById('demo').innerHTML="$$10\\x^2$$"
    MathJax.Hub.Queue(["Typeset",MathJax.Hub]);

}
</script>

</head>
<body>
<button onclick="ok()">Click</button>
<p id="demo1">Within html $$10\\x^2$$</p>
  <p id="demo"></p>
</body>
</html>

Результат не совсем тот же: / Но ваша проблема в том, что MathJax не обновляется при динамическом изменении данных.

Возможно, посмотрите здесь: https://github.com/mathjax/MathJax/blob/master/test/sample-dynamic.html

Я не знаю эту библиотеку, больше ничем не могу.

person Steeve Pitis    schedule 03.10.2016
comment
Обратную косую черту необходимо удвоить в текстовых строковых литералах javascript (поскольку обратная косая черта является специальным символом в строках). Итак, вам нужно innerHTML="$$10\\\\x^2$$", чтобы получить тот же результат, что и исходный HTML. - person Davide Cervone; 04.10.2016
comment
Примечание из будущего: срок службы cdn.mathjax.org приближается к концу, проверьте mathjax .org / cdn-shutting-down для получения советов по миграции. - person Peter Krautzberger; 11.04.2017