Skip to content

Commit 222d366

Browse files
authored
imgmath: Fix relative file path (#10965)
1 parent 965768b commit 222d366

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Features added
1616
Bugs fixed
1717
----------
1818

19+
* #10944: imgmath: Fix resolving image paths for files in nested folders.
20+
1921
Testing
2022
--------
2123

sphinx/ext/imgmath.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ def render_math(
207207
"""Render the LaTeX math expression *math* using latex and dvipng or
208208
dvisvgm.
209209
210-
Return the filename relative to the built document and the "depth",
210+
Return the image absolute filename and the "depth",
211211
that is, the distance of image bottom and baseline in pixels, if the
212212
option to use preview_latex is switched on.
213-
Also return the temporary and destination files.
214213
215214
Error handling may seem strange, but follows a pattern: if LaTeX or dvipng
216215
(dvisvgm) aren't available, only a warning is generated (since that enables
@@ -317,7 +316,8 @@ def html_visit_math(self: HTMLTranslator, node: nodes.math) -> None:
317316
image_format = self.builder.config.imgmath_image_format.lower()
318317
img_src = render_maths_to_base64(image_format, rendered_path)
319318
else:
320-
relative_path = path.relpath(rendered_path, self.builder.outdir)
319+
bname = path.basename(rendered_path)
320+
relative_path = path.join(self.builder.imgpath, 'math', bname)
321321
img_src = relative_path.replace(path.sep, '/')
322322
c = f'<img class="math" src="{img_src}"' + get_tooltip(self, node)
323323
if depth is not None:
@@ -357,7 +357,8 @@ def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None
357357
image_format = self.builder.config.imgmath_image_format.lower()
358358
img_src = render_maths_to_base64(image_format, rendered_path)
359359
else:
360-
relative_path = path.relpath(rendered_path, self.builder.outdir)
360+
bname = path.basename(rendered_path)
361+
relative_path = path.join(self.builder.imgpath, 'math', bname)
361362
img_src = relative_path.replace(path.sep, '/')
362363
self.body.append(f'<img src="{img_src}"' + get_tooltip(self, node) +
363364
'/></p>\n</div>')

0 commit comments

Comments
 (0)