[tex-k] Discrepancy between \openin and \pdf* causes problems with the graphicx package

meansquarederror meansquarederror at protonmail.com
Tue May 7 19:32:13 CEST 2019

The primitives \openin and \pdf* (\pdffilesize, \pdfximage, etc) behave slightly differently with regard to the path that they search.

\openin always checks the output directory specified by -output-directory option of pdftex and if it fails to find the file there, it tries to search the regular TEXINPUT path.

This causes problems with the Latex package graphicx. Below is the bugreport that I sent to the Latex maintainers and they advised me to report it to the TexLive maintainers.

There is a bug in the graphicx package which prevents \includegraphics from including a valid image which is located in the graphics path. The bug show up when the following conditions are met:

- We are using pdflatex on Linux.
- An directory is listed in \graphicspath, in the example below it is /root/texout/
- That directory contains a valid .pdf file, in the example below it is myimg.pdf
- The \includegraphics macro includes an image specified by its filename only (with or without an extension). In our example it is called "myimg" (without the double quotes).
- The compiled tex file is placed in a directory which is different from the directory that contains the image file and the current directory is not an ancestor directory of the directory with the image file.
  In our example the .tex file is in /root/archive/downloads/zzz/graphics_bug.tex.
- When we invoke pdflatex our current directory is the directory that contains the tex file. In our case the current directory is /root/archive/downloads/zzz/
- pdflatex is run from a current directory
- The directory that contains the .pdf file is specified as an output directory of pdflatex. In our case the pdflatex is invoked as:
  pdflatex -output-directory=/root/texout/ ./graphics_bug.tex

This is the sample file located in /root/archive/downloads/zzz/graphics_bug.tex

pdflatex should be able to find and include successfully the file myimg.pdf, but instead it shows the following error:
! Package pdftex.def Error: File `myimg.pdf' not found: using draft setting.

See the pdftex.def package documentation for explanation.
Type  H <return>  for immediate help.

l.8 \includegraphics{myimg}

If we run pdflatex without the -output-directory argument, then the file is compiled successfully:

Output written on graphics_bug.pdf (1 page, 8989 bytes).
Transcript written on graphics_bug.log.

This bug is caused by the fact that \includegraphics uses \IfFileExists which in turn uses \openin which is able to find graphics_bug.pdf in the output directory even if it is not specified in the .tex search path, but the corresponding \pdffilesize and \pdfximage are not able to find it.

You can see the full discussion here https://github.com/latex3/latex2e/issues/145 and why the Latex developers think it is an issue in TexLive and should be fixed there.

The attached patch fixes this bug for the pdf backend. Most likely the other backends have similar problems but they are not fixed by this patch.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/tex-k/attachments/20190507/70edf5ab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: find_input_file.patch
Type: text/x-patch
Size: 4268 bytes
Desc: not available
URL: <https://tug.org/pipermail/tex-k/attachments/20190507/70edf5ab/attachment.bin>

More information about the tex-k mailing list