How to pdflatex a file that incorporates encapsulated Postscript graphics

Let's take a sample EPS file (triangle.eps)
%!PS-Adobe-3.0  EPSF-3.0
%%BoundingBox: 25 0 75 30
newpath
25 0 moveto
75 0 lineto
40 30 lineto
closepath
stroke
showpage

and a sample LaTex file (triangledrawing.tex)
\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
 This is a postscript figure

 \includegraphics{triangle.eps}
\end{document}

This file is successfully LaTeXed into triangledrawing.dvi. However the command
pdf triangledrawing 
results in the error message:
 Unknown graphics extension: .eps.

Solution

  1. Convert an eps graphics file into a pdf file using the command
     ps2pdf triangle.eps triangle.pdf
     
  2. Edit the LaTeX file into the following:
    \documentclass[12pt]{article}
    \ifx\pdftexversion\undefined  % in the case of `latex' command
      \usepackage[dvips]{graphics}
      \usepackage[dvips]{color}
    \else                         % in the case of `pdflatex' command
      \usepackage[pdftex]{graphics}
      \usepackage[pdftex]{color}
    \fi
    \begin{document}
       This is a postscript figure 
    
    \ifx\pdftexversion\undefined 
                      % no action
                      % standard latex processing requires no position adjustment
      
    \else 
    \vspace*{-750pt}  % pdflatex requires a vertical adjustment of graphics            
                      % - unfortunately different in different cases 
    \fi                         
    
    \includegraphics{triangle}   % Do not specify extension!
                                % The program will automatically choose whether to use
                                % `triangle.eps' or `triangle.pdf'
    
    \end{document}
    

Do we need this at all?

Maybe not. After all, a dvi can be converted to a pdf using the commands dvips, ps2pdf (or similar, depending on the system) However, one situation where pdflatexed file seems to work better (in my experience) is a slide presentation.


Author: Dr. Sergey Sadov (Dept.of Mathematics and Statistics, Memorial University of Newfoundland), serge dot sadov at google dot com