Nicola Talbot
This document is also available in PDF formatted either in A4 for printing or 6inx4in for on-line viewing. You can download a sample file illustrating the commands described in this document from the sample webpagelatex filename.texyou would need to type:
pdflatex filename.texIf you are using TeXnicCenter select the output profile
LaTeX => PDF
, and click
on the `Build' icon. If you are using WinEdt, click on the `PDFLATEX' icon. If you
are using some other front-end, check the manual.
Figure 1 shows an example.
This information can be saved to the PDF file using the command:
where info should be entered in PDF notation. For example:
\pdfinfo{ /Author (Nicola Talbot) /Title (Creating a PDF document using PDFLaTeX) /CreationDate (D:20040502195600) /Subject (PDFLaTeX) /Keywords (PDF;LaTeX) }If the creation date field is omitted, the current date and time is inserted. Note that all fields should be entered in the form:
/Title | |
/Author | |
/Creator | |
/Producer | |
/CreationDate | |
/ModDate | |
/Subject | |
/Keywords |
\pdfinfo{ /Author (Nicola Talbot) /Title (Creating a PDF document using PDFLaTeX) /CreationDate (D:20040502195600) /ModDate (D:\pdfdate) /Subject (PDFLaTeX) /Keywords (PDF;LaTeX) }Note that the command \pdfinfo is defined by PDFLATEX1 but not LATEX, which means you'll get an error message if you try to use LATEX instead of PDFLATEX. The package ifpdf defines the conditional \ifpdf which can be used to determine whether you are using PDFLATEX or LATEX. For example the following code:
This is \ifpdf a PDF \else not a PDF \fi document.will produce the output:
\ifpdf \pdfinfo{ /Author (Nicola Talbot) /Title (Creating PDF documents using PDFLaTeX) /CreationDate (D:20040502195600) /ModDate (D:\pdfdate) /Subject (PDFLaTeX) /Keywords (PDF;LaTeX) } \fiNote that if you are using the ifthen package, you can use
This is \ifthenelse{\boolean{pdf}}{a PDF}{not a PDF} document.will produce the output:
\ifpdf \includegraphics{shapes.pdf} \else \includegraphics{shapes.ps} \fihowever it is simpler to omit the file extension:
\includegraphics{shapes}If you are using PDFLATEX, the graphicx package will assume a .pdf or .png extension, otherwise it will assume a .ps or .eps extension.
If you like using pstricks, it is still possible to do so using PDFLATEX, however you will need to use the pdftricks package. Check the pdftricks documentation for further information.
\usepackage[pdfpagemode=FullScreen,bookmarks=true]{hyperref}or as the argument to the command \hypersetup, e.g.
\hypersetup{pdftoolbar=false}If you are switching on an option, you can omit =true, e.g.
\hypersetup{bookmarks}
.
One more thing to note: the hyperref package must always be the last package to be included (unless
of course, you are using a package that modifies the behaviour of the hyperref package, e.g. backrefx).
See section~\ref{sec:hyperref}will by default look like:
\usepackage[colorlinks]{hyperref}
). The above example would then look like:See \autoref{sec:hyperref}will look like:
See \autoref{fig:docinfo}will look like:
\caption{Document Properties} \label{fig:docinfo}This produces the following entry in the auxiliary file:
\newlabel{fig:docinfo}{{1}{2}{Document Information\relax }{figure.1}{}}In this case, the relevant counter is figure, so the \autoref command will use the command \figurename, if it exists, to generate the context name. So, if you want to define a new counter that you want to reference using \autoref, you will also need to define the corresponding
\
counter-namename
command. For example:
\newcounter{exercise} \newcommand{\exercisename}{Exercise}Another way of creating a hyperlink is to use the command
For example, the following code:
In the \hyperref[sec:intro]{introduction} \ldotswould produce the following output:
\hyperref[sec:hyperref]{See section~\ref*{sec:hyperref} (on page~\pageref*{sec:hyperref})}would look like:
Hyperlinks to URLs can be created using the command:
For example:
See the \href{http://theoval.cmp.uea.ac.uk/~nlct/latex/csed/}{course web site} for further details.This would produce the following: See the course web site for further details.
Note that you don't need to worry about the tilde in the first argument to \href, nor do you have to worry about escaping the # character:
\href{http://theoval.cmp.uea.ac.uk/~nlct/index.html#latex}% {\LaTeX\ information}This would produce: LATEX information
Alternatively, if you simply want to print the web address as an active link, you can use:
For example:
\url{http://theoval.cmp.uea.ac.uk/~nlct}would produce: http://theoval.cmp.uea.ac.uk/~nlct
The hyperref package also turns \cite commands into active links.
See ``The \LaTeX\ Web Companion''~\cite[Chapter~2]{goossens1999} for further details.This would produce: See ``The LATEX Web Companion'' [1, Chapter 2] for further details.
The backref package can be used to create a set of back-references within the bibliography. To implement this, use the backref option to the hyperref package. By default this will reference the section number, but you can change it to reference the page instead, by doing either
\usepackage[backref=page]{hyperref}or
\usepackage[pagebackref]{hyperref}There is another package backrefx which extends the backref package, so that the back-references are in the form: (Cited on pages 1, 4 and 6.) instead of a simple list of numbers. The backrefx package should be included after the hyperref package, e.g.:
\usepackage[pagebackref]{hyperref} \usepackage{backrefx}Note that both the backref and backrefx packages assume that the bibliographic entries are separated by a paragraph break. This is done automatically by BIBTEX, but it is something that you will need to remember if you are writing the thebibliography environment by yourself.
The option bookmarksopen can be set if you want all the bookmark subtrees expanded, and the option bookmarksnumbered can be set if you want the section numbers included in the bookmarks. The bookmark entries are taken from the chapter, section etc headings, but note that the text in the PDF bookmark will not follow any LATEX formatting.
\subsubsection{An Example Heading: $a^2+b^2=c^2$}If you view the PDF version of this document in Acrobat Reader, you will be able to see that this section heading in the bookmarks has appeared as: An Example Heading: a2+b2=c2. LATEXing this document produces the following warnings:
Package hyperref Warning: Token not allowed in a PDFDocEncoded string, (hyperref) removing `math shift' on input line 388. Package hyperref Warning: Token not allowed in a PDFDocEncoded string, (hyperref) removing `superscript' on input line 388.This means that the $ and
^
symbols have been ignored.
The command
\texorpdfstring{LATEX text}{PDF text}
can be used to vary the text, depending on whether it is to be processed by LATEX or whether
it will appear in the PDF bookmark. The above section heading could then be changed to
\subsubsection{An Example Heading\texorpdfstring{: $a^2+b^2=c^2$}{}}In this case, the equation will be printed in the section heading within the document, but will not appear in the bookmark.
! pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has been already used, duplicate ignoredThis can be overcome by switching off the plainpages option:
\usepackage[plainpages=false]{hyperref}This will change the identifiers so that they are constructed using the formatted form of the page number instead of solely the Arabic form (e.g.
page.i
instead of
page.1
) You may still find a problem arising from the title page using, say the
report class, where although the page number does not appear, it is assigned the
page number 1, but the first page of your main matter is also page 1. This problem can
be overcome by using a different page numbering style for the title page, that does not
occur in the rest of the document. For example:
\documentclass{report} \usepackage[plainpages=false]{hyperref} \begin{document} \title{A Sample Document} \author{Me} \pagenumbering{alph} \maketitle \clearpage\pagenumbering{roman} \tableofcontents \clearpage\pagenumbering{arabic} \chapter{Introduction}In this case, switching to alph pagenumbering does not affect the visual formatting as the page number does not appear on the title page, but it will yield unique identifiers.
can be used to access the relevant Acrobat menu item, where menuitem is the Acrobat menu option name
and text is the link text. For example:
\Acrobatmenu{GeneralInfo}{Document Summary}will produce an active link containing the text Document Summary which will produce the general information dialogue box if you click on it when viewing the PDF document using Acrobat Reader. Note that text doesn't have to simply be text, it can be any LATEX code, which means you could use a picture instead. A full list of menu options is given in ``The LATEX Web Companion'' [1], but the most commonly used ones are: PrevPage, NextPage, FirstPage, LastPage, GoBack, GoForward and Quit. It is therefore possible to incorporate your own navigation panel within your document by defining a new page style that includes \Acrobatmenu commands. For example, this document defines a new page style called online, which is used for the on-line PDF version, and is defined as follows:
\newcommand\ps@online{ \renewcommand{\@oddhead}{} \renewcommand{\@evenhead}{} \renewcommand{\@oddfoot}{\hfill \Acrobatmenu{PrevPage}{Previous} \Acrobatmenu{NextPage}{Next} \Acrobatmenu{FirstPage}{First} \Acrobatmenu{LastPage}{Last} \Acrobatmenu{GoBack}{Back} \Acrobatmenu{GoForward}{Forward} \hyperref[sec:index]{Index}\hfill\thepage} \renewcommand{\@evenfoot}{\@oddfoot}}As can be seen the headers are blank, and the footer contains the \Acrobatmenu commands. It also uses the \hyperref command to provide a link to the index, and the \hfill commands neatly centre the text, with the page number pushed to the far right. The theindex environment was also redefined so that it incorporated the
\label{sec:index}
command. This was necessary because \printindex
starts a new page, so placing the label before this command would link to the page before
the index, and placing the label after \printindex would link to the end of the index.
There are some packages that seem to interfere with the commands that generate these links. I've noticed that using the subfigure package seems to cause this problem. (I haven't worked out why.)
pdfTeX error (ext4): link annotations can't be nested. \grf@@shipout ->\grf@org@shipout \box \@cclv \relaxbut I don't have any nested annotations.
This error can be caused by a page break occurring in the middle of a link. For example, suppose you have the following:
\hyperref[sec:optional]{optional arguments}If a page break occurs between the words ``optional'' and ``arguments'', a shipout command will occur whilst a link is still being created, which will cause the error. To get around this, you can split the link up into two links:
\hyperref[sec:optional]{optional} \hyperref[sec:optional]{arguments}
PDFLATEX can't handle PostScript fonts, so check to see if you have included any package that use PostScript fonts (such as pifont).
This is caused by the fact that the document containing the label definition uses the hyperref package, and the document referencing doesn't. Recall from section 4.1 that the hyperref package redefines the \label command. The line in the auxiliary file now contains additional information, and since both documents read in the same auxiliary file, they must both have the same definitions of \label.
! Argument of \@fifthoffive has an extra }This is the same kind of problem as the previous one, but in this case the \label has been defined in a file that doesn't include the hyperref package, but the document referencing it does.