Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a tex file with \includegraphic elements for some PNG images. I use MikTeX on Windows and the PDF is fine.

Now, I need a DVI so I tried using: \pdfoutput=0 This creates a DVI, but only after I remove all the PNG images… Otherwise I get errors like:

! LaTeX Error: Cannot determine size of graphic in math-box-plot.png (no BoundingBox).
share|improve this question
    
You should also consider compiling to PDF rather than DVI. –  Juan A. Navarro Feb 16 '11 at 10:06
    
I converted the PNG files to EPS and used those in includegraphics and it works. –  Hagai Cibulski Feb 18 '11 at 9:17
add comment

3 Answers

I always make portable latex source equally suitable for compiling both with latex and pdflatex. My remedy is rather simple.

Put \usepackage{graphicx} into preample (without any driver specified).

Import eps or pdf graphics with \includegrpahics{filename}; latex compiler then loads filename.eps whereas pdflatex takes filename.pdf. MikTeX automatically converts eps into pdf on fly if the epstopdf packege is loaded.

Import png graphics with \includegrpahics[nathwith=<XX>bp, natheight=<YY>bp, width=<width>]{filename.png} with .png extension explicitely shown; in that case you dont need to invent \DeclareGraphicsRule. Natural height and width of bitmap graphics can be determined from file properties in Windows Explorer or any graphics editor, e.g. Windows Paint.

share|improve this answer
add comment

Install the program ImageMagick, then you can do it on the fly:

\documentclass{article}

\usepackage[dvips]{graphicx}
\DeclareGraphicsRule{.png}{eps}{.bb}{`convert #1 eps:-}
\DeclareGraphicsRule{.gif}{eps}{.bb}{`convert #1 eps:-}
\usepackage{grfext}
\AppendGraphicsExtensions*{.png,.gif}
\usepackage{bmpsize}

\makeatletter
\newcommand*{\IncludeGraphics}[2][]{%
  \begingroup
    \let\@found\@empty
    \@for\@type:=\bmpsize@types\do{%
      \ifx\@found\@empty
        \@nameuse{bmpsize@read@\@type}{#2.\@type}%
        \ifbmpsize@ok
          \let\@found=\@type
        \fi
      \fi
    }%
    \ifx\@found\@empty
      \includegraphics[{#1}]{#2}%
    \else
      \includegraphics[{natwidth=\bmpsize@width,natheight=\bmpsize@height,#1}]{#2}%
    \fi
  \endgroup
}
\makeatother

\begin{document}
  \IncludeGraphics{lion}\qquad % a png image
  \IncludeGraphics{knuth-tex}  % a gif image
\end{document}

btw: you do not need the \pdfoutput=0 simply run latex instead of pdflatex

share|improve this answer
    
It may be too tricky for new TeXers, with no actual advantage. BTW, ImageMagick may be overkill, bmeps is enough. –  Leo Liu Feb 16 '11 at 11:34
1  
no, it isn't, and ImagaMagick can be used for any other conversion, hence it is no overkill. –  Herbert Feb 16 '11 at 12:07
add comment

TeX is text based, it cannot determine the size of PNG image itself by default.

A quick solution:

\usepackage{bmpsize}

And use

\usepackage[dvipdfmx]{graphicx}

It is better to use extractbb (also named ebb, xbb) program to produce .bb or .xbb file for LaTeX. Use this command in 'Command Prompt':

for %i in (*.png) do xbb %i

(or for %i in (*.png) do extractbb -x %i, I'm not sure about MiKTeX.)

And use

\usepackage[dvipdfmx]{graphicx}

(I use TeX Live, only dvipdfmx supports png images. But MiKTeX seems different, I can't remember well.)

share|improve this answer
1  
Leo, you better use <code> ... </code> blocks for the command line and similar text to avoid the TeX syntax highlighter. –  Martin Scharrer Feb 16 '11 at 8:41
    
@Martin: I did not realise that the two were handled differently –  Joseph Wright Feb 16 '11 at 9:28
    
@Joseph: The syntax highlighting is done in <pre class="prettyprint lang-tex"> tags around <code>. Therefore single <code> tags on their own are not highlighted. –  Martin Scharrer Feb 16 '11 at 9:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.