Include EPS graphics in pdflatex

It’s a shame that pdflatex supports jpg, png, pdf… graphic type but not EPS while latex supports EPS but not the others. From my previous post, there is an easy way to convert EPS to pdf.  But it is just annoying that every time you want to include an eps graphic you have to do the conversion manually. After googling, I found out that there is a way to let pdflatex do the conversion for you. Here is how.

1. Install texlive-extra-utils which contains epstopdf.

sudo apt-get install texlive-extra-utils

2. Insert the following code in in the preamble of your document.

\newif\ifpdf
\ifx\pdfoutput\undefined
   \pdffalse
\else
   \pdfoutput=1
   \pdftrue
\fi
\ifpdf
   \usepackage{graphicx}
   \usepackage{epstopdf}
   \DeclareGraphicsRule{.eps}{pdf}{.pdf}{`epstopdf #1}
   \pdfcompresslevel=9
\else
   \usepackage{graphicx}
\fi

3. Include eps graphics like usual

\includegraphics[width=7in]{result_1.eps}

4. Compile the tex file with -shell-escape option

 pdflatex -shell-escape texWithEPSYAY.tex

During the compiling pdflatex converts the included eps graphic files into pdf files on the fly using epstopdf. After compiling, esptopdf generates a lot of pdf files (conversion from eps files). You will find the compile (is compile a noun?) a little bit slow. That is because it takes some time for epstopdf to convert eps files to pdf files. As one can imagine, it will become REALLY slow as the number of eps graphics included in a document increases. One way to fix this problem is that when inserting an eps graphic in a document, LEAVE THE FILE EXTENSION OFF. For example, instead of

\includegraphics[width=7in]{result_1.eps}

use

\includegraphics[width=7in]{result_1}.

By this way, pdflatex first checks if result_1.pdf exists. If not, it locates result_1.eps and converts it to a pdf file. When result_1.pdf does exist, it simply inserts result_1.pdf in the document. Therefore, pdflatex only does the conversion when the corresponding pdf file does not exist. If you do NOT leave the file extension off, pdflatex would convert the eps graphics in the document to pdf files every time you compile.

Hope this helps.

5 Responses to “Include EPS graphics in pdflatex”

  1. Maurya Says:

    This is not working under window xp. Can you help me. The output of the compilation is as follow:

    %%%%%%%%%%%%%%%%%%
    This is pdfTeX, Version 3.1415926-1.40.9 (MiKTeX 2.7)
    entering extended mode
    (tst1.tex
    LaTeX2e
    Babel and hyphenation patterns for english, dumylang, nohyphenation, ge
    rman, ngerman, german-x-2008-06-18, ngerman-x-2008-06-18, french, loaded.
    (“C:\Program Files\MiKTeX 2.7\tex\latex\base\report.cls”
    Document Class: report 2005/09/16 v1.4f Standard LaTeX document class
    (“C:\Program Files\MiKTeX 2.7\tex\latex\base\size12.clo”))
    (“C:\Program Files\MiKTeX 2.7\tex\latex\graphics\graphicx.sty”
    (“C:\Program Files\MiKTeX 2.7\tex\latex\graphics\keyval.sty”)
    (“C:\Program Files\MiKTeX 2.7\tex\latex\graphics\graphics.sty”
    (“C:\Program Files\MiKTeX 2.7\tex\latex\graphics\trig.sty”)
    (C:\localtexmf\tex\latex\misc\graphics\graphics.cfg)
    (“C:\Program Files\MiKTeX 2.7\tex\latex\pdftex-def\pdftex.def”)))
    (C:\localtexmf\tex\latex\misc\oberdiek\epstopdf.sty) (tst1.aux)
    (“C:\Program Files\MiKTeX 2.7\tex\context\base\supp-pdf.tex”
    [Loading MPS to PDF converter (version 2006.09.02).]
    )

    ! Package pdftex.def Error: File `kw.pdf’ not found.

    See the pdftex.def package documentation for explanation.
    Type H for immediate help.

    l.22 \includegraphics[width=7in]{kw.eps}

    ?
    Overfull \hbox (133.51482pt too wide) in paragraph at lines 22–23
    [][]
    [1{C:/Documents and Settings/All Users/Application Data/MiKTeX/2.7/pdftex/confi
    g/pdftex.map}] (tst1.aux) )
    Output written on tst1.pdf (1 page, 6551 bytes).
    Transcript written on tst1.log.

  2. Jirka Says:

    You should state, that you need to use
    \epstopdfsetup{suffix=}
    in the other case the name of your created pdf is default nameofthefile-eps-converted-to.pdf and pdtlatex call error because nameofthefile.eps doesnt exist…

  3. Jirka Says:

    But thank you! I like it :)

  4. Heitor Says:

    That is a great hint! thank you very much!!!!!

  5. JM Says:

    Thanks! Works perfect!

Leave a Reply