0

I'd like to combine the answers of @moewe, here, and @lockstep, here, to get completely-hyperlinked authoryear citations using biblatex as follows.

\documentclass{memoir}

\usepackage{xcolor}

\usepackage[backend=biber, defernumbers=true, bibstyle=authoryear,style=ext-authoryear]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @misc{A01,
        author = {Author, A.},
        year = {2001},
        title = {Alpha},
    }
\end{filecontents}

\bibliography{\jobname.bib}

%to be put citations in brackets
\DeclareOuterCiteDelims{parencite}{\bibopenbracket}{\bibclosebracket}

%%% To make author hyperlink, just like year, in citations
\DeclareCiteCommand{\parencite}[\mkbibparens]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{citeyear}}}
{\multicitedelim}
{\usebibmacro{postnote}}

\usepackage[colorlinks=true, urlcolor=blue, linkcolor=violet, citecolor=violet]{hyperref}                   

\begin{document}

\parencite{A01}

\printbibliography
    
\end{document}

The result is completely hyperlinked, although the surrounding elements are parentheses rather then brackets.

How can I fix this?

2
  • Note that bibstyle=authoryear,style=ext-authoryear is redundant and equivalent to style=ext-authoryear. style sets both bibstyle and citestyle, so the later style overwrites the earlier bibstyle. defernumbers=true, is generally not needed with non-numeric styles. – moewe Aug 3 '20 at 5:36
  • \bibliography takes the file name of the bibliography database without extension, so \bibliography{\jobname.bib} should be \bibliography{\jobname}. On modern systems it is no longer an issue to wrongly include the .bib extension, but until very recently MikTeX's BibTeX would not find the .bib file in that case. With biblatex \addbibresource is preferred over \bibliography anyway. In \addbibresource you must include the file extension. So \addbibresource{\jobname.bib} would be even better. – moewe Aug 3 '20 at 5:39
2

biblatex-ext's \DeclareOuterCiteDelims is usually implemented via the wrapper definition of the cite command. To wit \parencite is defined in the standard authoryear.cbx as

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

but ext-authoryear.cbx has

\DeclareCiteCommand{\parencite}[\mkouterparencitedelims]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

So if you redefine \parencite you need to preserve \mkouterparencitedelims. Hence,

\DeclareCiteCommand{\parencite}[\mkbibparens]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{citeyear}}}
{\multicitedelim}
{\usebibmacro{postnote}}

would have to be

\documentclass{memoir}
\usepackage{xcolor}
\usepackage[backend=biber, style=ext-authoryear]{biblatex}
\usepackage[colorlinks=true, urlcolor=blue, linkcolor=violet, citecolor=violet]{hyperref}

\DeclareOuterCiteDelims{parencite}{\bibopenbracket}{\bibclosebracket}

\DeclareCiteCommand{\parencite}[\mkouterparencitedelims]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{biblatex-examples.bib}

\begin{document}
\parencite{sigfridsson}

\printbibliography
\end{document}

Something is a bit off here, though. That definition of \parencite only prints the year (\usebibmacro{citeyear}). It looks more like the definition of \parencite*. For the full citation you'd need \usebibmacro{cite}.

Note that you could run into trouble with double link targets if you just said

\DeclareCiteCommand{\parencite}[\mkouterparencitedelims]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

something like

\documentclass{memoir}
\usepackage{xcolor}
\usepackage[backend=biber, style=ext-authoryear]{biblatex}
\usepackage[colorlinks=true, urlcolor=blue, linkcolor=violet, citecolor=violet]{hyperref}

\DeclareOuterCiteDelims{parencite}{\bibopenbracket}{\bibclosebracket}

\DeclareFieldFormat{citehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{#1}}

\DeclareCiteCommand{\parencite}[\mkouterparencitedelims]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[citehyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{biblatex-examples.bib}

\begin{document}
\parencite{sigfridsson}

\printbibliography
\end{document}

is safer in that regard (see hyperlink name with biblatex authoryear (biblatex 1.4b)).

[Sigfridsson and Ryde 1998]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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