0

I'm using \citeall with a custom entry formatter to list all the entries in my bib file, but I'd like to conditionally format entries from a specific journal. To do this, I've tried using \ifthenelse to string compare against the result of \citefield{key}{journaltitle}, but it's not working. Snippet:

\newcommand{\completecite}[1]{%
    \ifstrequal{\citefield{#1}{journaltitle}}{CoRR}{TRUE}{FALSE}
}
\citeall[\completecite]

spits out "FALSE" for every entry, even though

\newcommand{\completecite}[1]{%
    \citefield{#1}{journaltitle}
}
\citeall[\completecite]

has many outputs that are "CoRR". I figure the problem is that the string \citefield{#1}{journaltitle} is being compared against "CoRR", when what I want is to compare against the result of calling the \citefield macro.

I've tried \expandafter and various other more elaborate string compare examples, but nothing has worked yet. I've tinkered with the xstring, xifthen and pdftexcmds packages too. Heck, even using etoolbox's \ifdefstring as

\newcommand{\completecite}[1]{%
    \ifdefstring{\citefield{#1}{journaltitle}}{CoRR}{TRUE}{FALSE}
}
\citeall[\completecite]

didn't work.

2 Answers 2

1

You're running into a problem similar to what came up with this question: Why does \ifx consider \MakeUppercase{1} and \MakeLowercase{1} different?

\citefield is a command to print the field contents, and not a function that returns the text (TeX's language is based on macro expansion so there really aren't functions per se, which is a whole other issue).

Someone more familiar with BibLaTeX internals might be able to find a way to extract the journal title in a way that makes sense (and I'm guessing that there's possibly something pre-rolled that does what you want if you're able to be more explicit about what your end goal is).

1

This is similar to the issue discussed in Apply a string replacement on the citation as returned by \cite.

As Don Hosek explained in his answer, biblatex's \...cite... commands are meant for typesetting, they do not expand to (or return) the typesettable text itself. That means that with normal TeX tools you can neither compare nor replace bits of the ouptut produced by \...cite... commands with simple text.

It is possible to compare field contents in biblatex, but that has to happen at a different level, while you are in a 'biblatex context'. Usually that is not a problem, since if you want to influence the output of citations or the bibliography, you have to work in that context anyway.

Here is a very simple example using \iffieldequalstr. We use \AtEveryBibitem to hook into the biblatex context: Normally you'd use a test like this in the bibmacro you modify.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\AtEveryBibitem{%
  \iffieldequalstr{journaltitle}{CoRR}
    {T}
    {F}}

\begin{filecontents}{\jobname.bib}
@article{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  journal = {CoRR},
  date    = {1980},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}


\begin{document}
\cite{sigfridsson,appleby}
\printbibliography
\end{document}

TAppleby, Humphrey (1980). ‘On the Importance of the Civil Service’. In: CoRR.//FSigfridsson, Emma and Ulf Ryde (1998). ‘Comparison of methods for deriving atomic charges from the electrostatic potential and moments’. In: Journal of Computational Chemistry 19.4, pp. 377–395. doi: 10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P.


There may be other ways to detect certain classes of entries better than by string comparison on certain fields (which is always a bit tricky). It is common to to define a new option or set a keyword explicitly in case the property you are looking for is not easily established from the data already present.


If you refer to the arXiv CoRR (https://arxiv.org/corr), then I'd argue that like the arXiv itself, CoRR isn't really a journal. For entries like that I'd use @online (cf. Format of @article without journal title field in biblatex bibliography entries).

You must log in to answer this question.

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