Skip to content

feat!: upgrade to mathjax v4 - #33555

Merged
feanil merged 23 commits into
openedx:masterfrom
open-craft:navin/upgrade-mathjax-v3
Nov 5, 2026
Merged

feanil merged 23 commits into
openedx:masterfrom
open-craft:navin/upgrade-mathjax-v3

Conversation

@navinkarkera

@navinkarkera navinkarkera commented Oct 22, 2023 •

Copy link
Copy Markdown
Contributor

Description

Upgrades MathJax from v2.7.5 → v4.1.2 across LMS, CMS, and xblock iframes.

Key changes:

  • API replacement — MathJax.Hub calls replaced by window.MathJax config + startup.promise / typesetPromise / typesetClear
  • Output processor — SVG → CHTML (Common HTML output, faster + CSS-driven)
  • Delimiter compatibility preserved — \(...\), \[...\], [mathjaxinline]...[/mathjaxinline], [mathjax]...[/mathjax]
  • AsciiMath — CAPA preview backtick parsing unchanged

Co-authored by: GPT 5.5(xhigh), GPT 5.6(sol)

Supporting information

Screenshots

  • Studio Preview
    image
  • LMS
    image
  • Discussions
    image

Testing instructions

Setup

cd /path/to/edx-platform
git checkout navin/upgrade-mathjax-v3
tutor mounts add /path/to/edx-platform
tutor images build openedx-dev && tutor dev launch -I --skip-build
tutor dev start -d

1. Verify MathJax v4 is loaded

Open browser DevTools → Network tab, filter for mathjax. Confirm [email protected]/tex-mml-chtml.js is loaded in both LMS and Studio, and no v2 files.

2. Studio content editing

HTML Block

Create a Raw HTML block with:

<html display_name="MathJax HTML Test">
  <p>Inline math: [mathjaxinline]E=mc^2[/mathjaxinline]</p>
  <p>Display math: [mathjax]\int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}[/mathjax]</p>
  <p>Fraction: [mathjaxinline]3/4[/mathjaxinline]</p>
  <p>Quadratic: [mathjax]x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}[/mathjax]</p>
</html>

Problem Block — Text + Formula Input

Paste into Advanced Editor:

<problem display_name="MathJax Problem Test" markdown="null">
  <p>Simplify <strong>[mathjaxinline]3/4[/mathjaxinline]</strong>.</p>
  <p>The quadratic formula: <strong>[mathjax]x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}[/mathjax]</strong></p>
  <p>What is <strong>[mathjaxinline]x^2[/mathjaxinline]</strong> when <strong>[mathjaxinline]x=3[/mathjaxinline]</strong>?</p>
  <numericalresponse answer="9">
    <formulaequationinput label="9"/>
  </numericalresponse>
</problem>

Problem Block — Formula Preview Only

<problem display_name="MathJax Formula Preview" markdown="null">
  <p>Try <strong>x^2+1</strong>, <strong>x*y</strong>, <strong>1/2</strong>, <strong>(x+1)/(x-1)</strong>, <strong>sqrt(x)</strong>.</p>
  <formularesponse type="ci" samples="x@1:5" answer="x^2+1">
    <label>Enter expression:</label>
    <formulaequationinput size="40"/>
  </formularesponse>
  <solution>
    <div class="detailed-solution">
      <p>Explanation</p>
      <p>The expression <strong>[mathjaxinline]x^2+1[/mathjaxinline]</strong> is a quadratic.</p>
    </div>
  </solution>
</problem>

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

  • Pass: All math renders as formatted equations. No raw [mathjax], [mathjaxinline], $, or $$ delimiters visible in student view.
  • Pass: Formula equation input preview updates on every keystroke. Clear input → preview clears, no errors.
  • Pass: Discussion posts render math inline and block correctly. Thread list gracefully handles math in preview text.
  • Pass: Browser console shows zero errors matching:
    • MathJax.Hub is undefined / Hub.Queue is not a function
    • MathJax.Hub.getAllJax is not a function
    • MathJax.Callback is undefined
    • typesetClear / typesetPromise is not a function
    • Cannot read properties of undefined (reading 'root')
  • Fail: Any of the above console errors, raw tags visible, or preview not updating.

Notes / known follow-ups

  • v4 CHTML output is CSS-driven — verify .mjx-container overflow and responsive width in all themes.
  • Companion PR — xblocks-core#270 must be merged before for full non-iframe xblock coverage.
  • No intentional workflow changes — visual output may differ slightly because v4 uses CHTML instead of SVG.
  • Performance — v4 startup is faster; CHTML avoids SVG DOM overhead.
  • Iframe xblocks — tested via the iframe rendering path; if an xblock bypasses the standard pipeline, check its own MathJax loading.

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_SVG output classes and XBlocks or other frontend code that call the MathJax.Hub API stop rendering math until they move to the MathJax 4 API (window.MathJax config and typesetPromise) and the mjx-container output.

@openedx-webhooks

openedx-webhooks commented Oct 22, 2023 •

Copy link
Copy Markdown

Thanks for the pull request, @navinkarkera!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 22, 2023
@navinkarkera
navinkarkera force-pushed the navin/upgrade-mathjax-v3 branch 4 times, most recently from 3f5125c to 6d29ae7 Compare October 25, 2023 06:56
@navinkarkera
navinkarkera marked this pull request as ready for review October 25, 2023 08:10
@CefBoud

CefBoud commented Oct 26, 2023

Copy link
Copy Markdown
Contributor

@navinkarkera Great work on this!
Mathjax2 is also used in frontend-app-library-authoring. Can you please take a look?

@navinkarkera

Copy link
Copy Markdown
Contributor Author

Mathjax2 is also used in frontend-app-library-authoring. Can you please take a look?

@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.

@CefBoud CefBoud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

  • 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-secure repository.

@navinkarkera
navinkarkera force-pushed the navin/upgrade-mathjax-v3 branch 2 times, most recently from 5315c9c to c7ed9e1 Compare October 30, 2023 04:38
@navinkarkera navinkarkera self-assigned this Oct 30, 2023
@wittjeff

wittjeff commented Nov 7, 2023 •

Copy link
Copy Markdown

Please see discussion re upgrade paths for MathML rendering not being simple in this earlier PR: #32418
If you'd like to implement a course-level Advanced Option (with at least MathJax v2.7.9 and 3.2.1), that'd be super.

@navinkarkera

Copy link
Copy Markdown
Contributor Author

@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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread cms/static/cms/js/require-config.js Outdated

// 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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3.2.2 available

Comment thread cms/static/cms/js/spec/main.js Outdated
'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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3.2.2 available

Comment thread cms/static/cms/js/spec/main_squire.js Outdated
'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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3.2.2 available

Comment thread cms/static/sass/studio-main-v1.scss Outdated
@import 'build-v1'; // shared app style assets/rendering


.MathJax>svg {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I thought v3 eliminated SVG rendering. No? SVG rendering is problematic when used as items in a select element.

],
autoload: {
color: [],
colorv2: ['color']

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3.2.2 available

Comment thread common/templates/mathjax_include.html Outdated
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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3.2.2 available

Comment thread lms/static/lms/js/spec/main.js Outdated
'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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3.2.2 available

Comment thread lms/static/sass/lms-course.scss Outdated
}
}

.MathJax>svg {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of SVG??

@wittjeff

wittjeff commented Nov 8, 2023

Copy link
Copy Markdown

@Yagnesh1998

Copy link
Copy Markdown
Member

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

@rayzhou-bit

Copy link
Copy Markdown
Contributor

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?

@navinkarkera

Copy link
Copy Markdown
Contributor Author

@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.

@itsjeyd itsjeyd added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Mar 11, 2024

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

@mphilbrick211 mphilbrick211 removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Oct 30, 2024
@mphilbrick211

Copy link
Copy Markdown

Hi @navinkarkera! Are you planning to pursue this PR?

@mphilbrick211 mphilbrick211 added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Oct 30, 2024
@navinkarkera

Copy link
Copy Markdown
Contributor Author

@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 feanil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

feanil added a commit to openedx/edx-ora2 that referenced this pull request Oct 1, 2026
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]>
feanil added a commit to openedx/edx-ora2 that referenced this pull request Oct 26, 2026
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]>
feanil added a commit to openedx/edx-ora2 that referenced this pull request Oct 26, 2026
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]>
feanil added a commit to openedx/edx-ora2 that referenced this pull request Oct 26, 2026
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]>
@feanil

feanil commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@navinkarkera openedx/xblocks-core#270 is out as xblocks-contrib==1.0.8 and openedx/edx-ora2#2454 as ora2==7.1.3. Can you bump both pins in this PR(make upgrade-package package=xblocks-contrib and make upgrade-package package=ora2)? Once CI is green I think we can land this.

@navinkarkera

Copy link
Copy Markdown
Contributor Author

@feanil Done.

@feanil

feanil commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@navinkarkera I think this is good to squash and merge, looks like there is a conflict to resolve.

@navinkarkera
navinkarkera force-pushed the navin/upgrade-mathjax-v3 branch from 0c6bf2b to 4a8ee02 Compare November 4, 2026 11:13
@navinkarkera

navinkarkera commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

@feanil Done.

Should we post a message in risky-changes slack channel after merging this?

@feanil
feanil merged commit 78b892c into openedx:master Nov 5, 2026
42 checks passed
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions Nov 5, 2026
@feanil

feanil commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

We don't need to post there anymore, I'll do so anyway though.

irfanuddinahmad added a commit to irfanuddinahmad/xblocks-core that referenced this pull request Nov 6, 2026
…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]>
irfanuddinahmad added a commit to irfanuddinahmad/xblocks-core that referenced this pull request Nov 10, 2026
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]>
irfanuddinahmad added a commit to irfanuddinahmad/xblocks-core that referenced this pull request Nov 10, 2026
…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]>
blarghmatey added a commit to mitodl/mitx-grading-library that referenced this pull request Nov 16, 2026
* 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
blarghmatey added a commit to mitodl/lehrer that referenced this pull request Nov 17, 2026
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
blarghmatey added a commit to mitodl/lehrer that referenced this pull request Nov 17, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

10 participants