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

Request for Supporting Self-Hosted Fonts and chtml.js Module for mathjax-fira Font #3304

Open
agrigoriadis1977 opened this issue Nov 7, 2024 · 1 comment
Labels
Code Example Contains an illustrative code example, solution, or work-around Feature Request v4

Comments

@agrigoriadis1977
Copy link

We are using MathJax v4 (currently beta) on our publishing platform and have encountered an issue with the 'mathjax-fira' font.

We have observed that when the 'mathjax-fira' font is loaded from the MathJax CDN, there's a 2-3 second delay before the math content is rendered correctly. This delay causes equations to first appear in a fallback font and then switch to the correct font, which is disruptive to our users.

Since the font files are fetched from the CDN, we have limited control over their loading behavior. Additionally, preloading the font is unreliable because the CDN URLs can change, leading to broken links.

We request that MathJax provide support for loading self-hosted fonts and the associated chtml.js module for the 'mathjax-fira' font. This would enable us to preload the font, reducing the rendering delay and improving the user experience.

Additionally, we noticed that the fonts are currently provided in WOFF format. Offering the fonts in WOFF2 format would reduce the file size further enhancing loading performance.

Please let me know if you need any additional information or if there's any way we can assist in implementing this feature.

@dpvc
Copy link
Member

dpvc commented Nov 8, 2024

MathJax already has the ability to set the location from which the fonts are taken. It is the fontURL option in the chtml block of your MathJax configuration. E.g.:

MathJax = {
  chtml: {
    fontURL: "https://myserver.com/mathjax-modern-font/chtml/woff"
  }
}

If you want to convert the fonts to woff2 and load those instead, you could use a configuration like the following:

MathJax = {
  chtml: {
    fontURL: 'https://myserver.com/mathjax-modern-font/chtml/woff2'
  },
  startup: {
    ready() {
      const {ChtmlFontData} = MathJax._.output.chtml.FontData;
      Object.assign(ChtmlFontData, {
        _addFontURLs_: ChtmlFontData.addFontURLs,
        addFontURLs(styles, fonts, url) {
          for (const [name, def] of Object.entries(fonts)) {
            def.src = def.src.replace(/woff/g, 'woff2');
          }
          this._addFontURLs_(styles, fonts, url);
        }
      });
      MathJax.startup.defaultReady();
    }
  }
}

This patches the CHTML output jax's font URL handler to replace woff by woff2.

@dpvc dpvc added the Code Example Contains an illustrative code example, solution, or work-around label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Example Contains an illustrative code example, solution, or work-around Feature Request v4
Projects
None yet
Development

No branches or pull requests

2 participants