# includegraphics choosing pdf instead of eps [closed]

I previously posted this on stackoverflow.com where it was suggested that I post it here. So apologies in advance for cross-posting.

I am using LaTeX in ubuntu 10.04 to build a TeX file that uses \includegraphics. I am not specifying the file extension to allow latex to auto decide. I have both .pdf and .eps files for each image I am including.

My problem is that if I build with pdflatex everything works. However if I build with latex I get errors of the form:

 ! LaTeX Error: Cannot determine size of graphic in images/DetailedArch.pdf
(no BoundingBox).


I assumed that running latex would automatically choose the EPS version of the file. If I specify the .eps extension in the \includegraphics command everything works fine. I have tried various options such as using \ifpdf but have failed to find a solution.

One point that I notice is that in Ubuntu 10.04 latex is a link to pdftex -- not sure if this is part of the issue.

-

## closed as too localized by Martin Scharrer♦Jun 21 '11 at 16:11

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Did you specify the driver?, as in \usepackage[dvips]{graphicx}. As a rule of thumb, I always use the form above and specify the extension .eps. No problems so far. –  Zhenya Jun 20 '11 at 21:41
...in Ubuntu 10.04 latex is a link to pdftex... That pretty much seems to be the reason why. –  Lorem Ipsum Jun 20 '11 at 23:23
@Zhenya I think your solution is to specify the file extension (correct me if I am wrong). This is not a solution for me since I want to be able to compile the same latex file using latex and pdftex without changing the latex file. –  johnmcd Jun 20 '11 at 23:31
Thanks @yoda, any ideas why latex would link to pdftex. Also I would have thought that if pdflatex can extract the bounding box from the pdf file then pdftex should be able to achieve the same. Obviously not... –  johnmcd Jun 20 '11 at 23:34
@johnmcd Welcome to TeX-SE! Usually it's best not to cross-post like this -- if your question is better served on another place, a moderator could help you migrate it, along with all comments and answers it had accumulated. You do need a tiny bit of reputation in order to flag for moderation attention (15, IIRC), and then you can just use the "flag" link under your question. –  Martin Tapankov Jun 21 '11 at 11:41

The best way to do this is to declare the graphics extension to be used using \DeclareGraphicsExtensions and do not supply an extension when including the image:

\usepackage{graphicx}
\usepackage{ifpdf}
\ifpdf
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\else
\DeclareGraphicsExtensions{.eps}
\fi

% In the document:
\includegraphics{image_name}%  no extension!


I personally gave up on this dual compilation stuff and only use pdflatex since years. There are some packages which help you if you need PS-related stuff.

-
@Martin: With the standard settings on a modern TeX system, EPS versus PDF selection is automatic provided graphics are included without extension. So messing with \DeclareGraphicsExtensions should not be needed. –  Joseph Wright Jun 21 '11 at 11:57
@Joseph: Oh, yeah, you are right. I know remember using the above code mostly to change the order of extensions, e.g. have PNG before JPG because it is lossless. –  Martin Scharrer Jun 21 '11 at 12:25
I have tried the above but it didn't work i.e. when I run latex it still includes the pdf file but without. I think the problem is related to the fact that on my system Ubuntu 10.04 64 bit /usr/bin/latex is just a link to /usr/bin/pdftex. The package that "owns" /usr/bin/latex is texlive-latex-base. I will construct an example as suggested and post it. –  johnmcd Jun 21 '11 at 15:39
@johnmcd: latex as symlink to pdftex is normal. This simply uses pdflatex in DVI mode, which is the way the modern LaTeX does it. Please add a minimal working example (MWE) that illustrates your problem, i.e. causes this behavior. Without it we can only guess what's wrong. –  Martin Scharrer Jun 21 '11 at 15:47
In trying to construct a minimal solution I have, somewhat embarrassingly, solved the problem. Basically I am using a thesis class file which referenced a common macros file that had built up within our group over the past number of years. I have just realised that someone had (quite stupidly) inserted \DeclareGraphicsExtensions{.pdf} in the middle of that macro file. Thanks for the help, and apologies for not having spotted this myself earlier. –  johnmcd Jun 21 '11 at 16:08

The extensions and their order are declared in the driver file of the graphics package. The standard dvips driver e.g. contains

\def\Gin@extensions{.eps,.ps,.eps.gz,.ps.gz,.eps.Z}


And this means that if this driver is used .pdf graphics will not be used.

Which driver your document use depends on your document and your system. Make a minimal example that demonstrates your problem and show it to us along with the log-file of the latex run.

-