So you want to compile your latex to PDF, eh? And you want to use hyperref, eh? Since I am a 0-Warning(s)-kinda guy, let me help you become one, too. First of all, if you need DVI compilation for, say, preview features of [the LaTeX editor](http://latexeditor.org), I recommend using ifpdf:
\usepackage{ifpdf}
\ifpdf
\usepackage[pdftex]{hyperref}
\else
\usepackage[dvips,dviwindo,hypertex]{hyperref}
\fi
But let us juice that up a little and learn how to control the PDF output a bit better, shall we? Before my {document}
\begin
's, I usually go like
\hypersetup{
pdfauthor={Jesko Hüttenhain},
pdfdisplaydoctitle,
pdfkeywords={},
pdfsubject={Awesome Math},
pdftitle={\thetitle},
bookmarks=True,
bookmarksopen=True,
pdfstartpage={1},
pdfstartview={FitH \hypercalcbp{\paperheight-\topmargin-1in}},
pdfview={FitH 0},
unicode,
}
Many of this should be self-explanatory. The values for author, subject, keywords, title will not be displayed by most readers unless you look at the document properties, but pdfdisplaydoctitle means that the pdf reader is supposed to display the value of pdftitle in the title bar, which I think is cool.
One rather important part is pdfstartview. Its value defines the default view when the PDF is openend. It can be one of the following:
* XYZ [left] [top] [zoom] (sets a coordinate and a zoom factor)
* Fit (fits the page to the window)
* FitH [top] (fits the width of the page to the window and vertically scrolls to the position given by top)
* FitV [left] (fits the height of the page to the window and horizontally scrolls to the position given by left)
* FitR [left] [bottom] [right] [top] (fits the rectangle specified by the four coordinates to the window)
* FitB (fits the page bounding box to the window)
* FitBH [top] (like FitH, but fits the bounding box instead of the page)
* FitBV [left] (like FitV, but fits the bounding box instead of the page)
In my code, I also used the hypercalcbp macro to translate the LaTeX-length
\paperheight-\topmargin-1in
to PDF units. You can find more about all this stuff in the hyperref manual, of course. For colors that don't scream at you quite as much as the default, I recommend
\definecolor{cc}{rgb}{0.7,0.08,0.08}
\definecolor{lc}{rgb}{0.08,0.08,0.7}
\definecolor{uc}{rgb}{0.08,0.08,0.9}
\hypersetup{
colorlinks=true,
breaklinks=true,
linkcolor=lc,
menucolor=cc,
citecolor=cc,
filecolor=lc,
urlcolor=uc,
frenchlinks=false,
pdfhighlight={/N},
}
As a final remark, it might happen to you that
\newcommand{\thetitle}{The wonders of $\pi$}
causes you pain in the form of
Package hyperref Warning:
Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)
removing `math shift' on input line 1.
In this case, your new best friend is the \texorpdfstring macro. Usage:
\newcommand{\thetitle}{The wonders of \texorpdfstring{$\pi$}{Pi}}
Can you see what I did there? Sure you can. Whenever the string is used for a PDF-internal field, the string "Pi" is used. However, inside your LaTeX document, it will be still displayed as a $\pi$. Remember that \texorpdfstring
is also great for section or chapter headings that include math characters which cause trouble as a PDF bookmark.