From ad17443ff1a66d69822401b47d34b4f2f85a83ac Mon Sep 17 00:00:00 2001 From: Ilia Kats Date: Wed, 4 Mar 2026 15:21:43 +0100 Subject: [PATCH 1/2] mathjax4 compat --- myst_parser/sphinx_ext/mathjax.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/myst_parser/sphinx_ext/mathjax.py b/myst_parser/sphinx_ext/mathjax.py index ec46e5b8..5e449178 100644 --- a/myst_parser/sphinx_ext/mathjax.py +++ b/myst_parser/sphinx_ext/mathjax.py @@ -59,22 +59,29 @@ def override_mathjax(app: Sphinx): mjax_classes = app.env.myst_config.mathjax_classes # type: ignore[attr-defined] - if "mathjax3_config" in app.config: + mathjax_opt = None + for opt in ("mathjax4_config", "mathjax3_config"): + if getattr(app.config, opt, None): + mathjax_opt = opt + break + if mathjax_opt is not None: # sphinx 4 + mathjax 3 - app.config.mathjax3_config = app.config.mathjax3_config or {} - app.config.mathjax3_config.setdefault("options", {}) + # sphinx 9 + mathjax 4 + config = getattr(app.config, opt, {}) or {} + config.setdefault("options", {}) if ( - "processHtmlClass" in app.config.mathjax3_config["options"] - and app.config.mathjax3_config["options"]["processHtmlClass"] + "processHtmlClass" in config["options"] + and config["options"]["processHtmlClass"] != mjax_classes ): log_override_warning( app, 3, - app.config.mathjax3_config["options"]["processHtmlClass"], + config["options"]["processHtmlClass"], mjax_classes, ) - app.config.mathjax3_config["options"]["processHtmlClass"] = mjax_classes + config["options"]["processHtmlClass"] = mjax_classes + setattr(app.config, opt, config) elif "mathjax_config" in app.config: # sphinx 3 + mathjax 2 app.config.mathjax_config = app.config.mathjax_config or {} From 3c3d94bf5efe290f6649a0d86ee4df273c14db4d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:30:43 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- myst_parser/sphinx_ext/mathjax.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/myst_parser/sphinx_ext/mathjax.py b/myst_parser/sphinx_ext/mathjax.py index 5e449178..50498bd8 100644 --- a/myst_parser/sphinx_ext/mathjax.py +++ b/myst_parser/sphinx_ext/mathjax.py @@ -67,12 +67,11 @@ def override_mathjax(app: Sphinx): if mathjax_opt is not None: # sphinx 4 + mathjax 3 # sphinx 9 + mathjax 4 - config = getattr(app.config, opt, {}) or {} + config = getattr(app.config, opt, {}) or {} config.setdefault("options", {}) if ( "processHtmlClass" in config["options"] - and config["options"]["processHtmlClass"] - != mjax_classes + and config["options"]["processHtmlClass"] != mjax_classes ): log_override_warning( app,