diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index 5bfca8d4d03..ddef581870a 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -308,7 +308,7 @@ def html_visit_math(self: HTMLTranslator, node: nodes.math) -> None: raise nodes.SkipNode from exc if self.builder.config.imgmath_embed: image_format = self.builder.config.imgmath_image_format.lower() - img_src = render_maths_to_base64(image_format, outfn) + img_src = render_maths_to_base64(image_format, imgpath) else: # Move generated image on tempdir to build dir if imgpath is not None: @@ -350,7 +350,7 @@ def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None self.body.append('') if self.builder.config.imgmath_embed: image_format = self.builder.config.imgmath_image_format.lower() - img_src = render_maths_to_base64(image_format, outfn) + img_src = render_maths_to_base64(image_format, imgpath) else: # Move generated image on tempdir to build dir if imgpath is not None: diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 7b11ea3be56..855bef3059e 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -1,6 +1,7 @@ """Test math extensions.""" import re +import shutil import subprocess import warnings @@ -33,6 +34,7 @@ def test_imgmath_png(app, status, warning): raise pytest.skip.Exception('dvipng command "dvipng" is not available') content = (app.outdir / 'index.html').read_text(encoding='utf8') + shutil.rmtree(app.outdir) html = (r'
\s*

\s*\s*

\s*
') assert re.search(html, content, re.S) @@ -51,6 +53,7 @@ def test_imgmath_svg(app, status, warning): raise pytest.skip.Exception('dvisvgm command "dvisvgm" is not available') content = (app.outdir / 'index.html').read_text(encoding='utf8') + shutil.rmtree(app.outdir) html = (r'
\s*

\s*\s*

\s*
') assert re.search(html, content, re.S) @@ -70,6 +73,7 @@ def test_imgmath_svg_embed(app, status, warning): pytest.skip('dvisvgm command "dvisvgm" is not available') content = (app.outdir / 'index.html').read_text(encoding='utf8') + shutil.rmtree(app.outdir) html = r'