# Ryan's Blog

## Including graphics in a LaTeX document

Posted in latex by ryanlayer on October 6, 2009

There are two ways to incorporate images into your LaTeX document, and both use the graphicx package by means of putting the command  \usepackage{graphicx} near the top of the LaTeX file, just after the documentclass command.

The two methods are

1. include only PostScript images (esp. “Encapsulated PostScript”) if your goal is a PostScript document using dvips
2. include only PDF, PNG, JPEG and GIF (Stefan correctly pointed out that GIF is not supported, you must convert to a supported fomat) images if your goal is a PDF document using pdflatex, TeXShop, or other PDF-oriented compiler.

In all cases, each image must be in an individual 1-image file; no animation files or multipage documents.

## Only PostScript images

Most mathematical/scientific graphics software allows you to save graphics (figures, diagrams, graphs) in PostScript form; this includes Mathematica, Maple, Matlab, IDL, and xfig (a marvelous X figure-drawing program). Even bitmap images like JPEG and PNG files can be converted to PostScript form with programs like “xv” or “convert

”.

Where you want a PostScript image to appear, use the \includegraphics command, possibly with scaling or rotation options, e.g.,

```  \includegraphics{myfig.eps}
\includegraphics[width=60mm]{myfig.eps}
\includegraphics[height=60mm]{myfig.eps}
\includegraphics[scale=0.75]{myfig.eps}
\includegraphics[angle=45,width=52mm]{myfig.eps}
```

Of course, any of these can be inserted into a figure environment, and/or a centering environment or a framebox.

Then you must compile the document with latex followed by dvips -Ppdf, which produces a PostScript document with embedded PostScript images. You can convert the PostScript document to PDF using “ps2pdf” or “dvipdf”.

Two characteristics which the component (Encapsulated) PostScript image files must have are

• no file contains more than one page
• each has a valid BoundingBox line

If the PostScript file does not include a bounding box line, you can insert it using the text editor of your choice.

## Only non-PostScript images

The compiler pdflatex (Unix) and TeXShop (Macintosh) convert LaTeX source directly to PDF, and do not accept PostScript images. Instead, they take PDF images, as well as bitmap pictures in PNG or JPEG or GIF format. So to use pdflatex, you must convert any PostScript images to one of these other forms. For photos, JPEG is best. For other bitmap images, PNG is best. For non-bitmap images (e.g., graphs, drawings, stuff with text and symbols) it is best to convert to PDF, using the command epstopdf (in the usual TeX bin directory, e.g., /usr/local/tex/bin/epstopdf). The command

`unix>   epstopdf myfig.eps`

produces the file myfig.pdf, which can then be used in the command \includegraphics{myfig.pdf}. for compilation with pdflatex or TeXShop.

The possible \includegraphics options with PDF/PNG/JPEG images are much the same as with PostScript, e.g.,

```  \includegraphics{myfig.pdf}
\includegraphics[width=60mm]{myfig.png}
\includegraphics[height=60mm]{myfig.jpg}
\includegraphics[scale=0.75]{myfig.pdf}
\includegraphics[angle=45,width=52mm]{myfig.jpg}
```

With PNG or JPEG you should specify an explicit width or height rather than “scale”, since bitmap images have no intrinsic size, nothing corresponding to Bounding Box information, although graphicx seems to use 72 pixels per inch as a default size for bitmap images.