diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index a78d54a16..87b9c5c45 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -1166,7 +1166,11 @@ def setup_js_tag_helper(app: Sphinx, pagename: str, templatename: str,
else:
# str value (old styled)
attrs.append('src="%s"' % pathto(js, resource=True))
- return '' % (' '.join(attrs), body)
+
+ if attrs:
+ return '' % (' '.join(attrs), body)
+ else:
+ return '' % body
context['js_tag'] = js_tag
diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py
index bd124c8c6..ebe2c0f38 100644
--- a/tests/test_ext_math.py
+++ b/tests/test_ext_math.py
@@ -215,11 +215,23 @@ def test_math_compat(app, status, warning):
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax'],
- 'mathjax_config': {'extensions': ['tex2jax.js']}})
-def test_mathjax_config(app, status, warning):
+ 'mathjax3_config': {'extensions': ['tex2jax.js']}})
+def test_mathjax3_config(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').read_text()
+ assert MATHJAX_URL in content
+ assert ('' in content)
+
+
+@pytest.mark.sphinx('html', testroot='ext-math',
+ confoverrides={'extensions': ['sphinx.ext.mathjax'],
+ 'mathjax2_config': {'extensions': ['tex2jax.js']}})
+def test_mathjax2_config(app, status, warning):
+ app.builder.build_all()
+
+ content = (app.outdir / 'index.html').read_text()
+ assert MATHJAX_URL in content
assert ('' in content)