1

My problem is similar to the one here. But I am unable to make the solution work for my use case. I need it for parencite, and I am calling biblatex with options from the ones used in the other case. Here is my MWE:

\documentclass{article}

\usepackage[citestyle=authoryear-comp,bibstyle=authoryear,hyperref=true,maxcitenames=3,doi=false,url=true,backend=biber,natbib=true,maxbibnames=99,uniquename=false,uniquelist=false,indexing=cite]{biblatex}

\usepackage{xpatch}
\xpatchbibmacro{parencite}
  {\setunit{\addcomma}\usebibmacro{cite:extrayear}}
  {\setunit{\compcitedelim}\usebibmacro{cite:labelyear+extrayear}}
  {}
  {}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{auth00a,
  author = {Author},
  title = {MyBook A},
  date = {2000}
}
@article{auth00b,
  author = {Author},
  title = {MyBook B},
  date = {2000}
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\parencite{auth00a,auth00b}
\end{document}
  • If you want that for all commands, \renewbibmacro*{cite:extrayear}{\usebibmacro{cite:labelyear+extrayear}} might be the easiest way to go. But that will not take care of the separator, I will add an answer to ensure it is treated correctly. – moewe Aug 22 '15 at 13:43
1

The \parencite command relies on the bibmacro cite, and we will have to patch that. As such

\xpatchbibmacro{cite}
  {\setunit{\addcomma}%
   \usebibmacro{cite:extrayear}}
  {\setunit{\compcitedelim}\usebibmacro{cite:labelyear+extrayear}}
  {}
  {}

Should suffice.

If you want the same to apply to \citeyear, you will also need

\xpatchbibmacro{citeyear}
  {\setunit{\addcomma}%
   \usebibmacro{cite:extrayear}}
  {\setunit{\compcitedelim}\usebibmacro{cite:labelyear+extrayear}}
  {}
  {}

One could probably clean up the whole citation command now, since some of its finesse is not needed any more.

It would then look like this

\makeatletter
\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\addspace}%
        \usebibmacro{cite:labelyear+extrayear}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\setunit{\compcitedelim}%
           \usebibmacro{cite:labelyear+extrayear}}
          {\printnames{labelname}%
           \setunit{\nameyeardelim}%
           \usebibmacro{cite:labelyear+extrayear}%
           \savefield{namehash}{\cbx@lasthash}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}
\makeatother

Of course, as so often, the xpatch solution is shorter.

\documentclass{article}

\usepackage[citestyle=authoryear-comp,bibstyle=authoryear,hyperref=true,maxcitenames=3,doi=false,url=true,backend=biber,natbib=true,maxbibnames=99,uniquename=false,uniquelist=false,indexing=cite]{biblatex}

\usepackage{xpatch}
\xpatchbibmacro{cite}
  {\setunit{\addcomma}%
   \usebibmacro{cite:extrayear}}
  {\setunit{\compcitedelim}\usebibmacro{cite:labelyear+extrayear}}
  {}
  {}

\addbibresource{biblatex-examples.bib}

\begin{document}
\parencite{knuth:ct:b,knuth:ct:c}
\end{document}

enter image description here

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.