[Tex/LaTex] Automatically Locate Included Images

automationfile-lookupgraphicspaths

Do you think it's possible to include images into LaTeX without specifying the exact path to them. So instead of:

\includegraphics{path/to/image/myfig.pdf}

It would be:

\includegraphics{myfig.pdf}

While the image would still reside in the path/to/image/ directory. Basically, I'm asking if there is a macro that can recursively search for the image.

An alternative for me is to write a script outside of LaTeX that determines all the images that are included, performs the recursive search and copies those files temporarily in the same directory as the .tex file.

Best Answer

You can do this the following ways:

  1. Use the \graphicspath macro:

    \graphicspath{{path/to/image/}{other/path/}}
    
  2. Define the environment variable TEXINPUTS to contain the path:

    TEXINPUTS=".:path/to/image:other/path:"
    

    Note the leading '.' (current dir) and the trailing empty field (default texmf tree).

  3. Put your graphics in an own local texmf tree, so that they are found automatically. Then the path doesn't has to be defined. However this causes problems if you have multiple files with the same name in different directories.