Skip to content

Commit d542932

Browse files
committed
mathjax4 compat
1 parent 9364edb commit d542932

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

myst_parser/sphinx_ext/mathjax.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,29 @@ def override_mathjax(app: Sphinx):
5959

6060
mjax_classes = app.env.myst_config.mathjax_classes # type: ignore[attr-defined]
6161

62-
if "mathjax3_config" in app.config:
62+
mathjax_opt = None
63+
for opt in ("mathjax4_config", "mathjax3_config"):
64+
if opt in app.config:
65+
mathjax_opt = opt
66+
break
67+
if mathjax_opt is not None:
6368
# sphinx 4 + mathjax 3
64-
app.config.mathjax3_config = app.config.mathjax3_config or {}
65-
app.config.mathjax3_config.setdefault("options", {})
69+
# sphinx 9 + mathjax 4
70+
config = getattr(app.config, opt, None) or {}
71+
config.setdefault("options", {})
6672
if (
67-
"processHtmlClass" in app.config.mathjax3_config["options"]
68-
and app.config.mathjax3_config["options"]["processHtmlClass"]
73+
"processHtmlClass" in config["options"]
74+
and config["options"]["processHtmlClass"]
6975
!= mjax_classes
7076
):
7177
log_override_warning(
7278
app,
7379
3,
74-
app.config.mathjax3_config["options"]["processHtmlClass"],
80+
config["options"]["processHtmlClass"],
7581
mjax_classes,
7682
)
77-
app.config.mathjax3_config["options"]["processHtmlClass"] = mjax_classes
83+
config["options"]["processHtmlClass"] = mjax_classes
84+
setattr(app.config, opt, config)
7885
elif "mathjax_config" in app.config:
7986
# sphinx 3 + mathjax 2
8087
app.config.mathjax_config = app.config.mathjax_config or {}

0 commit comments

Comments
 (0)