From e5cf9e0da88f8a9835011d89c15146d25806f619 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Mon, 3 Nov 2025 23:03:06 +0100 Subject: [PATCH 01/11] allow mathjax3_config to point to a JS file --- CHANGES.rst | 2 ++ doc/usage/extensions/math.rst | 7 ++--- sphinx/ext/mathjax.py | 26 ++++++++++++++++--- .../_static/custom_mathjax_config.js | 1 + tests/test_extensions/test_ext_math.py | 17 ++++++++++++ 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 tests/roots/test-ext-math/_static/custom_mathjax_config.js diff --git a/CHANGES.rst b/CHANGES.rst index 3a90d66f08d..ec602f9c0a3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -68,6 +68,8 @@ Features added Patch by Jean-François B. * #13508: Initial support for :pep:`695` type aliases. Patch by Martin Matouš, Jeremy Maitin-Shepard, and Adam Turner. +* 14023: Allow ``mathjax3_config`` to be a string pointing to a JS file. + Patch by Randolf Scholz. Bugs fixed ---------- diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index fb41d66d8fb..e8885cb0f0d 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -264,12 +264,13 @@ Sphinx but is set to automatically include it from a third-party site. or "defer" key is set. .. confval:: mathjax3_config - :type: :code-py:`dict[str, Any] | None` + :type: :code-py:`str | dict[str, Any] | None` :default: :code-py:`None` The configuration options for MathJax v3 (which is used by default). - The given dictionary is assigned to the JavaScript variable - ``window.MathJax``. + A custom javascript file path can be given as a string. + If a dictionary is given, it is converted to a JSON object and assigned + to the JavaScript variable ``window.MathJax``. For more information, please read `Configuring MathJax`__. __ https://docs.mathjax.org/en/latest/web/configuration.html#configuration diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index 62220cc697f..cf0667013e1 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -105,9 +105,27 @@ def install_mathjax( ) body = 'MathJax.Hub.Config(%s)' % json.dumps(app.config.mathjax2_config) builder.add_js_file('', type='text/x-mathjax-config', body=body) - if app.config.mathjax3_config: - body = 'window.MathJax = %s' % json.dumps(app.config.mathjax3_config) - builder.add_js_file('', body=body) + match app.config.mathjax3_config: + case None: + pass + case str(config_filename): + config_filepath = app.srcdir / config_filename + if not config_filepath.exists(): + raise ExtensionError(f'mathjax3_config file not found') + if not config_filepath.is_file(): + raise ExtensionError('mathjax3_config is not a file') + if config_filepath.suffix != '.js': + raise ExtensionError('mathjax3_config must be a .js file') + with config_filepath.open(encoding='utf-8') as f: + body = f.read() + builder.add_js_file('', body=body) + case dict(config_dict): + body = f"window.MathJax = {json.dumps(config_dict)}" + builder.add_js_file('', body=body) + case _: + raise ExtensionError( + 'mathjax3_config must be a str (filename), dict, or None' + ) options = {} if app.config.mathjax_options: @@ -147,7 +165,7 @@ def setup(app: Sphinx) -> ExtensionMetadata: types=frozenset({dict, NoneType}), ) app.add_config_value( - 'mathjax3_config', None, 'html', types=frozenset({dict, NoneType}) + 'mathjax3_config', None, 'html', types=frozenset({dict, str, NoneType}) ) app.connect('html-page-context', install_mathjax) diff --git a/tests/roots/test-ext-math/_static/custom_mathjax_config.js b/tests/roots/test-ext-math/_static/custom_mathjax_config.js new file mode 100644 index 00000000000..7a2bda39383 --- /dev/null +++ b/tests/roots/test-ext-math/_static/custom_mathjax_config.js @@ -0,0 +1 @@ +window.MathJax = {"extensions": ["tex2jax.js"]} \ No newline at end of file diff --git a/tests/test_extensions/test_ext_math.py b/tests/test_extensions/test_ext_math.py index 9c8e620d655..529a5916886 100644 --- a/tests/test_extensions/test_ext_math.py +++ b/tests/test_extensions/test_ext_math.py @@ -376,6 +376,23 @@ def test_mathjax3_config(app: SphinxTestApp) -> None: assert '' in content +@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 '' in content + + @pytest.mark.sphinx( 'html', testroot='ext-math', From 2d7dbb0b610879fa0771b38543788204153be3cc Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Mon, 3 Nov 2025 23:12:28 +0100 Subject: [PATCH 02/11] linter fixes --- sphinx/ext/mathjax.py | 17 ++++++++--------- tests/test_extensions/test_ext_math.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index cf0667013e1..548a330665c 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -111,21 +111,20 @@ def install_mathjax( case str(config_filename): config_filepath = app.srcdir / config_filename if not config_filepath.exists(): - raise ExtensionError(f'mathjax3_config file not found') - if not config_filepath.is_file(): - raise ExtensionError('mathjax3_config is not a file') - if config_filepath.suffix != '.js': - raise ExtensionError('mathjax3_config must be a .js file') + msg = f'mathjax3_config file not found: {config_filepath!s}' + raise ExtensionError(msg) + if not config_filepath.is_file() or config_filepath.suffix != '.js': + msg = 'mathjax3_config must be a .js file' + raise ExtensionError(msg) with config_filepath.open(encoding='utf-8') as f: body = f.read() builder.add_js_file('', body=body) case dict(config_dict): - body = f"window.MathJax = {json.dumps(config_dict)}" + body = f'window.MathJax = {json.dumps(config_dict)}' builder.add_js_file('', body=body) case _: - raise ExtensionError( - 'mathjax3_config must be a str (filename), dict, or None' - ) + msg = 'mathjax3_config must be a str (filename), dict, or None' + raise ExtensionError(msg) options = {} if app.config.mathjax_options: diff --git a/tests/test_extensions/test_ext_math.py b/tests/test_extensions/test_ext_math.py index 529a5916886..629997ea4aa 100644 --- a/tests/test_extensions/test_ext_math.py +++ b/tests/test_extensions/test_ext_math.py @@ -381,7 +381,7 @@ def test_mathjax3_config(app: SphinxTestApp) -> None: testroot='ext-math', confoverrides={ 'extensions': ['sphinx.ext.mathjax'], - 'mathjax3_config': "_static/custom_mathjax_config.js", + 'mathjax3_config': '_static/custom_mathjax_config.js', }, ) def test_mathjax3_js_config(app: SphinxTestApp) -> None: From fbe53c3fdaf19ce2fee148fb7d1082170061fe84 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Wed, 5 Nov 2025 19:44:22 +0100 Subject: [PATCH 03/11] updated docstring --- doc/usage/extensions/math.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index e8885cb0f0d..75588d5ddd5 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -268,9 +268,9 @@ Sphinx but is set to automatically include it from a third-party site. :default: :code-py:`None` The configuration options for MathJax v3 (which is used by default). - A custom javascript file path can be given as a string. - If a dictionary is given, it is converted to a JSON object and assigned - to the JavaScript variable ``window.MathJax``. + Expects a string with the relative path to a javascript file with the config. + Alternatively, a dictionary can be given, which is converted to a JSON object + and assigned to the JavaScript variable ``window.MathJax``. For more information, please read `Configuring MathJax`__. __ https://docs.mathjax.org/en/latest/web/configuration.html#configuration From 3b58c27919e53430a38fd80a6f8a2c05e0707f40 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Thu, 6 Nov 2025 18:39:05 +0100 Subject: [PATCH 04/11] added missing hashtag --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 59519680eb8..aada4097bc2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -68,7 +68,7 @@ Features added Patch by Jean-François B. * #13508: Initial support for :pep:`695` type aliases. Patch by Martin Matouš, Jeremy Maitin-Shepard, and Adam Turner. -* 14023: Allow ``mathjax3_config`` to be a string pointing to a JS file. +* #14023: Allow ``mathjax3_config`` to be a string pointing to a JS file. Patch by Randolf Scholz. Bugs fixed From ee27a683e578bf818b971cbb8546483746306add Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 7 Nov 2025 08:38:01 +0100 Subject: [PATCH 05/11] Update doc/usage/extensions/math.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- doc/usage/extensions/math.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index 75588d5ddd5..d44624b070f 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -268,7 +268,7 @@ Sphinx but is set to automatically include it from a third-party site. :default: :code-py:`None` The configuration options for MathJax v3 (which is used by default). - Expects a string with the relative path to a javascript file with the config. + Expects a string with the relative path to a JavaScript file with the config. Alternatively, a dictionary can be given, which is converted to a JSON object and assigned to the JavaScript variable ``window.MathJax``. For more information, please read `Configuring MathJax`__. From 813fbe02e4b49ea9dea4f8e88445ee06c75d248c Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 7 Nov 2025 08:45:31 +0100 Subject: [PATCH 06/11] addressed review --- sphinx/ext/mathjax.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index 548a330665c..3f45bb5e675 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -106,7 +106,8 @@ def install_mathjax( body = 'MathJax.Hub.Config(%s)' % json.dumps(app.config.mathjax2_config) builder.add_js_file('', type='text/x-mathjax-config', body=body) match app.config.mathjax3_config: - case None: + case _ if not app.config.mathjax3_config: + # None, empty string or empty dict pass case str(config_filename): config_filepath = app.srcdir / config_filename @@ -114,10 +115,9 @@ def install_mathjax( msg = f'mathjax3_config file not found: {config_filepath!s}' raise ExtensionError(msg) if not config_filepath.is_file() or config_filepath.suffix != '.js': - msg = 'mathjax3_config must be a .js file' + msg = f'mathjax3_config: expected a .js file, but got {config_filepath!s}' raise ExtensionError(msg) - with config_filepath.open(encoding='utf-8') as f: - body = f.read() + body = config_filepath.read_text(encoding='utf-8') builder.add_js_file('', body=body) case dict(config_dict): body = f'window.MathJax = {json.dumps(config_dict)}' From 95c09cc3ea752cb89be023f36050636b507e4a3c Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Sun, 23 Nov 2025 22:05:19 +0100 Subject: [PATCH 07/11] updated usage documentation --- doc/usage/extensions/math.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index d44624b070f..9d7cbe07da4 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -196,6 +196,7 @@ are built: .. module:: sphinx.ext.mathjax :synopsis: Render math using JavaScript via MathJax. + .. warning:: Version 4.0 changes the version of MathJax used to version 3. You may need to override ``mathjax_path`` to @@ -218,6 +219,14 @@ Sphinx but is set to automatically include it from a third-party site. :rst:role:`role `, not the native MathJax ``$$``, ``\(``, etc. +.. note:: + + Version 8.3 allows to configure MathJax using a Javascript file by passing a string to + ``mathjax3_config`` / ``mathjax4_config``. This is useful for more complex configurations + that are difficult to express using a Python dictionary. Some examples, MathJax 4.0 + offers so called `Pre- and Post-Filters `_ that can be configured this way. + + .. confval:: mathjax_path :type: :code-py:`str` :default: :code-py:`'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'` @@ -276,6 +285,7 @@ Sphinx but is set to automatically include it from a third-party site. __ https://docs.mathjax.org/en/latest/web/configuration.html#configuration .. versionadded:: 4.0 + .. versionchanged:: 8.3 Now also accepts a string with the path to a JavaScript file. .. confval:: mathjax2_config :type: :code-py:`dict[str, Any] | None` @@ -361,3 +371,4 @@ Config value: .. _MathJax: https://www.mathjax.org/ .. _jsMath: https://www.math.union.edu/~dpvc/jsMath/ .. _LaTeX preview package: https://www.gnu.org/software/auctex/preview-latex.html +.. _MathJaxFilters: https://docs.mathjax.org/en/v4.0/advanced/synchronize/filters.html#mathjax-pre-and-post-filters \ No newline at end of file From 010f4b44f6879d289d0a0f7ec3af86e1a50c89f5 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Sun, 23 Nov 2025 22:12:45 +0100 Subject: [PATCH 08/11] linter --- doc/usage/extensions/math.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index 9d7cbe07da4..3a4f6e6ecf9 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -221,11 +221,11 @@ Sphinx but is set to automatically include it from a third-party site. .. note:: - Version 8.3 allows to configure MathJax using a Javascript file by passing a string to - ``mathjax3_config`` / ``mathjax4_config``. This is useful for more complex configurations - that are difficult to express using a Python dictionary. Some examples, MathJax 4.0 - offers so called `Pre- and Post-Filters `_ that can be configured this way. - + Version 8.3 allows to configure MathJax using a JavaScript file by passing a + relative file path as a string to ``mathjax3_config``/``mathjax4_config``. + This is useful for more complex configurations that are difficult to express + using a Python dictionary. For example, MathJax 4.0 offers so called + `Pre- and Post-Filters `_ that can be configured this way. .. confval:: mathjax_path :type: :code-py:`str` @@ -371,4 +371,4 @@ Config value: .. _MathJax: https://www.mathjax.org/ .. _jsMath: https://www.math.union.edu/~dpvc/jsMath/ .. _LaTeX preview package: https://www.gnu.org/software/auctex/preview-latex.html -.. _MathJaxFilters: https://docs.mathjax.org/en/v4.0/advanced/synchronize/filters.html#mathjax-pre-and-post-filters \ No newline at end of file +.. _MathJaxFilters: https://docs.mathjax.org/en/v4.0/advanced/synchronize/filters.html#mathjax-pre-and-post-filters From b69a184269b8bc952251455a3ff4363a5cdb5017 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 24 Nov 2025 20:38:02 +0000 Subject: [PATCH 09/11] Switch to ``mathjax_config_path`` --- CHANGES.rst | 4 +- doc/usage/extensions/math.rst | 46 ++++++++++++----- sphinx/ext/mathjax.py | 51 +++++++++---------- .../_static/custom_mathjax_config.js | 2 +- tests/test_extensions/test_ext_math.py | 10 ++-- 5 files changed, 65 insertions(+), 48 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index fc805e8cf54..d657669eaa6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -68,8 +68,8 @@ Features added Patch by Jean-François B. * #13508: Initial support for :pep:`695` type aliases. Patch by Martin Matouš, Jeremy Maitin-Shepard, and Adam Turner. -* #14023: Allow ``mathjax3_config`` to be a string pointing to a JS file. - Patch by Randolf Scholz. +* #14023: Add ``mathjax_config_path`` to load MathJax configuration from a file. + Patch by Randolf Scholz and Adam Turner. Bugs fixed ---------- diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index 3a4f6e6ecf9..f39aaa24fd2 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -196,10 +196,9 @@ are built: .. module:: sphinx.ext.mathjax :synopsis: Render math using JavaScript via MathJax. - .. warning:: - Version 4.0 changes the version of MathJax used to version 3. You may need to - override ``mathjax_path`` to + Sphinx 4.0 changes the version of MathJax used to version 3. + You may need to override :confval:`mathjax_path` to ``https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML`` or update your configuration options for version 3 (see :confval:`mathjax3_config`). @@ -218,14 +217,13 @@ Sphinx but is set to automatically include it from a third-party site. You should use the math :rst:dir:`directive ` and :rst:role:`role `, not the native MathJax ``$$``, ``\(``, etc. +.. tip:: -.. note:: + MathJax configuration can be supplied in a JavaScript file + by using the :confval:`mathjax_config_path` option. + This is useful for more complex configurations that are hard to express + only using a Python dictionary, for example JavaScript functions. - Version 8.3 allows to configure MathJax using a JavaScript file by passing a - relative file path as a string to ``mathjax3_config``/``mathjax4_config``. - This is useful for more complex configurations that are difficult to express - using a Python dictionary. For example, MathJax 4.0 offers so called - `Pre- and Post-Filters `_ that can be configured this way. .. confval:: mathjax_path :type: :code-py:`str` @@ -273,19 +271,18 @@ Sphinx but is set to automatically include it from a third-party site. or "defer" key is set. .. confval:: mathjax3_config - :type: :code-py:`str | dict[str, Any] | None` + :type: :code-py:`dict[str, Any] | None` :default: :code-py:`None` The configuration options for MathJax v3 (which is used by default). - Expects a string with the relative path to a JavaScript file with the config. - Alternatively, a dictionary can be given, which is converted to a JSON object + If given, the dictionary is converted to a JSON object and assigned to the JavaScript variable ``window.MathJax``. + For more information, please read `Configuring MathJax`__. __ https://docs.mathjax.org/en/latest/web/configuration.html#configuration .. versionadded:: 4.0 - .. versionchanged:: 8.3 Now also accepts a string with the path to a JavaScript file. .. confval:: mathjax2_config :type: :code-py:`dict[str, Any] | None` @@ -329,6 +326,28 @@ Sphinx but is set to automatically include it from a third-party site. This has been renamed to :confval:`mathjax2_config`. :confval:`mathjax_config` is still supported for backwards compatibility. +.. confval:: mathjax_config_path + :type: :code-py:`str` + :default: :code-py:`''` + + If given, this must be the path of a JavaScript (:file:`.js`) file + (path relative to the :term:`configuration directory`) + that contains the configuration options for MathJax. + Example: + + .. code-block:: python + + mathjax_config_path = 'mathjax-config.js' + + .. important:: The user is responsible for ensuring that the given file + is compatible with the version of MathJax being used. + + For more information, please read `Configuring MathJax`__. + + __ https://docs.mathjax.org/en/latest/web/configuration.html#configuration + + .. versionadded:: 8.3 + :mod:`sphinxcontrib.jsmath` -- Render math via JavaScript --------------------------------------------------------- @@ -371,4 +390,3 @@ Config value: .. _MathJax: https://www.mathjax.org/ .. _jsMath: https://www.math.union.edu/~dpvc/jsMath/ .. _LaTeX preview package: https://www.gnu.org/software/auctex/preview-latex.html -.. _MathJaxFilters: https://docs.mathjax.org/en/v4.0/advanced/synchronize/filters.html#mathjax-pre-and-post-filters diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index 3f45bb5e675..d8d083725c4 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -95,47 +95,43 @@ def install_mathjax( builder = cast('StandaloneHTMLBuilder', app.builder) page_has_equations = context.get('has_maths_elements', False) + + # Enable mathjax only if equations exists if app.registry.html_assets_policy == 'always' or page_has_equations: - # Enable mathjax only if equations exists 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) + body = f'MathJax.Hub.Config({json.dumps(app.config.mathjax2_config)})' builder.add_js_file('', type='text/x-mathjax-config', body=body) - match app.config.mathjax3_config: - case _ if not app.config.mathjax3_config: - # None, empty string or empty dict - pass - case str(config_filename): - config_filepath = app.srcdir / config_filename - 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': - msg = f'mathjax3_config: expected a .js file, but got {config_filepath!s}' - raise ExtensionError(msg) - body = config_filepath.read_text(encoding='utf-8') - builder.add_js_file('', body=body) - case dict(config_dict): - body = f'window.MathJax = {json.dumps(config_dict)}' - builder.add_js_file('', body=body) - case _: - msg = 'mathjax3_config must be a str (filename), dict, or None' + + if app.config.mathjax3_config: + body = f'window.MathJax = {json.dumps(app.config.mathjax3_config)}' + builder.add_js_file('', body=body) + + if app.config.mathjax_config_path: + config_path = app.confdir / app.config.mathjax_config_path + if not config_path.exists(): + msg = f'mathjax_config_path file not found: {config_path}' + raise ExtensionError(msg) + if not config_path.is_file() or config_path.suffix != '.js': + msg = f'mathjax_config_path: expected a .js file, but got {config_path}' raise ExtensionError(msg) + body = config_path.read_text(encoding='utf-8') + builder.add_js_file('', 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 + if app.config.mathjax2_config or app.config.mathjax_config: + # Load old MathJax versions via the 'async' method options['async'] = 'async' + else: + # Load MathJax v3+ via the 'defer' method + options['defer'] = 'defer' builder.add_js_file(app.config.mathjax_path, **options) @@ -164,8 +160,9 @@ def setup(app: Sphinx) -> ExtensionMetadata: types=frozenset({dict, NoneType}), ) app.add_config_value( - 'mathjax3_config', None, 'html', types=frozenset({dict, str, NoneType}) + 'mathjax3_config', None, 'html', types=frozenset({dict, NoneType}) ) + app.add_config_value('mathjax_config_path', '', 'html', types=frozenset({str})) app.connect('html-page-context', install_mathjax) return { diff --git a/tests/roots/test-ext-math/_static/custom_mathjax_config.js b/tests/roots/test-ext-math/_static/custom_mathjax_config.js index 7a2bda39383..bdcc29251b0 100644 --- a/tests/roots/test-ext-math/_static/custom_mathjax_config.js +++ b/tests/roots/test-ext-math/_static/custom_mathjax_config.js @@ -1 +1 @@ -window.MathJax = {"extensions": ["tex2jax.js"]} \ No newline at end of file +window.MathJax = {"extensions": ["tex2jax.js"]} diff --git a/tests/test_extensions/test_ext_math.py b/tests/test_extensions/test_ext_math.py index 629997ea4aa..f93abc7356d 100644 --- a/tests/test_extensions/test_ext_math.py +++ b/tests/test_extensions/test_ext_math.py @@ -381,16 +381,18 @@ def test_mathjax3_config(app: SphinxTestApp) -> None: testroot='ext-math', confoverrides={ 'extensions': ['sphinx.ext.mathjax'], - 'mathjax3_config': '_static/custom_mathjax_config.js', + 'mathjax_config_path': '_static/custom_mathjax_config.js', }, ) -def test_mathjax3_js_config(app: SphinxTestApp) -> None: +def test_mathjax_config_path(app: SphinxTestApp) -> None: app.build(force_all=True) content = (app.outdir / 'index.html').read_text(encoding='utf8') assert MATHJAX_URL in content - assert '