importing pictures in LaTex

Any LaTex users here? I’m currently trying to teach myself. Right now, I’m trying to import a picture file. It was orginally a .bmp, but I converted it to an .eps file. However, it seems to just show up as a white rectangle of the specified size, rather than the actual picture.

Here’s the code I’m using:

In the preamble:
\usepackage{graphicx}

In the body:
\begin{figure}
\includegraphics[width=5cm]{temp.eps}
\end{figure}

I thought this would display the picture (shrunk to 5cm wide), but as far as I can tell it’s just inserting a 5cm wide white rectangle.

(By the way, I realize this question might be more appropriate to a LaTex forum. I can find some on Google, but I don’t know which of them are particularly active – can anyone recommend a good one for getting answers to basic questions quickly? Like I said, I’m just learning this stuff.)

Your code looks basically correct. A couple of ideas:

First, are you looking at the DVI file or the PS/PDF output? Many DVI readers won’t display raster images, and you have to convert to a more concrete file output before it’ll be included.

Second, if that’s not the case, it may be a BoundingBox issue. In the EPS file, there should be a line that reads something like

%BoundingBox: 0 0 100 150

or some such. These are supposed to tell LaTeX how much space the image elements take up, but they might be missing or incorrect. You can try manually tinkering with the bounding box in LaTeX, by using a command of the form

\includegraphics[width=5in,bb=0 0 200 492]{test.eps}

where the first two numbers are the coordinates of the lower left corner of your manually set bounding box, and the last two are the upper right.

Hope this helps. I’d also be interested in info on which LaTeX forums are best, BTW.

Thanks for the reply. I’m working with a program called PCTeX (basically just a LaTeX interface), which produced and displayed my DVI file (sans graphic). Following your suggestion, I tried having PCTeX export this file to PDF, but the PDF file still just shows a blank space where the graphic should be. It’s possible my problem is with some setting of PCTeX, not with my LaTeX code.

(I also checked the bounding box coordinates, and they seem to be right.)

I agree with MikeS, the code looks correct. The problem may be the EPS file itself, or the DVI viewer/converter.

If you’re going to be working with TeX and EPS files, you probably want to install GSView and GhostScript on your computer anyway. I’d use it to check the EPS file, especially the bounding box. (There’s an option to display the bounding box. I believe you can also “export” the file as EPS, and you get a chance to define the bounding box.)

I don’t know anything about PCTeX, but if it has an option to output a PostScript file, I think that would have the best chance of success. You can use GSView to view the resulting PS file.

I suppose it’s also possible that TeX isn’t finding and loading the graphicx package properly. Make sure you’re not getting any error messages while TeX runs.

tim314, I also use PCTex as my editor/typesetter/viewer … check under Settings >> Default Settings >> Advanced, find Method for Rendering DVI, and select “Postscript”. (I’ve got an old, old version, btw, so the menus may have changed a bit, but that setting’s in there somewhere.) That said, it’s probably not the problem - PCTex is a great “one click does it all” LaTeX environment, and I’ve never had any hassles from it … but bitmap to .eps graphics conversion is a misery… this program adds extra crap and triggers errors, this one leaves off the bounding box, *this * one mangles the fonts, blah, blah, argh! What did you use to convert? If you’d like me to send you a .tex file and .eps graphic that I know will render in PCTex, so you can test if it’s a problem with your graphic or the viewer, drop me an email.

That’s true. It’s worth trying different programs to generate the EPS file.

Also, if it’s a diagram or graph (i.e. vector graphics) generated by some other Windows program, you’ll get much better results using WMF2EPS. Installation is a bit tedious, but shouldn’t be too difficult if you read the documentation. But I wouldn’t recommend it for photos - it creates huge uncompressed files, IIRC.

The figure was originally a plot produced by MatLab, but I saved it as a BMP so I could add some text and other markings using a picture editor. (Probably it’s possible to make those annotations in MatLab, but I’m fairly new to that program too and was more comfortable just editing the BMP)

I converted from BMP to EPS using Adobe Acrobat. When I look at the EPS in GhostView, it looks right (I also used GhostView to check the bounding box).

Also, I checked whether PCTeX is set to render the DVI using PostScript, and it is. Yet, the graphic still shows up as a blank white space in the DVI file, and even if I have PCTeX extract to PostScript and view the resulting file in GhostView, it’s still a blank space.

lynne, I’ll be e-mailing you to request a file to test, like you suggested. Thanks.

You’ll probably be ten times better off if you export the file from MatLab directly to EPS; I did this extensively when I was prepping my undergrad thesis, and never had any problems. If you can’t figure out how to do the annotations you want directly within MatLab, you can modify the EPS file from Adobe Illustrator or some other vector-graphics-based drawing program.

Rule #1 of LaTeX graphics: Using BMP or other raster graphics in LaTeX when you don’t have to is just going to make your life more difficult.

Seconded… MATLAB and Maple both export to .eps with no mess. The trick is when you want to start doodling on / marking up / adding to your plot. For vector graphic programs, I’ve found that Illustrator has problems with exporting … and for whatever reason, Flash handles it beautifully (and allows me to get around some annoying font export problems by breaking text). For an all-around-totally-free-gives-no-extra-garbage conversion program, though, I’d recommend

the GIMP

(the above’ll get you the Windows installers)

Thanks for the help, everyone. I’ve got the problem fixed now. It turns out it wasn’t the file format – it seems to be some problem with PCTex finding the file. The thing is, I had been trying to keep all my figures in a separate folder . . . but I added the path to some sort of “optional directories” menu option (I can’t remember if it was exactly that – I’m at my home computer right now, which doesn’t have PCTex installed). I thought this caused it to look in the correct path without me having to type out the full path in the \includegraphic statement. At least, it made the “File not found” error go away. But I guess it didn’t do what I thought, because when I stuck the EPS file in the same path as my TEX file, suddenly things started working.

I still don’t get why my “File not found” error went away if it still wasn’t looking in the right directory. But it’s working, so for now I’m not going to worry about it.

Special thanks to lynne, whose sample code and picture eventually caused me to realize the problem – because I finally figured out that the only real difference between it and mine was where I’d saved the EPS file.