Skip to content

feat!: upgrade to mathjax v3#33555

Draft
navinkarkera wants to merge 9 commits into
openedx:masterfrom
open-craft:navin/upgrade-mathjax-v3
Draft

feat!: upgrade to mathjax v3#33555
navinkarkera wants to merge 9 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 version 2 to 3.2.1. MathJax v3 is a complete rewrite of MathJax with changes in its internal structure so it is not a drop in replacement to v2.

This PR implements the changes required to make use of v3 and still have the same functionality as before and hopefully without breaking anything.

Useful information to include:

  • This will impact both learners and course authors.
  • There are no changes in UI

Supporting information

Testing instructions

  • Setup master devstack
  • Start lms, cms and frontend-app-learning using make {lms,cms,frontend-app-learning}-up.
  • Checkout this PR/branch and run make {lms,cms}-static.
  • Restart lms and cms using make {lms,cms}-restart to make sure new static files are served.
  • Visit studio on http://localhost:18010/
  • Go to Network tab in console and search for mathjax to make sure that mathjax v3 is being loaded.
  • Go to demo course and create a new unit.
  • Add a following components:
    • Problem > numerical input
    • Problem > advanced > Math expression input problem
    • Text > Raw HTML: add \[\mathbf{x}^{G} = \frac{1} {M}\sum^{3}_{i=1}m_i\mathbf{x}^{G}_i\] formulae in the text.
  • In the problem blocks input field try adding some asciimath formulas, for example: R_1*R_2/R_3, A*x^2 + sqrt(y). Make sure preview works as expected.
  • Go to unit with title Mathematical Expressions in second section and play with the input field. In this field you can also enter tex as it is directly converted by MathJax while numerical input problems use a python library called calc to parse the text first and they cannot parse tex.
  • Go to next section with title Chemical Equations, play with the input field.
  • Publish the changes and click on View Live Version button and test above blocks again in LMS.
  • To test mathematical expressions in discussions, go to discussions tab and create a post. Add some text with math and tex formulas.
    • Remember to escape backtick with \, example: \`A*x^2 + sqrt(y)\`
    • Escape \[ and \( with additional \ for tex commands, example: \\[A \cdot x^2 + \sqrt{y}\\], \\(A \cdot x^2 + \sqrt{y}\\)
  • Repeat above tests with and without this PR changes, i.e. with MathJax v2 and v3.

Please let me know if we are using mathjax in some other components which we need to test.

Deadline

None

Other information

None

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

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.

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

Comment thread common/static/js/capa/src/formula_equation_preview.js Outdated
@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/mathjax@2.7.5/MathJax.js'
+ '?config=TeX-MML-AM_SVG&delayStartupUntil=configured',
'https://cdn.jsdelivr.net/npm/mathjax@3.2.1/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/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_HTMLorMML';
vendorScript.src = 'https://cdn.jsdelivr.net/npm/mathjax@3.2.1/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

@mphilbrick211 mphilbrick211 removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Aug 5, 2025
@mphilbrick211

Copy link
Copy Markdown

Hi @navinkarkera! Just checking in on this :)

@openedx-webhooks openedx-webhooks added the core contributor PR author is a Core Contributor (who may or may not have write access to this repo). label Sep 24, 2025
@navinkarkera

Copy link
Copy Markdown
Contributor Author

@mphilbrick211 Sorry, I don't have any update here.

@wittjeff

Copy link
Copy Markdown

Version 4.0.0 is now available.

@feanil

feanil commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

@navinkarkera I'm gonna move this to draft until you're ready to with the MathJax 4.0 update. Once it's ready for review let me know and I can help get it reviewed and landed.

@feanil feanil marked this pull request as draft November 19, 2025 20:31
@feanil feanil self-assigned this Nov 19, 2025
fix: use asciimath

test: fix mathjax related tests

fix: lint issues

fix: mathjax_delay_renderer

test: fix mathjax related tests
@navinkarkera navinkarkera force-pushed the navin/upgrade-mathjax-v3 branch from c7ed9e1 to e6c9a20 Compare November 28, 2025 15:14
@feanil feanil added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Jan 9, 2026
@feanil

feanil commented May 8, 2026

Copy link
Copy Markdown
Contributor

@navinkarkera are you planning to come back to this?

@navinkarkera

Copy link
Copy Markdown
Contributor Author

@feanil I do have a branch that works with version 4 but need to rebase and test it out. But the ability to select different versions per course is not implemented and I don't have the capacity right now.

- Pin CDN URLs to mathjax@4.1.2
- Fix mathjax_delay_renderer.js immediate path to pass DOM node
- Add null guard in capa/display.js for missing math element
- Fix CSS syntax: comma to semicolon in MathJax SVG rules
- Pass textContent instead of innerHTML for security
- mathjax_delay_renderer.js: add typesetClear before .html() in both immediate and delayed paths, so MathJax v3/v4 re-renders replaced content
- capa/display.js refreshMath: replace v2 Hub.Queue/getAllJax with v3/v4 typesetClear/typesetPromise; add typesetClear before setting preview textContent; unify rendering to AsciiMath/backtick for all non-tex-delimited input (fixes formula preview for formulaequationinput where * → multiplication and / → fraction instead of literal chars)
- capa/display_spec.js: add tests for calculator syntax backtick wrapping, TeX delimiter preservation, and empty-input early return
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 waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc.

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

10 participants