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

Figures go missing from latex pdf if their files have the same base name and they use a post transform #11110

Closed
aaron-cooper opened this issue Jan 7, 2023 · 3 comments · Fixed by #11113

Comments

@aaron-cooper
Copy link
Contributor

Describe the bug

I'm trying to build a pdf from a document that contains some svg images. The images have identical names, but reside in different directories. I use sphinxcontrib.rsvgconverter from sphinxcontrib-svg2pdfconverter to convert them from svg to pdf.

When multiple svg images with the same base name are passed to rsvgconverter.convert, the destination path for both images is identical, therefore all but the last image is discarded when it is overwritten by a subsequent transformation.

The result is that the final pdf will have the last converted svg repeated several times instead of each svg appearing when it is supposed to.

How to Reproduce

Here is a repo containing some code that reproduces the issue.

The file foo_expected.pdf (github doesn't show the full content of the pdf, remember to click "more pages" I guess...) shows what I would expect the output to be, and foo_actual.pdf shows what it actually is. Notice that the two identically named png files are shown correctly in foo_actual.pdf, but for the two svg's a red circle is shown twice, instead of a black circle and then a red circle.

Environment Information

Please paste all output below into the bug report template



Platform:              linux; (Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.35)
Python version:        3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0])
Python implementation: CPython
Sphinx version:        6.1.2
Docutils version:      0.19
Jinja2 version:        3.0.3
Pygments version:      2.13.0

Sphinx extensions

No response

Additional context

No response

@aaron-cooper
Copy link
Contributor Author

I found a way to fix the issue, but I'm not savvy about this project so I have no idea if it would be a reasonable fix or not. Either way, here is the commit from my fork, in case someone here finds that helpful.

@jfbu jfbu added this to the 6.2.0 milestone Jan 8, 2023
@jfbu
Copy link
Contributor

jfbu commented Jan 8, 2023

Good catch! I could reproduce this issue with

Running Sphinx v1.6.3
Sphinx version: 1.6.3
Python version: 3.7.5 (CPython)
Docutils version: 0.16 release
Pygments version: 2.14.0
Jinja2 version: 2.3

with sphinxcontrib-svg2pdfconverter at 1.0.0 and using Inkscape on my mac osx.

So this is a really long-standing issue... I will do some more testing.

@jfbu jfbu added the extensions label Jan 8, 2023
@jfbu
Copy link
Contributor

jfbu commented Jan 8, 2023

@aaron-cooper could you please make a PR with your patch? I used it in the

diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py
index 1871a0f9c..410de82f0 100644
--- a/sphinx/transforms/post_transforms/images.py
+++ b/sphinx/transforms/post_transforms/images.py
@@ -236,7 +236,7 @@ class ImageConverter(BaseImageConverter):
         else:
             srcpath = node['candidates']['*']
 
-        filename = get_filename_for(srcpath, _to)
+        filename = get_filename_for(self.env.images[srcpath][1], _to)
         ensuredir(self.imagedir)
         destpath = os.path.join(self.imagedir, filename)
 

shape.

It appears to work fine. Sadly I am not much familiar with this myself.

Recently we have merged some changes with sphinx.ext.imgmath (see #10944, #10888 which was merged at 5.3.0 but did not get a CHANGES entry yet) but these things look very unrelated to sphinx/transforms/post_transforms/images.py, and so I see no problem there.


completely unrelated: in modifying a bit the test so that multiple pdfs end up in same page I encountered the

pdfTeX warning: pdflatex (file ./img1.pdf): PDF inclusion: multiple pdfs with p
age group included in a single page

warning which is amply commented as a tex.sx question. There is no such warning with latex_engine set to 'xelatex' or 'lualatex' although I do not know if the underlying problems may also arise there. But this is more like something for missinglinkelectronics/sphinxcontrib-svg2pdfconverter attention, and is not related in anyway to this issue.

@jfbu jfbu removed the builder:latex label Jan 8, 2023
jfbu added a commit to jfbu/sphinx that referenced this issue Apr 3, 2023
jfbu added a commit to jfbu/sphinx that referenced this issue Apr 3, 2023
jfbu added a commit to jfbu/sphinx that referenced this issue Apr 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants