Mathjax not rendering when partial is reloaded in chrome

383 views
Skip to first unread message

reac...@gmail.com

unread,
Oct 4, 2015, 7:55:28 PM10/4/15
to MathJax Users
I've added mathjax to a partial in my rails application. The issue is when a user clicks part 1 button they see the equation edited properly. If they click part 2 or three and then click part 1 again the equations don't render properly. You'll have to visit the application links below to see what I am talking about. I've only noticed the issue in chrome on mac desktop and laptop Yosemite 10.10

So what I did was add the following code I found online

<script type="text/javascript">
  MathJax.Hub.Queue(
  ["resetEquationNumbers",MathJax.InputJax.TeX],
  ["Typeset",MathJax.Hub]
);
</script>

That script removed the problem, but now I have a js error in my DOM inspector and it looks like my equations are rendering late. Does anybody know how to get past this error without hosting mathjax on my local server?

The project is on github here

And the code is live here (click buttons for part 1 2 or 3)

The related question is on stackoverflow here:
Thanks for any help.

Murray

unread,
Oct 5, 2015, 3:32:59 AM10/5/15
to MathJax Users
Hello

(1) The js error is on this bit:

<script type="text/javascript">
  MathJax.Hub.Queue(
  ["resetEquationNumbers",MathJax.InputJax.TeX],
  ["Typeset",MathJax.Hub]
);
</script>

I suspect it's because it is getting to this bit before MathJax is loaded.

MathJax does load afterwards and renders your math OK (and doesn't need the above), without further error.

I would suggest trying either:

(1) Removing the "resetEquationNumbers, Typeset" bit, since it's not necessary and causing your error; or (and I think the following is better):

(2) Not loading your MathJax from within your jQuery. Just load it at the bottom of the page, so it's ready to perform its magic. (It has nothing to do but load at this point.)

Then in your jQuery, you can do the following so MathJax will process the math after all your MathML has loaded:

<script type="text/javascript">
  MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
</script>

It will be happy to run because MathJax is already defined and has been patiently waiting for something to do.

Hope it helps.

Regards
Murray

Davide P. Cervone

unread,
Oct 5, 2015, 5:25:53 AM10/5/15
to mathja...@googlegroups.com
You could do 

<script type="text/javascript">
if (window.MathJax) {

  MathJax.Hub.Queue(
    ["resetEquationNumbers",MathJax.InputJax.TeX],
    ["Typeset",MathJax.Hub]
  );
}
</script>

so that the first time through (when MathJax hasn't been loaded), the calls aren't made (and they aren't needed on the first pass, as Murray points out), but the calls WILL be made on the second and subsequent times you press the "Part 1" button, where they are needed.  Note that the resetEquationNumbers call is only needed if you are using automatic equation numbers or use the \label macro.  But it doesn't hurt anything if you use it.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

reac...@gmail.com

unread,
Oct 5, 2015, 12:55:51 PM10/5/15
to MathJax Users
Thanks Murray and Davide for your help! 

I ended up using the script Davide provided. 

<script type="text/javascript">
if (window.MathJax) {

  MathJax.Hub.Queue(
    ["resetEquationNumbers",MathJax.InputJax.TeX],
    ["Typeset",MathJax.Hub]
  );
}
</script>

Everything's working correctly now as tested on my laptop. I will push changes to the app live this afternoon when I get home from my other machine. Thanks again guys.
Reply all
Reply to author
Forward
0 new messages