Open agrigoriadis1977 opened 6 days ago
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.
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.