Skip to content

Commit

Permalink
Allow ?config=... in mathjax_path (#11659)
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Aug 30, 2023
1 parent 4692208 commit 7d046a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
-------
Expand Down
8 changes: 7 additions & 1 deletion sphinx/builders/html/__init__.py
Expand Up @@ -1085,7 +1085,13 @@ def js_tag(js: _JavaScript | str) -> str:
return f'<script>{body}</script>'

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'<script {" ".join(sorted(attrs))} src="{uri}"></script>'
Expand Down
28 changes: 28 additions & 0 deletions tests/test_ext_math.py
Expand Up @@ -283,6 +283,34 @@ def test_mathjax_options_defer_for_mathjax2(app, status, warning):
assert ('<script defer="defer" src="%s">' % MATHJAX_URL in content)


@pytest.mark.sphinx(
'html', testroot='ext-math',
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax_path': 'MathJax.js',
},
)
def test_mathjax_path(app):
app.builder.build_all()

content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<script async="async" src="_static/MathJax.js"></script>' 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 '<script async="async" src="_static/MathJax.js?config=scipy-mathjax"></script>' 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):
Expand Down

0 comments on commit 7d046a8

Please sign in to comment.