Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{}
\listadd{\commission}{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}{}
\listadd{\commission}{commission}
\DeclareBibliographyDriver{misc}{%
  \usebibmacro{begentry}%
  \printfield{title}\setunit{\addspace}%
    \iflistequals{institution}{\commission}%
    {}
    {\printfield{number}}
  \usebibmacro{finentry}}
\end{filecontents}

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

\addbibresource{\jobname.bib}

\begin{document}
\cite{unique}
\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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}%
    \printfield{title}\setunit{\addspace}%
    \printlist[list:number]{institution}%
    \usebibmacro{finentry}}
\end{filecontents}

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

\begin{document}
\cite{ref1}, \cite{ref2}, \cite{ref3}, \cite{ref4}
\printbibliography
\end{document}

enter image description here

share|improve this answer
    
+1, and I am considering to change my username into "Audrey's sockpuppet". –  lockstep Jun 6 '11 at 16:39
    
@lockstep You'd better not. My last attempt at a question was a trainwreck. –  Audrey Jun 6 '11 at 16:49
    
Thank you. That feels idiomatic. I was about to post my own solution (extracted by grimly watching macros trace and hacking randomly) which involved ifxing and edefing and other unattractive things; but this is so clearly superior it would be pointless. –  Paul Stanley Jun 6 '11 at 17:27
    
@Paul You're welcome. I am terrible at expansion control, so I'd probably find your solution helpful. –  Audrey Jun 6 '11 at 18:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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