# LaTeX, PostScript, and PDF

Note: If you want to use LaTeX to make presentations in PDF, see PPower4 or beamer.

Note: psTricks doesn't work in pdflatex. You could use pdfTricks.

The traditional way to translate your LaTeX document into PostScript is to run the latex program to get a DVI file, and then dvips to get a PostScript file.

With PDF being used more often nowadays, you could run the ps2pdf program to convert PostScript into PDF. (Or use a commercial application such as Acrobat Distiller.) The visual result is usually not nearly as good as it could be (because the way fonts are handled in the process), and you are still missing all those nifty things like an expandable contents menu and hyperlinked references. To take advantage of the possibilities of PDF, you can use pdflatex to translate your LaTeX documents directly into PDF.

But suppose you still want PostScript (as well as PDF)? You can convert PDF to PostScript, using acroread or gs. However, this too has its disadvantages. (For one, the PostScript file can be huge.)

What you want is one LaTeX document that can be converted into PostScript and PDF without having to convert PostScript into PDF or vice versa:

There are just a few things to take care of so your LaTeX document can be processed by both latex and pdflatex. These have to do with setting up all the extras such as hyperlinks for PDF only, and taking care of the different way external images are included into the document.

Here is the frame of a LaTeX document that takes care of these things:


\documentclass[a4paper]{article}
\usepackage{ifpdf}

% here you should include other packages with \usepackage

\ifpdf

% one of these two:
\usepackage[pdftex]{graphicx}  % note the x at the end
%\usepackage[pdftex]{epsfig}

% hyperref should be the last package loaded:
\usepackage[pdftex]{hyperref}

\else

% one of these two:
\usepackage[dvips]{graphicx}  % note the x at the end
%\usepackage[dvips]{epsfig}

% make the command \href from hyperref available as a 'print only'
\newcommand{\href}[2]{#2}

\fi

\begin{document}

% some text

% include some figure:
\includegraphics[width=\textwidth]{figure}  % note: no file extension

% if you use the 'epsfig' package instead of 'graphicx' you could use:
%\epsfig{file=figure,width=\textwidth}   % note: no file extension

% more text

\end{document}


The package hyperref takes care of all the PDF extras, such as menu's and hyperlinks, and much more. It is loaded (\usepackage) with the pdftex option, necessary for the program pdflatex, but there are many more options you could set. See the hyperref manual for details.

Inclusion of images is handled differently in latex and pdflatex. Different versions of images are included, selected by file name extension. That is why you should not use a file name extension in you LaTeX document.

In latex, images are included by searching for a file with the extension .eps or .ps, which must be an Encapsulated PostScript file.

pdflatex can't handle PostScript images. Instead, it will look for a file with one of these extensions:

    .png .pdf .jpg .mps

As you can see, you can include certain types of bitmap images. Vector graphics in PostScript should be converted first, preferably to PDF, so the image is still a vector graphic. You can convert a PostScript graphic into PDF with the epstopdf program. Don't use ps2pdf!

image type for latex for pdflatex
png, jpg, mps convert to EPS
(e.g. with xv)
use it
other bitmap image convert to EPS
(e.g. with xv)
convert to PNG
(e.g. with xv)
PostScript graphic use it convert to PDF
with epstopdf

To do (perhaps): a more complex example with psTricks and pdfTricks.