1

There are many packages that contain graphic files. For example, rutitlepage has logo.pdf, hand.pdf in notes, and so on.

If I want to use my own logo.pdf, which I want to load from a subfolder, then the next example will load the logo.pdf of the rutitlepage package:

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{figures/}}
\begin{document}
\includegraphics[width=5cm]{logo}
\end{document}

Can it be resolved, that the compiler searches the graphic files first in the current directory, then in the graphicspath, and only last in the packages?

2

The package searches first for the unprefixed name then names prefixed with each segment from the graphics path so first looks for logo.pdf then if that fails, looks for figures/logo.pdf

Assuming a web2c based TeX using kpathsea (miktex, texlive, ...) on each of those attempts, the TEXINPUTS path will be searched, except that parts of the tex inputs tree prefixed with !! in the path will only be searched via the pre-calculated ls-R file database.

so typically it will look first in the current directory then anywhere under ~/texmf/tex (while looking for logo.pdf) then it will (on my system) find /usr/local/texlive/2018/texmf-dist/tex/latex/rutitlepage/logo.pdf as that is in the standard search directory, then if that file had not been found it will look for figures/logo.pdf under the current directory then figures/logo.pdf under ~/texmf/tex then anywhere pre-indexed in the standard search.

As you see the behaviour is much simpler to describe if you give your files unique names. myinstitution-logo.pdf is much less likely to be found by accident.


Personally (despite having written it) I wouldn't use \graphicspath if you used \includegraphcs{figures/logo} then the rutitlepage one would not be found.

Also if the file has a more specific name name \includegraphcs{hair-splitter-logo} then most issues are avoided.

  • Yes, that's OK. But if I use an image file name, which works fine today, and tomorrow a new package use similar file name, then the source will produce incorrect result. This is a serious problem in a large document! – hair-splitter Nov 10 '18 at 15:43
  • @hair-splitter ctan distributes tens of thousands of files and the only thing that stops everything clashing is a convention not to re-use other peoples filenames, in theory it should not scale to a global delivery network but in practice it survives well enough. The current directory is always searched first so there is always that possibility. – David Carlisle Nov 10 '18 at 16:56
  • Thank you very much your answer, and the report to maintainer of rutitlepage. I just wanted to know if the search order of files could be changed. So the answer is NOT. I will not use \graphicspath in the future. – hair-splitter Nov 11 '18 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.