# [texhax] Using .png, .jpg, .gif

Beverley Eyre fbe2 at comcast.net
Wed Aug 5 23:07:52 CEST 2009

Uwe,

First, I'd like t say thanks for your replies. They are just what I need.

Ok, given that the situation is as you describe it, the next obvious
question is, since LaTeX (or the graphicx package)  goes to the trouble
to find the bounding box info for [e]ps files, can we get it to get it
to find the bounding box info from .png or .jpg files? We know it can be
done because both convert and pdflatex do it. This sounds like a
question of a few lines of code, no?

Before I try it, I'd like your input.

thanks again

Bev

Uwe Lück wrote:
> Bev,
>
> sorry, I did not pay proper attention to the aspect of your posting
> concerning `convert' in \DeclareGraphicsRule:
>
> At 05:43 02.07.09, Beverley Eyre wrote:
>> I'd like to get \DeclareGraphicsRule to work, but it seems more
>> trouble to use than just converting each image file by hand.
>>
>> For example, if I want to use a .png file:
>> \DeclareGraphicsExtensions{.png, .eps}
>> \DeclareGraphicsRule{.png}{eps}{*}{`convert #1}      %% (the last arg
>> I've done in many different ways, e.g. {`convert #1 eps:- } )
>>
>> then, in the body:
>>
>> \includegraphics[width=1in]{myimage}   %% (which is myimage.png)
>>
>> I get an error msg telling me that I there is no bounding box. So in
>> order to use it, I have to determine the bounding box for the image
>> first, and then include that info into one or the other command.
>> But, if I just do:
>>
>> > convert myimage.png myimage.eps
>>
>> on the command line, it converts it without having to know the
>> bounding box info. I'm not sure why convert needs the bounding box
>> info in one case (latex) but not the other (command line).
>
> It is important to recognize that importing a graphics file with LaTeX
> has two parts: 1. the LaTeX run (building a .dvi), 2. previewing or
> printing (executing \special commands from the .dvi).
>
> The LaTeX run only needs to know the dimensions of the image. This is
> where the famous `bounding box' error occurs. LaTeX does not care
> about other contents of the graphics file. This other content is only
> used at getting visible output from the .dvi.
>
> The command in the fourth argument is only used at the second step,
> creating a screen display or printout from the .dvi. This is too late
> to tell LaTeX the bounding box info!
>
> Repeating:
>
>> But, if I just do:
>>
>> > convert myimage.png myimage.eps
>>
>> on the command line, it converts it without having to know the
>> bounding box info.
>
> It is wrong to say `convert' doesn't need knowledge of the bounding
> box. The truth is that `convert' is able to extract the bounding box
> information from myimage.png while LaTeX is not.
>
>>  I'm not sure why convert needs the bounding box info in one case
>> (latex) but not the other (command line).
>
> It is also wrong to say `convert' needs the bounding box info `in the
> LaTeX case'. The error message comes from LaTeX when it looks for that
> info in building the .dvi. As I said, `convert' is not involved at
> this first step.
>
> HTH -- Uwe.
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/