diff options
Diffstat (limited to 'sphinx/ext/mathjax.py')
-rw-r--r-- | sphinx/ext/mathjax.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index eb06908d3..30d038d84 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -81,11 +81,6 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: Dict domain = cast(MathDomain, app.env.get_domain('math')) 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( @@ -97,6 +92,18 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: Dict body = 'window.MathJax = %s' % json.dumps(app.config.mathjax3_config) app.add_js_file(None, body=body) + options = {} + if app.config.mathjax_options: + options.update(app.config.mathjax_options) + if 'async' not in options and 'defer' not in options: + if app.config.mathjax3_config: + # Load MathJax v3 via "defer" method + options['defer'] = 'defer' + else: + # Load other MathJax via "async" method + options['async'] = 'async' + app.add_js_file(app.config.mathjax_path, **options) + def setup(app: Sphinx) -> Dict[str, Any]: app.add_html_math_renderer('mathjax', |