Search code examples
javascriptprintingcallbackmathjax

How to trigger a javascript function when "Processing Math" in MathJax reaches 100%


I would like to call a javascript Print() function when the js library MathJax finishes to process the visited web page.

At the moment the Print() function is triggered using onload but it seems to stop the Processing Math task of MathJax (demo here); users need to dismiss the browser's Print pop-up to lets MathJax finishes its processing.

I would like to be able to call Print() just when Processing Math in MathJax reaches 100%.
Any ideas?


Solution

  • Push the Print command onto the MathJax processing queue so that it will be called after MathJax finishes typesetting the page. E.g.,

    MathJax.Hub.Queue(Print);
    

    or

    MathJax.Hub.Queue(function () {
      // do stuff here
      Print();
    });
    

    See the documentation at

    http://www.mathjax.org/resources/docs/?queues.html#the-mathjax-processing-queue

    for more details.