summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Schueller <schueller@phimeca.com>2023-01-05 12:54:32 +0100
committerGitHub <noreply@github.com>2023-01-05 11:54:32 +0000
commit222d366eadc1afa6c9344e9f0d3781a11a8c1ac4 (patch)
tree3b8e79cb561b2129d63b5067871a0f648d2bf343
parent965768bfda2a00ba6466cdb12a7a46efdce47023 (diff)
downloadsphinx-git-222d366eadc1afa6c9344e9f0d3781a11a8c1ac4.tar.gz
imgmath: Fix relative file path (#10965)
-rw-r--r--CHANGES2
-rw-r--r--sphinx/ext/imgmath.py9
2 files changed, 7 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 303dae009..577c1c783 100644
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,8 @@ Features added
Bugs fixed
----------
+* #10944: imgmath: Fix resolving image paths for files in nested folders.
+
Testing
--------
diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py
index 0c034a599..5ebf8d8d2 100644
--- a/sphinx/ext/imgmath.py
+++ b/sphinx/ext/imgmath.py
@@ -207,10 +207,9 @@ def render_math(
"""Render the LaTeX math expression *math* using latex and dvipng or
dvisvgm.
- Return the filename relative to the built document and the "depth",
+ Return the image absolute filename and the "depth",
that is, the distance of image bottom and baseline in pixels, if the
option to use preview_latex is switched on.
- Also return the temporary and destination files.
Error handling may seem strange, but follows a pattern: if LaTeX or dvipng
(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:
image_format = self.builder.config.imgmath_image_format.lower()
img_src = render_maths_to_base64(image_format, rendered_path)
else:
- relative_path = path.relpath(rendered_path, self.builder.outdir)
+ bname = path.basename(rendered_path)
+ relative_path = path.join(self.builder.imgpath, 'math', bname)
img_src = relative_path.replace(path.sep, '/')
c = f'<img class="math" src="{img_src}"' + get_tooltip(self, node)
if depth is not None:
@@ -357,7 +357,8 @@ def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None
image_format = self.builder.config.imgmath_image_format.lower()
img_src = render_maths_to_base64(image_format, rendered_path)
else:
- relative_path = path.relpath(rendered_path, self.builder.outdir)
+ bname = path.basename(rendered_path)
+ relative_path = path.join(self.builder.imgpath, 'math', bname)
img_src = relative_path.replace(path.sep, '/')
self.body.append(f'<img src="{img_src}"' + get_tooltip(self, node) +
'/></p>\n</div>')