Skip to content
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

Extension loaded via autoload may not be available in time when ui/lazy is also loaded #3161

Closed
AlexEdgcomb opened this issue Jan 12, 2024 · 3 comments

Comments

@AlexEdgcomb
Copy link

AlexEdgcomb commented Jan 12, 2024

Issue Summary

An extension (e.g., cancel) that is loaded via autoload may not be available in time when ui/lazy is also loaded, leading to the typeset showing the macro name in red, like \cancel.

Steps to Reproduce:

  1. Go to https://codepen.io/alexedgcomb/pen/KKEgLOJ
  2. Refresh if typesetting worked
    Observed: About 1 in 5 page refreshes, the cancel package is not found before typesetting
image

I tried to reduce the config as much as possible. Seems that each of the remaining pieces is necessary to produce the issue.

Technical details:

  • MathJax Version: 4.0.0-beta.3
  • Client OS: Mac OS 13.4
  • Browser: Firefox 121.0.1

I am using the following MathJax configuration:

MathJax = {
  loader: { load: [ 'ui/lazy' ] },
  options: { lazyAlwaysTypeset: '.disable-lazy-typesetting' },
  output: { font: 'mathjax-tex' },
};

and loading MathJax via

<script src="https://cdn.jsdelivr.net/npm/[email protected]/tex-mml-svg.js"></script>

I am using a delayed call to both add content and typeset:

async function typeset() {
  document.getElementById('test').innerHTML = '<div class="disable-lazy-typesetting"><p>\\( \\cancel{x} \\)</p></div>';
  await MathJax.startup.promise;
  MathJax.typesetPromise([ document.getElementById('test') ]);
}

setTimeout(typeset, 10);

Supporting information:

  • Also sometimes happens in:
  • No console errors/warnings
  • A simple workaround is to add the needed extensions (e.g., cancel) to the configuration. No less, I thought y'all might appreciate this report :)
@dpvc
Copy link
Member

dpvc commented Jan 12, 2024

This turns out to be an issue with how MathJax.startup.promise is resolved, and is a duplicate of #3130.

You can work around it by adding

    startup: {
      pageReady() {
        const config = MathJax.config.startup;
        const output = MathJax.config.output;
        return (config.loadAllFontFiles && output.font ? output.font.loadDynamicFiles() : Promise.resolve())
          .then(config.typeset && MathJax.typesetPromise ?
                () => MathJax.startup.typesetPromise(config.elements) : Promise.resolve);
      }
    }

to your Mathjax configuration for now.

BTW, I do get a console error about null not having a parentNode, so I'm not sure why you aren't seeing that.

@AlexEdgcomb
Copy link
Author

@dpvc , thank you! Works wonderfully.

BTW, I do get a console error about null not having a parentNode, so I'm not sure why you aren't seeing that.

Doh, I do see that. Not sure how I missed that... Definitely would have helped me find #3130 on my own!

@dpvc
Copy link
Member

dpvc commented Jan 12, 2024

Doh, I do see that. Not sure how I missed that... Definitely would have helped me find #3130 on my own!

No problem. I'm just glad it wasn't something that I had to fix. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants