Skip to content

Workaround for issue with MathJax 4 in RTL contexts - #3106

Merged
pstaabp merged 1 commit into
openwebwork:WeBWorK-2.21from
taniwallach:mathjax-413-rtl-patch
Aug 3, 2026
Merged

Workaround for issue with MathJax 4 in RTL contexts#3106
pstaabp merged 1 commit into
openwebwork:WeBWorK-2.21from
taniwallach:mathjax-413-rtl-patch

Conversation

@taniwallach

@taniwallach taniwallach commented Aug 3, 2026

Copy link
Copy Markdown
Member

MathJax 4.1.3 does not display math properly when inside an RTL setting, and that version will be in WeBWorK 2.21 (unless MathJax 4.2 is released and a transition is made before the release of 2.21).

The problem occurs in both SVG an CHTML output.

Things were fine with MathJax 3.

@dpvc provided the workaround added here in mathjax/MathJax#3589 .

For the future, MathJax 4.2 will fix the issue by adding a dir="ltr" attribute to the mjx-container element. That is in mathjax/MathJax-src#1526
so this change can be removed WeBWorK transitions to MathJax 4.2.

The issue can be seen using the following sample problem. Pay attention to how the inline math renders in the Hebrew portion which is in a DIV set to rtl.


DOCUMENT();

loadMacros( 'PGstandard.pl', 'PGML.pl');

BEGIN_PGML

When [` a \ne 0 `], there are two solutions to [` ax^2 + bx + c = 0 `] and they are
[```
  x = {-b \pm \sqrt{b^2-4ac} \over 2a}.
```]

[@ openDiv( { 'dir' => 'rtl' } )  @]*
כאשר [` a \ne 0 `]
יש 2 פתרונות למשוואה
[` ax^2 + bx + c = 0 `]
והם
[```
  x = {-b \pm \sqrt{b^2-4ac} \over 2a}
```]

[@ closeDiv() @]*
END_PGML
ENDDOCUMENT();

Here is an images of the issue when this problem is rendered before the change in this PR.
MathJax-4-RTL-issue

Once the patch is applied, the two portions of inline math will display properly.

@taniwallach
taniwallach requested a review from drgrice1 August 3, 2026 12:27
@drgrice1

drgrice1 commented Aug 3, 2026

Copy link
Copy Markdown
Member

Make sure to run npm run prettier-format from the htdocs directory when JavaScript or CSS files are modified (and when .html.ep files are modified with the develop branch). Then commit the changes. That is the reason for the errors from the formatting workflow.

See mathjax/MathJax#3589 where @dpvc provided
the workaround added here into mathjax-config.js.

For the future, MathJax 4.2 will fix the issue by adding a dir="ltr"
attribute to the mjx-container element. That is in
mathjax/MathJax-src#1526
so this change can be removed WeBWorK transitions to MathJax 4.2.
@taniwallach
taniwallach force-pushed the mathjax-413-rtl-patch branch from 7a669ec to 84de776 Compare August 3, 2026 18:17
@taniwallach

Copy link
Copy Markdown
Member Author

npm run prettier-format

Thanks - done. Sorry, I have not been doing much coding for WW recently, and am not on top of these additional steps.

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

Looks good.

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

Looks good.

@pstaabp
pstaabp merged commit 815d7b4 into openwebwork:WeBWorK-2.21 Aug 3, 2026
2 checks passed
@taniwallach
taniwallach deleted the mathjax-413-rtl-patch branch August 3, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants