How to verify if entry `country = {}` is empty in a custom BibLaTeX library?
You should check whether the field exists as part of the \DeclareCiteCommand
using \iffieldundef
(or something similar; see section 4.6.2 Stand-alone Tests in the biblatex
documentation):
\DeclareCiteCommand{\citecountry}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\iffieldundef{country}{}{(\printtext{\printfield{country}})}}
{\multicitedelim}
{\usebibmacro{postnote}}
and here is \printcontrib
:
\newcommand{\printcontrib}[1]{%
\citeauthor*{#1},
\citetitle*{#1},
\citeevent{#1},
\citecity{#1}
\citecountry{#1},
\citedate{#1} (\citeyear{#1})
}
You may also write a larger \DeclareCiteCommand
rather using \printcontrib
.
In biblatex
, field formatting such as brackets or emphasis or italics should not be written into the macro directly in most cases, they should be achieved with \DeclareFieldFormat
. That way you make sure that biblatex
can properly detect empty fields and do nothing in that case.
You could just do
\DeclareFieldFormat{country}{\mkbibparens{#1}}
\DeclareCiteCommand{\citecountry}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\printfield{country}}
{\multicitedelim}
{\usebibmacro{postnote}}
The field is then wrapped in brackets whenever it is shown and ignored otherwise. Note that there is no need to wrap a single \printfield
into a \printtext
without argument, \printfield{country}
will do the same as \printtext{\printfield{country}}
.
Instead of defining \citecontrib
as you do now, you should probably just define a bibliography driver for @contribution
like so (this is just a first rough shot at this, but you get the idea)
\DeclareFieldFormat{country}{\mkbibparens{#1}}
\DeclareFieldFormat[contribution]{title}{\mkbibemph{#1}}
\newbibmacro*{event+venue+city+country+date}{%
\printfield{eventtitle}%
\newunit
\printfield{eventtitleaddon}%
\newunit
\printeventdate
\newunit
\printfield{city}
\setunit{\addspace}%
\printfield{country}
\newunit}
\DeclareBibliographyDriver{contribution}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\printdelim{nametitledelim}}\newblock
\usebibmacro{title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{event+venue+city+country+date}%
\newunit\newblock
\printfield{howpublished}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{location+date}\printdate%
\newunit\newblock
\iftoggle{bbx:url}
{\usebibmacro{url+urldate}}
{}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}}
Then you can just use \fullcite
and you are done.