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

Last modified on 17 Dec 2015


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)
  • This you can easily use to convert (almost) any postscript(.ps)-document to PDF (.pdf). It is the easiest way, if you do not need hyper-references, or thumbnails. You do not have to change your TeX-source! In particular, you can go on including .eps (Encapsulated-Postscript) files in your document.
  • This also supports hyper-references (and thumbnails) with the hyperref-package (and the thumbpdf-package).
  • Use "dvips -Ppdf" in order to include scalable Type-1 fonts (i.e., postscript-fonts instead of the standard bitmap(PK)-fonts) into your ps-document, otherwise the resulting PDF-file will look quite ugly on screen.
  • If you want to have hyper-references, be aware that this path currently does not correctly support references which exceed one line (i.e., the "breaklinks=true" - option of the hyperref-package)! Such hyper-references usually occur for long headings in the "Table of Contents", or figure-/table-captions in the "List of Figures/Tables".

II) pdfLaTeX (+bibTeX)

  • First of all: For this path you must convert all your included .eps-graphics into PDF format. This can be done by "epstopdf". In addition you have to change your TeX-file, at minimum to include the .pdf-graphics.
  • If you start a new document from scratch, intended to get a PDF, this path is the first choice, although pdfLaTeX is still in "beta-state".
  • LaTeX and pdfLaTeX behave by default differently concerning the character-spacing. As a result, the same TeX-File compiled with LaTeX and pdfLaTeX may show different line-breaks, paragraphs, page-breaks etc. Fortunately, there is a switch in pdfLaTeX to ensure LaTeX spacing.
  • pdfLaTeX uses per default Type-1 fonts.

... 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:
  • thumbpdf --modes=dvips pdf-file for ps2pdf
  • thumbpdf pdf-file for pdfLaTeX

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):

  • other packages which should be mentioned:
    • "ifpdf" (by Heiko Oberdiek): a more robust switch than the one used in the example file above
    • "epstopdf": If the named pdf file/figure doesn't exist the package/macro will look for a ps/eps file with the same name and use epstopdf automatically to convert to pdf
    • "pdftricks": Makes it possible to use pstricks with pdflatex by automatically converting eps (produced by the pstricks enviroment) to pdf.
    • "pdfpages" - makes it very easy to include pages from other pdf-files into your document. Very convenient for collections of articles or if you just need a couple of pages from earlier works. (Only works with pdflatex as far as I know.)
    • "purifyeps" - makes it possible to use one single eps file for both dvips and pdflatex. (No need to store both a eps and pdf version of a figure.)
    All packages are available at CTAN - for example at ftp.dante.de
  • the figures should be included without extensions (as in the example above), i.e, \includegraphics{myfig} to make the transition between ps and pdf easy
  • definition of the graphics extensions in the above example is not required, since this is done automatically by the graphicx package

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

  • Here is an example for colored text:
    \usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
    \definecolor{pink}{rgb}{1,0.5,0.5} % color values Red, Green, Blue
    \begin{document}
    \textcolor{red}{Hello} this is a test
    \end{document}
  • Informations on forms and java in the PDF can be found here: http://tug.daimi.au.dk/texshowcase

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

  • The packages ae and aecompl provide 8-bit Type 1 (virtual) fonts
  • Using bibTeX and hyperref causes problems with bookmarks and tableofcontents and the bibliography entry. To solve these, use: \clearpage
    \phantomsection
    \addcontentsline{toc}{chapter}{Bibliography}
    \bibliography{biblio}
  • Acrobat 5 displays automatically the thumbnails, without using the thumbpdf package.
  • Older versions of ps2pdf (ghostscript <= 6.53) have a bug in the conversion of blank pages. In the PDF document the line
    /Contents [] has to be replaced by a line of 12 blank spaces.

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

  • Weird characters in dvips output:
    (Original source: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=charshift )
    You've innocently generated output, using dvips, and there are weird transpositions in it: for example, the fi ligature has appeared as a £ symbol. This is an unwanted side-effect of the precautions outlined in generating PostScript for PDF. The -G1 switch discussed in that question is appropriate for Knuth's text fonts, but doesn't work with text fonts that don't follow Knuth's patterns (such as fonts supplied by Adobe).
    If the problem arises, suppress the -G1 switch: if you were using it explicitly, don't; if you were using -Ppdf, add -G0 to suppress the implicit switch in the pseudo-printer file.
    The problem has been corrected in dvips v 5.90 (the version distributed with the TeX-Live 7 CDROM and in other TeX distributions from that date onwards).
  • TeX Frequently Asked Questions

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

  • Using the sort & compress option of natbib with hyperref requires the package hypernat.sty. hyperref does then not longer destroy the compression of references.
  • breaklinks=true works with ps2pdf (gs 7.05.3)
  • More information about LaTeX/PDF can be found here: www.ibnm.uni-hannover.de/Mitarbeiter/beuerman/LaTeX2PDF.pdf

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

  • The line \usepackage[T1]{fontenc} (as for example automatically included by LyX) forces (PDF)LaTeX to use bitmap fonts.
    Comment from Hans Fr. Nordhaug ( hans dot fredrik at nordhaug dot no): This is true if the standard TeX fonts are used. For fonts like CM-super, latin modern and some others (which are free fonts) it's completely fine to use \usepackage[T1]{fontenc}.
    Comment from Lionel Elie Mamane ( lionel at mamane dot lu): But it is possible to use the CM fonts (the standard LaTeX fonts when using OT1 encoding - the default without the above line) with a T1 encoding. This is implemented by the line: \usepackage{ae,aecompl,aeguill} This will again permit your LaTeX processing chain to use outline (vector) fonts, while keeping the many advantages of the T1 encoding for non-English languages.

Stephen Bespalko ( sjbespa at comcast dot net):

  • Using \addcontentsline within the text (together with the hyperref-package) for additional entries in the table of contents generates a hyperlink anchor on the page where the respective section starts, and not - as would be desired - on the page, where the new entry is located. The technique to change this behaviour is the command \phantomsection which needs to be placed immediately before \addcontentsline. Then the page anchor is generated correctly.

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

  • There is a third option for creating PDF files from LaTeX sources: dvipdfm (available at http://gaspra.kettering.edu/dvipdfm/). As the name implies, this program is similar to dvips but it produces PDF files as output instead of postscript. It has full support for packages such as hyperref and for most pdfmark operators, links, outlines, named destinations, etc.

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

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

  • Some further information for using gnuplot eps figures with (PDF)LaTeX and the hyperref-package: info_01.txt

Stefan Alfredsson ( Stefan dot Alfredsson at kau dot se):

  • Long URL's (the most common case of long hyper-references) can be broken into multiple lines with \usepackage{breakurl} loaded after the hyperref package.

Paul Colin Gloster ( Colin_Paul_Gloster at ACM dor org):

  • According to http://TUG.org/applications/hyperref/ftp/doc/slides.pdf there is another way to modify the general document information:
       |---------------------------------------------------|
       |%             General document information         |
       |Example for setting /CreationDate and /ModDate:    |
       |\pdfinfo{/CreationDate (D:19990909000000-01'00')}  |
       |\begingroup                                        |
       |  \def\twodigits#1{\ifnum#1<10 0\fi\the#1}%        |
       |  \count0=\time \divide\count0 by 60               |
       |  \edef\x{\twodigits{\count0}}%                    |
       |  \multiply\count0 by 60                           |
       |  \count1=\time \advance\count1 by -\count0        |
       |  \edef\x{\x\twodigits{\count1}}%                  |
       |  \edef\x{/ModDate (D:\the\year                    |
       |    \twodigits\month \twodigits\day \x 00-01'00')}%|
       |\expandafter\endgroup                              |
       |\expandafter\pdfinfo\expandafter{\x}%             %|
       |---------------------------------------------------| 
     

This page was last modified on 10 Jan 2012.

 

Impressum / Imprint - Datenschutzerklärung / Privacy Policy