MathJax
MathJax copied to clipboard
[v4 beta 6] overline + prime causing unexpected "double exponent" error
Our testing ran into a lot of unexpected Prime causes double exponent: use braces to clarify processing errors after upgrading.
It seems to always come down to overline and primes, e.g.,
-
\overline{\mathfrak{D}}'_j -
\overline{c}''=\overline{n} -
\begin{equation*} \|\overline{c}'\|_{\infty }\leqslant \|\overline{n}\|_{1}= \|n\|_{1}. \end{equation*}
This is due to the changes from mathjax/MathJax-src/pull/1069, which left out a check after
https://github.com/mathjax/MathJax-src/blob/70ea011e8f84eeefb352e5167e843a6033c42d3a/ts/input/tex/base/BaseMethods.ts#L260
like
https://github.com/mathjax/MathJax-src/blob/70ea011e8f84eeefb352e5167e843a6033c42d3a/ts/input/tex/base/BaseMethods.ts#L161
Here is a configuration that can be used to add that in:
MathJax = {
tex: {packages: {'[+]': ['fix-primes']}},
startup: {
ready() {
const {MacroMap} = MathJax._.input.tex.TokenMap;
const {Configuration} = MathJax._.input.tex.Configuration;
const NodeUtil = MathJax._.input.tex.NodeUtil.default;
const {entities} = MathJax._.util.Entities;
new MacroMap('fix-primes', {
'\'': 'Prime',
'\u2019': 'Prime',
'\u2032': 'Prime'
}, {
Prime(parser, c) {
let base = parser.stack.Prev();
if (!base) {
base = parser.create('token', 'mi');
}
if ((NodeUtil.isType(base, 'msubsup') && !NodeUtil.isType(base, 'msup') &&
NodeUtil.getChildAt(base, base.sup)) ||
(NodeUtil.isType(base, 'munderover') && !NodeUtil.isType(base, 'mover') &&
NodeUtil.getChildAt(base, base.over) &&
!NodeUtil.getProperty(base, 'subsupOK'))) {
throw new TexError('DoubleExponentPrime', 'Prime causes double exponent: use braces to clarify');
}
let sup = '';
parser.i--;
do {
sup += entities.prime; parser.i++, c = parser.GetNext();
} while (c === '\'' || c === entities.rsquo || c === entities.prime);
sup = ['', '\u2032', '\u2033', '\u2034', '\u2057'][sup.length] || sup;
const node = parser.create('token', 'mo', {variantForm: true}, sup);
parser.Push(parser.itemFactory.create('prime', base, node));
}
});
Configuration.create('fix-primes', {
handler: {character: ['fix-primes']}
});
MathJax.startup.defaultReady();
}
}
};
I will make a PR to add the missing check.