# 2010-09-05 Including bitmaps in LaTeX documents (en)

I was asked some time ago how to include a jpg file in a LaTeX document. Well, if you use pdflatex, this is simple: you just `\usepackage{graphicx} `and then

```\includegraphics[options]{filename.jpg}
```

where options may be (among others) `width=...`, `height=...` (or both - but then the picture might be distorted unless you also include the `keepaspectratio` option; in that case, the actual width and height of the included picture may not be be both equal to the given dimensions, but they will never exceed them).

A problem arises, however, when one wants to create a dvi file instead of a pdf one. This might seem strange - does anyone still use dvi? Well, yes, and for a number of reasons.

• On slow computers, `xdvi` is noticeably faster than `xpdf`.
• It is highly nontrivial to obtain so-called source specials with pdf.
• Last but not least, many people rely on Postscript inclusions via dvips, so pdflatex is useless for them.

It turns out that the `graphicx` package supports dvips, but the only supported format is eps. This means that the jpg (or whatever) file must be first converted to eps (it is possible to do it automatically, but this is not trivial again…). There are many utilities which can do that; on Linux, ImageMagick is a standard one (it has a Windows version, too); GIMP can do it, too.

But there’s something more: it turns out that one may omit the extension, so that

```\includegraphics[options]{filename}
```

works equally well. In particular, this also means that if you have both `filename.jpg` and `filename.eps`, then you may run `latex` or `pdflatex` on the same source file and everything will Just Work™! But beware: what if you have, say, `filename.jpg`, `filename.png` and `filename.pdf` in the local directory? (The last one is especially tricky, since it might be the output file of your actual TeX job, which is currently being written - this may lead to a LaTeX error!) The answer (with `pdflatex`, of course) is: first a `filename.png` is looked for, then `filename.pdf`, then `filename.jpg`. (In fact, I’ve omitted a few more possible extensions here - see `pdftex.def` in your TeX distribution and look for the line containing the command `\Gin@extensions`.) So if you have both png and jpg, the first one will be used.