Use Mathjax v4 by default (#14080)

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
Matthias GeierandAdam Turner authored and GitHub committed 2025-11-27 21:36:07 +00:00
1 parent a82b34feea
commit 483daf722d
4 files changed
+103 -24

No files matched your search

+29 -6
View File
@@ -17,6 +17,8 @@ from sphinx.testing.util import assert_node
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
FAKE_MATHJAX_URL = 'https://example.org/fake-mathjax.js'
def has_binary(binary: str) -> bool:
try:
@@ -125,7 +127,7 @@ def test_mathjax_options(app: SphinxTestApp) -> None:
shutil.rmtree(app.outdir)
assert (
'<script defer="defer" integrity="sha384-0123456789" '
'src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">'
f'src="{MATHJAX_URL}">'
'</script>'
) in content
@@ -363,20 +365,38 @@ def test_math_compat(app: SphinxTestApp) -> None:
)
@pytest.mark.sphinx(
'html',
testroot='ext-math',
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax4_config': {'extensions': ['tex2jax.js']},
},
)
def test_mathjax4_config(app: SphinxTestApp) -> None:
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert MATHJAX_URL in content
assert '<script defer="defer" src="%s">' % MATHJAX_URL in content
assert '<script>window.MathJax = {"extensions": ["tex2jax.js"]}</script>' in content
@pytest.mark.sphinx(
'html',
testroot='ext-math',
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax3_config': {'extensions': ['tex2jax.js']},
'mathjax_path': FAKE_MATHJAX_URL,
},
)
def test_mathjax3_config(app: SphinxTestApp) -> None:
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert MATHJAX_URL in content
assert '<script defer="defer" src="%s">' % MATHJAX_URL in content
assert FAKE_MATHJAX_URL in content
assert f'<script defer="defer" src="{FAKE_MATHJAX_URL}">' in content
assert '<script>window.MathJax = {"extensions": ["tex2jax.js"]}</script>' in content
@@ -405,13 +425,14 @@ def test_mathjax_config_path_config(app: SphinxTestApp) -> None:
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax2_config': {'extensions': ['tex2jax.js']},
'mathjax_path': FAKE_MATHJAX_URL,
},
)
def test_mathjax2_config(app: SphinxTestApp) -> None:
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<script async="async" src="%s">' % MATHJAX_URL in content
assert f'<script async="async" src="{FAKE_MATHJAX_URL}">' in content
assert (
'<script type="text/x-mathjax-config">'
'MathJax.Hub.Config({"extensions": ["tex2jax.js"]})'
@@ -425,10 +446,10 @@ def test_mathjax2_config(app: SphinxTestApp) -> None:
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax_options': {'async': 'async'},
'mathjax3_config': {'extensions': ['tex2jax.js']},
'mathjax4_config': {'extensions': ['tex2jax.js']},
},
)
def test_mathjax_options_async_for_mathjax3(app: SphinxTestApp) -> None:
def test_mathjax_options_async_for_mathjax4(app: SphinxTestApp) -> None:
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
@@ -509,6 +530,7 @@ def test_mathjax_is_not_installed_if_no_equations(app: SphinxTestApp) -> None:
content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert 'MathJax.js' not in content
assert MATHJAX_URL not in content
@pytest.mark.sphinx(
@@ -575,6 +597,7 @@ def test_mathjax_is_not_installed_if_no_equations_singlehtml(
content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert 'MathJax.js' not in content
assert MATHJAX_URL not in content
@pytest.mark.sphinx(