From 2bbb60d37cf4ecef056783265a9b3f94dc854034 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 9 Feb 2026 12:57:00 -0600 Subject: [PATCH] Also host Mathjax 4 fonts It turns out that plain MathJax 4 will still make requests to the CDN for, e.g., `\mathbb` (but not otherwise) if the fonts are not also hosted. There doesn't seem to be a really canonical list of fonts needed, but this issue comment has some guidance: https://github.com/mathjax/MathJax/issues/3436#issuecomment-3481724702 --- frontend/js/base-with-markup.js | 10 +++++++ package-lock.json | 49 +++++++++++++++++++++++++++++++++ package.json | 5 ++++ relate/settings.py | 1 + 4 files changed, 65 insertions(+) diff --git a/frontend/js/base-with-markup.js b/frontend/js/base-with-markup.js index 814b09647..4ec2eec22 100644 --- a/frontend/js/base-with-markup.js +++ b/frontend/js/base-with-markup.js @@ -9,6 +9,16 @@ window.MathJax = { inlineMath: [['$', '$'], ['\\(', '\\)']], displayMath: [['$$', '$$'], ['\\[', '\\]']], }, + // based on https://github.com/mathjax/MathJax/issues/3436#issuecomment-3481724702 + loader: { + paths: { + fonts: '[mathjax]', + 'mathjax-mhchem-extension': '[fonts]/mathjax-mhchem-font-extension', + 'mathjax-bbm-extension': '[fonts]/mathjax-bbm-font-extension', + 'mathjax-bboldx-extension': '[fonts]/mathjax-bboldx-font-extension', + 'mathjax-dsfont-extension': '[fonts]/mathjax-dsfont-font-extension', + }, + }, options: { processHtmlClass: 'relate-markup', }, diff --git a/package-lock.json b/package-lock.json index 784d89a49..ca26b1045 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,11 @@ "@fullcalendar/list": "^6.1.20", "@fullcalendar/timegrid": "^6.1.20", "@lezer/highlight": "^1.2.3", + "@mathjax/mathjax-bbm-font-extension": "^4.1.0", + "@mathjax/mathjax-bboldx-font-extension": "^4.1.0", + "@mathjax/mathjax-dsfont-font-extension": "^4.1.0", + "@mathjax/mathjax-mhchem-font-extension": "^4.1.0", + "@mathjax/mathjax-newcm-font": "^4.1.0", "@popperjs/core": "^2.11.2", "@replit/codemirror-emacs": "^6.1.0", "@replit/codemirror-vim": "^6.3.0", @@ -563,6 +568,30 @@ "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==", "license": "MIT" }, + "node_modules/@mathjax/mathjax-bbm-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-bbm-font-extension/-/mathjax-bbm-font-extension-4.1.0.tgz", + "integrity": "sha512-GyZxYGZCyHXpKmxgrgIaJDePx8zkahavRfjzWBOzKO/OC+Y7Paqkf90VnTXF6FRHtgz4iMGDsqAfQngK/lyiqg==", + "license": "Apache-2.0" + }, + "node_modules/@mathjax/mathjax-bboldx-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-bboldx-font-extension/-/mathjax-bboldx-font-extension-4.1.0.tgz", + "integrity": "sha512-GikRQ+DmVau/7b4NRSkTeq7OoajMH63gqfBOXHx0WuvsFpQtMR5c68bm/5w1jU5L7rruJ/g+c8/F3Thz2ZylNg==", + "license": "Apache-2.0" + }, + "node_modules/@mathjax/mathjax-dsfont-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-dsfont-font-extension/-/mathjax-dsfont-font-extension-4.1.0.tgz", + "integrity": "sha512-aJ8Mj0GREOzWCBOHFSID3j65uQRlmJUhklZKylSMu2GLCUp4mJ3zI+ex+gol8HwUW1jZ6hf/f8/5hx5RByhpqg==", + "license": "Apache-2.0" + }, + "node_modules/@mathjax/mathjax-mhchem-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-mhchem-font-extension/-/mathjax-mhchem-font-extension-4.1.0.tgz", + "integrity": "sha512-1FWrDbsHmcp3AoGl3lD/7Q9ZeIss6DzU/owcSScCmjFLp8twC1horSBHiVhbHrAF+ewP2pMXkK3N4nWqEjK01A==", + "license": "Apache-2.0" + }, "node_modules/@mathjax/mathjax-newcm-font": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@mathjax/mathjax-newcm-font/-/mathjax-newcm-font-4.1.0.tgz", @@ -8454,6 +8483,26 @@ "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz", "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==" }, + "@mathjax/mathjax-bbm-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-bbm-font-extension/-/mathjax-bbm-font-extension-4.1.0.tgz", + "integrity": "sha512-GyZxYGZCyHXpKmxgrgIaJDePx8zkahavRfjzWBOzKO/OC+Y7Paqkf90VnTXF6FRHtgz4iMGDsqAfQngK/lyiqg==" + }, + "@mathjax/mathjax-bboldx-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-bboldx-font-extension/-/mathjax-bboldx-font-extension-4.1.0.tgz", + "integrity": "sha512-GikRQ+DmVau/7b4NRSkTeq7OoajMH63gqfBOXHx0WuvsFpQtMR5c68bm/5w1jU5L7rruJ/g+c8/F3Thz2ZylNg==" + }, + "@mathjax/mathjax-dsfont-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-dsfont-font-extension/-/mathjax-dsfont-font-extension-4.1.0.tgz", + "integrity": "sha512-aJ8Mj0GREOzWCBOHFSID3j65uQRlmJUhklZKylSMu2GLCUp4mJ3zI+ex+gol8HwUW1jZ6hf/f8/5hx5RByhpqg==" + }, + "@mathjax/mathjax-mhchem-font-extension": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@mathjax/mathjax-mhchem-font-extension/-/mathjax-mhchem-font-extension-4.1.0.tgz", + "integrity": "sha512-1FWrDbsHmcp3AoGl3lD/7Q9ZeIss6DzU/owcSScCmjFLp8twC1horSBHiVhbHrAF+ewP2pMXkK3N4nWqEjK01A==" + }, "@mathjax/mathjax-newcm-font": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@mathjax/mathjax-newcm-font/-/mathjax-newcm-font-4.1.0.tgz", diff --git a/package.json b/package.json index e047d1034..7b77165d5 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,11 @@ "katex": "^0.16.28", "markdown-it": "^14.1.0", "mathjax": "^4.1.0", + "@mathjax/mathjax-newcm-font": "^4.1.0", + "@mathjax/mathjax-mhchem-font-extension": "^4.1.0", + "@mathjax/mathjax-bbm-font-extension": "^4.1.0", + "@mathjax/mathjax-bboldx-font-extension": "^4.1.0", + "@mathjax/mathjax-dsfont-font-extension": "^4.1.0", "prosemirror-commands": "^1.7.1", "prosemirror-example-setup": "^1.2.3", "prosemirror-inputrules": "^1.5.1", diff --git a/relate/settings.py b/relate/settings.py index 16c487320..5ae81a2f0 100644 --- a/relate/settings.py +++ b/relate/settings.py @@ -247,6 +247,7 @@ STATICFILES_DIRS = ( join(BASE_DIR, "relate", "static"), join(BASE_DIR, "node_modules", "mathjax"), + join(BASE_DIR, "node_modules", "@mathjax"), join(BASE_DIR, "frontend-dist"), )