Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imgmath: Fix relative file path #10965

Merged
merged 3 commits into from Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -16,6 +16,8 @@ Features added
Bugs fixed
----------

* #10944: imgmath: Fix resolving image paths for files in nested folders.

Testing
--------

Expand Down
9 changes: 5 additions & 4 deletions sphinx/ext/imgmath.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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>')
Expand Down