3

Question:

I am using \iffieldequals{pubstate}{str} to test the pubstate of two different .bib entries. But even pubstate={foo}, it still behaves as if pubstate={str}. This is in response to the answer to the question:

Biblatex replace title with alternate field

M(N)WE:

\documentclass{article}

\usepackage{filecontents}

\usepackage[backend=biber,firstinits=true]{biblatex}
\newbibmacro{ur}{under review}
\newbibmacro{ta}{to appear}

\renewbibmacro{in:}{%
  \ifentrytype{article}
    {\iffieldequals{pubstate}{ur}{\printtext{Under review at\intitlepunct}}{}\clearfield{pubstate}}
    % {\iffieldequals{pubstate}{ur}{\printtext{Under review at\intitlepunct}}{\iffieldequals{pubstate}{ta}{\printtext{To appear in\intitlepunct}}{}}\clearfield{pubstate}}
    {\printtext{\bibstring{in}\intitlepunct}}%
}

\begin{filecontents}{./pubs.bib}
@article{key1,
  author = {Name AA and Name BB},
  title = {Article title name one},
  Year = {2016},
  journal = {Journal Name One},
  pubstate = {under review},
  }

@article{key2,
  author = {Name CC and Name DD},
  title = {Article title name two},
  Year = {2016},
  journal = {Journal Name Two},
  pubstate = {to appear},
  }
\end{filecontents}
\bibliography{./pubs.bib}
\begin{document}

\fullcite{key1}

\fullcite{key2}
\end{document}

Output:

incorrect_image The output should not have "Under review" for key2 because it has pubstate={to appear}.

Thank you for your help.

4

Short answer: Use

\iffieldequalstr{pubstate}{under review}

or

\newcommand*\ur{under review}
\iffieldequals{pubstate}{\ur}

or

\newcommand*\ur{under review}
\iffieldequalcs{pubstate}{ur}

Where the first option is the preferred here I think.


Accoring to the documentation (p. 182)

\iffieldequals{<field>}{<macro>}{<true>}{<false>} Expands to true if the value of the <field> is equal to the definition of macro, and to false otherwise.

The value of the field in your case is under review.

If you issue \iffieldequals{pubstate}{ur} ur isn't even a macro and it evaluates to false (indeed I even got an error in one case).

What you need is a macro that expands to exactly under review, the easiest way is \def{\ur}{under review}, but \newcommand*\ur{under review} also works; on the other hand \newcommand\ur{under review} doesn't work because it defines a long macro. In that case you use

\iffieldequals{pubstate}{\ur}

What's more

\newbibmacro{ur}{under review}

does not actually define a macro called \ur, but a long macro called \abx@macro@ur. \newbibmacro*{ur}{under review} defines a "normal" macro called \abx@macro@ur

Alternatively, you can use \iffieldequalcs where you don't give a macro, but a control sequence name (the macro without the backslash)

\iffieldequals{pubstate}{ur}

This has the advantage of not creating the overhead of additional macros. And it makes the condition slightly easier to understand and read in the code. The best solution here seems to be to use \iffieldequalstr to check if the field is equal to the string given in the second argument

\iffieldequalstr{pubstate}{under review}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.