Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
@book{adams80,
  title = {The Restaurant at the End of the Universe},
  author = {Douglas Adams},
  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}
share|improve this question
1  
Without a true minimal example I'm pessimistic about qualified answers to this question. –  Thorsten Donig Jul 26 '11 at 16:54
add comment

1 Answer

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
\renewcommand\hyper@natlinkbreak[2]{#1}
\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}%
  \hyper@natlinkstart{\@citeb\@extra@b@citeb}#1%
  \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
  \hyper@natlinkend}
\renewcommand\hyper@natlinkbreak[2]{#1}

% 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},
  publisher = {Addison-Wesley},
  location = {Reading, Mass.},
  year = {1994}}
@Book{adams,
  title = {The Restaurant at the End of the Universe},
  author = {Douglas Adams},
  series = {The Hitchhiker's Guide to the Galaxy},
  publisher = {Pan Macmillan},
  year = {1980}}
\end{filecontents}

\renewcommand{\baselinestretch}{1.25}

\begin{document}
\noindent
cite: \cite{adams}, \cite{companion} \\
citet: \citet{adams}, \citet[see][p. 20]{adams} \\
multi citet: \citet{companion,adams} \\
citep: \citep{adams}, \citep[see][p. 20]{companion} \\
multi citep: \citep{companion,adams} \\
citetext, citealp: \citetext{see \citealp{companion}, or even better \citealp{adams}} \\
citeauthor: \citeauthor{adams}, \citeauthor{companion} \\
citeyear: \citeyear{adams}, \citeyear{companion} \\
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

enter image description here

share|improve this answer
    
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 at 12:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.