Open AlexEdgcomb opened 9 months ago
I wasn't able to reproduce in Firefox, but did see it in Chrome and Safari.
It took a bit of digging, but it turns out that the typeset: false
was also a significant part of the problem. It turns out that when the startup typeset is shipped, the metrics need for the typesetting (e.g., the ex and em sizes) aren't computed, and when the math is then processed by the lazy loader, the values for ex and em are not defined, and the results produce the NaN
values you re seeing. That means the final SVG is not properly scaled. The AssistiveMml extension plays a role because it requires the speech-rule engine to be set up, and that is done in a promise, so some code runs before that is processed, and MathJax thinks the metrics have been obtained when they haven't.
This code will work around the problem for now:
MathJax = {
loader: { load: [ 'ui/lazy' ] },
options: {
lazyAlwaysTypeset: '.disable-lazy-typesetting',
menuOptions: { settings: { assistiveMml: true } },
},
output: { font: 'https://cdn.jsdelivr.net/npm/mathjax-tex-font@1.0.0-alpha.1/es5/output/fonts/mathjax-tex' },
startup: {
typeset: false,
ready() {
const {AbstractMathItem, STATE} = MathJax._.core.MathItem;
Object.assign(AbstractMathItem.prototype, {
__state: AbstractMathItem.prototype.state,
state(state, restore) {
if (state === STATE.TYPESET - 1 && !this.metrics.hasOwnProperty('em')) {
state = STATE.METRICS - 1;
}
return this.__state(state, restore);
}
});
MathJax.startup.defaultReady();
}
},
};
but I will make a PR to fix the issue in the next release.
For me, Firefox doesn't process the math when typeset: false
is in play, but Chrome and Safari do. I'm trying to decide what the proper behavior should be for the lazy loader, but all three browser should really do the same thing, I would think. The typeset: false
really should prevent any typesetting until the first time MathJax.typeset
or MathJax.typesetPromise()
is called. I'm not sure why Safari and Chrome are doing the typesetting, and will have to look into that. It is probably the the IntersectionObserver fires in one case and not the other.
@dpvc , thank you for the explanation and fix!
I'm not sure why Safari and Chrome are doing the typesetting
I missed the fact that you have the math in a div
with class disable-lazy-typesetting
, so it is always typeset.
Now I'm wondering how that should interact with typeset: false
bing set. If typeset
is false, no initial typesetting should occur, and that should include lazy typesetting, I would think. That means any lazy typesetting (of either kind) should wait until after the first MathJax.typeset()
or MathJax.typesetPromise()
call when typeset: false
is set. So the always typesetting should wait until then as well.
Is there a reason you have typeset: false
set?
@dpvc , fair question! I set typeset: false
while seeking the simplest configuration to reproduce the enormous typesetting issue.
My production configuration [1] and use case [2] are quite complex, and reproducing the issue there is tricky [3].
I wanted to narrow down the issue before reporting: Maybe I'd find a solution myself, or even useful clues; or, at least, reduce the sleuthing on your end :) Took about 8 hours to come up with the configuration that I reported.
Of note, the workaround you provided resolves the issue in my production use case.
OK, it does seem pretty complicated.
I see that you are still using the alpha.1 version, and I'm wondering if you have tried beta.4 yet. Some of your issues are fixed there, I believe, so that might simplify your configuration.
@dpvc , thank you! A dev on my team was pushing me to do so yesterday, too. So, I guess it's time to try beta.4!
Oh, I meant to say that I was sorry you took 8 hours to come up with the version you sent, though I appreciate it, as it made understanding it much easier for me.
OK, I figured out why the math was being typeset even though typeset: false
is set. It turns out that by setting the menu option for the assistive MathML extension, that requires the menu to load that extension itself, and when the menu loads an extension, it also does a re-render action. That was causing the typeset to occur.
I have made a PR to improve the handling of extensions in the menu code, so the initial rendering will not occur of typeset: false
is in effect.
Issue Summary
Having both assistive MML and lazy typesetting causes enormous typesettings
Steps to Reproduce:
Expected: Typesetting is normal size
Console warnings:
No console error.
Technical details:
I am using the following MathJax configuration:
and loading MathJax via
Supporting information:
Also confirmed to reproduce in: