# natbib and hyperref for (Author, Year) style produces two links

I am using the bioinfo style with natbib and hyperref, using the (Author, Year) style citations. pdflatex produces two link boxes for each citation: one for the Author and one of the Year. I would prefer to get a single link for the entire [(Author, Year)] rather than ([Author], [Year]). I can turn off PDF link boxes and uses colors instead to somewhat improve the appearance of this, but I'd still prefer to just have a single link.

Thanks in advance for any suggestions on how to fix this.

Here is a minimal example:

\documentclass{article}

\usepackage{natbib}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
title = {The Restaurant at the End of the Universe},
series = {The Hitchhiker's Guide to the Galaxy},
publisher = {Pan Macmillan},
year = {1980}
}
\end{filecontents}
\begin{document}

A theory about the inexplicability of the Universe has been proposed by \citet{adams80}.

\bibliographystyle{plainnat}
\bibliography{\jobname}

\end{document}

-
Without a true minimal example I'm pessimistic about qualified answers to this question. –  Thorsten Donig Jul 26 '11 at 16:54

The two links are created by the command \hyper@natlinkbreak, which is defined by hyperref.sty. To remove the break you can revert back to the provisional definition from natbib.sty by inserting the following lines into your preamble:

\makeatletter
\makeatother


The results with this simple fix aren't great; links generated by \cite and \citet don't include the postnote and closing bracket, which looks funny. This can be resolved somewhat by patching the internal natbib macros using etoolbox. Spurious closing brackets are tedious to avoid in compact citations. The patches below side-step this issue by suppressing compact labels in \citet and its variants.

\documentclass{article}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{etoolbox}

\makeatletter

\pretocmd{\NAT@citex}{%
\let\NAT@hyper@\NAT@hyper@citex
\def\NAT@postnote{#2}%
\setcounter{NAT@total@cites}{0}%
\setcounter{NAT@count@cites}{0}%
\forcsvlist{\stepcounter{NAT@total@cites}\@gobble}{#3}}{}{}
\newcounter{NAT@total@cites}
\newcounter{NAT@count@cites}
\def\NAT@postnote{}

% include postnote and \citet closing bracket in hyperlink
\def\NAT@hyper@citex#1{%
\stepcounter{NAT@count@cites}%
\ifnumequal{\value{NAT@count@cites}}{\value{NAT@total@cites}}
{\ifNAT@swa\else\if*\NAT@postnote*\else%
\NAT@cmt\NAT@postnote\global\def\NAT@postnote{}\fi\fi}{}%
\ifNAT@swa\else\if\relax\NAT@date\relax
\else\NAT@@close\global\let\NAT@nm\@empty\fi\fi% avoid compact citations

% avoid extraneous postnotes, closing brackets
\patchcmd{\NAT@citex}
{\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
\if\relax\NAT@date\relax\else\NAT@@close\fi\fi}{}{}{}
\patchcmd{\NAT@citex}
{\if\relax\NAT@date\relax\NAT@def@citea\else\NAT@def@citea@close\fi}
{\if\relax\NAT@date\relax\NAT@def@citea\else\NAT@def@citea@space\fi}{}{}

\makeatother

\begin{filecontents}{\jobname.bib}
@Book{companion,
author = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
title = {The LaTeX Companion},
edition = {1},
year = {1994}}
title = {The Restaurant at the End of the Universe},
series = {The Hitchhiker's Guide to the Galaxy},
publisher = {Pan Macmillan},
year = {1980}}
\end{filecontents}

\renewcommand{\baselinestretch}{1.25}

\begin{document}
\noindent

I think this should be implemented into natbib. Splitting citations into two elements is not a great way of handling the same link (have to switch back from biblatex/biber, causes me all kind of headaches, including this...). –  Jörg Apr 19 '14 at 12:31