Frequently Asked Question List for TeX


Importing graphics into (La)TeX documents

Knuth, when designing the current version of TeX back in the early 1980s, could discern no “standard” way of expressing graphics in documents. He reasoned that this state could not persist for ever, but that it would be foolish for him to define TeX primitives that allowed the import of graphical image definitions. He therefore deferred the specification of the use of graphics to the writers of DVI drivers; TeX documents would control the drivers by means of \special commands.

There is therefore a straightforward way for anyone to import graphics into their document: read the specification of the \special commands your driver uses, and “just” code them. This is the hair-shirt approach: it definitely works, but it’s not for everyone.

Over the years, therefore, “graphics inclusion” packages have sprung up; most were designed for inclusion of Encapsulated PostScript graphics — which has become the lingua franca of graphics inclusion over the last decade or so.

Notable examples are the epsf package (distributed with dvips) and the psfig package. (Both of these packages were designed to work well with both Plain TeX and LaTeX 2.09; they are both still available.) All such packages were tied to a particular DVI driver (dvips, in the above two cases), but their code could be configured for others.

The obvious next step was to make the code configurable dynamically. The LaTeX standard graphics package and its derivatives made this step: it is strongly preferred for all current work.

Users of Plain TeX have two options allowing them to use graphicx: the miniltx “LaTeX emulator” and the graphicx.tex front-end allow you to load graphicx, and Eplain allows you to load it (using the full LaTeX syntax) direct.

The graphics package takes a variety of “driver options” — package options that select code to generate the commands appropriate to the DVI driver in use. In most cases, your (La)TeX distribution will provide a graphics.cfg file that will select the correct driver for what you’re doing (for example, a distribution that provides both LaTeX and pdfLaTeX will usually provide a configuration file that determines whether pdfLaTeX is running, and selects the definitions for it if so).

The graphics package provides a toolkit of commands (insert graphics, scale a box, rotate a box), which may be composed to provide most facilities you need; the basic command, \includegraphics, takes one optional argument, which specifies the bounding box of the graphics to be included.

The graphicx package uses the facilities of of graphics behind a rather more sophisticated command syntax to provide a very powerful version of the \includegraphics command. graphicx’s version can combine scaling and rotation, viewporting and clipping, and many other things. While this is all a convenience (at some cost of syntax), it is also capable of producing noticeably more efficient PostScript, and some of its combinations are simply not possible with the graphics package version.

The epsfig package provides the same facilities as graphicx, but via a \psfig command (also known as \epsfig), capable of emulating the behaviour (if not the bugs) the old psfig package. Epsfig also supplies homely support for former users of the epsf package. However, there’s a support issue: if you declare you’re using epsfig, any potential mailing list or usenet helper has to clear out of the equation the possibility that you’re using “old” epsfig, so that support is slower coming than it would otherwise be.

There is no rational reason to stick with the old packages, which have never been entirely satisfactory in the LaTeX context. (One irrational reason to leave them behind is that their replacement’s name tends not to imply that it’s exclusively related to PostScript graphics. The reasoning also excludes epsfig, of course.)

A wide variety of detailed techniques and tricks have been developed over the years, and Keith Reckdahl’s epslatex outlines them in compendious detail: this highly recommendable document is available from CTAN. An invaluable review of the practicalities of exchanging graphics between sites, “Graphics for Inclusion in Electronic Documents” has been written by Ian Hutchinson; the document isn’t on CTAN, but may also be browsed on the Web.

FAQ ID: Q-impgraph