# Hyperlinks In Latex Bibliography Chapter

By In 1

## Introduction

Let's start with a minimal working example, by simply importing the hyperref package all cross-referenced elements become hyperlinked.

\documentclass{book}\usepackage[utf8]{inputenc}\usepackage[english]{babel}   \usepackage{hyperref}   \begin{document}   \frontmatter   \tableofcontents   ... \end{document}

One must be careful when importing hyperref. Usually it has to be the last package to be imported, but there might be some exceptions to this rule.

Open an example of the hyperref package in ShareLaTeX

## Styles and colours

The default formatting for links can be changed so the information in your documents is more clearly presented. Below you can see an example:

\documentclass{book}\usepackage[utf8]{inputenc}\usepackage[english]{babel}   \usepackage{hyperref}\hypersetup{ colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan, }   \urlstyle{same}   \begin{document}   \tableofcontents   \chapter{First Chapter}   This will be an empty chapter and I will put some text here   $$\label{eq:1}\sum_{i=0}^{\infty} a_i x^i$$   The equation \ref{eq:1} shows a sum that is divergent. This formula will be latter used in the page \pageref{second}.   For further references see \href{http://www.sharelatex.com}{Something Linky} or go to the next url: \url{http://www.sharelatex.com} or open the next file \href{run:./file.txt}{File.txt}   It's also possible to link directly any word or \hyperlink{thesentence}{any sentence} in your document.   \end{document}

This is a complete example, it will be fully explained in the rest of the article. Below is a description of the commands related to the colour and styling of the links.

This will set the options to configure the behaviour of the links within the document. Every parameter must be comma-separated and the syntax must be in the forma parameter=value.
Links will be coloured, the default colour is red.
Internal links, those generated by cross-referenced elements, are displayed in blue.
Links to local files will be shown in magenta colour (see linking local files).
Default settings print links in mono-style spaced fonts, this command changes that and displays the links in the same style as the rest of the text.

Open an example of the hyperref package in ShareLaTeX

For further references see \href{http://www.sharelatex.com}{Something Linky} or go to the next url: \url{http://www.sharelatex.com}

There are two commands in the example that generate a link in the final document:

There are two parameters passed to this command, the first one is the url to the link, http://www.sharelatex.com in this case, and the second one is the clickable text to be shown, Something Linky.
This command will show the url passed as parameter and make it into a link, useful if you will print the document.

Open an example of the hyperref package in ShareLaTeX

The commands and presented in the previous section can be used to open local files

For further references see \href{http://www.sharelatex.com}{Something Linky} or go to the next url: \url{http://www.sharelatex.com} or open the next file \href{run:./file.txt}{File.txt}

The command prints the text "File.txt" that links to a local file called "file.txt" located in the current working directory. Notice the text "run:" before the path to the file.

The file path follows the conventions of UNIX systems, using . to refer the current directory and .. for the previous directory.

The command can also be used, with the same syntax described for the path, but it's reported to have some problems.

Open an example of the hyperref package in ShareLaTeX

It was mentioned before that all cross-referenced elements become links once hyperref is imported, thus we can use anywhere in the document and refer later those labels to create links. This is not the only manner to insert hyperlinks manually.

It's also possible to link directly any word or \hyperlink{thesentence}{any sentence} in you document.   If you read this text, you will get no information. Really? Is there no information?   For instance \hypertarget{thesentence}{this sentence}.

There are two commands to create user-defined links.

The first parameter passed inside braces to this command is a unique identifier for this sentence. The second parameter is the text "this sentence", and will be printed normally (depending on the value of anchorcolor, see the reference guide), but when a link pointing to the identifier "thesentence" is clicked the PDF file will scroll to this point.
This command prints the text "any sentence" as a clickable element that redirects to the point whose identifier is "thesentence".

Open an example of the hyperref package in ShareLaTeX

## PDF-specific options

Links in a document are created having in mind a document that will be read in PDF format. The PDF file can be further personalized to add additional information and change the way the PDF viewer displays it. Below an example:

Using the command , described in the section styles and colours, accepts extra parameters to set up the final PDF file.

Is the title of the PDF output file, to be displayed in the title bar of the window. In the example is "Sharelatex Example".
The document will be opened in full screen mode by the PDF reader.

See the reference guide for a full list of options that can be passed to .

Open an example of the hyperref package in ShareLaTeX

## Reference guide

Option Default value Description
true Makes the page numbers of index entries into hyperlinks
false Allows links to be broken into multiple lines.
false Colours the text for links and anchors, these colours will appear in the printed version
red Colour for normal internal links
black Colour for anchor (target) text
green Colour for bibliographical citations
cyan Colour for links that open local files

PDF-specific options

Option Default value Description
false Bookmarks are shown with all sub-trees expanded.
0 1 0 Colour of the box around citations in RGB format.
0 .5 .5 Colour of the box around links to files in RGB format.
1 0 0 Colour of the box around normal links in RGB format.
1 0 0 Colour of the box around menu links in RGB format.
0 1 1 Colour of the box around links to URLs in RGB format.
empty Determines how the file is opened. Possibilities are UseThumbs (Thumbnails), UseOutlines (Bookmarks) and FullScreen.
Sets the document title.
Sets the document Author.
1 Determines on which page the PDF file is opened.

When they write papers, scientists take a lot of time in preparing their bibliography and correctly citing all their references. However, bibliographies and the corresponding bibtex styles were designed when everyone read scientific papers on paper. This is rarely the case today and most scientific papers are read online. Still, we insist on placing volume numbers, pages numbers and other information from the paper era in each paper but rarely URLs or DOIs. This is probably a mistake...

When developing the first edition of Computer Networking : Principles, Protocols and Practice I quickly found that students read references provided that these references were easily accessible through hyperlinks. Today’s students and I guess a growing number of researchers are used to browse the web but rarely go to their library to read articles on paper. For the recently published SIGCOMM ebook on Recent Advances in Networking, we did a small experiment in adding hyperlinks directly to each chapter in pdf format. Adding these hyperlinks was surprisingly easy and I hope useful for the readers.

Each chapter was written in standard latex with a bibliography encoded in bibtex files. Nowadays, each scientific article can be uniquely identified by either :

URLs are very common and can be used to point to articles stored in digital repositories for example. Some scientific publishers provide stable URLs, but others don’t. DOIs are more useful. By design, they are short and stable. Major scientific publisher associate one DOI to each published article and the http://dx.doi.org/ server could be used to be redirected automatically to the corresponding article. I sent a few days adding the DOIs and if none was found the URL for most cited reference. For ACM papers, the easiest solution is to simply reuse the bibtex file provided by ACM, such as

@inproceedings{Paasch_Mobile:2012, author = {Paasch, C. and Detal, G. and Duchene, F. and Raiciu, C. and Bonaventure, O.}, title = {{Exploring mobile/WiFi handover with Multipath TCP}}, booktitle = {Proceedings of the 2012 ACM SIGCOMM workshop on Cellular networks: operations, challenges, and future design}, series = {CellNet '12}, year = {2012}, isbn = {978-1-4503-1475-6}, location = {Helsinki, Finland}, pages = {31--36}, numpages = {6}, url = {http://doi.acm.org/10.1145/2342468.2342476}, doi = {10.1145/2342468.2342476}, acmid = {2342476}, publisher = {ACM}, address = {New York, NY, USA}, keywords = {energy consumption, mptcp, vertical handover, wifi/3g}, }

It already contains the relevant information. The bibtex file provided by IEEExplore also contains the DOI. For RFCs, Roland Bless’s rfc.bib provides all the required information. For books, I found some URLs on books.google.com but not for all of them. With these rich bibtex files, I could then apply the bibtex modifications described by Andrew Comech on http://www.math.tamu.edu/~comech/tools/bibtex-doi-eprint/. First, make sure that you use the latex hyperref package. Then, you need to modify your preferred bibtex style file. For the SIGCOMM ebook, we reused the acm.bst file which is part of the standard ACM latex package. This file indicates how references must be pretty printed in the bibliography. It first defines under the ENTRY label the different types of information that can be placed inside bibtex files

ENTRY { address author booktitle chapter edition editor howpublished institution journal key month note number organization pages publisher school series title type volume year url doi }

You simply simply need to add to this entry the url and doi records. Then, you need to modify the functions that process titles to include the required information. For example, the function format.title processes the title of an article. It is defined in acm.bst as

FUNCTION {format.title} { title empty${ "" } { title "t" change.case$ } if$} To support URLs and DOIs, it can be rewritten as follows FUNCTION {format.title} { title empty$ { "" } { title "t" change.case$} if$ url empty${ doi empty$ { } { "\href{http://dx.doi.org/" doi * "}{" * swap$* "}" * } if$ } { "\href{" url * "}{" * swap$* "}" * } if$ }

The same modification can be applied for format.btitle and format.in.ed.booktitle. With this modified bibtex style sheet and the DOI/URL records in the bibtex files, all references become hyperlinks in the pdf file. You can see this in the individual chapters of the SIGCOMM ebook http://www.sigcomm.org/content/ebook. Unfortunately, the entire ebook had to be build by assembling the pdf files of all chapters together by using the pdfpages latex package that does not yet correctly support the inclusion of pdf files containing hyperlinks.

Posted by Olivier Bonaventure