3

I'm having trouble with my code. I'd like the 2nd \parencite to also include the authors name.

The \DeclareCiteCommand is causing the authors name to be absent after the first cite

\documentclass{article}

\begin{filecontents}{\jobname.bib}
    @misc{A01,
        author = {Sutherland and Varnam},
        year = {2001},
        title = {Title},
    }
\end{filecontents}

\usepackage[style=apa,backend=biber]{biblatex}

\addbibresource{\jobname.bib}

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

\usepackage{hyperref}

\begin{document}

    First cite \parencite{A01}.

    Second cite \parencite{A01}.

    \printbibliography

\end{document} 
Stefan Pinnow
  • 29,535

2 Answers2

4

biblatex-apa defines \parencite slightly different than the redefinition in your example assumes. That definition works for some of the standard styles, but not for more complicated styles like authoryear-icomp and apa.

For apa you need

\documentclass{article}

\usepackage[style=apa,backend=biber]{biblatex}
\usepackage{hyperref}

\addbibresource{biblatex-examples.bib}

\DeclareFieldFormat{bibhyperrefnonest}{%
  \DeclareFieldFormat{bibhyperref}{##1}%
  \bibhyperref{#1}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperrefnonest]{\usebibmacro{cite}}}
  {}
  {\usebibmacro{postnote}%
   \usebibmacro{cite:post}}

\DeclareCiteCommand{\textcite}
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperrefnonest]{\usebibmacro{textcite}}}
  {}
  {\usebibmacro{textcite:postnote}%
   \usebibmacro{cite:post}}


\begin{document}
  First cite \parencite{sigfridsson}.

  Second cite \parencite{sigfridsson}.

\citereset

  First cite \textcite{sigfridsson}.

  Second cite \textcite{sigfridsson}.

  \printbibliography
\end{document}

The MWE shows both citations with links and identical text "Sigfridsson & Ryde, 1998"

edit: Added a redefinition for \textcite as well. Note that the parentheses in \textcite may not be linked as expected. Fixing that would be much more complicated.

moewe
  • 175,683
  • I had the same issue and your answer solved it for me, Moewe. Do you know of a similar workaround for the \textcite command by any chance? Thanks in advance! – Michiel Schreurs Apr 08 '19 at 15:33
  • @MichielSchreurs See the edit for the analogue redefinition of \textcite. Note that that might not give exactly what you want w.r.t. the parentheses. Getting the links right there is much more complicated. If you want that you can ask a new question. – moewe Apr 08 '19 at 17:39
  • Revisiting this issue. The redefined \parencite worked as I had wished. Now for the \textcite. As you mentioned @moewe, the right parentheses is not hyperlinked. How much more complicated would it be to solve this issue? – Socadillo Apr 20 '19 at 16:10
  • @Socadillo I can't say from the top of my head, but I'm pretty sure it would more more complicated. Certainly so complicated that I would want to urge you to ask a new question, since I will not answer it in the comments here. – moewe Apr 20 '19 at 18:33
  • In the case of \parencite, this implementation also hyperlinks the comma between the author's name and the year, which isn't standard. Is there a way to exclude it? – Monika Jun 18 '22 at 08:56
  • @Jana Quite probably yes, but please ask a new question about that. – moewe Jun 18 '22 at 09:32
2

Not sure if still needed, but I tried with the following and it seem to inlcude the right parenthesis too:

\DeclareCiteCommand{\textcite}
{\usebibmacro{cite:init}%
    \usebibmacro{prenote}}
{\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{textcite}}}
{}
{\printtext[bibhyperref]{\usebibmacro{textcite:postnote}}%
    \usebibmacro{cite:post}}

Hope it helps, and apologies for not posting a MWE.