Search code examples
jquerydjangoajaxdjango-templatesmathjax

Is there any way to show dynamically rendered MathML text in django using Mathjax?


I am rendering some dynamic MathML text in django templates using jQuery and AJAX. Though non-dynamic contents are rendered properly using Mathjax library, but Mathjax is unable to convert dynamic contents. Does anyone knows anyone workaround to it.


Solution

  • You need to call the MathJax.typeset() function once the new MathJax is dynamically added to your page.

    From MathJax documentation:

    If you are writing a dynamic web page where content containing mathematics may appear after MathJax has already typeset the rest of the page, then you will need to tell MathJax to look for mathematics in the page again when that new content is produced. To do that, you need to use the MathJax.typeset() method. This will cause MathJax to look for unprocessed mathematics on the page and typeset it, leaving unchanged any math that has already been typeset.