javascript - How to trigger MathJax? -


i included mathjax script

<script type="text/javascript" async   src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/mathjax.js?config=tex-mml-am_chtml"> </script> 

this automatically replaces math codes formatted tags.

  1. how can trigger mathjax javascript click only, instead of upon load.
  2. how can tell mathjax put formatted element @ end of page instead of replacing original code?

1. how can trigger mathjax javascript click only, instead of upon load.

from docs: skipstartuptypeset: false

normally mathjax typeset mathematics on page page loaded. if want delay process, in case need call mathjax.hub.typeset() hand, set value true.


starting typeset

the mathjax.hub.typeset() command accepts parameter dom element content typeset. paragraph, or element, or mathjax math tag. dom id of such object, in case, mathjax dom element you. so

mathjax.hub.queue(["typeset",mathjax.hub,"mathexample"]); 

would typeset mathematics contained in element id mathexample. equivalent to

var math = document.getelementbyid("mathexample"); mathjax.hub.queue(["typeset",mathjax.hub,math]); 

if no element or element id provided, whole document typeset.

mathjax.hub.config({      skipstartuptypeset: true,      extensions: ["tex2jax.js", "tex/amsmath.js"],      jax: ["input/tex", "output/html-css"],      tex2jax: {          inlinemath: [["$", "$"]],          processescapes: true      }  });    function starttypesetting() {    var hub = mathjax.hub;    hub.queue(["typeset", hub, "render-me"]);  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/mathjax.js?config=tex-mml-am_chtml"></script>  <p id="render-me">$a+b=c$<p>    <button onclick="starttypesetting()">start typesetting</button>

2. how can tell mathjax put formatted element @ end of page instead of replacing original code?

it better know trying achieve, here 2 ways skip typesetting tags or classes, tex2jax preprocessors configs:

mathjax.hub.config({      tex2jax: {          skiptags: ["script","noscript","style","textarea","pre","code"],          ignoreclass: "tex2jax_ignore_1|tex2jax_ignore_2"     } } 

you can copy content of element want render element , start typesetting there:

mathjax.hub.config({      skipstartuptypeset: true,      extensions: ["tex2jax.js", "tex/amsmath.js"],      jax: ["input/tex", "output/html-css"],      tex2jax: {          inlinemath: [["$", "$"]],          processescapes: true      }  });    function starttypesetting() {    //copy content '#code-to-render' '#render-point'    var text = $('#code-to-render').val()    $('#render-point').text(text)        //start typesetting    var hub = mathjax.hub;    hub.queue(["typeset", hub, "render-point"]);  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/mathjax.js?config=tex-mml-am_chtml"></script>    <textarea id="code-to-render">$a+b=c$</textarea>  <p id="render-point"></p>    <button onclick="starttypesetting()">start typesetting</button>


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -