summaryrefslogtreecommitdiff
path: root/sphinx/ext
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2021-03-21 11:58:52 +0100
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-04-24 18:30:32 +0900
commit529fb1d1ce4be6979ec0d845c51902f2cbcea730 (patch)
tree6ae65a6df34811c67cd5703a231c44f075e6ab40 /sphinx/ext
parente21e18441fceefdcd64e52d6686100d7e1323664 (diff)
downloadsphinx-git-529fb1d1ce4be6979ec0d845c51902f2cbcea730.tar.gz
Add mathjax3_config config option
Diffstat (limited to 'sphinx/ext')
-rw-r--r--sphinx/ext/mathjax.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py
index 1cd2bd1cc..301c0d699 100644
--- a/sphinx/ext/mathjax.py
+++ b/sphinx/ext/mathjax.py
@@ -27,6 +27,8 @@ from sphinx.writers.html import HTMLTranslator
# https://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn
MATHJAX_URL = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
+logger = sphinx.util.logging.getLogger(__name__)
+
def html_visit_math(self: HTMLTranslator, node: nodes.math) -> None:
self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate nohighlight'))
@@ -84,9 +86,16 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: Dict
options.update(app.config.mathjax_options)
app.add_js_file(app.config.mathjax_path, **options) # type: ignore
- if app.config.mathjax_config:
- body = "MathJax.Hub.Config(%s)" % json.dumps(app.config.mathjax_config)
- app.add_js_file(None, type="text/x-mathjax-config", body=body)
+ 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)
def setup(app: Sphinx) -> Dict[str, Any]:
@@ -99,6 +108,8 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('mathjax_inline', [r'\(', r'\)'], 'html')
app.add_config_value('mathjax_display', [r'\[', r'\]'], 'html')
app.add_config_value('mathjax_config', None, 'html')
+ app.add_config_value('mathjax2_config', lambda c: c.mathjax_config, 'html')
+ app.add_config_value('mathjax3_config', None, 'html')
app.connect('html-page-context', install_mathjax)
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}