Skip to content

Conversation

@dpvc
Copy link
Member

@dpvc dpvc commented Aug 2, 2025

This PR fixes an issue that occurs when you load the output/chtml or output/svg components by hand (using startup.js) rather than using a combined component. Currently, these output components are built with no font (so they can be used with any of the fonts without incurring the cost of downloading the default font), and they are the basis of the -nofont combined components. Unfortunately, being built with no font means that you have to specify or load a font explicitly if you load the output component by hand.

This PR fixes this problem by configuring the font to load the default font (mathjax-newcm) when output/chtml or output/svg is loaded without specifying another font while still not having to include the font data for the default font.

The old approach worked by having webpack replace the reference to DefaultFont.js by a nofont.js file in the output directory. This PR changes that to instead replace the font's default.js file (which is loaded by Default.js to instead call a new nofont.js file in the font directory itself. This new file returns the font name and a null font class object, and the components/mjs/output/util.js file uses the null font class to cause the default font to load if another font wasn't specified.

I will need to rebuild the fonts to include the new nofont.js files, but for testing, you can just add node_modules/@mathjax/mathjax-newcm-font/mjs/nofont.js containing:

export const Font = {
    fontName: 'mathjax-newcm',
    DefaultFont: null
};

and that should allow you to pack the output components and the combined components. Note that this only affects the packed components, not loading components or modules from source.

This is not critical in the sense that you can get around the problem by specifying mathjax-newcm explicitly in the configuration, but it will make things easier for people.

@dpvc dpvc added this to the v4.0 milestone Aug 2, 2025
@codecov
Copy link

codecov bot commented Aug 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.72%. Comparing base (3167719) to head (bb59da7).
⚠️ Report is 11 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1327      +/-   ##
===========================================
- Coverage    86.72%   86.72%   -0.01%     
===========================================
  Files          337      337              
  Lines        84131    84130       -1     
  Branches      3139     4768    +1629     
===========================================
- Hits         72961    72960       -1     
+ Misses       11170    11147      -23     
- Partials         0       23      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@dpvc dpvc merged commit 7dfe1cb into develop Aug 4, 2025
3 checks passed
@dpvc dpvc deleted the fix/nofont branch August 4, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants