当 authoryear-comp 样式中的年份相同时,如何使 origyear 全部打印在引文中?

当 authoryear-comp 样式中的年份相同时,如何使 origyear 全部打印在引文中?

首先是一个 MWS,其输出如下。

\documentclass[american]{article}
\usepackage[style=authoryear-comp]{biblatex}
\addbibresource{\jobname.bib}

%add parenthesis around origyear----------------------------------
\DeclareFieldFormat{origdate}{(#1)}%\mkbibparens
%add origyrar in citiation--------------------------------------------
\renewbibmacro*{cite:labeldate+extradate}{%
    \iffieldundef{origyear}
    {}
    {\printorigdate}
    \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\printlabeldateextra}}}
%add origyear and delelte the parenthesis around year in bibliorgraphy
\renewbibmacro*{date+extradate}{%
    \iffieldundef{origyear}
    {}
    {\printorigdate%add origyear in 
        \setunit*{\addspace}}%add space after origyear
    \iffieldundef{labelyear}
    {}
    {\printtext{\printlabeldateextra}}}%delete parenthesis around year

\begin{filecontents*}[overwrite]{\jobname.bib}
@book{bookot,
  location = {Place},
  publisher={ABC},
  author  = {Name, Given},
  title   = {One title},
  year    = {2001},
  origyear={1978},
}
@book{bookat,
  location = {Place},
  publisher={ABC},
  author  = {Name, Given},
  title   = {Another title},
  year    = {2001},
  origyear={1976},
}
\end{filecontents*}

\begin{document}
some quote from \cite{bookot,bookat}

\printbibliography
\end{document}

在此处输入图片描述

如你所见,我在引文和参考书目中添加了原文年份。然后当年份相同时,如何使引用中的原始年份全部打印出来,即使“名称 (1976) 2001a,b”变为“名称 (1976) 2001a, (1978) 2001b”?

答案1

引用命令的日期打印代码分布在几个地方,所以我们必须更改几行不同的代码

\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}

\DeclareFieldFormat{origdate}{\mkbibparens{#1}}

\makeatletter
\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}%
        \usebibmacro{cite:labeldate+extradate}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\iffieldundef{origyear}
             {}
             {\undef\cbx@lastyear}%
           \ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                       \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
             {\setunit{\addcomma}%
              \usebibmacro{cite:extradate}}
             {\setunit{\compcitedelim}%
              \printorigdate
              \setunit*{\addspace}%
              \usebibmacro{cite:labeldate+extradate}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\printnames{labelname}%
           \setunit{\printdelim{nameyeardelim}}%
           \printorigdate
           \setunit*{\addspace}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\renewbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\iffieldundef{origyear}
             {}
             {\undef\cbx@lastyear}%
           \ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                       \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
             {\setunit{\addcomma}%
              \usebibmacro{cite:extradate}}
             {\setunit{\compcitedelim}%
              \printorigdate
              \setunit*{\addspace}%
              \usebibmacro{cite:labeldate+extradate}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\printorigdate
           \setunit*{\addspace}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
    {\iffieldundef{shorthand}
       {\iffieldundef{origyear}
          {}
          {\undef\cbx@lastyear}%
        \ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                    \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
          {\setunit{\addcomma}%
           \usebibmacro{cite:extradate}}
          {\setunit{\compcitedelim}%
           \printorigdate
           \setunit*{\addspace}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{labelyear}{\cbx@lastyear}}}
       {\setunit{\compcitedelim}%
        \usebibmacro{cite:shorthand}%
        \global\undef\cbx@lastyear}}
    {\ifnameundef{labelname}
       {\iffieldundef{shorthand}
          {\usebibmacro{cite:label}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nonameyeardelim}\bibopenparen}%
           \ifnumequal{\value{citecount}}{1}
             {\usebibmacro{prenote}}
             {}%
           \printorigdate
           \setunit*{\addspace}%
           \usebibmacro{cite:labeldate+extradate}}
          {\usebibmacro{cite:shorthand}}}
       {\printnames{labelname}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \iffieldundef{shorthand}
          {\iffieldundef{labelyear}
             {\usebibmacro{cite:label}}
             {\printorigdate
              \setunit*{\addspace}%
              \usebibmacro{cite:labeldate+extradate}}%
           \savefield{labelyear}{\cbx@lastyear}}
          {\usebibmacro{cite:shorthand}%
           \global\undef\cbx@lastyear}}%
     \stepcounter{textcitecount}%
     \savefield{namehash}{\cbx@lasthash}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
    \textcitedelim}}
\makeatother

\renewbibmacro*{date+extradate}{%
  \setunit*{\addcomma\space}%
  \printorigdate
  \setunit*{\addspace}%
  \iflabeldateisdate
    {\printdateextra}
    {\printlabeldateextra}}

\begin{filecontents*}{\jobname.bib}
@book{bookot,
  location  = {Place},
  publisher = {ABC},
  author    = {Name, Given},
  title     = {One title},
  year      = {2001},
  origyear  = {1978},
}
@book{bookat,
  location  = {Place},
  publisher = {ABC},
  author    = {Name, Given},
  title     = {Another title},
  year      = {2001},
  origyear  = {1976},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
some quote from \cite{bookot,bookat,sigfridsson,worman,geer}

some quote from \parencite{bookot,bookat,sigfridsson,worman,geer}

some quote from \textcite{bookot,bookat}

some quote from \textcite{bookot}

some quote from \parencite*{bookot}

\printbibliography
\end{document}

部分引述自 Geer 1985;Name (1976) 2001a, (1978) 2001b;Sigfridsson and Ryde 1998;Worman 2002

相关内容