[Tex/LaTex] Including graphics for both DVI and PNG

dvigraphicspdfpng

I'm asking a question is quite similar to this one (where I don't seem to be able to leave comments):

MikTex error for PNG images when trying to produce DVI

I'm producing a PDF document, but I'm using the DVI previewer inside LeD while doing so. Including graphics is a bit problematic. Suppose I want to include a file simple_ambiguity.png.

\includegraphics[width=\textwidth]{simple_ambiguity.png}

doesn't work with the DVI, because of a bounding box error. This is a nuisance because I don't actually care about having the graphics display accurately inside the DVI, or even having it take up the right amount of space — I just want it to compile.

At the moment I'm using a workaround: I'm creating a dummy `empty picture' file simple_ambiguity.eps whose dimensions I don't really care about, and then writing

\includegraphics[width=\textwidth]{simple_ambiguity}

But this is a nuisance because I have to manually create an eps every time I add a new picture. What I'm looking for is some simple fire-and-forget solution that will make the DVI just compile.

(Of the answers in the question I linked to, the first seems to involve manually creating bounding boxes, and the second involves invoking ImageMagick on every compile, which will be unnecessarily slow & introduce a rather awkward dependency.)

Best Answer

If you just want the image to go away in dvi/dvips mode then:

\makeatletter
\def\temp{dvips.def}
\ifx\Gin@driver\temp
\def\Ginclude@graphics#1{\def\temp{#1}---image \expandafter\strip@prefix\meaning\temp---}
\fi
\makeatother

In your preamble will have that effect.

Related Question