The order of preference when files with the same name and different extensions is
.png .pdf .jpg .mps .jpeg .jbig2 .jb2 .PNG .PDF .JPG .JPEG .JBIG2 .JB2
which is stored in the macro \Gin@extensions
. So if you have both image.png
and image.pdf
, pdflatex
will load the former.
If you are mixing case in extensions, then
\DeclareGraphicsExtensions{%
.png,.PNG,%
.pdf,.PDF,%
.jpg,.mps,.jpeg,.jbig2,.jb2,.JPG,.JPEG,.JBIG2,.JB2}
will ensure that PNG are always preferred over PDF files. For the final version it will be sufficient to switch the two lines.
A handier way, suggested by Heiko Oberdiek, is to use the package grfext
:
\usepackage{grfext}
\PrependGraphicsExtensions*{.png,.PNG}
that will have the same effect without the need to check in pdftex.def
for the list of extensions.
If you want also automatic conversion, you can say
\usepackage{graphicx}
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule{.pdf}{png}{.png}{convert #1 \OutputFile}
\DeclareGraphicsExtensions{%
.png,.PNG,%
.pdf,.PDF,%
.jpg,.mps,.jpeg,.jbig2,.jb2,.JPG,.JPEG,.JBIG2,.JB2}
When image.pdf
exists but not image.png
, the file image-pdf-converted-to.png
will be created and loaded in its place. Add the options you prefer between convert
and #1
(for example -density 100
or something like that).
You need to call pdflatex
with the --shell-escape
option for this automatic conversion to work. Of course you'll comment out the \epstopdfDeclareGraphicsRule
command for the final version, when only PDF files should be loaded (and switch the order of precedence in the lines below).
Rarely use spaces in file names, and be extra careful when including images that have spaces in their names. So, your use of
\includegraphics[..]{ test }
is interpreted as looking for file test .ext
- note the space before and after (where .ext
is one of the approved graphic file extensions associated with your driver). Similarly,
\includegraphics[..]{ test.png }
can't find a file extension .png
- note the space at the end. So, use
\includegraphics[..]{filename}
where the driver will look for the appropriate file name filename
(no spaces).
A work-around for when you actually do have spaces in your file names, are provided by the grffile
package.
Somewhat unrelated, but the following will also be problematic:
\documentclass{<class><space>}
as in \documentclass{article }
. However, it's fine to use
\usepackage{ <package> , <package> , ... }
Best Answer
The DVI producing
latex
doesn't support reading the size of PNG, JPG or PDF images. You need to usepdflatex
for this. Actuallylatex
ispdflatex
in DVI mode in modern distributions, but it can read the sizes only in PDF mode for some reason. You are however able to state the natural size of the images usingnatwidth
andnatheight
which will makelatex
compile without error. The produced DVI file will only link to the PDF and the DVI-to-PDF converter will need to include it in the final PDF. AFAIKdvpdf
doesn't support this butdvipdfm
does.Compile with either
or