Including graphics in LaTeX/PDF documents

Here we discuss how to include graphics in a LaTeX document intended to be later converted to PDF format, paying special attention to how to maintain simultaneous DVI and PDF versions of the same document.

If the document has no graphics, the DVI version can be produced with latex, and the PDF version with pdflatex:

latex filename.tex

pdflatex filename.tex
If the document does have graphics, then a solution is to produce a PostScript version with dvips (taking care of using the -Ppdf flag) and to distill it later with the Acrobat Distiller. In our system both operations can be done in one step by using the dvi2pdf command:
dvi2pdf filename.dvi
However this has several drawbacks. The Acrobat Distiller is a commercial program, so it costs money to purchase and upgrade (we have been using a "frozen" version purchased several years ago). Also in some situations it may give problems with fonts. So it is a good idea to have an alternative based on free software only. A possibility is to use the dvipdfm command (included in the RedHat distribution of Linux):
dvipdfm filename.dvi
Another alternative (which we discuss below) is to to include graphics in a way that both latex and pdflatex can manage.

Graphics can be produced in various formats. For inclusion in a DVI file by latex they must be in EPS (Encapsulated PostScript) format. Unfortunately EPS files cannot be included in PDF documents with pdflatex, they must be either in PDF format or in one of various graphic formats such as PNG or JPEG. The way graphics are usually included are also different: latex uses the \psfig command (and the psfig or epsfig package), and pdflatex uses \pdfimage. There is however a command that can be processed by both latex and pdflatex: \includegraphics from the graphics package - with added options if the graphicx package is used.

So assume that you have a figure in an EPS file and want to include it in a LaTeX file filename.tex to be processed by both latex and pdflatex. Do the following:

  1. Make a PDF version of the figure:
    That produces foo.pdf. You may also convert your EPS file to PNG or some other graphic format if you wish:
    convert foo.png 
    Keep both files, the original and the new foo.pdf (or foo.png, etc.) together in the working directory, since both will be needed.

  2. Include the graphicx package in your LaTeX file with \usepackage{graphicx}.

  3. Use the \includegraphics command with the name of the graphic file foo without extension. By doing so each of latex and pdflatex will choose the correct version of the file to be included, i.e., latex will use and pdflatex will use foo.pdf (or foo.png, or whatever graphic format you have chosen).

The following example illustrates the use of the graphicx package and the \includegraphics command:

Some text...

\caption{This is a figure.}

More text...


The syntax of the \includegraphics command is as follows:

where parameters is a comma-separated list of any of the following: bb=llx lly urx ury (bounding box), width=h_length, height=v_length, angle=angle, scale=factor, clip=true/false, draft=true/false.

Miguel A. Lerma, 7/25/2001