Question

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.

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top