diff --git a/CHANGES b/CHANGES
index 8465a6bf7d3..64aa161dfe2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -23,6 +23,7 @@ Bugs fixed
* #11634: Fixed inheritance diagram relative link resolution
for sibling files in a subdirectory.
Patch by Albert Shih.
+* #11659: Allow ``?config=...`` in :confval:`mathjax_path`.
Testing
-------
diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index 3515edd44aa..85067be0178 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -1085,7 +1085,13 @@ def js_tag(js: _JavaScript | str) -> str:
return f''
uri = pathto(os.fspath(js.filename), resource=True)
- if checksum := _file_checksum(outdir, js.filename):
+ if 'MathJax.js?' in os.fspath(js.filename):
+ # MathJax v2 reads a ``?config=...`` query parameter,
+ # special case this and just skip adding the checksum.
+ # https://docs.mathjax.org/en/v2.7-latest/configuration.html#considerations-for-using-combined-configuration-files
+ # https://github.com/sphinx-doc/sphinx/issues/11658
+ pass
+ elif checksum := _file_checksum(outdir, js.filename):
uri += f'?v={checksum}'
if attrs:
return f''
diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py
index 9e2367fe3fd..d5331f839bf 100644
--- a/tests/test_ext_math.py
+++ b/tests/test_ext_math.py
@@ -283,6 +283,34 @@ def test_mathjax_options_defer_for_mathjax2(app, status, warning):
assert ('' in content
+
+
+@pytest.mark.sphinx(
+ 'html', testroot='ext-math',
+ confoverrides={
+ 'extensions': ['sphinx.ext.mathjax'],
+ 'mathjax_path': 'MathJax.js?config=scipy-mathjax',
+ },
+)
+def test_mathjax_path_config(app):
+ app.builder.build_all()
+
+ content = (app.outdir / 'index.html').read_text(encoding='utf8')
+ assert '' in content
+
+
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax']})
def test_mathjax_is_installed_only_if_document_having_math(app, status, warning):