Welcome to Patrick Jöckel's
"How-to make a PDF-document from a LaTeX - source ?" - page

Last modified on 23 Jun 2008


Hi !

You want to produce a PDF (portable document format) from your LaTeX - source ?
-- Nothing is easier than that !

The result should look perfect, with bookmarks, hyper-references, thumbnails ?
-- No problem !

Really ???
-- As I say !!! O.K. Let's go ...


... first, a short intro for very beginners ...

What are hyper-references ?
The PDF-Format supports links comparable to conventional web-pages (HTML). With this you can (provided that your PDF-viewer supports it) jump per mouse-click to in-text-references, e.g., if you reference in your TeX-source a figure, table, or equation with the \label{...} command, a link to this label will be created whenever you use \ref{...}. This works also with citations (\cite{...}) when you use bibTeX.

What are bookmarks ?
These are special links, usually in a separate frame of your PDF-viewer. With those you can jump per mouse-click to chapters, sections, subsections, etc., and also to self-defined places in your document.

What are thumbnails ?
These are small pictograms with the page-layout and page number, usually in a separate frame of your PDF-viewer. Helps to find (and jump per mouse-click to) a special page.


... second, some general remarks ...

In principle there are two pathways to follow:

 I) LaTeX (+bibTeX) -> dvips -> ps2pdf (gs Version 6.01 or later)

II) pdfLaTeX (+bibTeX)


... third, a list of recipes ...

How do I include hyper-references ?
Include

\usepackage[option1,option2,...]{hyperref} as last package into the header of your TeX-file. Possible options are (not complete):
ps2pdf required for LaTeX -> dvips -Ppdf -> ps2pdf
pdftex required for pdfLaTeX
bookmarks=true generates bookmarks for all entries in the "Table of Contents"
bookmarksnumbered=true includes chapter-/header-/section-/subsection-/... -numbers for the entries in the "Table of Contents".
Note: The "depth" of entries you can choose with \setcounter{tocdepth}{...}, and the numbering with \setcounter{secnumdepth}{...} in your TeX-header.
hypertexnames=false this might be necessary in order to get the hyper-links to the figures right
breaklinks=true allows hyper-references (links) exceeding a single line
Note: NOT supported by all versions of dvips and/or ps2pdf !
linkbordercolor={0 0 1} if you prefer blue frames around the links instead of the default, which is red
Note: You can choose any color with {r g b}, where 0 < r,g,b < 1 are the fractions of red, green and blue.
pdfborder={0 0 112.0} (set width of frames in pixels), this may be necessary for ps2pdf, since some versions multiply the default ({0 0 1}) with 0.009
For a complete list of options, have a look at hyperref.pdf.

Can I set the PDF-Document-Info section of my document ?
(With the Acrobat-Reader you will get this dialog with Ctrl-D, or via the File->Document Info->General... menu.)
Yes, you can ! Include the following lines into your TeX-header (after the hyperref-package is included):

\hypersetup{
pdfauthor = {Name of Author},
pdftitle = {Title of docment},
pdfsubject = {Subject},
pdfkeywords = {Keyword1, Keyword2, ...},
pdfcreator = {LaTeX with hyperref package},
pdfproducer = {dvips + ps2pdf}}
Notes:
  1. Entries you do not set explicitly are set by default (probably empty).
  2. The "pdfcreator" and "pdfproducer" - fields are automatically set by pdfLaTeX.
  3. pdfLaTeX also sets automatically the /CreationDate - field (i.e., the date and time of creation of the PDF-document) in addition, which you CANNOT set manually with the \hypersetup - command.

Can I still set the CreationDate in the PDF-Document-Info section, if I use ps2pdf ?
Yes, you can:

Edit the Postscript-File (dvips-output) before ps2pdf. Search for "/Keywords". Introduce the following before it:
/CreationDate (D:20010124145052+01'00')
The format is D:YYYYMMDDhhmmss[+,-]HH'NN'
(YYYY=year, MM=month, DD=day, hh=hour (local), mm=minutes(local), ss(local), + or - for HH hours and NN minutes relative to UTC. The "'" belong to the syntax!
If you use LaTeX on UNIX, the tcsh-script pdftime will do the job for you (simply edit the UTC-offset for your time-zone !).
Usage: pdftime ps-file

How can I force pdfLaTeX to use the same spacing as LaTeX ?
Simply include

\pdfadjustspacing=1 to your TeX-header.

Is it possible to have one TeX-header for both LaTeX and pdfLaTeX ?
Yes, see the example below ...

How can I introduce additional bookmarks, e.g., for pages that have no entries in the "Table of Contents" ?
Simply include

\pdfbookmark[n]{Bookmarktitle}{internal_label} into your TeX-header. "n" is the category, the bookmark occurs, i.e., 1 for section, 2 for subsection, ... etc. in case of the article-style. "Bookmarktitle" is the name of the bookmark that occurs in the bookmarks-frame of your PDF-viewer, and "internal_label" is an internal, non-ambiguous label.

Why does the additional bookmark not work correctly, if I generate an additional line in the "Table of Contents", e.g., for the "List of Figures" with "\addcontentsline{toc}{section}{\listfigurename} ?"
The hyperref-package needs a "section" command for putting the page-anchor correctly. In the default TeX-environment, "List of Figures", "List of Tables", "References", and "Table of Contents" do not occur in the "Table of Contents". For including those explicitly, use the tocbibind-package, e.g.,

\usepackage[nottoc]{tocbibind} in your TeX-header. The "nottoc"-option prevents the entry "Table of Contents" in the "Table of Contents". In a similar way you can switch off the entries for "List of Figures", "List of Tables", "References". By default, i.e., without options, all entries are generated. With the tocbibind-package all bookmarks work correctly.

I use the tocbibind-package. I additionally want to use the "natbib.sty"-style for the "References". Is this possible ?
Yes. With recent LaTeX installations it should work.
If not ... Both packages redefine the standard "\thebibliography" environment of TeX. However, you can use

\usepackage[square]{natbib}
\usepackage[nottoc]{tocnatbibind}
instead. Download the file tocnatbibind.sty, which is only a "quick-and-dirty hack", and put it in the same directory where your TeX source is located. Note: tocnatbibind has the same options as tocbibind.

How can I include thumbnails in my PDF-document ?
Use thumbpdf.sty, i.e., include

\usepackage[ps2pdf]{thumbpdf} %% in case of ps2pdf
resp.
\usepackage[pdftex]{thumbpdf} %% in case of pdfLaTeX
(pdf)LaTeX your pdf-File as usually. Then run thumbpdf (thumbpdf.pl), which is a perl-script using ghostscript (Version > 6.01). This will create your thumbnails. Then redo (pdf)LaTeX to include the thumbnails. See also the example below ...
Note:

Where can I get all these packages, style files, etc. ?
Some LaTeX-distributions include all of those, e.g., the teTeX-distribution. You can download everything related to TeX from CTAN - for example at ftp.dante.de or www.dante.de.


... and last but not least, a documented example ...

The following TeX-header is an example which works for both pathways. It contains a switch which automatically recognizes whether it is processed by LaTeX or by pdfLaTeX.

example.tex
For use with LaTeX->dvips->ps2pdf you can process it with the sequence: # ----------------------------------
latex example.tex
bibtex example
latex example.tex
latex example.tex
latex example.tex
dvips -Ppdf example.dvi
pdftime example.ps
ps2pdf example.ps
# ----------------------------------
thumbpdf --modes=dvips example.pdf
latex example.tex
dvips -Ppdf example.dvi
pdftime example.ps
ps2pdf example.ps
# ----------------------------------
With pdfLaTex, do # ----------------------------------
pdflatex example.tex
bibtex example
pdflatex example.tex
pdflatex example.tex
pdflatex example.tex
thumbpdf example.pdf
pdflatex example.tex
# ----------------------------------

... finally, here are some comments I received ...
(Thanks a lot for the contributions !)

Hans Fr. Nordhaug ( hans dot fredrik at nordhaug dot no):

David Vannucci ( d dot vannucci at ee dot wits dot ac dot za):

Marco Caliari ( mcaliari at math dot unipd dot it):

Rolf Sander ( sander at mpch-mainz dot mpg dot de):

Martin Aichele ( martin dot aichele at uni-mainz dot de):

Andrew Archibald ( archibal at math dot mcgill dot ca):

Stephen Bespalko ( sjbespa at comcast dot net):

Lars Kellogg-Stedman ( lars at oddbit dot com):

Sebastian Stammler ( linuxcld at hrz dot tu-darmstadt dot de):

Adrian Vogel ( adrian dot vogel at desy dot de):



If you have comments or suggestions, e-mail me at pj@p-joeckel.de  !
You can visit my home-page at http://www.p-joeckel.de