0

I would like to compare the value of a \printfield command in \ifthenelse

It seems printfield does not return the value so ifthenelse can't check it.

How can I access the value in a way that ifthenelse can use?

What I want to achieve is to check wether the value is greater than 9 (two-digit) and prepend a 0 if it is not.

Edit - MWE:

%Short literatur.bib 
\begin{filecontents}{literatur.bib}
@Online{TEST2022,
  author   = {{Author}},
  title    = {Title},
  url      = {https://google.com},
  urldate  = {2022-06-02},
  date     = {2022},
  keywords = {test},
}
\end{filecontents}

\documentclass{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[backend=biber, labeldateparts=true, style=authortitle, isbn=false, dashed=false, maxnames=3, datezeroes=true]{biblatex}

\DeclareCiteCommand{\onlinezitat}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}
   \setunit{\addnbspace}
   online:
   \bibhyperref{\printnames[author]{labelname}}
   \setunit{\labelnamepunct}
   \newunit
   \printfield{labelyear}\printfield{extradate}
   \printtext{(}\printfield{urlday}\printtext{.}\printfield{urlmonth}\printtext{.}\printfield{urlyear}\printtext{)}}
  {\addsemicolon\space}
  {\usebibmacro{postnote}}
\renewcommand{\bibfootnotewrapper}[1]{\bibsentence#1}

\addbibresource{literatur.bib}

\begin{document}
Hallo\onlinezitat{TEST2022}.
\end{document}
1
  • 1
    \printfield prints, and printing instructions can normally not be viewed as value. You should better make a complete example that shows what you are after. Jun 28, 2022 at 9:43

1 Answer 1

0

As Ulrike Fischer points out in the comments, \printfield and friends are supposed to print the field contents and are not at all guaranteed to just expand to the value of the relevant field. That means that \printfield inside an \ifthenelse check is almost guaranteed to fail.

biblatex has an interface to retrieve field contents expandably (it does not offer such a feature for lists and name lists, since there is no natural single "value" associated to these lists, plus the internal representation of these lists is not very handy) with \thefield, e.g.

\thefield{entrykey}

\thefield can be extremely useful, but it almost always the wrong tool for the job if you want to format printed output. That is done much more naturally via \DeclareFieldFormat and friends.

In your example use case I would go for something else entirely, since dates should be printed with \print...date and not manually with \printfield{...year} etc.

\documentclass{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[
  backend=biber,
  labeldateparts=true,
  style=authortitle,
  isbn=false,
  dashed=false,
  maxnames=3,
  datezeros=true,
]{biblatex}

\NewBibliographyString{online}
\DefineBibliographyStrings{german}{
  online = {online},
}

\DeclareCiteCommand{\onlinezitat}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\DeclareFieldFormat{urldate}{\mkbibparens{####1}}%
   \usebibmacro{citeindex}%
   \bibstring{online}%
   \setunit{\addcolon\space}%
   \printnames{labelname}%
   \setunit{\printdelim{nameyeardelim}}%
   \printdateextra
   \setunit{\addspace}%
   \printurldate}
  {\addsemicolon\space}
  {\usebibmacro{postnote}}
\renewcommand{\bibfootnotewrapper}[1]{\bibsentence#1}

\begin{filecontents}{\jobname.bib}
@Online{TEST2022,
  author   = {{Author}},
  title    = {Title},
  url      = {https://google.com},
  urldate  = {2022-06-02},
  date     = {2022},
  keywords = {test},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
Hallo\onlinezitat{TEST2022}.
\end{document}

Online: Author 2022 (02.06.2022)

You must log in to answer this question.

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