使用 biblatex 防止匿名作品名称缩写

使用 biblatex 防止匿名作品名称缩写

这是在 biblatex 中缩写解决作者名字的缩写,其中@PLK提供了一个回答其中括号[]和它们之间的字符被替换为点.

这里有一个问题,我的文件中有一些.bib匿名出版物的条目,但我们知道作者是谁。在这种情况下,我会在括号内填写全名,例如[John Lennon]。在这种情况下,全部的.名称位于括号之间,不应用点替换。

问题:有没有办法用点代替括号中间的字符除了当整个author字段包含这样的序列时(例如,author = J[ohn] Lennon替换为author = J. Lennon,但author = [John Lennon]仍然存在author = [John Lennon]

或者换句话说,我能以某种方式“保护”author = [John Lennon]下面的条目不被命令攻击DeclareSourcemap吗?

\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\DeclareSourcemap{\maps[datatype = bibtex]{\map{\step[fieldsource = author, match = \regexp{\[[^]]+\]}, replace = .]}}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1970,
    AUTHOR = "J[ohn] Lennon",
    TITLE = "My life with the Beatles",
    YEAR = "1970",
    SORTNAME = "John Lennon"}
@BOOK{lennon1971,
    AUTHOR = "[John Lennon]",
    TITLE = "Moving on",
    YEAR = "1971",
    SORTNAME = "John Lennon"}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

问题biblatex 条目中的括号在这里也可能很重要。

答案1

您可以将正则表达式搜索锚定到字符串的开头,\A并使用 将其锚定到字符串的结尾\Z,请参阅http://perldoc.perl.org/perlre.html#Regular-Expressions如果您的输入被编码为

author = {[Lennon, John]}

然后你只需添加第一个测试

\step[fieldsource = author, notmatch = \regexp{\A\[.+\]\Z}, final]

跳过完全包含括号的字段。这也适用于

author = {[John Lennon]}

但是biber/biblatex随后将其Lennon]视为姓氏和[John名字和印刷

Lennon], [John

在参考书目中,这不是您想要的。

\documentclass{article}

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

\DeclareSourcemap{\maps[datatype = bibtex]{
\map{
  \step[fieldsource = author, notmatch = \regexp{\A\[.+\]\Z}, final]
  \step[fieldsource = author, match = \regexp{\[[^]]+\]}, replace = .]
}
\map{
 \step[fieldsource = author, match = \regexp{\A\[(.+)\s+([^\s]+)\]\Z},
 replace = {[$2, $1]}]}
}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1970,
    AUTHOR = "J[ohn] Lennon",
    TITLE = "My life with the Beatles",
    YEAR = "1970",
    SORTNAME = "John Lennon"}
@BOOK{lennon1971,
    AUTHOR = "[John Lennon]",
    TITLE = "Moving on",
    YEAR = "1971",
    SORTNAME = "John Lennon"}
@BOOK{lennon1972,
    AUTHOR = "[J. John Lennon]",
    TITLE = "Moving further on",
    YEAR = "1972",
    SORTNAME = "John Lennon"}
@BOOK{aasen1990,
    AUTHOR = "[{\AA}ge {\AA}sen]",
    TITLE = "Mitt liv",
    YEAR = "1990",
    SORTNAME = "{\AA}ge {\AA}sen"}
@BOOK{estevez1990,
    AUTHOR = "[{\'E}milio {\'E}stevez]",
    TITLE = "Hola",
    YEAR = "1990",
    SORTNAME = "{\'E}milio {\'E}stevez"}
@BOOK{aasen1991,
    AUTHOR = "{\AA}[ge] {\AA}sen",
    TITLE = "Mitt liv 2",
    YEAR = "1991",
    SORTNAME = "{\AA}ge {\AA}sen"}
@BOOK{estevez1991,
    AUTHOR = "{\'E}[milio] {\'E}stevez",
    TITLE = "Hola 2",
    YEAR = "1991",
    SORTNAME = "{\'E}milio {\'E}stevez"}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\printbibliography

\end{document}

在此处输入图片描述

相关内容