如何通过 biber sourcemapping 包装“作者”字段?

如何通过 biber sourcemapping 包装“作者”字段?

以下是 mwe:

% !TEX encoding = UTF-8 Unicode
% !TEX program = lualatex
% !BIB program = biber

\begin{filecontents}[overwrite]{\jobname.bib}
@customa{a,
  type = {type1},
  author = {Familyname, Givenname},
  title = {Title},
  date = {2000},
}
@customa{b,
  type = {type2},
  author = {Institution A},
  title = {Title},
  date = {3000},
}
@customa{c,
  type = {type3},
  author = {Institution B},
  title = {Title},
  date = {1000},
}
\end{filecontents}

\documentclass{article}
\usepackage[style=authortitle]{biblatex}
  \addbibresource{\jobname.bib}

\DeclareBibliographyDriver{customa}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \printnames{author}%
  \newunit\newblock
  \usebibmacro{title}%
  \newunit\newblock
  \printdate%
  \usebibmacro{finentry}}

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

author字段包含个人姓名(包括姓和名)和机构。出于各种原因,我更喜欢使用同一字段,而不是单独的字段(如authorinstitution)。

因此,在某些条件下,author字段必须用一对额外的花括号括起来,以防止数据解析将它们视为要分解成各个组成部分的个人名称(参见 biblatex 指南的§2.3.3)。

由于该字段的值type决定了作者的“类型”(个人姓名或机构名称),因此有关源映射的“伪条件”如下:

IF 
  entrytype = customa;
  field "type" is defined and its value <> "type1";
THEN
  wrap the field "author" in an extra pair of curly braces;
ELSE
  nothing

\step那么,要设置的是什么\DeclareSourcemap

答案1

我真的不认为这是一个好主意,因为它会导致.bib文件中的标记非常不一致。“公司作者”(在书目条目的“作者”字段中使用“公司作者”(完整拼写出姓名)) 应始终在名称字段中使用一对额外的花括号进行保护。要么对所有条目类型正确且一致地使用花括号,要么如果author不符合语义,则选择其他字段。

也就是说,这里有一个源映射,它使用 RegExp 替换为字段不等于的条目的字段author添加一对额外的花括号。@customatypetype1

\documentclass{article}
\usepackage[style=authortitle]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{customa}
      \step[fieldsource=type, final]
      \step[fieldsource=type, notmatch=\regexp{\Atype1\Z}, final]
      \step[fieldsource=author,
            match=\regexp{\A(.*)\Z},
            replace=\regexp{\{$1\}}]
    }
  }
}

\DeclareBibliographyDriver{customa}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \printnames{author}%
  \newunit\newblock
  \usebibmacro{title}%
  \newunit\newblock
  \printdate%
  \usebibmacro{finentry}}


\begin{filecontents}{\jobname.bib}
@customa{a,
  type   = {type1},
  author = {Givenname Familyname},
  title  = {Title},
  date   = {2000},
}
@customa{b,
  type   = {type2},
  author = {Institution A},
  title  = {Title},
  date   = {3000},
}
@customa{c,
  type   = {type3},
  author = {Institution B},
  title  = {Title},
  date   = {1000},
}
@customa{d,
  author = {Grivenname Flamilyname},
  title  = {Title},
  date   = {4000},
}
\end{filecontents}
\addbibresource{\jobname.bib}

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

姓氏,名字。头衔。2000。火姓,格里文姓。头衔。4000。机构 A。头衔。3000。机构 B。头衔。1000。

相关内容