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. <span id="more-145"></span> First of all, if you need DVI compilation for, say, preview features of [the LaTeX editor](http://latexeditor.org), I recommend using <b>ifpdf</b>:
```Latex
\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
```latex
\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 <b>author</b>, <b>subject</b>, <b>keywords</b>, <b>title</b> will not be displayed by most readers unless you look at the document properties, but <b>pdfdisplaydoctitle</b> means that the pdf reader is supposed to display the value of <b>pdftitle</b> in the title bar, which I think is cool.
One rather important part is <b>pdfstartview</b>. Its value defines the default view when the PDF is openend. It can be one of the following:
* <b>XYZ [left] [top] [zoom]</b> (sets a coordinate and a zoom factor)
* <b>Fit</b> (fits the page to the window)
* <b>FitH [top]</b> (fits the width of the page to the window and vertically scrolls to the position given by <b>top</b>)
* <b>FitV [left]</b> (fits the height of the page to the window and horizontally scrolls to the position given by <b>left</b>)
* <b>FitR [left] [bottom] [right] [top]</b> (fits the rectangle specified by the four coordinates to the window)
* <b>FitB</b> (fits the page bounding box to the window)
* <b>FitBH [top]</b> (like <b>FitH</b>, but fits the bounding box instead of the page)
* <b>FitBV [left]</b> (like <b>FitV</b>, but fits the bounding box instead of the page)
In my code, I also used the <b>hypercalcbp</b> macro to translate the LaTeX-length
```latex
\paperheight-\topmargin-1in
```
to PDF units. You can find more about all this stuff in the <b>hyperref</b> manual, of course. For colors that don't scream at you quite as much as the default, I recommend
```latex
\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
```latex
\newcommand{\thetitle}{The wonders of $\pi$}
```
causes you pain in the form of
```text
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 <b>\texorpdfstring</b> macro. Usage:
```latex
\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 <b>"Pi"</b> 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.