0

I'm having some issues with the using of MathJax updating after the page refresh.

In particoular, I've created a HTML doc with a LaTex formula "$$ \int \sin (x) = $$" and a button. The button add a new LaTex formula ("$$\int \cos(x) $$") at the bottom of the page. When I run the page the first formula is correctly shown in LaTex format. But when I click the button, the first one is still correctly shown while the new one is not, even though I insert the call of MathJax.Hub.Queue(["Typeset",MathJax.Hub]) method.

I attach HTML, button javascript code and output. HTML:

function btt(){ 
    $("#div2").append("$$\int \cos(x) $$");
        MathJax.Hub.Queue(["Typeset",MathJax.Hub]) 
    };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript"
    src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
   

    <div id="div1"> $$ \int \sin (x) = $$
    <button id= "btt" onclick= "btt()" name="a";> click! </button>
    </div>

    <div id="div2" class="container">  </div>
enter image description here

How can I show the second formula with a LaTex format? Thanks a lot.

prasanth
  • 22,145
  • 4
  • 29
  • 53
nhilo
  • 1
  • 1
  • 1
    Possible duplicate of [How to recall or restart MathJax?](http://stackoverflow.com/questions/5200545/how-to-recall-or-restart-mathjax) – Peter Krautzberger Oct 24 '16 at 11:53
  • In the replay you linked me, it was said to add MathJax.Hub.Queue(["Typeset",MathJax.Hub]) command, as I do in my js code. But my formula has only a cursive format and not a LaTex format. And I'm not understanding why. – nhilo Oct 24 '16 at 14:25
  • You need to escape backslashes in JavaScript strings, i.e., `$("#div2").append("$$\\int \\cos(x) $$");` – Peter Krautzberger Oct 24 '16 at 14:34
  • It works now, I really thank you – nhilo Oct 24 '16 at 19:03

0 Answers0