diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index 0c034a5994a..2fa1d467903 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -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'

\n')