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)

moewe
  • 175,683
glS
  • 546
  • Off-topic: style=authoryear, bibstyle=authoryear, citestyle=authoryear, is redundant. Shorten that to just style=authoryear,. – moewe Jan 10 '20 at 18:54
  • My go-to answer for linking everything in the citation is https://tex.stackexchange.com/q/15951/35864. Does that help? You could also look at https://tex.stackexchange.com/q/425283/35864 or https://tex.stackexchange.com/q/437717/35864. – moewe Jan 10 '20 at 18:56
  • Another one: https://tex.stackexchange.com/q/299050/35864 – moewe Jan 10 '20 at 19:05
  • Any news here? Did any of the suggested links work for you? – moewe Jan 14 '20 at 06:21
  • I voted to close this question as a duplicate of the standard "link all of biblatex's \cite output" question. If that doesn't work for you, please edit your question to explain why and we can reopen it. – moewe Feb 04 '20 at 20:11

0 Answers0