格式化参考书目中虚线条目后的句号和大写字母

格式化参考书目中虚线条目后的句号和大写字母

考虑以下 MWE。

\documentclass{article}

\usepackage{fontspec}
\setmainfont{EB Garamond}

\usepackage[style = authoryear-comp]{biblatex}
\usepackage{xpatch}
    \xpatchbibmacro{date+extradate}{\printtext[parens]}{\setunit*{\addperiod\space}\printtext}{}{} % remove parenthesis around year in bibliography
\DeclareFieldFormat{editortype}{\mkbibparens{#1}} % put editor in parenthesis when before publication year
\DeclareDelimFormat{editortypedelim}{\addspace}
%\renewcommand*\bibnamedash{\char"2E3B\addperiod\space} % use a 3em dash with period after it for dashed author names

\begin{filecontents}[overwrite]{\jobname.bib}
@book{anderson1980,
    AUTHOR = "Peter Anderson",
    TITLE = "My book",
    YEAR = "1980"}
@book{anderson1981,
    AUTHOR = "Peter Anderson",
    TITLE = "My second book",
    YEAR = "1981"}
@collection{anderson1982,
    EDITOR = "Peter Anderson",
    TITLE = "Interesting articles",
    YEAR = "1982"}
@collection{smith1983,
    EDITOR = "Harry Smith",
    TITLE = "Good chapters",
    YEAR = "1983"}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{anderson1980}\nocite{anderson1981}\nocite{anderson1982}\nocite{smith1983}

\printbibliography
\end{document}

输出看起来还不错:

在此处输入图片描述

但我想遵循 Bringhurst 的建议,使用三个破折号。此外,破折号只能替代名称,而不能替代标点符号,因此破折号后面应该跟一个句号。取消注释 MWE 中注释的行将得到以下内容:

在此处输入图片描述

虽然此处的第二条记录看起来正确,但第三条记录却不正确。破折号和括号之间不应该有句号(Ed.),因为这里一开始就没有句号,如第四条也是最后一条记录所示。其次,括号中的单词的首字母不应该大写(此处之所以大写是因为前面有句号,所以一旦删除句号,它可能会自行消失)。

简而言之,第三行应该是--- (ed.). 1982.,而不是---. (Ed.). 1982。如何才能实现这一点,同时又不从第二个条目中删除句点?

答案1

默认情况下,biblatex标准样式会打印\bibnamedashnot in\printtext或任何其他尊重标点符号缓冲区的命令。这让事情变得有点混乱。

我建议您修改相关的宏以\bibnamedash在内部打印\printtext,以便标点符号缓冲区可以实际使用。我们还重新定义了这些宏,以便它们始终打印editortypedelim/translatortypedelim标点符号。然后,\printtext{\bibnamedash}其行为与这些宏中的和朋友完全类似\printnames{author}。(如果您想将新宏与原始定义进行比较,可以在以下位置找到相关宏authoryear.bbx[版本 3.17 中第 202-268 行]

然后只需设置\bibnamedeash\char"2E3B(无需额外的标点符号)并打印所需的内容nameyeardelim

请注意,我删除了xpatch而采用了biblatex-extbiblabeldate字段格式。请参阅我的答案如何(正确地)删除 authoryear 样式中年份周围的括号?(v3)

\documentclass{article}

\usepackage{fontspec}
\setmainfont{EB Garamond}

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

\DeclareFieldFormat{biblabeldate}{#1}

\DeclareDelimFormat[bib]{nameyeardelim}{\addperiod\space}

\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
\DeclareDelimFormat{editortypedelim}{\addspace}

\renewcommand*\bibnamedash{\char"2E3B}

\makeatletter
\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\printtext{\bibnamedash}}
       {\usebibmacro{bbx:savehash}%
        \printnames{author}}%
     \setunit{\printdelim{authortypedelim}}%
     \usebibmacro{authorstrg}%
     \setunit{\printdelim{nameyeardelim}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\printdelim{nonameyeardelim}}}%
  \usebibmacro{date+extradate}}

\renewbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\printtext{\bibnamedash}}
       {\printnames{editor}%
        \usebibmacro{bbx:savehash}}%
     \setunit{\printdelim{editortypedelim}}%
     \usebibmacro{#1}%
     \clearname{editor}%
     \setunit{\printdelim{nameyeardelim}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\printdelim{nonameyeardelim}}}%
  \usebibmacro{date+extradate}}

\renewbibmacro*{bbx:translator}[1]{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\printtext{\bibnamedash}}
       {\printnames{translator}%
        \usebibmacro{bbx:savehash}}%
     \setunit{\printdelim{translatortypedelim}}%
     \usebibmacro{#1}%
     \clearname{translator}%
     \setunit{\printdelim{nameyeardelim}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\printdelim{nonameyeardelim}}}%
  \usebibmacro{date+extradate}}
\makeatother


\begin{filecontents}{\jobname.bib}
@book{anderson1980,
  author = {Peter Anderson},
  title  = {My book},
  year   = {1980},
}
@book{anderson1981,
  author = {Peter Anderson},
  title  = {My second book},
  year   = {1981},
}
@collection{anderson1982,
  editor = {Peter Anderson},
  title  = {Interesting articles},
  year   = {1982},
}
@collection{smith1983,
  editor = {Harry Smith},
  title  = {Good chapters},
  year   = {1983},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
Lorem
\nocite{anderson1980,anderson1981,anderson1982,smith1983}

\printbibliography
\end{document}

安德森,彼得。1980。我的书。⸻。1981。我的第二本书。⸻(编)。1982。有趣的文章。史密斯,哈利(编)。1983。精彩章节。

相关内容