pdfTeX and Figures
Back in the early '90s, exchanging TeX files with figures was a dodgy proposition. There was little interoperability between different implementations, and bandwidth considerations made shipping around (what, at the time, seemed rather large) figure files, which might not even work for the recipient, seem a less-than-attractive proposition.
Eventually, we settled on EPS figures, included with widely-supported macro packages, like epsf.tex
. (Heck, someone even did a Macintosh port for Textures!)
With LaTeX2e, graphicx.sty
became the standard package for including graphics, with even better cross-platform support. (Don’t even dare suggest using epsf.sty
, lest Dave Carlisle personally track you down and inform you of the error of your ways [I wish I could find that mailing list exchange from the mid '90s; it was priceless.].)
Anyway, this beautiful equilibrium was disrupted when MacOSX, TexShop and, pdfTeX came on the scene. PDF is the native-windowing environment under MacOSX, so pdfTeX was a pretty natural choice. Rather than the convoluted TeX→DVI→Postscript→PDF, you could go straight from TeX→PDF, with pdfTeX.
But pdfTeX works only with PDF figures, not EPS. At the very least, you’d need both a figure.eps
and a figure.pdf
file for interoperability. GhostScript will convert .eps
to .pdf
. In fact, just dropping such a figure file onto TexShop will do the conversion for you. So that’s not a problem.
But what about including the figure in your TeX file? It turns out that graphicx
handles both file formats with aplomb. All you have to do is remember to omit the file extension when inputting the figure:
\includegraphics[width=36ex]{foo}
and foo.pdf
will be used with pdfLaTeX, while foo.eps
will be used with LaTeX/dvips/GhostScript.
But what about Plain (pdf)TeX? For the longest time, I couldn’t figure out a solution. But then, quite by accident, I discovered that
\epsfxsize=36ex\epsfbox{foo.eps}
will work just fine with pdfTeX, provided you have both the .eps
and .pdf
figure files lying around. Apparently, epsf.tex
will read the .eps
file to get the bounding-box information, but then pdfTeX will auto-magically use the .pdf
file to produce the actual figure.
Update (8/28/2004): Whoops! That’s not what it’s doing at all. Looks like a little more work needs to be done to get intelligent figure inclusion in Plain (pdf)TeX.
Update (8/30/2004): Well, here’s one quasi-solution for Plain TeX: use graphicx.tex
, a Plain TeX wrapper around Dave Carlisle’s LaTeX package. Put a
\include graphicx
at the top of your TeX file and include the figures as above.
Unfortunately, unlike in the LaTeX version, the driver is hard-coded and defaults to dvips
. So what you need to do is
- Copy the file
to either/usr/local/teTeX/share/texmf.tetex/tex/plain/graphics/graphicx.tex
or to/usr/local/teTeX/share/texmf.local/tex/plain/graphics/
~/Library/texmf/tex/plain/graphics/
. - Edit the file to change the line
to read\def\Gin@driver{dvips.def}
instead.\def\Gin@driver{pdftex.def}
- Run
to make sure everything’s up-to-date.sudo texhash
Now the driver is hard-coded to pdftex
and will use the .pdf
figures. If your friend uses TeX/dvips, his TeX setup will pick up the .eps
figures as before.
It’s awkward to have to hard-code this choice. Maybe some TeX maven can figure out a way of auto-detecting which driver to use. After all, LaTeX manages to do it…
Update (8/31/2004): Nathan Goldschmidt is our hero for the day! With the (improved!) graphicx.tex
file, everything works automagically:
\input miniltx
\ifx\pdfoutput\undefined \def\Gin@driver{dvips.def} % we are not running PDFTeX \else \def\Gin@driver{pdftex.def} % we are running PDFTeX \fi
\input graphicx.sty \resetatcatcode
Update (10/4/2004): A conversation with Mark Srednicki made me realize that the advantages of using pdftex instead of tex/dvips/ghostscript were not drop-dead obvious to everyone. So here is a partial list:
- It’s faster, and generates fewer junk (.dvi, .ps) files along the way.
- Trouble-free PDF output, which won’t cause FastLane to hork a loogie.
- pdfsync support. With this (La)TeX macropackage, clicking on a spot in the PDF preview bring you to the corresponding point in the TeX source file. Amazingly useful while editing.
-
HyperTeX support. The hyperref macropackage creates clickable hyperlinks in your document. It automatically generates internal ones — to sections, numbered equations, references, etc. — and, with the help of things like my bibtex style file and modified article class one gets external links, to papers on the archives and
mailto:
links for author email address(es). Or you can add your own, with the\href{}{}
macro.Unfortunately, all these links are lost when passed through tex/dvips/ghostscript. You need to use pdftex.
- For really high-quality typography, you can enable margin kerning.
Re: pdfTeX and Figures
Maybe this will help… this is what I’ve always used in my preamble…
\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse % we are not running PDFLaTeX
\else
\pdfoutput=1 % we are running PDFLaTeX
\pdftrue
\fi
\ifpdf
\usepackage[pdftex]{graphicx}
\usepackage[pdftex,dvipsnames,usenames]{color}
\else
\usepackage{graphicx}
\usepackage[dvips,dvipsnames,usenames]{color}
\fi
\ifpdf
\DeclareGraphicsExtensions{.jpg, .pdf, .tif}
\else
\DeclareGraphicsExtensions{.eps}
\fi
I include graphics in this way:
\includegraphics[width=0.5\textwidth]{sample}