0

I used the \graphicspath command to tell my LaTeX document where the various pictures are located. However, I noticed that LaTeX first checks the directory where the TeX file is located and only afterwards looks in the directory specified in \graphicspath.

Is there a way to tell LaTeX to only look for graphics in the \graphicspath directory? Or is the only solution here to clean up the directory of the source file and make sure no graphics are located there?

2
  • 1
    I think latex will always check the folder with the tex file first and only then consult graphics path. (Perhaps it is also a good idea to use unique names for your graphics?)
    – daleif
    Commented Feb 14, 2019 at 9:03
  • you could change the internal macros to skip the current directory but simplest, if you want it to only look in a folder images is to use \includegraphics{images/mypicture.png} with the path in the includegraphics argument Commented Feb 14, 2019 at 9:07

1 Answer 1

1

A way where I suppose you have an image named MyImage.png inside a folder named images

\documentclass{article}
\usepackage{graphicx}
\let\oldIncludegraphics\includegraphics

\renewcommand{\includegraphics}[2][]{\oldIncludegraphics[#1]{images/#2}}

\begin{document}
\includegraphics[width=0.4\textwidth]{MyImage}
\end{document}
3
  • So this overwrites the includegraphics command so that it attaches a directory to the file name?
    – quarague
    Commented Feb 14, 2019 at 9:51
  • 1
    I would go mad if some document would do this somewhere, and so e.g. \includegraphics{example-image} no longer works. Commented Feb 14, 2019 at 10:01
  • 1
    @UlrikeFischer you are right, but it is the only example I thought it will fail when thought about it... Just an idea for this specific need. quarague.. Yes, this is exactly how it works.
    – koleygr
    Commented Feb 14, 2019 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .