如何测试 \printdate 之类的命令是否不打印“空”文本?

如何测试 \printdate 之类的命令是否不打印“空”文本?

这是如何验证自定义 BibLaTeX 库中的条目“country = {}”是否为空?

我有一个带有 BiBLaTeX 条目的自定义 BibLaTeX 库Contribution,我用它来管理我在会议、研讨会等上的所有口头和海报贡献。感谢我在上述网站上获得的帮助,我有一个很好的工作系统。

但是,有一些外观问题:我有一个名为的条目period,其中包括会议的时间段。它应出现在事件标题后面的括号中(见下面的示例)。在一个.dbx文件中,我将条目字段声明period为日期数据类型,因此我可以调用命令\printperiod。到目前为止一切顺利。

在一些 BibLaTeX 条目中,该字段period为空,因此period = {}

我如何通过“if”、“then”、“else”条件找出是否\printperiod正在打印文本,以便说明是否period = {}

我尝试过\iffieldundef{period}\ifciteindex其他方法,但没有成功。

到目前为止,这里首先是 MWE:

\begin{filecontents}{contribution.dbx}
\DeclareDatamodelEntrytypes{contribution}
\DeclareDatamodelFields[type=field,datatype=literal]{
  type,
  invited,
  title,
  event,
  eventshort,
  eventtype,
  league,
  url,
  place,
  city,
  country,
  year,
  note,
  timestamp
}
\DeclareDatamodelFields[type=field, datatype=datepart]{
  year,
  month,
  day,
  periodyear,
  periodmonth,
  periodday
}
\DeclareDatamodelFields[type=field, datatype=date, skipout]{
  date,
  period,
}
\DeclareDatamodelFields[type=list,datatype=name]{
  author,
  presenter,
}
\DeclareDatamodelEntryfields[contribution]{
  type,
  invited,
  author,
  presenter,
  title,
  event,
  eventshort,
  eventtype,
  league,
  url,
  place,
  city,
  country,
  date,
  period,
  year,
  note,
  timestamp}
\end{filecontents}


\begin{filecontents}{\jobname.bib}
@Contribution{Oral_2016_1,
  Type      = {Oral},
  Invited   = {invited},
  Author    = {Author1, A. and Author2, B. and Author3, C. and Author4, D.},
  Presenter = {Author2, B.},
  Title     = {{Cool stuff about the nano-world}},
  Event     = {{22$^{\rm nd}$ International Conference on Nanotechnology}},
  Eventshort= {{NANO-7}},
  Eventtype = {Conference},
  League    = {International},
  URL       = {},
  Place     = {Alto University},
  City      = {Helsinki},
  Country   = {Finland},
  Date      = {2016-05-31},
  Period    = {2016-05-22/2016-06-02},
  Year      = {2016},
  Note      = {},
  Timestamp = {}
}
@Contribution{Oral_2016_2,
  Type      = {Oral},
  Invited   = {},
  Author    = {Author1, A. and Author2, B. and Author3, C. and Author4, D.},
  Presenter = {Author1, B.},
  Title     = {{Cool stuff about the nano-world}},
  Event     = {{22$^{\rm nd}$ International Workshop on NanoPhenomena}},
  Eventshort= {{IWNP-8}},
  Eventtype = {Workshop},
  League    = {International},
  URL       = {},
  Place     = {University of Nano},
  City      = {Tokyo},
  Country   = {Japan},
  Date      = {2016-03-04},
  Period    = {},
  Year      = {2016},
  Note      = {},
  Timestamp = {}
}
\end{filecontents}


\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[datamodel=contribution,
            style=chem-acs,
            dateabbrev=false,
            natbib=true,
            backend=biber]
           {biblatex}
\addbibresource{\jobname.bib}



% My own command, which puts into format and prints the complete contribution.
\DeclareCiteCommand{\citeallstuff}
  {\defcounter{maxnames}{99}%
   \defcounter{minnames}{99}%
   \defcounter{uniquename}{2}%
   \boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {%
   \ifciteindex{\indexnames*{labelname}}{}\printnames{labelname}, %
   \iffieldundef{title}{}{\textit{\printtext{\printfield{title}}}\space}%
   \iffieldundef{event}{}{\printtext{\printfield{event}}}%
   \space(\printperiod)\addcomma\space% <============ What must I do there? 
   \iffieldundef{city}{}{\printtext{\printfield{city}}}%
   \iffieldundef{country}{\addcomma\space}{ \printtext{(\printfield{country}})\addcomma\space}%
   \printdate% <============ The same here? 
   \iffieldundef{note}{}{\addcomma\space\printtext{\printfield{note}}}%
   \iffieldundef{invited}{}{\addcomma\space{\textbf{\printtext{\printfield{invited}}}}}
   }   
  {\multicitedelim}
  {\usebibmacro{postnote}}




\begin{document}

\noindent\citeallstuff{Oral_2016_1}\\\\\\
\citeallstuff{Oral_2016_2}

\printbibliography
\end{document}

MWE 的输出

可以看到,第二条引文在事件标题后面有一个 (),因为“句号”字段为空,period = {}在这种情况下,不应该出现两个括号,而应该出现逗号和空格。

谢谢您的帮助。

PS:另外还有一个小问题:我怎样才能改变,May 31例如May 31$^{\rm st}$

答案1

这里有两个问题的结合。

第一,您不应该将裸格式写入 bibmacros 或 cite 命令,而应该使用\DeclareFieldFormat和朋友。

所以写

\DeclareFieldFormat{perioddate}{\mkbibparens{#1}}

然后后来

\printperioddate

期间日期将被括在括号中。使用此方法,您不必检查字段是否为空。如果为空,您将什么也得不到,如果包含内容,您将以正确的格式返回。如果您确实必须检查日期是否已定义,标准方法是检查其年份部分

\iffieldundef{periodyear}
  {<no date>}
  {<date>}

biblatex仅当日期有年份时才会打印日期,如果日期有年份,则biblatex至少打印年份。

所有这些都不适用于biblatex3.7/Biber 2.8,但是如果你输入空字段“明确”为

perioddate = {}

在这种情况下,你将会得到让periodyear = {}每个人都感到困惑的结果,因为就其biblatex本身而言,这算作一个确定的年份。

这是一个已知错误,将在 Biber 2.8 中解决,请参阅https://github.com/plk/biblatex/issues/528

与此同时,您所能做的就是放弃perioddate = {}在空白字段中书写的奇怪习惯,而不是将它们完全排除在条目之外。如果您出于某种原因不想这样做,请让 Biber 为您完成

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=perioddate, match=\regexp{^$}, final]
      \step[fieldset=perioddate, null]
      }
    }
}

相关内容