Using etoolbox
you can patch natbib
's internal author-year citation command so that it hyperlinks only the year whenever both the year and name are included in the citation label. The code below demonstrates patches for natbib.sty
, version 2010/09/13 8.31b
.
\documentclass{article}
\usepackage{natbib}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}
\makeatletter
% Patch case where name and year are separated by aysep
\patchcmd{\NAT@citex}
{\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb}%
\NAT@date}}
{\@citea\NAT@nmfmt{\NAT@nm}%
\NAT@aysep\NAT@spacechar\NAT@hyper@{\NAT@date}}{}{}
% Patch case where name and year are separated by opening bracket
\patchcmd{\NAT@citex}
{\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}%
{\@citeb\@extra@b@citeb}%
\NAT@date}}
{\@citea\NAT@nmfmt{\NAT@nm}%
\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi\NAT@hyper@{\NAT@date}}
{}{}
\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:life,
title = {Life, the Universe and Everything},
author = {Adams, Douglas},
series = {The Hitchhiker's Guide to the Galaxy},
publisher = {Pan Macmillan},
year = {1980}}
@book{adams:rest,
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}
\newcommand{\cmd}[1]{\textbackslash\texttt{#1}}
\defcitealias{companion}{GMS}
\begin{document}
\noindent
\cmd{citet}: \citet[1--10]{companion,adams:rest,adams:life} \\
\cmd{cite}: \cite[e.g.][100]{adams:life}; \cite{adams:rest} \\
\cmd{citep}: \citep[e.g.][1--10]{adams:rest,adams:life} \\
\cmd{citetext}; \cmd{citealp}:
\citetext{see \citealp[10]{adams:rest}; or even better \citealp{adams:life}} \\
\cmd{citeauthor}, \cmd{citeauthor*}: \citeauthor{adams:life}; \citeauthor*{companion} \\
\cmd{citeyear}, \cmd{citeyearpar}: \citeyear{adams:life}; \citeyearpar{adams:rest} \\
\cmd{citetalias}, \cmd{citepalias}: \citetalias{companion}; \citepalias{companion} \\
\cmd{citenum}: \citenum{adams:life,adams:rest}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
Both of these citations commands are defined in biblatex.def
. To add links, you can redefine them in your document preamble or configuration file. A linked variant of \citeauthor
is already addressed in this previous question. The \citetitle
command can be revised similarly, although note that you may wish to swap the order of the bibhyperref
and citetitle
formats.
\DeclareCiteCommand{\citetitle}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexfield{indextitle}}
{}%
\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
{\multicitedelim}
{\usebibmacro{postnote}}
Best Answer
Just apply the
bibhyperref
format in the citation command:Definitions for
bibhyperref
and\citeauthor
can be found inbiblatex.def
.