自定义同一作者同一年发表的多篇文章的引用样式

自定义同一作者同一年发表的多篇文章的引用样式

我的问题类似于这里。但我无法使该解决方案适用于我的用例。我需要它用于 parencite,并且我正在使用另一个案例中使用的选项调用 biblatex。这是我的 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}

答案1

\parencite命令依赖于 bibmacro cite,我们必须修补它。因此

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

就够了。

如果你希望同样适用\citeyear,你还需要

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

现在可能可以清理整个引用命令,因为它的一些技巧不再需要了。

然后它看起来就像这样

\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

当然,正如通常情况那样,xpatch解决方案更简短。

\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}

在此处输入图片描述

相关内容