Problem with fonts when embedding MathJax in HTML document

28 views
Skip to first unread message

JS Pieve

unread,
Aug 19, 2026, 3:44:37 AM (12 days ago) Aug 19
to MathJax Users
Hi,

I'm trying to build HTML documents (using Sphinx) that includes a copy of MathJax. This is because the server is behind a firewall and cannot access the CDN to use MathJax. This largely works, but I get some errors with fonts.

I have downloaded the zip file from the v4.1.3 release and unpacked that into the appropriate directory. Sphinx allows you to configure the location of MathJax with the option:
mathjax_path = "MathJax/tex-mml-chtml.js"

This generates the following headers in the HTML:
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="_static/MathJax/tex-mml-chtml.js?v=26396ac8"></script>

The math on the page is partly displayed, but I get several errors in the browser console, of the form:
[Error] Refused to load https://cdn.jsdelivr.net/npm/@mathjax/mathjax-n...@4.1.3/chtml/woff2/mjx-ncm-u.woff2 because it does not appear in the font-src directive of the Content Security Policy.

I'm not sure why it is attempting to access the fonts from the CDN because the documentation says that the fonts are bundled in the tex-mml-chtml.js component.

I tried to set the path to the fonts with the Sphinx option:
mathjax4_config = {
"loader": {
"paths": {
"fonts": "[mathjax]",
},
},
}

This appears to correctly update the HTML:
<script>window.MathJax = {"loader": {"paths": {"fonts": "[mathjax]"}}, "options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>

But I now get the following error in the browser console:
[Error] Failed to load resource: the server responded with a status of 404 () (mjx-ncm-zero.woff2, line 0)
https://.../_static/MathJax/mathjax-newcm-font/chtml/woff2/mjx-ncm-brk.woff2
(This is an internal URL)

Which is not surprising as the directory mathjax-newcm-font does not exist in the downloaded zip package. And I can't find it mentioned anywhere in the MathJax repos.

Any suggestions how to get this working?

Thanks

JS Pieve

unread,
Aug 19, 2026, 8:05:04 AM (12 days ago) Aug 19
to MathJax Users
I managed to get this working. I spotted the documentation for installing non-defaults fonts so I used that to install the default font:
npm install @mathjax/mathjax-newcm-font@4

Then copied that into my copy of the MathJax repo embedded in the document. This appears to work. Even though the documentation implies it shouldn't be necessary.

Davide Cervone

unread,
Aug 20, 2026, 4:24:59 PM (11 days ago) Aug 20
to mathja...@googlegroups.com
For others looking for more information, please see the discussion at



--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mathjax-users/1b9bbb60-321a-48ec-bbfb-0860d431aa90n%40googlegroups.com.

JS Pieve

unread,
Aug 21, 2026, 7:35:09 AM (10 days ago) Aug 21
to MathJax Users
To summarise, this was a combination of me not reading the documentation carefully enough and some confusion caused by my relative unfamiliarity with node. I hadn't realised that when you do:
npm install mathjax@4

 it also installs @mathjax/mathjax-newcm-font. So I had everything I needed, I just didn't realise it.

Reply all
Reply to author
Forward
0 new messages