Skip to content

'Can't make callback from given data' error if resetEquationNumbers is called when no math is typeset

Davide P. Cervone edited this page May 28, 2013 · 4 revisions

Hi,

I am resetting equation numbers and typesetting using the following code.

MathJax.Hub.Queue(
    ['resetEquationNumbers', MathJax.InputJax.TeX],
    ['Typeset', MathJax.Hub, previewArea]
);

When there is no math typeset in the page, it gives the following error (observed with Firebug console):

Can't make callback from given data
http://cdn.mathjax.org/mathjax/latest/MathJax.js Line 29
...n a.MathJax.elementJax}if(a&&a.isMathJax){while(a&&!a.jaxID){a=a.parentNode}if(a...

Here is a jsfiddle URL to demonstrate this: http://jsfiddle.net/sTAPt/

I fixed this using a firstUpdate flag which is initialized to false.

if (firstUpdate) {
    firstUpdate = false;
} else {
    MathJax.Hub.Queue(
        ['resetEquationNumbers', MathJax.InputJax.TeX]
    );
}
MathJax.Hub.Queue(['Typeset', MathJax.Hub, previewArea]);

This ensures that I am calling resetEquationNumbers only if there is some math typeset in the page. This solves the issue as can be seen here: http://jsfiddle.net/gPjwy/

I would like to know if there is a more straightforward way to solve this? For example, any variable or object in MathJax that I can test to know if there is some math typeset in the page?


The problem is that resetEquationsNumbers is defined in the AMSmath extension which isn't loaded until the main TeX input jax is loaded (which is when extensions are loaded). That doesn't happen until the first time that TeX code needs to be processed, which isn't until the first Typeset call (which is after the first resetEquationNumbers call, thus producing the error).

If you use

MathJax.Hub.Queue(
  function () {
    if (MathJax.InputJax.TeX.resetEquationNumbers) {
      MathJax.InputJax.TeX.resetEquationNumbers();
    }
  },
  ['Typeset', MathJax.Hub, previewArea]
);

instead, then that would do it.

Alternatively, you could load one of the predefined configurations that includes the extensions and jax code, since they preload the extensions. So

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  TeX: {equationNumbers: {autoNumber: "AMS"}},
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"></script>

would let the original MathJax.Hub.Queue() call work. I would recommend using a combined configuration file like this for your production system, since it will load faster than loading each file individually as is done with the in-line configuration as you currently have it.

Clone this wiki locally