0

I am having a problem which is unfortunately quite specific. Using biber and hyperref, I was trying to use the author’s name as a hyperref reference, too (not only the year) which is similar to bibtex/natbib. In general, I think it looks quite nice but there is a problem when trying to reference the same author twice in a row: enter image description here

What I would like to have when citing the same authors twice is the same output as in 4) but using \parencite or \textcite instead of \citeauthor and then \citeyear.

My code for producing the output above:

\documentclass{scrartcl}
\usepackage[backend=biber, style=apa]{biblatex}
\addbibresource{Bib.bib}
\usepackage{hyperref}
\usepackage{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={red!50!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}

\input{biberhyperlink.tex}

\begin{document}

  1. First citations \parencite{Meltzer.Richard.1981} work quite nicely \parencite{Facchini.2018}.

  2. However, when citing one author \parencite{Meltzer.Richard.1981} a second time in a row \parencite{Meltzer.Richard.1983}, it does not.

  3. \textcite{Meltzer.Richard.1981} and \textcite{Meltzer.Richard.1983} does not work properly either.

  4. \citeauthor{Meltzer.Richard.1981} (\citeyear{Meltzer.Richard.1981}) and \citeauthor{Meltzer.Richard.1983} (\citeyear{Meltzer.Richard.1983}) would work as a workaround.

\end{document}

Where the biberhyperlink.tex file defines the modified functions. I took them from other tex stackexchange questions (hyperlink name with biblatex authoryear and hyperlinking author names in biblatex when using \citeauthor) as noted below. I would guess there is a mistake but cannot figure it out myself:

% https://tex.stackexchange.com/questions/1687/hyperlink-name-with-biblatex-authoryear

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

\DeclareCiteCommand*{\cite} {\usebibmacro{prenote}} {\usebibmacro{citeindex}% \printtext[bibhyperref]{\usebibmacro{citeyear}}} {\multicitedelim} {\usebibmacro{postnote}}

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

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

\DeclareCiteCommand{\footcite}[\mkbibfootnote] {\usebibmacro{prenote}} {\usebibmacro{citeindex}% \printtext[bibhyperref]{ \usebibmacro{cite}}} {\multicitedelim} {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext] {\usebibmacro{prenote}} {\usebibmacro{citeindex}% \printtext[bibhyperref]{\usebibmacro{cite}}} {\multicitedelim} {\usebibmacro{postnote}}

\DeclareCiteCommand{\textcite} {\boolfalse{cbx:parens}} {\usebibmacro{citeindex}% \printtext[bibhyperref]{\usebibmacro{textcite}}} {\ifbool{cbx:parens} {\bibcloseparen\global\boolfalse{cbx:parens}} {}% \multicitedelim} {\usebibmacro{textcite:postnote}}

% https://tex.stackexchange.com/questions/75902/hyperlinking-author-names-in-biblatex-when-using-citeauthor \DeclareCiteCommand{\citeauthor} {\boolfalse{citetracker}% \boolfalse{pagetracker}% \usebibmacro{prenote}} {\ifciteindex {\indexnames{labelname}} {}% \printtext[bibhyperref]{\printnames{labelname}}} {\multicitedelim} {\usebibmacro{postnote}}

For reproduction purposes, this is my bib file Bib.bib:

@article{Facchini.2018,
 author = {Facchini, Francois},
 year = {2018},
 title = {{What Are the Determinants of Public Spending? An Overview of the Literature}}
}
@article{Meltzer.Richard.1981,
 author = {Meltzer, Allan H. and Richard, Scott F.},
 year = {1981},
 title = {{A Rational Theory of the Size of Government}}
}
@article{Meltzer.Richard.1983,
 author = {Meltzer, Allan H. and Richard, Scott F.},
 year = {1983},
 title = {{Tests of a Rational Theory of the Size of Government}}
}

If there is no solution to this problem, I would have to use the workaround shown in 4) but obviously, I would prefer a simpler solution.

moewe
  • 175,683
FF0497
  • 3

1 Answers1

1

The code from hyperlink name with biblatex authoryear was written for style=authoryear,. It simply does not work with biblatex-apa's style=apa,.

For biblatex-apa I suggest the approach shown in BibLaTeX Colors And Links Only The Year Not The Rest Of The Citation. This answer previously contained an MWE with code for v9.14 of biblatex-apa. To avoid spreading outdated code I decided to remove it here. Please refer to BibLaTeX Colors And Links Only The Year Not The Rest Of The Citation for an MWE.

moewe
  • 175,683
  • Very helpful, thanks! One additional question I did not specifically ask for in the original post: What if I still wanted to use the \citeauthor and \citeyear commands as linked citations in addition to your code? Example: \item \citeauthor{Meltzer.Richard.1981}'s (\citeyear{Meltzer.Richard.1981}) model shows\dots – FF0497 Jun 30 '21 at 19:08
  • @FF0497 Semantically, \citeyear is the wrong command here (but biblatex-apa uses a slightly unusual definition, which means that it actually does the right thing here). You should use \parencite*. (Answer updated with the code for those commands.) – moewe Jun 30 '21 at 19:20
  • I am sorry for adding yet another layer to this question but what if I also wanted have the following: "y is determined by x (shown e. g. by Meltzer and Richard, 1981)", with linked citations. With your code, I would get double brackets: "y is determined by x (shown e. g. by Meltzer and Richard (1981))" – FF0497 Jul 01 '21 at 08:15