LaTeX PDF production

Introduction

PDF (the format that can be read by Acrobat Reader) is an increasingly popular format for documents. The structured approach to document preparation encouraged by LaTeX makes it trivially easy to produce PDF documents. You can use nearly all the usual latex facilities, though graphics may require treatment. With just a little extra effort, PDF features like bookmarks can easily be employed.

The most direct way to produce PDF is to use pdflatex. The rest of this document assumes that pdflatex will be used. The only advantage of slower methods (involving latex, dvipfdm, dvips and ps2pdf) is that you use psfrag.

Fonts

Though the usual LaTeX fonts can be used, you can reduce file sizes and the risk of problems if you stick to the "core-14" set of postscript fonts - times, helvetica, courier and symbol. Fonts other than these will need to be embedded in the document. Non-postscript fonts pose extra problems if you have an old latex distribution. To use the postscript fonts use

• \usepackage{times}
• \usepackage{mathpazo} - times font plus extra support for maths
• \usepackage{courier}
• \usepackage{helvet} - helvetica as the sans serif font

Graphics

pdflatex can cope with PDF, JPEG and PNG formats using the usual \includegraphics command. You can convert existing encapsulated postscript using eps2pdf (it's also possible to convert them on-the-fly using the epstopdf package).

There 2 ways to compensate for the loss of psfrag

purifyeps

If you switch between latex and pdflatex, graphics can be a problem. You can

• Use \includegraphics{fig1} and have copies of the graphic file available for latex and for pdflatex (e.g. fig1.eps, fig1.jpg)
• Use purifyeps. This creates from an eps file a file that can be used both with latex and pdflatex. Do
   purifyeps --fontmap=/usr/share/pstoedit/mpost.fmp fig1.eps fig1.eps

to convert a file (fig1.eps in this case). pdflatex usually ignores eps files. Putting the following LaTeX code in your document's preamble will solve that
      % Tell pdfLaTeX that all .eps files were produced by MetaPost.
\usepackage{graphicx} % or graphics
\usepackage{ifpdf}
\ifpdf
\DeclareGraphicsRule{.eps}{mps}{*}{}
\makeatletter
\makeatother
\fi


Features

The hyperref package has many customisable features. These can be set when the package is initially loaded in (make sure it comes last of your loaded packages), or you can set options later. Here's a sample \usepackage line with some explanation. For further information see the documentation

\usepackage[pdftitle={Just a Test},pdfpagemode=UseOutlines,
bookmarks=true,pdftex=true]{hyperref}

• pdftitle - the title that the PDF viewer will show
• pdfauthor - the author that the PDF viewer will show
• pdfpagemode - the PDF viewer's initial mode of display
• pdfpagetransition - the page-transition effect
• bookmarks - whether bookmarks are required
• colorlinks - whether links should be in color (there are other options to change the color)
• pdftex - the target format. hyperref also supports HTML production, etc.

Associated packages

• The pdfpages package lets you include several PDF pages from another PDF document (there's an example below)
• The cmap package makes your PDF files searchable and copyable

Page size

There are several ways to start with a LaTeX file, convert it to PDF and print it out. At each stage there's a chance that the "paper size" will change, thus disturbing paper layout. If the defaults are incorrectly set, the following information might be useful.

• latex has a default paper size option that we set to A4. You can use "\documentclass[a4paper..." to force the issue.
• pdflatex has a default paper size option set in a config file pdftex.cfg
• acroread has "shrink/expand to page" options that you'll need to suppress. Check the "Page Setup" settings too.

If you're administrator on a recent Unix LaTeX installation, the following should fix all defaults to A4

   texconfig xdvi a4
texconfig dvips paper a4
texconfig pdftex paper a4
texconfig dvipdfm paper a4


Post-production

The teaching system has the following PDF utilities in /opt/Multivalent/bin. You won't normally need them, but they're useful if things go wrong.

• PDFvalidate
• PDFinfo - displays author, title, fonts used, etc
• PDFcompress - can sometimes reduce filesize to 20% of the original

An example

Here's an example of how to use CUED's unofficial IIBproject class. and get PDF features. Just save the file and run it through pdflatex

% The section titles here are typical of a report on an
% experimental project. Other types of projects will
% have different section titles.
% Tim Love (tpl@eng.cam.ac.uk), 24/2/06

\documentclass{IIBproject}
% Use documentclass[wide]{IIBproject} to have narrower margins
\usepackage{setspace}
\usepackage{pdfpages} % to import PDF pages
\usepackage{times}
\usepackage{cmap}     % to produce searchable PDF
\bibliographystyle{plain}
\pagestyle{empty}
% The next line sets 1.5 spacing
\onehalfspacing
\begin{document}

% Title Page
\author{A Student (college code)}
\title{Just a Test}
\projectgroup{A-E}
\maketitle
\thispagestyle{empty}

% Summary
\begin{abstract}
Just a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test
No more than 100 words.
\end{abstract}
\pagestyle{plain}
\tableofcontents
\newpage

\section{Introduction}
Just a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test
ust a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test

\section{Theory and Design of Experiment}
Just a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test
ust a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test

\includepdf[pages={3-5}]{/users0/cstaff/tpl/doc/latex/Masters/scripts.pdf}

\section{Apparatus and Experimental Results}
Just a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test
ust a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test

\section{Results and Discussion}
Just a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test
ust a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test

\section{Conclusions}
Just a test Just a test Just a test Just a test Just a test Just a test
Just a test Just a test Just a test Just a test Just a test Just a test

\bibliography{test}

\appendix

\section{Extra Stuff}

\end{document}

• © Cambridge University, Engineering Department, Trumpington Street, Cambridge CB2 1PZ, UK (map)
Tel: +44 1223 332600, Fax: +44 1223 332662
Contact: helpdesk