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..077fe3cfb2e 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -21,6 +21,24 @@ def has_binary(binary): return True +@pytest.mark.skipif(not has_binary('dvisvgm'), + reason='Requires dvisvgm" binary') +@pytest.mark.sphinx('html', testroot='ext-math-simple', + confoverrides={'extensions': ['sphinx.ext.imgmath'], + 'imgmath_image_format': 'svg', + 'imgmath_embed': True}) +def test_imgmath_svg_embed(app, status, warning): + app.builder.build_all() + if "LaTeX command 'latex' cannot be run" in warning.getvalue(): + pytest.skip('LaTeX command "latex" is not available') + if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue(): + pytest.skip('dvisvgm command "dvisvgm" is not available') + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + html = r'