# Which file does includegraphics select if there are multiple files with different extensions? [duplicate]

We usually write something like

\includegraphics{image}


\includegraphics{image.png}


That is, \includegraphics does not usually require a file extension such as .png .pdf .jpg, etc... That is,

Suppose that I have all of the following files in the same directory. Which file will \includegraphics embed?

my_pic.jpg
my_pic.psd
my_pic.png
my_pic.pdf
my_pic.jpeg
my_pic.gif


Document:

\documentclass{minimal}
\begin{document}
\begin{figure}[htpb]
\centering
\includegraphics[width=\linewidth]{my_pic}
\caption{Sunshine and Rainbows}
\Description{summertime}
\end{figure}
\end{document}


## marked as duplicate by Werner, Kurt, Troy, marmot, Stefan PinnowJan 12 at 6:55

• ! LaTeX Error: Environment figure undefined – David Carlisle Jan 11 at 20:49

It depends on the engine. With pdftex the current list (which you can find in pdftex.def) is:

\def\Gin@extensions{%
.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,%
.PDF,.PNG,.JPG,.JPEG,.JBIG2,.JB2%
}


That means that e.g. pdf will be prefered, then png etc.

• Very useful. It could be in graphicx documentation. – Sigur Jan 11 at 17:08
• I always wondered: what's the point of this? Why doesn't it simply accept the full name of the file? – Bakuriu Jan 11 at 18:50
• @Bakuriu it does accept the full name of the file. example-image.pdf works fine. – Ulrike Fischer Jan 11 at 18:51
• @Sigur the user documentation tells you how to set the list texdoc graphics section 4.5 \DeclareGraphicsExtensions the default is driver specific and initially there were dozens of different drivers they are not documented in the core documentation. – David Carlisle Jan 11 at 20:40

As documented in the graphics guide (section 4.5), this is user settable.

If you have

\DeclareGraphicsExtensions{.pdf,.png}


in your document then it will just try .pdf then .png in that order, and ignore the rest.

The default value as shown in Ulrike's answer is set in the driver file for the option you are using. (Using a lower level \def syntax rather than \DeclareGraphicsExtensions because the driver files might be loaded by the color package, before \DeclareGraphicsExtensions is defined.)