MathJax
MathJax copied to clipboard
How to reset MathJax instance welly both V2 and V3
Issue Summary
I need to reset MathJax instance in order to re-render the page with same instance, however I tried lot ways, it always ends up some issues.
For version 2, I use this workaround to do the reset job:
<script src="//cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_CHTML"></script>
MathJax.Hub.Queue(
['PreProcess', MathJax.Hub],
['resetEquationNumbers', MathJax.InputJax.TeX],
['PreProcess', MathJax.Hub],
['Reprocess', MathJax.Hub]
);
It works fine for re-rendering page, but sometimes I will get:
Uncaught Error: Can't make callback from given data
USING http://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_CHTML:19
Push http://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_CHTML:19
Queue http://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_CHTML:19
Related to issue#2935
For version 3, already tried following reset functions:
MathJax.startup.document.state();
MathJax.texReset();
MathJax.typesetClear()
But it will end up to:
Label 'eq:m1' multiply defined
For the temporary workaround, I can re-render labels without getting any error by:
<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
MathJax.startup.output.clearCache();
MathJax.startup.getComponents();
If this will be ok?
But if I change to use svg on Chrome 105(without change anything else):
<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-svg.js"></script>
Will always get:
tex-mml-svg.js:formatted:39500 Error: MathJax retry
at e.retryAfter (tex-mml-svg.js:formatted:41256:25)
at L (tex-mml-svg.js:formatted:20310:110)
at c (tex-mml-svg.js:formatted:16727:31)
at e.parse (tex-mml-svg.js:formatted:14673:31)
at t.parse (tex-mml-svg.js:formatted:12635:50)
at t.parse (tex-mml-svg.js:formatted:15329:63)
at t.controlSequence (tex-mml-svg.js:formatted:13186:23)
at t.parse (tex-mml-svg.js:formatted:14507:39)
at t.parse (tex-mml-svg.js:formatted:12635:50)
at t.parse (tex-mml-svg.js:formatted:15329:63)
Steps to Reproduce:
- Clone docsify-latex, enter into repo folder
- Modify
docs/index.md
with following text:
When $a \ne 0$, there are two solutions to $ax^2 + bx + c = 0$ and they are $\ref{eq:m1}$
$$
x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\tag{M1}\label{eq:m1}
$$
This equation $\eqref{eq:m1}$ is very important.
- Click to switch to
/#/example
page, then switch back to/#/
- Start the server to review via:
cd docs && python -m SimpleHTTPServer 3000
or
npm i docsify-cli -g
docsify serve docs
- You can see the result
For version 2:
- Replace MathJax v3 script to v2, do same steps as v3.
Technical details:
- MathJax Version: 2,7.9, 3.2.2
- Client OS: Windows 10
- Browser: Firefox
Supporting information:
Check this commit: https://github.com/scruel/docsify-latex/commit/136fe8c5950543107644281fdc4577c47aa7cd96#diff-ee52eacc98a34424ac3b8149882469d47619cc1e6c05e00d86bbba97c11d714d
I am not able to reproduce the errors you are seeing in either version 2 or version 3. The page renders fine after switching to the example and back.
The MathJax.texReset()
command should reset the labels, but perhaps there is a timing issue with when you are calling this, or that your typesetting code is being called more than once. I don't know how docsify works, and don' have the time to work that out myself.
The issue you are having with the callbacks in v2 is probably the one I mentioned in one of your other issues where the v2 configuration hasn't been loaded when your code tries to use MathJax.InputJax.TeX
.
I'm not sure why you are doing the preprocessing twice. In fact, I'm not sure why you don't just to a single
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
call.
So I'm not sure what to tell you, here, as I can't reproduce the issue you seem to be having.
I am not able to reproduce the errors
Might I already fixed some issues after I published this issue, I will leave more comments about how to reproduce remain issues to save ours time.
I'm not sure why you are doing the preprocessing twice
I don't know either why I did that x), and the following code works fine:
MathJax.Hub.Queue(
['resetEquationNumbers', MathJax.InputJax.TeX],
['PreProcess', MathJax.Hub],
['Reprocess', MathJax.Hub]
);
I'm not sure why you don't just to a single call.
Because docsify limited plugins' behavior, see https://github.com/mathjax/MathJax/issues/2926, I have to queue and escape the content to prevent the escaping by docsify, which will cause \$ $x$
to $ $x$
, which will produce the wrong result.
Hi all, just curious, do we have any updates on this issue? I'm also getting the
tex-chtml.js:1 Uncaught Error: MathJax retry
issue.