我想从 biblatex 中删除一位作者。以下 MWE 功能不多。
\documentclass{article}
\usepackage{biblatex}
\bibliography{biblatex-examples.bib}
\DeclareDatamodelFields[type=field, datatype=literal]{NameDeleted}
\DeclareFieldFormat{NameDeleted}{\mkbibbrackets{#1}}
\renewbibmacro*{author}{%
\ifboolexpr{
test \ifuseauthor
and
not test {\ifnameundef{author}}
}
{\printnames{author}%
\iffieldundef{authortype}
{}
{\setunit{\printdelim{authortypedelim}}%
\usebibmacro{authorstrg}}}
{}%
\newunit%
\printfield{NameDeleted}%
}
% The format of the name to be ignored is stored in \NameToDelete as
% \namepartfamily|\namepartgiven|\namepartprefix|\namepartsuffix
\newcommand{\NameToDelete}{Bertram|Aaron||}
\begin{document}
\cite{bertram,aksin}
\printbibliography
\end{document}
我希望 Bertram 引用不是获得标准输出,而是
Richard Wentworth [姓名已删除]。“黎曼曲面上全纯映射的 Gromov 不变量”。收录于:J. Amer. Math. Soc. 9.2 (1996),第 529-571 页。
也许最好用 来做这个\DeclareStyleSourcemap
,但是从 biblatex 文档来看,也许用 来做这个更好\DeclareNameInputHandler
(尽管这方面的文档很薄弱)。
答案1
似乎至少有 4 种方法可以解决这个问题。
最简单但功能最少的方法是直接编辑 bib 文件。这种方法的缺点是,如果你想做不同的事情,你必须再次编辑文件。这是你可以进行更改的最早时间
这biblatex publist包具有此功能。它会在最晚的时间(排版之前)处理名称。代码相对较长且复杂,并且对名称的输出格式进行硬编码,仅支持给定家族和给定家族格式。代码可能可以扩展以处理所有名称格式。
使用源映射来更改名称,因为它正在被 bib 文件读取到 bbl 文件中:
--
\DeclareStyleSourcemap{
\maps[datatype = bibtex]{
% Single author
\map{
\step[fieldsource = author, notmatch = \regexp{\s and\s}, final]
\step[fieldsource = author, match = \NameToDelete, final]
\step[fieldset = author, null]
\step[fieldset = usera, fieldvalue = {The Author Was Deleted}]
}
% First author
\map{
\step[fieldsource = author, match = \regexp{\s and\s}, final]
\step[fieldsource = author, match = {\NameToDelete\ and }, final]
\step[fieldsource = author, match = {\NameToDelete\ and }, replace = {and }]
\step[fieldsource = author, match = \regexp{^\s*and\s+(.+)}, replace = \regexp{$1}]
\step[fieldset = usera, fieldvalue = {The Author Was Deleted}]
}
% Middle author
\map{
\step[fieldsource = author, match = \regexp{\s and\s}, final]
\step[fieldsource = author, match = { and \NameToDelete\ and}, final]
\step[fieldsource = author, match = { and \NameToDelete\ and}, replace = { and and }]
\step[fieldsource = author, match = \regexp{(.+)\s+ and\s and\s+(.+)}, replace = \regexp{$1 \x20 and\x20 $2}]
\step[fieldset = usera, fieldvalue = {The Author Was Deleted}]
}
% Last author
\map{
\step[fieldsource = author, match = \regexp{\s and\s}, final]
\step[fieldsource = author, match = { and \NameToDelete}, final]
\step[fieldsource = author, match = { and \NameToDelete}, replace = { and}]
\step[fieldsource = author, match = \regexp{(.+)\s+ and$}, replace = \regexp{$1}]
\step[fieldset = usera, fieldvalue = {The Author Was Deleted}]
}
}
}
由于 biber 允许以 Doe、John 或 John Doe 的形式输入姓名,因此需要扩展示例以处理所有可能的情况。 正则表达式 foo 比我更好的人可能会让这个更简洁。 它还对 bib 文件中的空格数和定义敏感\NameToDelete
- 使用 将名称从 bbl 文件读入 LaTeX 进行处理
\DeclareNameInputHandler
。此时,名称已由 biber 处理,因此虚假空格已处理完毕,并且 bib 文件中名称部分的顺序无关紧要。为了使匹配更容易,可以简单地匹配 biber 创建的名称哈希。
--
\documentclass{article}
\usepackage{biblatex}
\newcommand{\HashToDelete}{8a5b475249c01d8aa99f2275128c1037}
\usepackage{xparse,expl3}
\newcounter{myAuthor}
\newtoggle{myNameDeleted}
\ExplSyntaxOn
\NewDocumentCommand{\DeleteName}{mm}{% Hash, Authors
\tl_set:Nn\l_tmpa_tl{#2}%
\str_if_in:nnTF{#2}{hash=#1}{%
\setcounter{myAuthor}{\numexpr\NewCount-1\relax}%
\edef\NewCount{\themyAuthor}%
\regex_replace_all:nnN{\cB\{\cB\{hash=#1.*?\cE\}\cE\}\cE\}}{}\l_tmpa_tl%
\edef\NewValue{\l_tmpa_tl}%
\global\toggletrue{myNameDeleted}
}{}
}
\ExplSyntaxOff
\DeclareNameInputHandler{author}{%
\global\togglefalse{myNameDeleted}
\expandafter\expandafter\expandafter\DeleteName%
\expandafter\expandafter\expandafter{%
\expandafter\HashToDelete\expandafter%
}\expandafter{%
\NewValue%
}%
}
\renewbibmacro*{author}{%
\ifboolexpr{
test \ifuseauthor
and
not test {\ifnameundef{author}}
}
{\printnames{author}%
\iffieldundef{authortype}
{}
{\setunit{\printdelim{authortypedelim}}%
\usebibmacro{authorstrg}}}
{}%
\newunit%
\iftoggle{myNameDeleted}{%
\printtext[brackets]{The Author Was Deleted}%
}{}%
}
\bibliography{biblatex-examples.bib}
\begin{document}
\cite{bertram,aksin}
\printbibliography
\end{document}
这个解决方案的问题是它不允许更改其他字段。\toggletrue
在打印参考书目时,该部分将被覆盖。