Dragon Arrow written by Tatsuya Nakaji, all rights reserved animated-dragon-image-0164

Rails: Mathjax is not reflected after page transition

イメージ
Aug 05, 2019

Mathjax  is not reflected after page transition


ENVIRONMENT


Rails 5.2

Ruby 2.4.2


Cause


turbolinks stops loading data when page transition.


Solution


select favorite solution in two.


solution1. add Typeset script in view file

every time to added view, MathJax will set again.

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

There is no need to limit view.

application.js or post.coffee, application.html.erb is OK!


I found this thanks to below nice resource!

https://stackoverflow.com/questions/19767982/rails-4-turbolinks-not-loading-mathjax/20783780#20783780


if you do like below, MathJax is set every view.

(application.html.erb)

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


solution2. add Queue script in coffee file

$(document).on 'turbolinks:load', -> MathJax.Hub.Queue(["Typeset", MathJax.Hub])


Summary


Select efficiently solution for you.

if you activate only one file, you don't need activate MathJax in every page.

That's all for now!!