Skip to content

Stop wrapping math in <script type="math/tex">...</script>. - #1499

Open
drgrice1 wants to merge 1 commit into
openwebwork:developfrom
drgrice1:mathjax-no-script-tags
Open

Stop wrapping math in <script type="math/tex">...</script>.#1499
drgrice1 wants to merge 1 commit into
openwebwork:developfrom
drgrice1:mathjax-no-script-tags

Conversation

@drgrice1

@drgrice1 drgrice1 commented Aug 12, 2026

Copy link
Copy Markdown
Member

This used to be handled directly by MathJax long ago, but it no longer does so. Using \(...\) or \[...\] now works. So just do that. Also make sure that &, <, and > are properly HTML escaped. This actually gets done when the post_process_content method is called, but just in case the general_math_ev3 method also does this. Note the Mojo::DOM parser is smart enough not to doubly escape these things.

The script tag handling in the webwork2 mathjax-config.js file seems to be causing issues in some cases, and switching to using \(...\) or \[...\] fixes those issues. See #1498 for details.

It is also time to start doing some code clean up. I just did some minimal clean up of the general_math_ev3 method.

@drgrice1
drgrice1 force-pushed the mathjax-no-script-tags branch from 2491b05 to b258d6f Compare August 12, 2026 21:20

@somiaj somiaj 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 can confirm it fixes the issue. Probably needs a hotfix.

@drgrice1
drgrice1 force-pushed the mathjax-no-script-tags branch from b258d6f to 149b0cd Compare August 12, 2026 22:02
@dpvc

dpvc commented Aug 12, 2026

Copy link
Copy Markdown
Member

If there are no more <script type="math"> tags being generated, you should be able to remove the lines

https://github.com/openwebwork/webwork2/blob/c7060fe858cb27b17aad5cf77574ff7d1ae3e1fa/htdocs/js/MathJaxConfig/mathjax-config.js#L147-L171

from the MathJax configuration, as well as

https://github.com/openwebwork/webwork2/blob/c7060fe858cb27b17aad5cf77574ff7d1ae3e1fa/htdocs/js/MathJaxConfig/mathjax-config.js#L133

It must have something to do with the faked MathItem that is created there. I'll look into it, but since these seems to resolve the problem, I'm n to sure ho much time I can put to it.

@drgrice1

Copy link
Copy Markdown
Member Author

I do plan to put in a pull request to webwork2 to remove that script tag handling in mathjax-config.js. I have it already committed in a branch. I was just tweaking this one with the HTML escaping. I need to check on the escaping of the feedback case in PG.pl yet.

@somiaj: The > doesn't really need it as long as there is not matching unescaped < preceding it.

@somiaj

somiaj commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Should we worry about breaking third party macros and the likes if we remove lines that deal with the script tags? I am not worried if we break them, just something to consider.

@drgrice1

Copy link
Copy Markdown
Member Author

How would removing the script tag break a third party macro?

@somiaj

somiaj commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

@drgrice1 Yea, I knew they didn't need to be escaped, I was just thinking in terms of consistency, someone might wonder why < changes to &lt; but > doesn't. Though might not affect the rendering in the end anyways.

@somiaj

somiaj commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

I was just considering what was happening of some third party macro was using <script type="math/tex">...</script> for their math output in HTML_MathJax mode. But probably not being done or something to worry about.

@drgrice1

Copy link
Copy Markdown
Member Author

Okay, since the feedback case is handled in post processing anyway, and always goes through Mojo::DOM, that case is always escaped. So this is good as is.

@drgrice1

Copy link
Copy Markdown
Member Author

@somiaj: You might note that in the usual way that problems are rendered via the translator, the > ends up getting escaped anyway when the post_process_content method of the translator is called, and the problem text is parsed by Mojo::DOM.

@drgrice1
drgrice1 force-pushed the mathjax-no-script-tags branch from 149b0cd to 1be02bb Compare August 12, 2026 22:58
@drgrice1

Copy link
Copy Markdown
Member Author

I switched to using HTML::Entities::decode_entities and encode > as well. Since the HTML::Entities package is available, might as well. It is already used more generally for HTML display mode below.

Comment thread lib/WeBWorK/PG.pm Outdated
@drgrice1
drgrice1 force-pushed the mathjax-no-script-tags branch from 1be02bb to 705618d Compare August 13, 2026 00:26

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

Double checked again that the issue is fixed. I still think this needs to be a hotfix as the broken problem was originally from the OPL.

drgrice1 added a commit to drgrice1/webwork2 that referenced this pull request Aug 13, 2026
The injection of `<script type="math/tex">...</script>` tags by PG is
removed by openwebwork/pg#1499.  So the script
tag handling in the `mathjax-config.js` file is no longer needed.
This used to be handled directly by MathJax long ago, but it no longer
does so.  Using `\(...\)` or `\[...\]` now works.  So just do that. Also
make sure that `&`, `<`, and `>` are properly HTML escaped. This
actually gets done when the `post_process_content` method is called, but
just in case the `general_math_ev3` method also does this. Note the
`Mojo::DOM` parser is smart enough not to doubly escape these things.

The script tag handling in the webwork2 `mathjax-config.js` file seems
to be causing issues in some cases, and switching to using `\(...\)` or
`\[...\]` fixes those issues.  See openwebwork#1498 for details.

It is also time to start doing some code clean up. I just did some
minimal clean up of the `general_math_ev3` method.
@drgrice1
drgrice1 force-pushed the mathjax-no-script-tags branch from 705618d to ef8a8ff Compare August 13, 2026 19:04
drgrice1 added a commit to drgrice1/webwork2 that referenced this pull request Aug 13, 2026
The injection of `<script type="math/tex">...</script>` tags by PG is
removed by openwebwork/pg#1499.  So the script
tag handling in the `mathjax-config.js` file is no longer needed.
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