Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MathJax configuration should appear before loading MathJax itself #9878

Closed
juliangilbey opened this issue Nov 21, 2021 · 1 comment
Closed

Comments

@juliangilbey
Copy link

Describe the bug

According to the MathJax docs (see v2.7: http://docs.mathjax.org/en/v2.7-latest/configuration.html#using-in-line-configuration-options and v3.2: http://docs.mathjax.org/en/v3.2-latest/web/configuration.html#configuration-using-an-in-line-script), it is necessary to run the configuration before loading MathJax itself. In

if app.registry.html_assets_policy == 'always' or domain.has_equations(pagename):
# Enable mathjax only if equations exists
options = {'defer': 'defer'}
if app.config.mathjax_options:
options.update(app.config.mathjax_options)
app.add_js_file(app.config.mathjax_path, **options) # type: ignore
if app.config.mathjax2_config:
if app.config.mathjax_path == MATHJAX_URL:
logger.warning(
'mathjax_config/mathjax2_config does not work '
'for the current MathJax version, use mathjax3_config instead')
body = 'MathJax.Hub.Config(%s)' % json.dumps(app.config.mathjax2_config)
app.add_js_file(None, type='text/x-mathjax-config', body=body)
if app.config.mathjax3_config:
body = 'window.MathJax = %s' % json.dumps(app.config.mathjax3_config)
app.add_js_file(None, body=body)
though, the app.add_js_file() method for the main MathJax.js script is called before the config scripts are added; the solution to this would be to move the first part of the code here, dealing with the MathJax.js script, after the two if blocks which handle the mathjax2_config and mathjax3_config.

How to Reproduce

$ git clone https://github.com/juliangilbey/abydos.git
$ cd abydos
$ git checkout sphinxbug
$ pip install cython
$ pip install -r requirements-dev.txt
$ pip install abydos
$ cd docs
$ make html SPHINXOPTS="-D language=de"
$ # open _build/html/abydos.distance.html and see the MathJax header lines, somewhere around line 18

(Note that there may be a lot of "undefined label" warnings, but I do not yet understand the source of these; this is an unrelated issue.)

Expected behavior

The MathJax lines in the above html file appear as:

        <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script type="text/x-mathjax-config">MathJax.Hub.Config("{tex2jax: {inlineMath: [ ['$','$'], ['\\(','\\)'] ], processEscapes: true}}")</script>

but should appear in the opposite order as:

        <script type="text/x-mathjax-config">MathJax.Hub.Config("{tex2jax: {inlineMath: [ ['$','$'], ['\\(','\\)'] ], processEscapes: true}}")</script>
        <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

Your project

https://github.com/juliangilbey/abydos.git

Screenshots

No response

OS

Linux

Python version

3.9

Sphinx version

4.2.0 (same issue occurs with 4.3.0)

Sphinx extensions

sphinx.ext.mathjax

Extra tools

No response

Additional context

No response

tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 21, 2021
@tk0miya tk0miya added this to the 4.4.0 milestone Nov 21, 2021
tk0miya added a commit that referenced this issue Nov 22, 2021
…oaded_earlier

Fix #9878: mathjax: MathJax config is placed after loading MathJax
@juliangilbey
Copy link
Author

Oh, and it turns out this fix, while harmless, is not actually needed, because the defer option means that MathJax.js is not actually loaded until later. But this order is the way it appears in the MathJax documentation, so it might be beneficial anyway. Sorry for the unnecessary issue, and thanks for dealing with it so efficiently.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants