Skip to content

Use Mathjax v4 by default#14080

Merged
AA-Turner merged 8 commits intosphinx-doc:masterfrom
mgeier:mathjax4
Nov 27, 2025
Merged

Use Mathjax v4 by default#14080
AA-Turner merged 8 commits intosphinx-doc:masterfrom
mgeier:mathjax4

Conversation

@mgeier
Copy link
Contributor

@mgeier mgeier commented Nov 22, 2025

Fixes #14022.

MathJax v4 has been released, and it seems to be compatible with v3.

I have added mathjax4_config for consistency, even though it would work just as well when mathjax3_config is used.

I don't remember what the original intention was, but I have found out that async was previously used by default, even though defer was suggested by the MathJax docs. I have now flipped that to using defer by default. This can be changed (just as before) via mathjax_options.

TODO

  • CHANGES.rst
  • update versionadded

@AA-Turner AA-Turner added the extensions:mathematics The `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensions label Nov 24, 2025
# Conflicts:
#	doc/usage/extensions/math.rst
#	sphinx/ext/mathjax.py
#	tests/test_extensions/test_ext_math.py
@AA-Turner
Copy link
Member

@mgeier what do you think of the changes here?

One thing I think we could do is put mathjax{2,3,4}_config in an if/elif/else block so that at most one of them is used. Currently, all will be added, but then they'll overwrite each other in the JS interpreter.

My understanding of #9094 is that it's useful for third-party extensions to continue to have different config options for this (instead of e.g. mathjax_version = {2,3,4,...}, but I don't know the detail here.

A

@AA-Turner AA-Turner added the awaiting:response Waiting for a response from the author of this issue label Nov 24, 2025
@mgeier
Copy link
Contributor Author

mgeier commented Nov 27, 2025

Thanks for the changes, they are looking good!

One thing I think we could do is put mathjax{2,3,4}_config in an if/elif/else block so that at most one of them is used. Currently, all will be added, but then they'll overwrite each other in the JS interpreter.

Yeah, we could do this.

I originally didn't to that for mathjax3_config because I considered it an unlikely enough error case, and I didn't do it here, either.

I'm fine with it either way.

My understanding of #9094 is that it's useful for third-party extensions to continue to have different config options for this (instead of e.g. mathjax_version = {2,3,4,...}, but I don't know the detail here.

Yes, it was useful for setting up some heuristics, but technically, the same thing could be done with mathjax_version.

However, I wouldn't recommend adding mathjax_version because:

  • it would be confusing to have mathjax_version and mathjax{2,3,4}_config at the same time, even if latter might become deprecated at some point
  • we would have to provide multiple default URLs for the different versions, currently we only need one default URL (which I think is a good thing)
  • it might be confusing if a user specifies some version (implicitly) with a custom URL and a different version with mathjax_version (however, to be honest, a similar, but I think less strong argument could be made with mathjax{2,3,4}_config)

@AA-Turner AA-Turner removed the awaiting:response Waiting for a response from the author of this issue label Nov 27, 2025
@AA-Turner AA-Turner merged commit 483daf7 into sphinx-doc:master Nov 27, 2025
51 of 52 checks passed
@mgeier mgeier deleted the mathjax4 branch November 27, 2025 21:54
@AA-Turner AA-Turner added this to the 9.0.0 milestone Dec 1, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

extensions:mathematics The `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MathJax 4.0 support

2 participants