Repository navigation
feat!: upgrade to mathjax v4 - #33555
Conversation
|
Thanks for the pull request, @navinkarkera! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
3f5125c to
6d29ae7
Compare
|
@navinkarkera Great work on this! |
@CefBoud Although I don't know if it is in the scope, I can update it as it seems to be used in only once place. |
6d29ae7 to
70f67b9
Compare
CefBoud
left a comment
There was a problem hiding this comment.
👍
- I tested this: in Text, Numerical Input, Math Expression and Problem components. Also in course Discussions. Inline and display expressions.
- I read through the code
- I checked for accessibility issues : Mathjax built-in accessibility functioning properly. Tested with Chrome Screen Reader extension.
-
Includes documentation -
I made sure any change in configuration variables is reflected in the corresponding client's.configuration-securerepository
5315c9c to
c7ed9e1
Compare
|
Please see discussion re upgrade paths for MathML rendering not being simple in this earlier PR: #32418 |
|
@wittjeff Thanks for pointing me to the PR. About implementing course level advance option to support both v2 and v3, I'll come back with an update/answer soon. |
| $script( | ||
| 'https://cdn.jsdelivr.net/npm/[email protected]/MathJax.js' | ||
| + '?config=TeX-MML-AM_SVG&delayStartupUntil=configured', | ||
| 'https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-mml-svg.js', |
There was a problem hiding this comment.
|
|
||
| // externally hosted files | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-svg.js?noext', |
| 'URI': 'xmodule_js/common_static/js/vendor/URI.min', | ||
| 'mock-ajax': 'xmodule_js/common_static/js/vendor/mock-ajax', | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-svg.js?noext', |
| 'domReady': 'xmodule_js/common_static/js/vendor/domReady', | ||
| 'URI': 'xmodule_js/common_static/js/vendor/URI.min', | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-svg.js?noext', |
| @import 'build-v1'; // shared app style assets/rendering | ||
|
|
||
|
|
||
| .MathJax>svg { |
There was a problem hiding this comment.
I thought v3 eliminated SVG rendering. No? SVG rendering is problematic when used as items in a select element.
| ], | ||
| autoload: { | ||
| color: [], | ||
| colorv2: ['color'] |
There was a problem hiding this comment.
Do we need to consider accessibility (particularly contrast) of a MathJax color palette?
| } | ||
| }; | ||
| vendorScript.src = 'https://cdn.jsdelivr.net/npm/[email protected]/MathJax.js?config=TeX-MML-AM_HTMLorMML'; | ||
| vendorScript.src = 'https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-mml-svg.js'; |
| It can't be run through static.url because MathJax uses crazy url introspection to do lazy loading of | ||
| MathJax extension libraries --> | ||
| <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG"></script> | ||
| <script type="text/javascript" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-svg.js"></script> |
| 'jasmine-imagediff': 'xmodule_js/common_static/js/vendor/jasmine-imagediff', | ||
| 'domReady': 'xmodule_js/common_static/js/vendor/domReady', | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_HTMLorMML&delayStartupUntil=configured', // eslint-disable-line max-len | ||
| mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-svg.js?noext', |
| } | ||
| } | ||
|
|
||
| .MathJax>svg { |
|
Related discussion re Canvas use of MathJax: https://community.canvaslms.com/t5/Canvas-Question-Forum/Canvas-s-MathJax-Needs-An-Update/m-p/583189 |
|
I submitted a PR because I'm having some issues with MathJax on the edX platform.Let me know if there is anything I can do here |
|
Hi @navinkarkera, I tried testing this recently with a more current version of edx-platform and could not get it to work. Is it still working on your environment? |
|
@rayzhou-bit Thanks for testing it. I am currently occupied with another project and we haven't received any confirmation from the original stakeholders yet, but I hope to get back to this soon. |
OmarIthawi
left a comment
There was a problem hiding this comment.
Thanks @navinkarkera for your contribution. This is really useful and the update is much needed to improve performance.
I recommend using HTML CSS instead of SVG whenever possible. SVG is challenging for MathJax plugin makers like myself when it comes to Arabic and RTL support.
Additionally, Open edX needs to support mobile and to stay accessible which I think MathJax SVG isn't very well suited for:
|
Hi @navinkarkera! Are you planning to pursue this PR? |
|
@mphilbrick211 Yes, once mathjax 4 is released, we plan to upgrade since it is already in beta. For more info, please see this discussion |
feanil
left a comment
There was a problem hiding this comment.
Blocked on two PRs merging first.
openedx/xblocks-core#270 needs to merge and be released, and the xblocks-contrib pin here needs to move to it. Problems, HTML blocks and discussions render through xblocks-contrib by default, pinned at 1.0.5, and every 1.0.x
release still calls MathJax.Hub. Merging this first stops math rendering on stock settings.
openedx/edx-ora2#2454 fixes the same break in ORA. It works on v2 and v4 both, so it can merge whenever.
Nothing else outstanding. Delimiters are unchanged at every config site and input/asciimath is loaded, so nothing changes for course authors.
openedx/openedx-platform#33555 upgrades the platform from MathJax 2.7.5 to 4.1.2. v4 removed the queue-based `MathJax.Hub` API in favour of `MathJax.typesetPromise`, so the two `MathJax.Hub.Queue` calls in ORA throw once that lands and math stops rendering in prompts and in submitted responses. The stub in oa_shared.js did not cover this. It only installed a no-op `Hub` when `window.MathJax` was undefined, and under v4 the global is defined, it just has no `Hub`. Route both call sites through a `typesetMath` helper that prefers the v4 API, falls back to the v2 one, and does nothing when the runtime provides no MathJax at all. That last case is what the stub was for, so the stub goes away. Supporting both versions means this does not have to be sequenced against the platform upgrade. Co-Authored-By: Claude Opus 5 <[email protected]>
openedx/openedx-platform#33555 upgrades the platform from MathJax 2.7.5 to 4.1.2. v4 removed the queue-based `MathJax.Hub` API in favour of `MathJax.typesetPromise`, so the two `MathJax.Hub.Queue` calls in ORA throw once that lands and math stops rendering in prompts and in submitted responses. The stub in oa_shared.js did not cover this. It only installed a no-op `Hub` when `window.MathJax` was undefined, and under v4 the global is defined, it just has no `Hub`. Route both call sites through a `typesetMath` helper that prefers the v4 API, falls back to the v2 one, and does nothing when the runtime provides no MathJax at all. That last case is what the stub was for, so the stub goes away. Supporting both versions means this does not have to be sequenced against the platform upgrade. Co-Authored-By: Claude Opus 5 <[email protected]>
The response step before submission had no `allow--latex` class, unlike the submitted, graded, self, peer, training, grade and leaderboard steps, so `Server.renderLatex` skipped it. The prompt's math only rendered when the platform's one-time MathJax startup typeset happened to run after ORA inserted the step. Under MathJax 4 (openedx/openedx-platform#33555) that race loses most of the time: prompt math rendered on 2 of 8 page loads in a local test, and on 8 of 8 with this class added. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MathJax 3 and 4 only define `MathJax.typesetPromise` once startup has finished, so requiring it up front skipped the v3/v4 branch whenever ORA rendered before startup was done. MathJax 4's AsciiMath input also defines a legacy `MathJax.Hub`, so in that window the call fell through to the v2 branch and queued into a Hub that does nothing. Wait on `MathJax.startup.promise` instead. The same race left the textline preview blank in the problem block on the MathJax 4 test stack for openedx/openedx-platform#33555. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@navinkarkera openedx/xblocks-core#270 is out as |
|
@feanil Done. |
|
@navinkarkera I think this is good to squash and merge, looks like there is a conflict to resolve. |
0c6bf2b to
4a8ee02
Compare
|
@feanil Done. Should we post a message in |
|
We don't need to post there anymore, I'll do so anyway though. |
…pecs openedx/openedx-platform#33555 added six specs for the built-in block's client-side refreshMath formula-equation preview, which openedx/openedx-platform#38751 removes. The extracted block renders these previews only via the server (preview_formcalc, 989ae32), so add tests asserting that path's behavior for the same inputs: - calculator syntax R_1*R_2/R_3 renders as LaTeX - \(..\), \[..\], $$..$$ and $..$ inputs are rejected with a parse error The binding spec maps to existing coverage (formula_equation_preview_spec 'makes a request on user input' and display_spec 'does not bind refreshMath to formula equation inputs'). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ports three tests that openedx/openedx-platform#33555 (MathJax v4 upgrade) added to xmodule/js/spec/capa/display_spec.js, which openedx/openedx-platform#38751 removes along with the built-in Problem block: - should clear and typeset the math element - wraps calculator input in backticks for input.math - clears preview and skips typesetPromise on empty input Names, bodies and assertions are unchanged except for the extracted block's Problem(runtime, element) constructor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pecs openedx/openedx-platform#33555 added six specs for the built-in block's client-side refreshMath formula-equation preview, which openedx/openedx-platform#38751 removes. The extracted block renders these previews only via the server (preview_formcalc, 989ae32), so add tests asserting that path's behavior for the same inputs: - calculator syntax R_1*R_2/R_3 renders as LaTeX - \(..\), \[..\], $$..$$ and $..$ inputs are rejected with a parse error The binding spec maps to existing coverage (formula_equation_preview_spec 'makes a request on user input' and display_spec 'does not bind refreshMath to formula equation inputs'). Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Support MathJax 4 in MJxPrep.js openedx/openedx-platform#33555 moves the LMS from MathJax 2.7.5 to 4.1.2 and drops the MathJax.Hub API. MJxPrep.js re-rendered previews with MathJax.Hub.Queue before clearing its poll, so on MathJax 4 answer previews for saved answers stay empty in every course that uses it. MathJax 4's AsciiMath component still exposes the legacy AM object (and a legacy MathJax.Hub), so the symbol definitions carry over unchanged. The re-render now branches on MathJax.version: v2 keeps Hub.Queue(Reprocess), v4 waits for MathJax.startup.promise and replays a keyup on the inputs CAPA binds Problem.refreshMath to. The poll stops before anything that can throw and gives up after a minute, and the console log carries the file's version (also on window.MJxPrep.version) so a course's copy can be identified. Claude-Session: https://claude.ai/code/session_01FGZebFEDxey1jTnNLNZAbD * Test MJxPrep.js in a browser against MathJax 2.7.5 and 4.1.2 The Jest tests run in jsdom, which can't run MathJax, so nothing caught MJxPrep.js breaking on MathJax 4. This adds a Playwright test that loads MJxPrep.js into a page mimicking a CAPA textline problem, with the MathJax config and CAPA refreshMath from before and after openedx/openedx-platform#33555. MathJax is requested from the same CDN URLs the LMS uses and served from node_modules, so the test runs offline. It checks that saved answers preview with MJxPrep's preprocessor and AsciiMath definitions, that there are no console errors, and that the AsciiMath poll stops. MJXPREP_JS points it at another copy, e.g. a course's. Renovate leaves the MathJax packages alone because they mirror what edx-platform serves. Claude-Session: https://claude.ai/code/session_01FGZebFEDxey1jTnNLNZAbD * Check for AsciiMath as soon as MJxPrep.js loads CAPA loads the preprocessor script right before it renders saved answers. When MathJax 4 has already started by then, the first poll tick 200 ms later is too late: the previews render with stock AsciiMath first, and MathJax logs a TypeError parsing {:hbar:}. On MathJax 2.7 the hidden dynamath MathML kept the stock rendering, since Reprocess only redraws the visible preview. Claude-Session: https://claude.ai/code/session_01FGZebFEDxey1jTnNLNZAbD * Cover late MJxPrep.js loads and formulaequationinput in browser tests Each MathJax version now also runs with MJxPrep.js loaded after MathJax's first typeset, the order that exposed the AsciiMath timing bug, and checks a formulaequationinput preview on MathJax 4, which goes through AsciiMath without a preprocessor. The MathJax 4 font package is pinned to 4.1.2 to match MathJax (npm resolved ^4.1.2 to 4.1.3, which MathJax warned about), and the test fails on that warning. The poll check now also requires that the poll started. Claude-Session: https://claude.ai/code/session_01FGZebFEDxey1jTnNLNZAbD * Note that MathJax 4 previews formulaequationinput through AsciiMath On MathJax 4, CAPA renders formulaequationinput previews client-side with AsciiMath, so MJxPrep's symbol definitions apply to them, which the renderer docs said was impossible. Claude-Session: https://claude.ai/code/session_01FGZebFEDxey1jTnNLNZAbD
mitxonline is held at edx-platform d2dbc6a5930, the commit before the MathJax 4 upgrade (openedx/openedx-platform#33555), so it loads MathJax 2.7.5. That commit already pins xblocks-contrib 1.0.8, whose problem and discussion blocks only call the MathJax 4 API, so formula previews break on rc ([FormulaEquationInput] Oops no mathjax). 1.0.7 is the last release using the MathJax 2 API, and its dependencies are the same as 1.0.8's. The pin has to come out once mitxonline builds 78b892c6e2d or later: from there the platform loads MathJax 4, which 1.0.7 breaks in reverse, and from 6f85d63c7f9 on edx-platform depends on xblocks-core, so the pin would add a second copy of the blocks. Renovate is told to leave it alone until then. https://github.mit.edu/mitxonline/mitxonline-issues/issues/1652 Claude-Session: https://claude.ai/code/session_01FGZebDvGwVSXfw1tvwmscW
mitxonline is held at edx-platform d2dbc6a5930, the commit before the MathJax 4 upgrade (openedx/openedx-platform#33555), so it loads MathJax 2.7.5. That commit already pins xblocks-contrib 1.0.8, whose problem and discussion blocks only call the MathJax 4 API, so formula previews break on rc ([FormulaEquationInput] Oops no mathjax). 1.0.7 is the last release using the MathJax 2 API, and its dependencies are the same as 1.0.8's. The pin has to come out once mitxonline builds 78b892c6e2d or later: from there the platform loads MathJax 4, which 1.0.7 breaks in reverse, and from 6f85d63c7f9 on edx-platform depends on xblocks-core, so the pin would add a second copy of the blocks. Renovate is told to leave it alone until then. https://github.mit.edu/mitxonline/mitxonline-issues/issues/1652 Claude-Session: https://claude.ai/code/session_01FGZebDvGwVSXfw1tvwmscW
Description
Upgrades MathJax from v2.7.5 → v4.1.2 across LMS, CMS, and xblock iframes.
Key changes:
MathJax.Hubcalls replaced bywindow.MathJaxconfig +startup.promise/typesetPromise/typesetClear\(...\),\[...\],[mathjaxinline]...[/mathjaxinline],[mathjax]...[/mathjax]Co-authored by: GPT 5.5(xhigh), GPT 5.6(sol)
Supporting information
Private-ref: BB-7992Screenshots
Testing instructions
Setup
1. Verify MathJax v4 is loaded
Open browser DevTools → Network tab, filter for
mathjax. Confirm[email protected]/tex-mml-chtml.jsis loaded in both LMS and Studio, and no v2 files.2. Studio content editing
HTML Block
Create a Raw HTML block with:
Problem Block — Text + Formula Input
Paste into Advanced Editor:
Problem Block — Formula Preview Only
Discussion Posts
Post #1 — Inline:
I was wondering about the famous equation $E=mc^2$.Post #2 — Block:
The quadratic formula: $$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$Post #3 — Mixed:
Trig: $\sin^2\theta + \cos^2\theta = 1$. Also: $\mu$ for mean, $\sigma$ for std dev.Pass / Fail Criteria
[mathjax],[mathjaxinline],$, or$$delimiters visible in student view.MathJax.Hubis undefined /Hub.Queueis not a functionMathJax.Hub.getAllJaxis not a functionMathJax.Callbackis undefinedtypesetClear/typesetPromiseis not a functionCannot read properties of undefined (reading 'root')Notes / known follow-ups
.mjx-containeroverflow and responsive width in all themes.Please let me know if we are using mathjax in some other components which we need to test.
Deadline
None
Other information
None
BREAKING CHANGE: The platform now loads MathJax 4.1.2 with CHTML output in place of 2.7.5 with SVG output. Custom themes that style the
MathJax_SVGoutput classes and XBlocks or other frontend code that call theMathJax.HubAPI stop rendering math until they move to the MathJax 4 API (window.MathJaxconfig andtypesetPromise) and themjx-containeroutput.