Skip to content

feat(mathjax): upgrade mathjax from v2 to v4#270

Draft
navinkarkera wants to merge 4 commits into
openedx:mainfrom
navinkarkera:navin/mathjax-v4
Draft

feat(mathjax): upgrade mathjax from v2 to v4#270
navinkarkera wants to merge 4 commits into
openedx:mainfrom
navinkarkera:navin/mathjax-v4

Conversation

@navinkarkera

Copy link
Copy Markdown

Summary

Upgrade MathJax from v2.7.5 → v4.1.2 across all XBlocks (problem, discussion, html). The v2 MathJax.Hub.Queue(...) / .Hub.Config() / .Hub.getAllJax() API is removed upstream. This PR ports all JS interactions to v4's MathJax.typesetPromise() / MathJax.typesetClear() / MathJax.startup.promise API.

Co-authored by: GPT 5.5(xhigh)

Manual testing

Before merging, verify each xblock type in a devstack with the corresponding edx-platform MathJax v4 branch:

1. Problem XBlock — formula preview (AsciiMath / calculator syntax)

  1. Create a problem containing <formulaequationinput> (e.g., the built-in "Formula Problem" template).
  2. Type R_1*R_2/R_3 into the input field.
  3. Expected: The preview below the input renders the formula (no raw text). The loading spinner <img.loading> remains visible while a request is in flight and is not destroyed by the preview update.
  4. Open devtools console. Type sin(x) and sqrt(y^2+1).
  5. Expected: No console errors. Each keystroke updates the rendered preview.

2. Problem XBlock — formula preview (explicit TeX syntax)

  1. In the same input, type \(E=mc^2\).
  2. Expected: The preview renders E=mc² as math; the TeX delimiters are preserved and not double-wrapped in backticks.
  3. Type $$\sum_{i=1}^{\infty} \frac{1}{n^2}$$.
  4. Expected: Display math renders correctly with double-dollar delimiters preserved.

3. Discussion — math rendering in posts

  1. Navigate to a course discussion topic.
  2. Create a post containing $x^2 + y^2 = z^2$ (inline) and $$\int_0^\infty e^{-x}\,dx$$ (display).
  3. Expected: Both render as math, not raw source. The discussion thread view, profile view, and response comments all show typeset math.
  4. Edit an existing post that contains math. The WMD editor should not throw errors related to MathJax.Hub.Browser.
  5. Expected: Editing works, the IE branch (if applicable) falls back to UA sniffing without throwing.

4. HTML XBlock — math in content

  1. Create an HTML component containing \[ \sum_{i=1}^n i = \frac{n(n+1)}{2} \].
  2. Save and view the unit.
  3. Expected: Display math renders. The HTML XBlock calls MathJax.startup.promise.then(() => typesetPromise([element])) on initialization — no console errors.

5. Graceful degradation — CDN failure

  1. Open devtools → Network tab → block cdn.jsdelivr.net.
  2. Reload any page with math content.
  3. Expected: Page loads without JS errors. No unhandled promise rejections from startup.promise.then(...) chains (.catch() is present in formula_equation_preview.js; utils.js and html.py skip typesetting when MathJax is absent).

Risks

  • Host dependency: xblocks-contrib expects the host platform (edx-platform) to provide MathJax v4 with input/asciimath loaded. Its own mathjax_include.js is a guarded fallback (if (typeof MathJax === 'undefined')). If the host changes config without enabling AsciiMath input, formula preview (backtick-delimited syntax) breaks silently.
  • noerrors package: Loaded in config; silently swallows MathJax rendering errors. Same behavior as v2, intentional.
  • messageStyle: "none" not ported — v4 may show brief "Loading MathJax..." overlay. Cosmetic only.

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jun 29, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @navinkarkera!

This repository is currently maintained by @openedx/axim-engineering.

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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


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.

Migrate MathJax v2 Hub.Queue/Hub.getAllJax/Callback APIs to v3/v4 startup.promise/typesetPromise/typesetClear in Problem display.js, formula_equation_preview.js, and HtmlBlock init.

- Problem.display.js: replace Hub.Queue(Typeset) with startup.promise.then(typesetPromise), Hub.getAllJax with startup.document.getMathItemsWithin, jax.root.toMathML with startup.toMML
- Formula equation preview: replace Hub.signal.Interest/Queue/getAllJax with startup.promise.then(typesetClear; textContent; typesetPromise)
- HtmlBlock: call typesetPromise on student_view load
- Bump version to 0.17.1
Update display_spec.js and formula_equation_preview_spec.js MathJax mocks from v2 (Hub.Queue, Hub.getAllJax, Startup.signal.Interest, Callback.After, jax.root.toMathML) to v3/v4 (startup.promise synchronous mock, typesetClear, typesetPromise, startup.toMML, startup.document.getMathItemsWithin).
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: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants