# Which graphics formats can be included in documents processed by latex or pdflatex?

There several types of graphics files. In no particular order .jpeg .eps .pdf .png .tif .jif (and no doubt others). Some work with latex, dvips and some work with pdflatex. How am I supposed to know which?

Just to confuse matters, metapost produces .eps but I can use these with pdflatex as long as I put in a four line incantation.

Can anyone explain this?

-
See also tex.stackexchange.com/questions/165/… for much useful related information. –  András Salamon Aug 5 '10 at 16:35
Thanks to everyone for these responses. –  BWW Aug 8 '10 at 17:02

Formats that work with LaTeX (dvi mode, using dvips):

• eps

Formats that work with LaTeX (dvi mode, using dvipdfm(x)):

• pdf
• png
• jpeg
• eps

Formats that work with pdfLaTeX (pdf mode):

LuaTeX can also read

TeX Live since 2010 will automatically convert eps files to pdf format. This can currently be done if you include the epstopdf package in your preamble, but of course you have to remember.

The reason for this way of working is that in dvi mode TeX simply leaves a space for the graphics. eps are included in the output by dvips.

pdfLaTeX includes graphics directly in the pdf, using the features available in that format. The pdf format can include other pdfs (no surprise), png, jpeg, jpeg2000 and jbig2 graphics. It can't be used to include eps graphics as this would require a full PostScript interpreter in pdfTeX. The eps format is complex, and so this is completely impractical.

Note that the LaTeX graphics package and associated helper code will search automatically for appropriate file extensions. As a result the extension should be omitted when including a graphic, for example

\includegraphics{foo}


for a file foo.eps. With a recent TeX system this will allow e.g. pdfLaTeX to auto-convert and .eps file to PDF format and find it 'auto-magically'.

-
Nice answer, but there's a slight typo: you've put a spurious 'd' in "epstopdf". I thought I'd mention it since it's the name of an important package in your answer! –  Arthur Reutenauer Aug 5 '10 at 13:15
Typo fixed, thanks –  Joseph Wright Aug 5 '10 at 13:26
It is worth mentioning here that screenshots should be saved in png (not jpeg) format if they will be imported from within the LaTeX input file compiled using pdfLaTeX. –  xport May 30 '11 at 14:37
It is often misunderstood that latex (dvi mode) support some kind of graphics. That's not true. The output driver decides the image formats: dvips supports PostScript, while dvipdfm(x) supports PDF, PNG and JPEG (with help of a .bb or .xbb file), and EPS (with help of GhostScript). –  Leo Liu Aug 3 '11 at 18:30
@leo liu: it depends what you mean by "support". latex processes an eps file (the dimensions of the figure are present in the file as text), and instructs its back-end (dvips) to incorporate the eps at the correct scale, rotation and position. this isn't "support"? hmmm... –  wasteofspace Jan 8 '13 at 23:54

Nowadays everything is actually very simple. In essence, you only need to worry about three different file formats:

• PDF for vector graphics

• JPEG for photos

• PNG for other kinds of raster graphics.

pdflatex supports all of these, and virtually any graphics file can be converted to one of these formats.

And pdflatex not only supports these, but it does it extremely well. For example, a JPEG file is included in the resulting PDF file as is. It is not uncompressed and re-compressed; nothing is lost, and you know that including a 100 KB JPEG file in your document will enlarge the resulting PDF file by exactly 100 KB.

(With tools such as latex + dvips + ps2pdf, all bets are off; typically you will get huge PDF files or low-quality re-compressed JPEG files or both. But fortunately nowadays you can use almost always pdflatex instead of latex.)

-

This is not an answer to the question as asked, but I think it may be of use to those trying to work out which format to use and how to select it.

If you are using the graphicx package and your intention is to be flexible (in that you want to be able to produce different output formats from the same source file) then there is a simple way to avoid having to know which to use: if you leave off the file extension in the \includegraphics command then it selects the best one available according to the mode. Thus if you've got the .eps and the .pdf versions of the graphic available, then latex + dvips will choose the .eps whilst pdflatex will choose the .pdf. The command is:

\includegraphics{MonaLisa}


Which one it chooses is even customisable: there's a list of extensions for each output type and it goes through the list until it finds a file that exists. Redefining that list changes the priorities. The list is stored in a comma-separated macro called \Gin@extensions so redefining that will change the order. Here's a simple way to ensure that .pdf is selected first when producing PDF output (since, oddly, the list for PDF output starts with .png):

\documentclass{article}

\usepackage{ifpdf}

\ifpdf
\PassOptionsToPackage{pdftex}{graphicx}
\fi

\usepackage{graphicx}
\ifpdf
\makeatletter
\let\orig@Gin@extensions\Gin@extensions
\def\Gin@extensions{.pdf,\orig@Gin@extensions} %prepend .pdf before .png
\makeatother
\fi
\begin{document}

\includegraphics{pullback}

\end{document}


For actually converting between formats, there are of course many ways to do that. TeXLive comes with a program epstopdf which converts an .eps file to a .pdf and there is even a LaTeX package epstopdf which will attempt to do the conversion for you (assuming that PDFTeX is allowed to do shell escapes) if it detects an .eps image!

For commandline conversion (ie on a U*nx system, including MacOSX), ghostscript can easily convert back and forth and comes with two scripts pdf2ps and ps2pdf that will do the conversion and the netpbm tools can convert between PDF, PS and lots of other graphics formats (of course there are many other such tools).

Thus by ensuring that you have each type of the image in the directory, you can be ensure that latex will pick up the right one for the right output.

-
That doesn't really answer the question: this feature of graphicx only helps if you already have the picture in a format that your TeX engine will understand; if you're running pdfTeX and you only have an EPS file, it won't magically convert it to something pdfTeX can use. –  Arthur Reutenauer Aug 5 '10 at 12:08
@Arthur Reutenauer: nonetheless, I think that it is a useful feature of graphicx for people to know about and that someone interested in this question might well find it useful. However, I have added a little on converting back and forth and, in particular, found a package that will do the conversion that you want! –  Loop Space Aug 5 '10 at 12:37
Sure, it's useful. But it's definitely not a “way to avoid having to know which [format] to use”, that's just wrong. On the contrary, you need to know which format to use in which case, and you need to do the conversion beforehand (except in the notable case of epstopdf, as mentioned by Joseph). –  Arthur Reutenauer Aug 5 '10 at 13:14
@Arthur Reutenauer: I interpret it a little differently, I think. The question "I always use pdflatex so which do I use?" has a simple - and boring - answer. The question "I find myself using both pdflatex and latex and get confused as to what to use. Can anyone help me?" is a little more complicated. What I do, is ensure that I have both formats available so that whichever I use, it Just Works^{TM}. That is what I was trying to explain, and that is what I think is useful to know. –  Loop Space Aug 5 '10 at 13:31
I know what you do. But you don't explain it in your main answer. As is, your first sentence is really misleading and unhelpful. –  Arthur Reutenauer Aug 5 '10 at 13:51

The graphics formats that you can use depend on the graphics driver not on (pdf)LaTeX:

As others have said pdfLaTeX in pdf-mode can use pdf, png, jpg, and mps.

LaTeX in dvi-mode and dvips as driver can use eps (and mps).

LaTeX in dvi-mode and dvipdfmx as driver can use eps (and mps), pdf, png, and jpg if you provide information about the bounding box and inform graphicx that you use dvipdfmx:

% test.tex
\documentclass{article}
\usepackage[dvipdfm]{graphicx}

\begin{document}

\includegraphics{demo.png}

\end{document}


First generate demo.bb with the bounding box information:

ebb demo.png


then compile to dvi with latex:

latex test.tex


and finally generate the pdf:

dvipdfmx test.dvi

-

This question has received excellent answers to the general question relating to what graphics formats the two Tex engines, but the Metapost part has been neglected (Just to confuse matters, metapost produces .eps but I can use these with pdflatex as long as I put in a four line incantation), so I shall document what you can get from Metapost.

Hobby's original implementation, mpost, only supported Postscript as its scaleable graphics format Metapost, and came with some other utilities to allow typesetting of labels (makempx, mpto). there are several other options.

1. Most usefully for the original problem, there is mptopdf, which is a modification of Hobby's mpost to create PDFs natively that was implemented, I think, by Hans Hagen together with the Metafun extensions, and is the parent of the mplib codebase used to set Metapost in Luatex. See Pragma's Metapost and Metafun pages.
2. John Hobby extended the Metapost programs to support their use with the Troff typesetting system in a manner very similar to its use with Tex. This opens up possibilities for setting Metapost, but ones that are inconvenient to use with Tex and which I think are not actively maintained.
3. Taco Hoekwater has extended mplib/mptopdf to natively support SVG, which is an image format that can be embedded in PDFs and is a more convenient graphical representation than either PS or PDF in some circumstances.
-

unfortunately, the psfrag command which can be of little help when dealing with graphics is not handled by pdflatex. For font consistency along your document, it may be a non-negligible shortcoming (you can still use tikz instead). Also, the next-generation vector format svg should become the most used one soon. I cannot tell if either latex or pdflatex accept it.

-