%%!TEX TS-program = pdflatex
%%!TEX encoding = UTF-8 Unicode
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}

%\usepackage{tmmlucida}
% \usepackage[expert]{fourier}
\usepackage{fourier}
\usepackage[scaled=0.85]{berasans}
\usepackage[scaled=0.85]{beramono}

\newcommand{\eps}{\texttt{eps}}
\newcommand{\pdf}{\texttt{pdf}}
\newcommand{\png}{\texttt{png}}
\newcommand{\jpg}{\texttt{jpg}}
\newcommand{\tiff}{\texttt{tiff}}
\newcommand{\graphicx}{\texttt{graphicx}}
\newcommand{\epstopdf}{\texttt{epstopdf}}

\newcommand{\MacTeX}{Mac\kern-.13em\TeX}
\newcommand{\BibTeX}{B\textsc{i\kern-.025em  b}\kern-.13em\TeX}
\newcommand{\TS}{\textsf{\TeX Shop}}

\usepackage{url}
\usepackage[letterpaper, margin=1.25in]{geometry}

\usepackage{microtype}

\usepackage[compact]{titlesec}

\usepackage{graphicx}

\title{Using \eps\ and \tiff\ Graphics \\ with \texttt{pdflatex}}
\author{by \\H. Schulz and R. Koch}
\date{2012/05/26}

\begin{document}
\maketitle

\section*{Introduction}

Users who include \eps\ and \tiff\ figures in documents are sometimes surprised to find that they have a problem when compiling those files using \texttt{pdflatex}. By default \texttt{pdflatex} can include \jpg, \png\ and \pdf\ files but not \eps\ or \tiff\ files. This document discusses a way of including \eps\ and \tiff\ files in documents compiled with \texttt{pdflatex}. It involves the ability to convert one graphic format to another on the fly and then include the converted file in the document. In the end these methods use Ghostscript or Apple's distiller and ``convert'' from ImageMagick or Apple's \texttt{sips} program, so conversion may fail if you did not install Ghostscript and ImageMagick.

\section*{Conversion Is Automatic in TeX Live 2011 and Later }

Since \eps\ illustrations cause such trouble for users switching from \TeX\ to pdf\TeX, the authors of TeX Live 2011 made a concerted effort to solve the problem once and for all. Instead of having to explicitly use the \epstopdf\ package the good news is that conversion of \eps\ files to \pdf\ files is now automatic in TeX Live 2011 and later if you use the \graphicx\ package, as almost all users do.

Here's how it works. Suppose your document contains the line
\begin{verbatim}
     \includegraphics{foo.eps}
\end{verbatim}
then the \graphicx\ package will automatically convert \texttt{foo.eps} to \texttt{foo-eps-converted-to.pdf} and load that pdf file. When the file is typeset again, \texttt{foo.eps} will be converted again only if it is newer than \texttt{foo-eps-converted-to.pdf}, but in any case \texttt{foo-eps-converted-to.pdf} will be loaded.

Some users omit the extension and just write
\begin{verbatim}
     \includegraphics{foo}
\end{verbatim}
which will also work as above: the file \texttt{foo.eps} will be converted to \texttt{foo-eps-converted-to.pdf} and so forth. But there is one tricky point. Suppose the source folder contains both \texttt{foo.eps} and a completely unrelated file named \texttt{foo.pdf}. Then the graphics command will load \texttt{foo.pdf} first and not even notice the \eps\ file. 

Incidentally, the system  names the converted file \texttt{foo-eps-converted-to.pdf} rather than \texttt{foo.pdf} precisely because a few users might have source files containing unrelated \eps\ and \pdf\ files with the same name; these users wouldn't appreciate an automatic conversion that destroyed their original \pdf\ file!

Users upgrading from earlier versions of TeX Live will be familiar with the command
\begin{verbatim}
    \usepackage{epstopdf}
\end{verbatim}
This command is not needed in TeX Live 2011 and later, although it does no harm, because the \graphicx\ package automatically loads it. Users may also be familiar with the \TeX\ command-line flag ``\texttt{--shell-escape}'', which gives \TeX\ the ability to call external programs during typesetting. This flag is also not needed in TeX Live 2011 or later for \eps\ to \pdf\ conversion because the system implements ``restricted shell escape'' which allows a small list of special system commands to be executed even if shell escape is not set. 

\section*{Using Apple's Distiller}

By default, conversion of eps files to pdf files is done with Ghostscript. Apple provides an alternate conversion program (often called a distiller), pstopdf. To use
this program instead of Ghostscript, add the following line to the document header immediately following inclusion of the \texttt{graphicx} package: 
\begin{verbatim}
     \usepackage{epstopdf}
     \epstopdfDeclareGraphicsRule{.eps}{pdf}{.pdf}{%
         /usr/bin/pstopdf #1 -o \OutputFile
         }
\end{verbatim}

Note: \textbf{The \texttt{--shell-escape} flag must be active for this to work}.

\section*{More Conversions}

The most common graphic file formats are  \eps, \pdf, \png, \jpg\ and \tiff. In particular, many scanners output \tiff\ files. The authors of TeX Live 2011 were unable to automate conversion of \tiff\ to \png\ using the \texttt{convert} program from ImageMagick because on Windows machines there is an unrelated program named \texttt{convert} which would cause security concerns if called indiscriminately from \TeX.

It is possible to automate this conversion on the Macintosh. But in that case, the \texttt{epstopdf} package must be explicitly loaded, \textbf{and the ``\texttt{--shell-escape}'' flag must be active}. Then add the following commands to the document header immediately following inclusion of the \texttt{graphicx} package:
\begin{verbatim}
     \usepackage{epstopdf}
     \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{convert #1 \OutputFile}
     \epstopdfDeclareGraphicsRule{.tiff}{png}{.png}{convert #1 \OutputFile}
     \PrependGraphicsExtensions{.tif, .tiff}
\end{verbatim}
or
\begin{verbatim}
     \usepackage{epstopdf}
     \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{%
         sips -s format png #1 --out \OutputFile}
     \epstopdfDeclareGraphicsRule{.tiff}{png}{.png}{%
         sips -s format png #1 --out \OutputFile}
     \PrependGraphicsExtensions{.tif, .tiff}
\end{verbatim}
if you wish to use Apple's \texttt{sips} converter rather than \texttt{convert} installed by MacTeX.

\subsection*{Automating More Conversions}

If you use \tiff\ conversions often you may wish to always load the lines given above automatically. You may do this by creating an \texttt{epstopdf.cfg} file containing only the conversion lines
\begin{verbatim}
     \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{convert #1 \OutputFile}
     \epstopdfDeclareGraphicsRule{.tiff}{png}{.png}{convert #1 \OutputFile}
     \PrependGraphicsExtensions{.tif, .tiff}
\end{verbatim}
or
\begin{verbatim}
     \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{%
         sips -s format png #1 --out \OutputFile}
     \epstopdfDeclareGraphicsRule{.tiff}{png}{.png}{%
         sips -s format png #1 --out \OutputFile}
     \PrependGraphicsExtensions{.tif, .tiff}
\end{verbatim}
and place it in your personal \texttt{texmf} tree at \url{~/Library/texmf/tex/latex/config/}. But remember that others that see your source file may not have your \texttt{epstopdf.cfg} file and a compile will fail for them.

If you create the \texttt{epstopdf.cfg} file you needn't include the \verb|\usepackage{epstopdf}| in your source document but \textbf{you still must use the command-line ``\texttt{--shell-escape}'' flag} to do the extra conversions.

\section*{Why all this talk about the ``\texttt{--shell-escape}'' flag?}

You'll notice that except for the default \eps\ to \pdf\ conversion noted above all the other conversions require the ``\texttt{--shell-escape}'' flag to be set to allow \texttt{pdflatex} to execute external commands. However, this ability to execute any program from within a \texttt{pdflatex} run is somewhat of a security concern.

\TS\ 3.10 and later are now shipped with the ``\texttt{--shell-escape}'' option turned off by default. It is believed most other ``front end'' applications for the \TeX\ distribution already do this.  This will immediately change things for new users of \TS\ but also previous users if they ever have to go back to the default preferences. So most of the conversions given above may stop working out of the box!

\section*{What do I have to do to ``fix things up''?}

There are basically three methods to convert your \tiff\ files to \png\ so you can get back to work.

\subsection*{Recommended: convert \tiff\ to \png\ before using the graphic}

To make up for the loss of automating \tiff\ to \png\ conversion \TS\ 3.10 has an additional menu item, \texttt{File}\,\(\to\)\,\texttt{Convert Tiff} (see the left side of Figure \ref{fig:ConvertTiffMenu}). The resulting listing of possible \tiff\ files to convert in the source file folder allows you to maneuver to the folder where the files are located and also choose multiple files (see the right side of Figure \ref{fig:ConvertTiffMenu}).
\begin{figure}
\centering
\includegraphics[width=2.35in]{figs/ConvertTiffMenu}\hfill\includegraphics[width=3.25in]{figs/ConvertTiffMenu2}
\caption{The \texttt{Convert Tiff} Menu in \TS\ 3.10}
\label{fig:ConvertTiffMenu}
\end{figure}

If you prefer using the command line you use `\texttt{convert}' or Apple's `\texttt{sips}' to do the conversion: use
\begin{verbatim}
convert myfile.tiff myfile.png
\end{verbatim}
or
\begin{verbatim}
sips -s format png myfile.tiff --out myfile.png
\end{verbatim}
to get \texttt{myfile.tiff} converted to \texttt{myfile.png}.





\end{document}
