当缺少名字时,在 biblatex 中缩写名称

当缺少名字时,在 biblatex 中缩写名称

这是对使用 biblatex 防止匿名作品名称缩写,本身就是在 biblatex 中缩写解决作者名字的缩写

简而言之,我需要打印出作者在其原创作品中出现的名字。.bib另一方面,在我的文件中,我总是在括号内提供缺少的姓名信息。因此,诀窍是以适当的方式删除这些额外信息。

现在,使用 Andrew Swann 的代码回答对于我的问题,我注意到,当我的.bib文件中有一个条目缺少作者的名字,但在括号中提供时,输出会打印作者的姓氏,后跟逗号加空格加句点,因为代码将名字缩写为空格字符:

Lennon, . (1974)

适当的输出将是仅打印姓氏:Lennon (1974)。其他姓名应按照此 MWE 中的方式显示。

有什么建议么?

\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{lennon1973,
    AUTHOR = "John Lennon",
    TITLE = "Still moving on",
    YEAR = "1973",
    SORTNAME = "John Lennon"}
@BOOK{lennon1974,
    AUTHOR = "[John] Lennon",
    TITLE = "I'm out of here",
    YEAR = "1974",
    SORTNAME = "John Lennon"}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述


编辑

申请以下是 moewe 的建议,当字段中有多个带括号的作者时,就会出错AUTHOR

\documentclass{article}

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

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
      \step[fieldsource = author, match = \regexp{\A\[(.+)\s+([^\s]+)\]\Z}, replace = {[$2, $1]}]
    }
    \map{
      \step[fieldsource = author, match = \regexp{(\w+)\[(.+)\]}, replace ={$1.}]
    }
    \map{
      \step[fieldsource = author, notmatch = \regexp{\A\[(.+)\]\Z}, final]
      \step[fieldsource = author, match = \regexp{(\A|\,\s)\[(.+)\]}, 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"}
@BOOK{lennon1972,
    AUTHOR = "[J. John Lennon]",
    TITLE = "Moving further on",
    YEAR = "1972",
    SORTNAME = "John Lennon"}
@BOOK{lennon1973,
    AUTHOR = "John Lennon",
    TITLE = "Still moving on",
    YEAR = "1973",
    SORTNAME = "John Lennon"}
@BOOK{lennon1974,
    AUTHOR = "[John] Lennon",
    TITLE = "I'm out of here",
    YEAR = "1974",
    SORTNAME = "John Lennon"}
@BOOK{lennon1975,
    AUTHOR = "Lennon, [John]",
    TITLE = "I'm out of here",
    YEAR = "1975",
    SORTNAME = "John Lennon"}
@BOOK{beatles1970,
    AUTHOR = "John W[inston] Lennon and J[ames] Paul McCartney",
    TITLE = "Let it be",
    YEAR = "1970"}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

答案1

这些正则表达式技巧可能非常复杂,并且这里的解决方案也可能有其缺点,但是这里......

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

第一个映射是从 MWE 中详细提取的,因此是 Andrew Swann 的答案。第二个映射将紧跟在单词字符(即字母)后面的括号对转换为缩写点。最后,如果用括号括起来,第三部分将删除整个名字([John] Lennon并且Lennon, [John]两者都匹配并转换为Lennon)。

平均能量损失

\documentclass{article}

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

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
      \step[fieldsource = author, match = \regexp{\A\[(.+)\s+([^\s]+)\]\Z}, replace = {[$2, $1]}]
    }
    \map{
      \step[fieldsource = author, match = \regexp{(\w+)\[(.+?)\]}, replace ={$1.}]
    }
    \map{
      \step[fieldsource = author, notmatch = \regexp{\A\[(.+)\]\Z}, final]
      \step[fieldsource = author, match = \regexp{(\A|\,\s)\[(.+?)\]}, replace = {$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{lennon1973,
    AUTHOR = "John Lennon",
    TITLE = "Still moving on",
    YEAR = "1973",
    SORTNAME = "John Lennon"}
@BOOK{lennon1974,
    AUTHOR = "[John] Lennon",
    TITLE = "I'm out of here",
    YEAR = "1974",
    SORTNAME = "John Lennon"}
@BOOK{lennon1975,
    AUTHOR = "Lennon, [John]",
    TITLE = "I'm out of here",
    YEAR = "1975",
    SORTNAME = "John Lennon"}
@BOOK{beatles1970,
    AUTHOR = "John W[inston] Lennon and J[ames] Paul McCartney",
    TITLE = "Let it be",
    YEAR = "1970"}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

相关内容