-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught [TypeError: Cannot read property 'setAttribute' of undefined] #441
Comments
The main issue is that you have specified that your expression is an AsciiMath one, but really it is a TeX one. It appears that AsciiMath produces bad MathML when given this TeX expression. If you change
to
it should work for you. An additional issue is that you have included
But setting the wrong format is the one that is causing you the errors above. |
Thank you for your reply, but:
My main concern is that I need to be able to recover from this error. Similar errors (bad MathML, bad TeX) throw errors I can catch. This one puts me in a weird limbo state. My app crashes and I can't do anything. Express.js simply hangs forever. I cannot do Here's the app in question: https://github.com/pressbooks/pb-mathjax Here's a URL that crashes it:
If I pass the same "junk" to MathML:
It complains just as much, but I can catch the error and do something about it. Ideas? |
This is, ultimately, an upstream issue in MathJax and asciimath. There should be a better error handling on MathJax's end and, ultimately, asciimath should produce some reasonable output for this (bad) input. However, since your project is in its early stages (great to see PB making this btw!), you might consider jumping ahead to MathJax v3. |
I've filed asciimath/asciimathml#106 and mathjax/MathJax#2153 -- reduced test case: |
Thanks for the reply and upstream reports! I looked at mj3-demos-node and see: For now, for this particular issue, I've set a timer that exits the script if (I think that) something crashed. Works like: // Consider an init longer than 5 seconds a crash and exit
const tooLong = setTimeout(() => {
// @see https://github.com/mathjax/MathJax-node/issues/441
console.error('Too long, Something crashed? Please restart the server.');
process.exit(1);
}, 5000);
mjAPI.config(configs.mathjax);
mjAPI.typeset(configs.typeset).then((data) => {
clearTimeout(tooLong);
// ... snip ...
}).catch((err) => {
clearTimeout(tooLong);
// ... snip ...
}); Node severs like |
Sorry, I thought you meant the resulting output was bad, not the input provided to MathJax. I understand what you re saying now.
It turns out that mathjax-node doesn't handle the case where the SVG wasn't created (in this case, due to AsciiMath crashing on the bad input). Because MathJax is running inside a jsdom virtual DOM inside mathjax-node, your If you add
in between lines 697 and 698 Lines 697 to 698 in c7e5bf3
in
The AsciiMath input jax has not yet been ported to v3, but there is a legacy v2 AsciiMath input jax that is patched in for testing purposes. To use it, you would need to use the "direct" method of loading MathJax, rather than the components (since no AsciiMath components are included), or you could build your own component for AsciiMath (starting with the MathML input component as a template, it should not be too hard). The legacy AsciiMath input jax is asynchronous, so you would have to use the promise-based conversion features; but you are already working with promises, so that should not be a problem. It would take a little more work to get AsciiMath working in v3 than to make the one-line fix to mathjax-node that I give above, but I suspect it will be worth it, as it will be both faster, more stable, and more maintainable in the long run. |
…case the input jax fails). See issue #441.
I was just trying out an AsciiMath component for MathJax v3, and realized that because of the legacy v2 code, you can't webpack it. If your app requires the code to be webpacked, then you won't be able to use AsciiMath until it is properly ported to v3. |
OK, it is possible to make a webpackable asciimath component by changing to
and to
Then the component can be modeled on |
I've made a asciimath-component branch of the v3 code that includes the webpackable AsciiMath component. |
Update: I'm going to hold off on MathJax3. The syntax & convention changes from this project to that one aren't trivial for me. I spent an hour trying to wedge it into pb-mathjax and failed. Would love #442 integrated though. Regards, |
I'm working on an express.js app that wraps this library and returns a PNG image. Sometimes the equations will be less than stellar, possibly garbage. This example crashes my node app, leaves it in an usable state, I have to restart the server:
Equation:
\begin{equation*} A = \left[ \begin{array}{cccc} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \end{array} \right] \end{equation*}
Error:
Configs:
I've tried putting the code in a
try/catch
block but it doesn't do anything.Help?
The text was updated successfully, but these errors were encountered: