pmq20 / mathjax-rails

Simple gem to integrate MathJax with Rails and maintains MathJax at a system-wide directory.
MIT License
66 stars 30 forks source link

Turbolinks Compatability #13

Open samozeleznik opened 9 years ago

samozeleznik commented 9 years ago

This gem does not work with turbolinks by default. Is there a solution for that?

zerocool4u2 commented 8 years ago

now with turbolinks 5 works perfect, the only detail is if you wanna use a config file(not an embed script on the view) you will need to load it after the mathjax_tag method or, a more simple way, do something like this:

$(document).on 'turbolinks:load', ->
    MathJax.Hub.Queue(["Typeset", MathJax.Hub])
    MathJax.Hub.Config
        showMathMenu: false
        tex2jax:
            inlineMath: [[ '$', '$']]
mag2007 commented 5 years ago

I am facing same problem, but it is more complicated. I have a dynamical content on site, which is loaded after mathjax does his job. And i am running turbolinks 5.2.0. Before updating my turbolinks gem i was using two script files

mathjax config

window.MathJax = {
  extensions: ["Safe.js"],
  tex2jax: {
    inlineMath: [ ['$$','$$'], ['$','$'], ['\\(','\\)'] ],
    processEscapes: true
  }

mathjax load config needed for dynamic content (called at the end of page)

if (window.MathJax) {
  MathJax.Hub.Queue(
    ["Typeset",MathJax.Hub]
  );
}

Now when i switch between pages using "back and forward" my mathjax is rendered twice or even more, depending on how ofter i go back and forward. I am sure it is because turbolinks calls mathjax multiple times, but i cant figure out why.