[Tex/LaTex] Path of includegraphics is relative – but to what

graphicspdftex

I am trying to include graphics for a document. The arborescence is as follows:

+ REPORT
+-- RESOURCES
|   + icon.png
+-- TEX
    + report.tex
    + report.cls

The report.tex starts with {report}, and the report.cls file has the following lines :

\RequirePackage(graphicx)
[...]
\includegraphics[...]{../RESOURCES/icon}

Now, when I run pdflatex on that .tex like this, everything runs smoothly :

> pdflatex report.tex

However, when I run it from another directory, it seems to me that the "relative" path is taken as "relative from the execution directory" and not "relative from the .tex file".

> pdflatex TEX/report.tex
[...]
!pdfTex error : pdflatex file {../RESOURCES/icon.png} : cannot find image file

This seems to be confirmed by this answer.

I tried using \graphicspath{{../RESOURCES/}} before my \begin{document}, but it wasn't successful.

So, my question is : is there any way of having relative paths in .tex regarded as relative to the .tex rather than to the execution dir when using pdflatex?

Best Answer

It is a feature of the underlying tex system that relative paths are relative to the working directory not to the directory of the current file or the top level file of the document. This applies to input tex files and packages as well as images.

Related Question