Friday, October 9, 2009

Using .eps Graphics with PDF output

For quite some time now, the graphicx package would automatically sort out which file types to use whenever it encounters \includegraphics{some_file}, where the extension of some_file is not specified.

That is to say, if you are generating to a .dvi, the system would look for some_file.eps. If you are generating to a .pdf, it looks for some_file.{pdf|jpg|png}.

But what if you want a .pdf and you work with .pdf, .jpg and .png graphic files, but suddenly you received a .eps graphics from your collaborator? (This actually happened to a lecturer at my university.)

Well, you could always convert it manually to a .pdf yourself with GhostScript or GIMP, of course. But now the process can be automated if you're using MikTeX 2.8 or TeXLive 2009, as highlighted by Rob Hyndman.

In MikTeX 2.8, use the epstopdf package together with graphicx, like so:

\documentclass{article}
\usepackage{graphicx,epstopdf}
\begin{document}
\includegraphics[width=\textwidth]{some_file}
\end{document}

If all you have is some_file.eps, it will be automatically converted to a some_file-eps-converted-to.pdf during the first time the LaTeX document is compiled and included in the final document output.

If you're using TeXLive 2009, you don't even have to load epstopdf explicitly, but I say include it anyway, for portability's sake.

No comments: