在 biblatex 中使用虚线条目在作者后添加句号

在 biblatex 中使用虚线条目在作者后添加句号

我需要在参考书目中的(最后一位)作者之后、印刷年份之前添加一个句号。从当 terseinits = true 时,biblatex 中最后一个作者姓名后的句号我了解到我可以用

\usepackage{xpatch}
\xpretobibmacro{date+extrayear}{\setunit{\addperiod\space}}{}{}

但是当biblatex选项dashed设置为true,并且一年内有多个条目,需要添加字母ab来分隔它们时,句点会添加在括号内的年份后面,而不是在破折号后面。

\documentclass{article}
\usepackage[style = authoryear-comp, dashed = true]{biblatex}
\usepackage{xpatch}
\xpretobibmacro{date+extrayear}{\setunit{\addperiod\space}}{}{}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{lennon1963,
    AUTHOR = "John Lennon",
    TITLE = "Does she love you? Yeah, yeah, yeah",
    JOURNALTITLE = "Top of the Pops",
    YEAR = "1963",
    PAGES = "5--13"}
@article{lennon1967a,
    AUTHOR = "John Lennon",
    TITLE = "A day in whose life?",
    JOURNALTITLE = "Top of the Pops",
    YEAR = "1967",
    PAGES = "12--24"}
@article{lennon1967b,
    AUTHOR = "John Lennon",
    TITLE = "Is love all you need?",
    JOURNALTITLE = "Top of the Pops",
    YEAR = "1967",
    PAGES = "25--34"}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

答案1

您可以检查破折号是否已打印,如果是,我们就不添加句点,否则我们就打印它。

\xpretobibmacro{date+extrayear}
  {\usebibmacro{bbx:dashcheck}
    {}
    {\setunit{\addperiod\space}}}
  {}{}

但是,我认为在这种情况下,长解决方案是最可靠的。(您可以看到修补使宏变得多么变化无常。)

我们\setunit{\addspace}用和宏\setunit{\addperiod\space}中的author一些替换它们:bbx:editorbbx:translator

\makeatletter
\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\usebibmacro{bbx:savehash}%
        \printnames{author}%
        \iffieldundef{authortype}
          {\setunit{\addperiod\space}}
          {\setunit{\addcomma\space}}}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}%
        \setunit{\addperiod\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\adddperiod\space}}%
  \usebibmacro{date+extrayear}}


\newbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames{editor}%
        \setunit{\addcomma\space}%
        \usebibmacro{bbx:savehash}}%
     \usebibmacro{#1}%
     \clearname{editor}%
     \setunit{\addperiod\space}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addperiod\space}}%
  \usebibmacro{date+extrayear}}


\newbibmacro*{bbx:translator}[1]{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames{translator}%
        \setunit{\addcomma\space}%
        \usebibmacro{bbx:savehash}}%
     \usebibmacro{translator+othersstrg}%
     \clearname{translator}%
     \setunit{\addperiod\space}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \usebibmacro{date+extrayear}}
\makeatother

平均能量损失

\documentclass{article}
\usepackage[style = authoryear-comp, dashed = true]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{lennon1963,
    AUTHOR = "John Lennon",
    TITLE = "Does she love you? Yeah, yeah, yeah",
    JOURNALTITLE = "Top of the Pops",
    YEAR = "1963",
    PAGES = "5--13"}
@article{lennon1967a,
    AUTHOR = "John Lennon",
    TITLE = "A day in whose life?",
    JOURNALTITLE = "Top of the Pops",
    YEAR = "1967",
    PAGES = "12--24"}
@article{lennon1967b,
    AUTHOR = "John Lennon",
    TITLE = "Is love all you need?",
    JOURNALTITLE = "Top of the Pops",
    YEAR = "1967",
    PAGES = "25--34"}
\end{filecontents*}
\addbibresource{\jobname.bib}
\makeatletter
\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\usebibmacro{bbx:savehash}%
        \printnames{author}%
        \iffieldundef{authortype}
          {\setunit{\addperiod\space}}
          {\setunit{\addcomma\space}}}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}%
        \setunit{\addperiod\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\adddperiod\space}}%
  \usebibmacro{date+extrayear}}


\newbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames{editor}%
        \setunit{\addcomma\space}%
        \usebibmacro{bbx:savehash}}%
     \usebibmacro{#1}%
     \clearname{editor}%
     \setunit{\addperiod\space}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addperiod\space}}%
  \usebibmacro{date+extrayear}}


\newbibmacro*{bbx:translator}[1]{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames{translator}%
        \setunit{\addcomma\space}%
        \usebibmacro{bbx:savehash}}%
     \usebibmacro{translator+othersstrg}%
     \clearname{translator}%
     \setunit{\addperiod\space}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \usebibmacro{date+extrayear}}
\makeatother
\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述


要在破折号后添加句号,请使用

\renewcommand*{\bibnamedash}{%
  \ifdimless{\leftmargin}{0.75em}
    {\mbox{\textemdash\addperiod\space}}
    {\makebox[\leftmargin][l]{%
       \ifdimless{\leftmargin}{1.25em}
         {\textendash\addperiod}
         {\textemdash\addperiod}}}}

这只是\addperiod在不同的破折号后添加。

相关内容