Skip to content

Commit 6627618

Browse files
authored
imgmath: Fix embed mode (#10878)
1 parent a651e6b commit 6627618

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sphinx/ext/imgmath.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def html_visit_math(self: HTMLTranslator, node: nodes.math) -> None:
308308
raise nodes.SkipNode from exc
309309
if self.builder.config.imgmath_embed:
310310
image_format = self.builder.config.imgmath_image_format.lower()
311-
img_src = render_maths_to_base64(image_format, outfn)
311+
img_src = render_maths_to_base64(image_format, imgpath)
312312
else:
313313
# Move generated image on tempdir to build dir
314314
if imgpath is not None:
@@ -350,7 +350,7 @@ def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None
350350
self.body.append('</span>')
351351
if self.builder.config.imgmath_embed:
352352
image_format = self.builder.config.imgmath_image_format.lower()
353-
img_src = render_maths_to_base64(image_format, outfn)
353+
img_src = render_maths_to_base64(image_format, imgpath)
354354
else:
355355
# Move generated image on tempdir to build dir
356356
if imgpath is not None:

tests/test_ext_math.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test math extensions."""
22

33
import re
4+
import shutil
45
import subprocess
56
import warnings
67

@@ -33,6 +34,7 @@ def test_imgmath_png(app, status, warning):
3334
raise pytest.skip.Exception('dvipng command "dvipng" is not available')
3435

3536
content = (app.outdir / 'index.html').read_text(encoding='utf8')
37+
shutil.rmtree(app.outdir)
3638
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"'
3739
r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
3840
assert re.search(html, content, re.S)
@@ -51,6 +53,7 @@ def test_imgmath_svg(app, status, warning):
5153
raise pytest.skip.Exception('dvisvgm command "dvisvgm" is not available')
5254

5355
content = (app.outdir / 'index.html').read_text(encoding='utf8')
56+
shutil.rmtree(app.outdir)
5457
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"'
5558
r'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
5659
assert re.search(html, content, re.S)
@@ -70,6 +73,7 @@ def test_imgmath_svg_embed(app, status, warning):
7073
pytest.skip('dvisvgm command "dvisvgm" is not available')
7174

7275
content = (app.outdir / 'index.html').read_text(encoding='utf8')
76+
shutil.rmtree(app.outdir)
7377
html = r'<img src="data:image/svg\+xml;base64,[\w\+/=]+"'
7478
assert re.search(html, content, re.DOTALL)
7579

@@ -81,6 +85,7 @@ def test_mathjax_options(app, status, warning):
8185
app.builder.build_all()
8286

8387
content = (app.outdir / 'index.html').read_text(encoding='utf8')
88+
shutil.rmtree(app.outdir)
8489
assert ('<script async="async" integrity="sha384-0123456789" '
8590
'src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">'
8691
'</script>' in content)
@@ -92,6 +97,7 @@ def test_mathjax_align(app, status, warning):
9297
app.builder.build_all()
9398

9499
content = (app.outdir / 'index.html').read_text(encoding='utf8')
100+
shutil.rmtree(app.outdir)
95101
html = (r'<div class="math notranslate nohighlight">\s*'
96102
r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&amp;= \\pi r\^2\\\\'
97103
r'V \&amp;= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]</div>')

0 commit comments

Comments
 (0)