将编辑器和发布者设置为无,并将这些字段重新声明为未定义

将编辑器和发布者设置为无,并将这些字段重新声明为未定义

我要求检查大型书目中的系列和编号,并得到了这个问题的答案https://tex.stackexchange.com/a/582962/18561。我想将其扩展到发布者和编辑者字段,但它们的类型不同,我无法按照评论中的提示进行设置。名称字段和列表字段似乎不同。那么:如何做到这一点?

\documentclass{article}

\begin{filecontents}{seriescheck.dbx}
\DeclareDatamodelFields[type=field, datatype=literal, skipout]{optseries}

\DeclareDatamodelEntryfields[
  book,mvbook,inbook,
  collection,mvcollection,incollection
]{optseries}
\DeclareDatamodelConstraints[
  book,mvbook,inbook,
  collection,mvcollection,incollection]
{
  \constraint[type=mandatory]{
    \constraintfield{series}
  }
  \constraint[type=conditional]{
    \antecedent[quantifier=all]{
      \constraintfield{series}
    }
    \consequent[quantifier=all]{
      \constraintfield{number}
    }
  }
}
\end{filecontents}

\usepackage[
  backend=biber,
  datamodel=seriescheck,
]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
       \step[fieldsource=series, match=\regexp{\Anone\Z}, final]
       \step[fieldset=number, fieldvalue=none]
    }
  }
}

\DeclareFieldInputHandler{series}{%
  \ifdefstring{\NewValue}{none}
    {\def\NewValue{}}
    {}}

\DeclareFieldInputHandler{number}{%
  \ifdefstring{\NewValue}{none}
    {\def\NewValue{}}
    {}}

\begin{filecontents}{\jobname.bib}
@book{nussbaum,
  author       = {Nussbaum, Martha},
  title        = {Aristotle's \mkbibquote{De Motu Animalium}},
  date         = 1978,
  publisher    = {Princeton University Press},
  location     = {Princeton},
  series       = {none},
}
@book{worman,
  author       = {Worman, Nancy},
  title        = {The Cast of Character},
  date         = 2002,
  publisher    = {University of Texas Press},
  location     = {Austin},
}
@collection{omeara,
  editor       = {O'Meara, Dominic J.},
  title        = {Studies in {Aristotle}},
  date         = 1981,
  series       = {Studies in Philosophy and the History of Philosophy},
  number       = 9,
  publisher    = {The Catholic University of America Press},
  location     = {Washington, D.C.},
  pages        = {161-191},
}
@book{aristotle:poetics,
  author       = {Aristotle},
  title        = {Poetics},
  date         = 1968,
  editor       = {none},
  series       = {Clarendon {Aristotle}},
  publisher    = {none},
  location     = {Oxford},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\printbibliography
\end{document}

答案1

从实现角度来看,列表和名称字段要复杂得多。

通常你看不到这一点,你唯一需要担心的是使用适当的命令来处理列表和名称字段而不是字段。在这里你需要的是\DeclareListInputHandler\DeclareNameInputHandler而不是\DeclareFieldInputHandler

但这还不够,因为列表和名称字段的内部结构比字段的内部结构更复杂。对于字段,其内容直接保存在宏中,但列表和名称字段的结构更复杂。因此,虽然none输入的结果为字段,但列表none的内部表示为,而名称的内部表示为(如果 Unicode 算法更新,哈希值可能会发生变化,您可以从文件中获取正确的哈希值)。因此,您需要针对略有不同的值进行测试。none{none}{{hash=334c4a4c42fdb79d7ebc3e73b517e6f8}{family={none}, familyi={n\bibinitperiod}}}.bbl\NewValue

\documentclass{article}

\begin{filecontents}{seriescheck.dbx}
\DeclareDatamodelFields[type=field, datatype=literal, skipout]{optseries}

\DeclareDatamodelEntryfields[
  book,mvbook,inbook,
  collection,mvcollection,incollection
]{optseries}
\DeclareDatamodelConstraints[
  book,mvbook,inbook,
  collection,mvcollection,incollection]
{
  \constraint[type=mandatory]{
    \constraintfield{series}
    \constraintfield{publisher}
    \constraintfield{editor}
  }
  \constraint[type=conditional]{
    \antecedent[quantifier=all]{
      \constraintfield{series}
    }
    \consequent[quantifier=all]{
      \constraintfield{number}
    }
  }
}
\end{filecontents}

\usepackage[
  backend=biber,
  datamodel=seriescheck,
]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
       \step[fieldsource=series, match=\regexp{\Anone\Z}, final]
       \step[fieldset=number, fieldvalue=none]
    }
  }
}

\DeclareFieldInputHandler{series}{%
  \ifdefstring{\NewValue}{none}
    {\def\NewValue{}}
    {}}

\DeclareFieldInputHandler{number}{%
  \ifdefstring{\NewValue}{none}
    {\def\NewValue{}}
    {}}

\DeclareNameInputHandler{editor}{%
  \ifdefstring
    {\NewValue}
    {{{hash=334c4a4c42fdb79d7ebc3e73b517e6f8}{family={none}, familyi={n\bibinitperiod}}}}
    {\def\NewValue{}}
    {}}

\DeclareListInputHandler{publisher}{%
  \ifdefstring{\NewValue}{{none}}
    {\def\NewValue{}}
    {}}

\begin{filecontents}{\jobname.bib}
@book{nussbaum,
  author       = {Nussbaum, Martha},
  title        = {Aristotle's \mkbibquote{De Motu Animalium}},
  date         = 1978,
  publisher    = {Princeton University Press},
  location     = {Princeton},
  series       = {none},
}
@book{worman,
  author       = {Worman, Nancy},
  title        = {The Cast of Character},
  date         = 2002,
  publisher    = {University of Texas Press},
  location     = {Austin},
}
@collection{omeara,
  editor       = {O'Meara, Dominic J.},
  title        = {Studies in {Aristotle}},
  date         = 1981,
  series       = {Studies in Philosophy and the History of Philosophy},
  number       = 9,
  publisher    = {The Catholic University of America Press},
  location     = {Washington, D.C.},
  pages        = {161-191},
}
@book{aristotle:poetics,
  author       = {Aristotle},
  title        = {Poetics},
  date         = 1968,
  editor       = {none},
  series       = {Clarendon {Aristotle}},
  publisher    = {none},
  location     = {Oxford},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\printbibliography
\end{document}

输出中没有“无”值的参考书目。

相关内容