Question

I have a Rails4 app which uses MathJax. I use MathJax CDN by placing the following line in the <head> section of my app/views/layouts/application.html.erb file:

<script type="text/javascript" src="path-to-mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

More information on: http://docs.mathjax.org/en/latest/start.html#mathjax-cdn

Because of Turbolinks, MathJax loads only on the homepage and won't load on other pages unless I refresh the page (which is not desirable). Instead I want MathJax to load only on /Math/New and Physics/Show pages. What should I do? (I don't want to deactivate turbolinks)

Thanks a lot for your help.

Was it helpful?

Solution 3

Three great solutions can be found here: http://reed.github.io/turbolinks-compatibility/mathjax.html

OTHER TIPS

I was also struggling with the same issue since last few days. Finally figured out the way to solve this. Here is the explaination for the same:

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.Hub.Typeset() method. This will cause the preprocessors (if any were loaded) to run over the page again, and then MathJax will look for unprocessed mathematics on the page and typeset it, leaving unchanged any math that has already been typeset.

So the simplest solution is to add the following in app/views/layouts/application.html.erb file:

<script>
      MathJax.Hub.Typeset();
</script>

Don't add this in head section. Add it after closing the body tag.

You can add data-no-turbolink only for that link to make it work as regular link, take a look at https://github.com/rails/turbolinks/#opting-out-of-turbolinks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top