v4 beta mathtools prescript error
pkra opened this issue · 2 comments
Not sure if it's related to #3078.
While investigating another issue, I ran into a crash from mathtools when using v4 client-side.
Minimal example:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>mj test</title>
</head>
<body>
<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/tex-mml-chtml.js">
</script>
\(\require{mathtools} \prescript {h_{l-1}}{}{P}\)
</body>
</html>
The console logs out:
Uncaught ReferenceError: can't access lexical declaration 'F' before initialization
r https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/input/tex/extensions/mathtools.js:1
<anonymous> https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/input/tex/extensions/mathtools.js:1
<anonymous> https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/input/tex/extensions/mathtools.js:1
mathtools.js:1:183
It's actually #3072, not 3078. I know what the problem is, but unfortunately I can't give you a patch as the file needs too be rebuilt.
It has to do with how webpack handled the Symbol
class in input/tex/Symbol.js
, and requires that we change the name of that class to something else so that it doesn't clash with the default Symbol
class in javascript. Webpack makes the imported Symbol
a global variable, overriding the default one, but it also references Symbol
in its startup code, leading to the error you are seeing (when it is minified). This only affects the packing of ESM modules because the imports are handled differently there. I thought I had worked around it, but it only worked when input/tex/Symbol.js
was imported directly, not when it is a shared library, as it is in TeX packages like mathtools
. This also affects several other packages as well.
The fix requires a new release, but I can't do that until we are a little father with the code cleanup PRs.
Thanks, Davide.