Next: , Up: Graphics package configuration   [Contents][Index]

22.2.1 \graphicspath


\graphicspath{list of dir names inside curly brackets}

Declare a list of directories to search for graphics files. This allows you to later say something like \includegraphics{lion.png} instead of having to give its path.

LaTeX always looks for graphic files first in the current directory. The declaration below tells the system to then look in the subdirectory pix, and then ../pix.

\usepackage{graphicx}   % or graphics; put in preamble
\graphicspath{ {pix/} {../pix/} }

The \graphicspath declaration is optional. If you don’t include it then LaTeX’s default is to search all of the places that it usually looks for a file (it uses LaTeX’s \input@path). In particular, in this case one of the places it looks is the current directory.

Enclose each directory name in curly braces; for example, above it says ‘{pix}’. Do this even if there is only one directory. Each directory name must end in a forward slash, /. This is true even on Windows, where good practice is to use forward slashes for all the directory separators since it makes the document portable to other platforms. If you have spaces in your directory name then use double quotes, as with {"my docs/"}. Getting one of these rules wrong will cause LaTeX to report Error: File `filename' not found.

Basically, the algorithm is that with this example, after looking in the current directory,

\graphicspath{ {pix/} {../pix/} }

for each of the listed directories, LaTeX concatenates it with the file name and searches for the result, checking for pix/lion.png and then ../pix/lion.png. This algorithm means that the \graphicspath command does not recursively search subdirectories: if you issue \graphicspath{{a/}} and the graphic is in a/b/lion.png then LaTeX will not find it. It also means that you can use absolute paths such as \graphicspath{{/home/jim/logos/}} or \graphicspath{{C:/Users/Albert/Pictures/}}. However, using these means that the document is not portable. (You could preserve portability by adjusting your TeX system settings configuration file parameter TEXINPUTS; see the documentation of your system.)

You can use \graphicspath anywhere in the document. You can use it more than once. Show its value with \makeatletter\typeout{\Ginput@path}\makeatother.

The directories are taken with respect to the base file. That is, suppose that you are working on a document based on book/book.tex and it contains \include{chapters/chap1}. If in chap1.tex you put \graphicspath{{plots/}} then LaTeX will not search for graphics in book/chapters/plots, but instead in book/plots.

Unofficial LaTeX2e reference manual