Skip to the Main Content

Note:These pages make extensive use of the latest XHTML and CSS Standards. They ought to look great in any standards-compliant modern browser. Unfortunately, they will probably look horrible in older browsers, like Netscape 4.x and IE 4.x. Moreover, many posts use MathML, which is, currently only supported in Mozilla. My best suggestion (and you will thank me when surfing an ever-increasing number of sites on the web which have been crafted to use the new standards) is to upgrade to the latest version of your browser. If that's not possible, consider moving to the Standards-compliant and open-source Mozilla browser.

August 28, 2004

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

  1. Copy the file
    /usr/local/teTeX/share/texmf.tetex/tex/plain/graphics/graphicx.tex
    to either
    /usr/local/teTeX/share/texmf.local/tex/plain/graphics/
    or to ~/Library/texmf/tex/plain/graphics/ .
  2. Edit the file to change the line
    \def\Gin@driver{dvips.def}
    to read
    \def\Gin@driver{pdftex.def}
    instead.
  3. Run
    sudo texhash
    to make sure everything’s up-to-date.

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:

  1. It’s faster, and generates fewer junk (.dvi, .ps) files along the way.
  2. Trouble-free PDF output, which won’t cause FastLane to hork a loogie.
  3. 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.
  4. 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.

  5. For really high-quality typography, you can enable margin kerning.
Posted by distler at August 28, 2004 12:59 AM

TrackBack URL for this Entry:   https://golem.ph.utexas.edu/cgi-bin/MT-3.0/dxy-tb.fcgi/425

3 Comments & 0 Trackbacks

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}

Posted by: Nathan Goldschmidt on August 31, 2004 12:15 AM | Permalink | Reply to this

Re: pdfTeX and Figures

Much of that seems to me to be superfluous. Under LaTeX, I can just do

\usepackage{graphicx}

and the include graphics with

\includegraphics[width=...]{foo}

and the correct driver (dvips.def or pdftex.def) will be automatically selected and the correct file (foo.eps or foo.pdf) will loaded.

But your conditional does seem to do the trick under Plain TeX. Here’s my graphicx.tex file:

\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

Now, exactly the same TeX file will work either under pdfTeX or under TeX/dvips/GhostScript.

Posted by: Jacques Distler on August 31, 2004 1:39 AM | Permalink | PGP Sig | Reply to this

Re: pdfTeX and Figures

Hi,

In your post you mentioned that to make pdf file of your tex document that includes ‘graphicx’, we must have 2 versions of our graphics - one as .pdf and the other as .eps. Also that we must \includegraphic{filename} as opposed to \includegraphic{filename.eps}

This works in TeXcenter. And I cannot tell you how much I love you for posting this. I mean you saved my life. ;)

Posted by: N on February 10, 2007 3:26 AM | Permalink | Reply to this

Post a New Comment