0

I've been using the code given in this answer to tune the authoryear citation style to my needs. More specifically, I'm trying to have references in the form (First Author, year), with everything within parentheses linking to the bibliography.

Unfortunately, the link created with this method doesn't actually work. Consider the following MWE:

\documentclass{article}

\usepackage{nameref}
\usepackage[colorlinks=true]{hyperref}
\usepackage[nameinlink]{cleveref}

\usepackage{filecontents}

\begin{filecontents}{bibliography.bib}
@article{cubitt2017universal,
    author = {Cubitt, T. and Montanaro, A. and Piddock, S.},
    journal = {arXiv:1701.05182},
    title = {Universal Quantum Hamiltonians},
    url = {https://arxiv.org/abs/1701.05182},
    year = {2017}
}
\end{filecontents}

\usepackage[
    backend=biber,
    style=authoryear,
    bibstyle=authoryear,
    citestyle=authoryear,
    maxcitenames=1,
    natbib
]{biblatex}
% \renewcommand{\cite}{\mycitep}

% -------------- START AUTHORYEAR FIX
\usepackage{twoopt}
\usepackage{ifthen}

\newcommand\black[1]{\textcolor[rgb]{0,0,0}{#1}}
\makeatletter 
\newcommand{\multicite}[1]{% taken from egreg, see link
  \@tempswafalse
  \@for\next:=#1\do
    {\if@tempswa;~\else\@tempswatrue\fi
    \hyperlink{cite.\next}{\citeauthor{\next}\black{,~}\citeyear{\next}}%
    }%
}
\makeatother

\newcommandtwoopt{\mycitep}[3][aa][bb]{%        
    \ifthenelse{\equal{#1}{aa}}                                                                  % if nargin == 1
      {(\multicite{#3})}                                                                         %    \citep{key(s)}
      {\ifthenelse{\equal{#2}{bb}}                                                               % elseif nargin == 2
          {(\hyperlink{cite.#3}{\citeauthor{#3}\black{,~}\citeyear{#3}\black{,~}#1})}            %    \citep[pg]{key}
          {\ifthenelse{\equal{#1}{}}                                                             % elseif #1 = []
              {(\hyperlink{cite.#3}{\citeauthor{#3}\black{,~}\citeyear{#3}\black{,~}#2})}        %    \citep[][pg]{key}
              {\ifthenelse{\equal{#2}{}}                                                         % elseif #2 == []
                  {(#1~\multicite{#3})}                                                          %    \citep[eg][]{key(s)}
                  %                                                                              % else
                  {(#1~\hyperlink{cite.#3}{\citeauthor{#3}\black{,~}\citeyear{#3}\black{,~}#2})} %    \citep[eg][pg]{key}}
              }
          }
      }
}
% ------------------- END AUTHORYEAR FIX

\addbibresource{bibliography.bib}

\begin{document}

This link works~\citep{cubitt2017universal}, but this doesn't~\mycitep{cubitt2017universal}.

\printbibliography
\end{document}

This gives

enter image description here

which would be great if not for the fact that the link produced by \mycitep doesn't work: clicking on it does nothing, whereas the same reference created with \citep correctly sends me to the relevant bit in the bibliography.

How can I fix this? (another way to have the same type of reference style with working links would be equally good for me)

Browse other questions tagged or ask your own question.