# Biblatex: Idiom for testing contents of list field

I am creating a Biblatex bibliography style for legal citations. In one particular case, I need to format the citation (of a court decision, i.e. jurisdiction) differently depending on the particular institution that produced the decision. Specifically if the institution is commission I need to suppress printing of the number field, but otherwise I need to print it.

I have become familiar with the way of testing such things in other cases using \iffieldequals; but I can't get that to work in this case -- presumably because the institution field is a literal list, and I therefore need to use appropriate tests for a list (although, in practice, the institution field which I want to test will consist of a list with one item only: the entry commission).

I've tried a number of approaches: attempting to create a list of my own which consists simply of commission and testing for that with \iflistequals, attempting to use various of the list testing functions from etoolbox, and even edefing temporary macros to compare using \ifx. So far, no joy -- and I think I am at or beyond the outer limits of my rather modest understanding of conditionals and expansion. In each case, the conditional is executing the false branch when I would want it to execute true.

Is there an idiom for testing whether a particular string (preferably but not essentially "held" as a macro definition, for simplicity of customisation) is present in a literal list field? I realise I could work around this by using either a custom field or a keyword instead of the institution field; but I'd rather keep the bibliography file more-or-less semantically correct, and institution is in these terms the "right" field to be testing.

Since the nearest my reason told me I was comming to a "correct" approach was using \iflistequals I give that as my example, in case I'm doing something wrong before I reach the test.

\newcommand\commission{}

% in bibmacro expanded by driver
\iflistequals{institution}{\commission}%
{}
{\printfield{number}}


A more complete M(N)WE follows:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{unique,
title = {Title},
number = {Number},
institution = {commission}
}
\end{filecontents}
\begin{filecontents}{\jobname.bbx}
\RequireBibliographyStyle{verbose}
\newcommand{\commission}{}
\DeclareBibliographyDriver{misc}{%
\usebibmacro{begentry}%
\iflistequals{institution}{\commission}%
{}
{\printfield{number}}
\usebibmacro{finentry}}
\end{filecontents}

\usepackage[backend=biber,bibstyle=\jobname,citestyle=verbose]{biblatex}

\begin{document}
\cite{unique}
\end{document}

-

I would guess the underlying problem is that the formats of etoolbox internal lists and biblatex literal lists are different. One way to solve this is to use list item processing offered by \printlist via \DeclareListFormat.

\documentclass{article}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{ref1,
title = {Title},
number = {Number},
institution = {commission}}
@misc{ref2,
title = {Title},
number = {Number},
institution = {commissioner}}
@misc{ref3,
title = {Title},
number = {Number},
institution = {school and commission}}
@misc{ref4,
title = {Title},
number = {Number},
institution = {commission and school}}
\end{filecontents}

\begin{filecontents}{\jobname.bbx}
\RequireBibliographyStyle{verbose}
\newcommand{\commission}{commission}
\DeclareListFormat{list:number}{%
\ifnumless{\value{listcount}}{\value{liststop}}
{\ifdefstring{\commission}{#1}{\listbreak}{}}
{\ifdefstring{\commission}{#1}{}{\printfield{number}}}}
\DeclareBibliographyDriver{misc}{%
\usebibmacro{begentry}%
\printlist[list:number]{institution}%
\usebibmacro{finentry}}
\end{filecontents}

\usepackage[bibstyle=\jobname,citestyle=verbose]{biblatex}