2

This is a follow-up question to How to verify if entry `country = {}` is empty in a custom BibLaTeX library?

I have a custom BibLaTeX library with the BiBLaTeX entry Contribution, which I use to manage all my oral and poster contributions on conferences, workshops etc. Thanks to the help I got on the site mentioned above, I have a nice working system.

However, there are some cosmetic issues: I have an entry called period which includes the time period of, e.g., a conference. It shall appear behind the event title in brackets (see example below). In a .dbx file, I declare the entry field period as a date datatype, and I can therefore call the command \printperiod. So far, so good.

In some BibLaTeX entries, this field period is empty, so period = {}.

How can I find out via an 'if', 'then' 'else' condition, if \printperiod is printing text, so as to say if period = {}?

I tried out \iffieldundef{period}, \ifciteindex and other things but I don't get it working.

So far, here is first the 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}

The output of the MWE

As one can see, the second citation has a () behind the event title, because the field 'period' is empty, period = {}. In this case, the two brackets should not appear but instead a comma and space.

Thanks for some help.

PS: Small additional question: How can I change, e.g., May 31 to May 31$^{\rm st}$?

5
  • Your datamodel doesn't work for me in bibilatex 3.7/Biber 2.7. date-like fields must end in date, so you can' have period, it must be called perioddate.
    – moewe
    Commented Jan 25, 2017 at 7:55
  • Note that there is already the field eventdate for conference proceedings that you could probably reuse. There is also the field venue which you could use instead of maybe place.
    – moewe
    Commented Jan 25, 2017 at 8:20
  • Note that most of your \iffieldindefs are not necessary if you use \DeclareFieldFormat and \newunit/\setunit properly. Have a look at my alternative answer to your other question, maybe that can give you an idea of how to approach this in a more biblatex-y way. Read §4.11.7 Using the Punctuation Tracker of the biblatex documentation
    – moewe
    Commented Jan 25, 2017 at 12:03
  • Thanks a lot, moewe! It is a good idea to use 'eventdate' and 'venue', I've completely overseen. Then, I will do what you propose below, and I will also consider this '\newunit' and '\setunit' stuff. I will let you know, probably this evening. - BTW: I use biber version 2.5 on Ubuntu 14.04, upgraded by a PPA (ppa:jonathonf/texlive-2016)
    – Krumpel
    Commented Jan 25, 2017 at 12:13
  • Ah, Biber 2.5 is a bit outdated now with 2.7 being out. On older Linux systems it can be a good idea to install vanilla TeX live (tex.stackexchange.com/q/1092/35864). But note that some of the code you have in your MWE will probably have to be adapted as mentioned in my comment above (if you decide to use eventdate though, you might be able to get away with few changes).
    – moewe
    Commented Jan 25, 2017 at 14:12

1 Answer 1

2

There is a combination of two issues here.

No. 1 is that you should not write bare formatting into bibmacros or cite commands, you should use \DeclareFieldFormat and friends.

So write

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

and then later

\printperioddate

and the period date will be wrapped in parentheses. With this method you do not have to check if the field is empty. If it is empty you get nothing, if it contains something you get that back in the correct format. If you really must check if a date is defined, the standard method is to check for its year part

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

biblatex will only ever print a date if it has a year and if the date has a year, biblatex prints at least that.

All of this does not work with biblatex 3.7/Biber 2.8 however, if you input empty fields 'explicitly' as

perioddate = {}

In that case you will get back periodyear = {} which confuses everybody, because as far as biblatex concerns that counts as a defined year.

This is a known bug that will be resolved with Biber 2.8, see https://github.com/plk/biblatex/issues/528.

In the meantime all you can do is drop the strange habit of writing perioddate = {} for empty fields instead of leaving them out of the entry altogether. If you for some reason don't want to do that, let Biber do it for you with

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .