Skip to content

Conversation

@randolf-scholz
Copy link

@randolf-scholz randolf-scholz commented Nov 3, 2025

Fixes #14023

Note: git was telling me that these two files were modified, I'm not sure what's going on:

(sphinx) rscholz@Z890:~/github/CONTRIBUTING/sphinx$ git reset --hard
error: failed to encode 'tests/roots/test-root/wrongenc.inc' from UTF-8 to latin-1
error: failed to encode 'tests/roots/test-warnings/wrongenc.inc' from UTF-8 to latin-1
HEAD is now at e5cf9e0da allow mathjax3_config to point to a JS file
(sphinx) rscholz@Z890:~/github/CONTRIBUTING/sphinx$ git status
On branch mathjax_custom_js
Your branch is up to date with 'origin/mathjax_custom_js'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   tests/roots/test-root/wrongenc.inc
        modified:   tests/roots/test-warnings/wrongenc.inc

if not config_filepath.exists():
msg = f'mathjax3_config file not found: {config_filepath!s}'
raise ExtensionError(msg)
if not config_filepath.is_file() or config_filepath.suffix != '.js':
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other extension than .js to consider? I am not familiar with javascript

Comment on lines +379 to +395
@pytest.mark.sphinx(
'html',
testroot='ext-math',
confoverrides={
'extensions': ['sphinx.ext.mathjax'],
'mathjax3_config': '_static/custom_mathjax_config.js',
},
)
def test_mathjax3_js_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


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just duplicated the test above and moved the config to _static/custom_mathjax_config.js.

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.

MathJax: allow passing custom JS config

1 participant