# Hyperlink with authoryear-comp in beamer

Consider the following MWE:

\documentclass{beamer}

\usepackage{xpatch}
\usepackage{lmodern}

\usepackage[style=authoryear-comp,backend=biber]{biblatex}

% Combine label and labelyear links
\xpatchbibmacro{cite}
{\usebibmacro{cite:label}%
\usebibmacro{cite:labelyear+extrayear}}
{\printtext[bibhyperref]{%
\DeclareFieldAlias{bibhyperref}{default}%
\usebibmacro{cite:label}%
\usebibmacro{cite:labelyear+extrayear}}}{}{}

% Include labelname in labelyear link
\xpatchbibmacro{cite}
{\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}}
{\printtext[bibhyperref]{%
\DeclareFieldAlias{bibhyperref}{default}%
\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}}}{}{}

% Access hyperref's citation link start/end commands
\makeatletter
\@ifnextchar[%]
\makeatother

% Include parentheses around labelyear in \textcite only in
% single citations without pre- and postnotes
\ifboolexpr{ test {\ifnumequal{\value{multicitetotal}}{0}} and
test {\ifnumequal{\value{citetotal}}{1}} and
test {\iffieldundef{prenote}} and
test {\iffieldundef{postnote}} }}

\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\DeclareFieldAlias{bibhyperref}{default}%
\printnames{labelname}}
{\printtext[bibhyperref]{\printnames{labelname}}}}{}{}

\xpatchbibmacro{textcite}
{\usebibmacro{cite:label}}
{\DeclareFieldAlias{bibhyperref}{default}%
\usebibmacro{cite:label}}
{\usebibmacro{cite:label}}}{}{}

\xpretobibmacro{textcite:postnote}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
{}}
{}
{\xpatchbibmacro{textcite}% patch earlier releases
{\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
{}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}}
{}{}}

\begin{document}
\begin{frame}
\textcite{knuth:ct:e}
\end{frame}
\begin{frame}
\frametitle{Bibliography}
\printbibliography
\end{frame}
\end{document}


Since I want hyperlink in citations to include the name of the author and not just the year, I'm using, after the line that begins with \hypersetup, the code in this answer. However by doing this I'm getting the error: Undefined control sequence.

The problem might be with this part of the code:

\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\DeclareFieldAlias{bibhyperref}{default}%
\printnames{labelname}}
{\printtext[bibhyperref]{\printnames{labelname}}}}{}{}


When I remove it, the error goes away but I don't get the desired result of hyperlinking both the author and the year.

• Which code? .... – cfr Sep 22 '14 at 21:15
• @cfr See my updated question please. – petobens Sep 22 '14 at 21:55
• And how is the biblatex code integrated in your example .tex file? That file has its own problem: you use \hypersetup without first loading the hyperref package. Add \usepackage{hyperref} before the line \hypersetup. – jon Sep 27 '14 at 0:34
• @jon Mm I'm pretty sure beamer loads hyperref by default (adding it explicitly still generates the error). In the post I state how the code is integrated in my file: after the \hypersetup line. – petobens Sep 27 '14 at 1:01
• Ah, true. Never noticed that before. However, I can compile your .tex file without problems --- is the posted file the one that is causing the problems? Because, if so, then none of the biblatex code can be the culprit, since it is not being used in the example file. And if you are simply adding those lines in your preamble, that will fail miserably for a few reasons. Please edit your question so that you have one complete file that leaves no guesswork to others. – jon Sep 27 '14 at 1:05

If you replace the problematic part of your code with

\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\printtext[bibhyperref]{\printnames{labelname}}}{}{}


You get a clickable author name and year. Only the space between and the parenthesis remain unclickable. Is this enough clickability?

\documentclass{beamer}

\usepackage{xpatch}
\usepackage{lmodern}

\usepackage[style=authoryear-comp,backend=biber]{biblatex}

% Combine label and labelyear links
\xpatchbibmacro{cite}
{\usebibmacro{cite:label}%
\usebibmacro{cite:labelyear+extrayear}}
{\printtext[bibhyperref]{%
\DeclareFieldAlias{bibhyperref}{default}%
\usebibmacro{cite:label}%
\usebibmacro{cite:labelyear+extrayear}}}{}{}

% Include labelname in labelyear link
\xpatchbibmacro{cite}
{\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}}
{\printtext[bibhyperref]{%
\DeclareFieldAlias{bibhyperref}{default}%
\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}}}{}{}

% Access hyperref's citation link start/end commands
\makeatletter
\@ifnextchar[%]
\makeatother

% Include parentheses around labelyear in \textcite only in
% single citations without pre- and postnotes
\ifboolexpr{ test {\ifnumequal{\value{multicitetotal}}{0}} and
test {\ifnumequal{\value{citetotal}}{1}} and
test {\iffieldundef{prenote}} and
test {\iffieldundef{postnote}} }}

%\xpatchbibmacro{textcite}
%{\printnames{labelname}}
%   {\DeclareFieldAlias{bibhyperref}{default}%
%       \printnames{labelname}}
%   {\printtext[bibhyperref]{\printnames{labelname}}}}{}{}

\xpatchbibmacro{textcite}
{\printnames{labelname}}
{\printtext[bibhyperref]{\printnames{labelname}}}{}{}

\xpatchbibmacro{textcite}
{\usebibmacro{cite:label}}
{\DeclareFieldAlias{bibhyperref}{default}%
\usebibmacro{cite:label}}
{\usebibmacro{cite:label}}}{}{}

\xpretobibmacro{textcite:postnote}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
{}}
{}
{\xpatchbibmacro{textcite}% patch earlier releases
{\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}}
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
{}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}}
{}{}}

\begin{document}
\begin{frame}
\textcite{knuth:ct:e}
\end{frame}
\begin{frame}
\frametitle{Bibliography}
\printbibliography
\end{frame}
\end{document}