# Efficiently applying the same patch to several bibdrivers

In this answer to a question about getting Biblatex to print the ISSN field for books, I suggest a solution which uses the `\xpatchbibdriver` command of the `xpatch` package:

``````\xpatchbibdriver{book}{%
{\printfield{isbn}}
}{%
{\printfield{issn}\newunit\newblock\printfield{isbn}}
}{}{}
``````

A problem with my answer is that the patch needs to be applied separately for each book-like bibliography type (book, collection, proceedings, incollection, inproceedings, etc.).

Is there a nicer way to patch all the entries at once? I'm vaguely familiar with the `\foreach` command of the `pgffor` package, but the following naïve usage of it doesn't work, probably because it `\i` doesn't get expanded before getting passed to `\xpatchbibdriver`:

``````\usepackage{pgffor}
\foreach \i in {incollection,proceedings,book,inproceedings}{%
\xpatchbibdriver{\i}{%
{\printfield{isbn}}
}{%
{\printfield{issn}\newunit\newblock\printfield{isbn}}
}{}{}
}
``````

Is there a way I can force the expansion of `\i`? Do I need an `\expandafter` in here somewhere? (Alternatively, is there an even better way of doing what I'm doing without using `pgffor` and/or `xpatch`?)

• A starter document would be nice, instead fragments of code ;-) – user31729 Dec 8 '15 at 14:11

## 1 Answer

Since `\xpatchbibdriver` builds a command name with `\csname...\endcsname`, the `\i` macro is expanded

The patch is not performed because `\foreach` does its workings in a group and so the patch will disappear at the end. Use `\@for`:

``````\makeatletter
\@for\next:=incollection,proceedings,book,inproceedings\do{%
\xpatchbibdriver{\next}
{{\printfield{isbn}}}
{{\printfield{issn}\newunit\newblock\printfield{isbn}}}
{}{}%
}
\makeatother
``````

With `etoolbox` features:

``````\renewcommand{\do}[1]{%
\xpatchbibdriver{#1}
{{\printfield{isbn}}}
{{\printfield{issn}\newunit\newblock\printfield{isbn}}}
{}{}%
}
\docsvlist{incollection,proceedings,book,inproceedings}
``````

With `xparse`:

``````\documentclass{article}
\usepackage{biblatex}
\usepackage{xpatch,xparse}

\ExplSyntaxOn
\NewDocumentCommand{\massxpatchbibdriver}{mmmmm}
{
\clist_map_inline:nn { #1 }
{
\xpatchbibdriver{##1}{#2}{#3}{#4}{#5}
}
}
\ExplSyntaxOff

\massxpatchbibdriver{incollection,proceedings,book,inproceedings}
{{\printfield{isbn}}}
{{\printfield{issn}\newunit\newblock\printfield{isbn}}}
{}{}
``````
• Thanks; I've used this to update the answer mentioned in my question. – Psychonaut Dec 8 '15 at 14:41