如何測試 \printdate 之類的命令是否不列印「空」文字?

如何測試 \printdate 之類的命令是否不列印「空」文字?

這是一個後續問題如何驗證自訂 BibLaTeX 庫中的條目“country = {}”是否為空?

我有一個帶有 BiBLaTeX 條目的自訂 BibLaTeX 庫Contribution,我用它來管理我在會議、研討會等上的所有口頭和海報貢獻。系統。

然而,存在一些外觀問題:我有一個名為的條目period,其中包括例如會議的時間段。它應出現在事件標題後面的括號中(請參閱下面的範例)。在.dbx文件中,我將輸入欄位聲明period為日期資料類型,因此我可以呼叫命令\printperiod.到目前為止,一切都很好。

在某些 BibLaTeX 條目中,該欄period位為空,因此period = {}.

我如何透過「if」、「then」、「else」條件找出 if\printperiod正在列印文本,從而說出 if 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 31May 31$^{\rm st}$

答案1

這裡有兩個問題的組合。

第一是你不應該將裸格式寫入 bibmacros 或 cite 指令,你應該使用\DeclareFieldFormat和 朋友。

所以寫

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

然後後來

\printperioddate

期間日期將包含在括號中。使用此方法,您不必檢查該欄位是否為空。如果它是空的,你什麼也得不到,如果它包含一些東西,你就會以正確的格式得到它。如果您確實必須檢查日期是否已定義,標準方法是檢查其年份部分

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

biblatex僅當日期有年份時才會列印日期,如果日期有年份,則biblatex至少列印該日期。

biblatex但是,如果您「明確」輸入空字段,則所有這些都不適用於3.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]
      }
    }
}

相關內容