Javascript Mathjax

こ雲淡風輕ζ 提交于 2019-12-11 07:58:48

问题


I use mathjax on a website, and I'm building a little javascript web app. Mathjax is configured so that when text is surrounded with dollar signs, like $10^2$, it is converted to a math format. This works if I insert the text in html. ie:

<div id=mathDiv">$10^2$</div>

displays 10 with a superscript 2. However, if I insert this text via javascript, I don't get a 10 with a superscript 2:

document.getElementById(mathDiv).innerHTML = "$10^2$";

returns the text $10^2$

I know this is a simple javascript-string misunderstanding on my part, but I can't figure out how to get the $10^2$ inserted via javascript to be parsed by mathjax rather than just interpreted as a string. I am not using the jQuery framework at the moment.


回答1:


As per sdespont: Mathjax typesets the page once upon loading. If you need to update the math after the page has finished loading (i.e. with javascript/ajax) then call

MathJax.Hub.Typeset();


来源:https://stackoverflow.com/questions/20652568/javascript-mathjax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!