I'd like to compact this code sample with \forcsvlist
(provided by the etoolbox
package).
\newcommand\mycmd[2]{
\pagestyle{#2}
\csname tit#1\endcsname
\cleardoublepage
}
\def\DOtitlepages{
\iftoggle{togfancy}{ \mycmd{fancy}{empty} }{}
\iftoggle{togplain}{ \mycmd{plain}{empty} }{}
\iftoggle{toguser}{ \mycmd{user}{plain} }{}
}
I'd like just to move the \iftoggle
s to \mycmd
and define the pairs of arguments in a 'list'. However I don't know if it is possible to pass more than one argument at a time to forcvslist
.
After the great answers by @Andrew and @Werner, I've written this command as multiargument version of \forcsvlist
:
\documentclass{article}
\usepackage{etoolbox}
\newcommand\mycmd[2]{#1 \par#2 \par}
\newcommand\forcsvlistargs[2]{
\expandafter\providecommand\csname \detokenize{#1}aux\endcsname[1]{\csname \detokenize{#1}\endcsname##1\relax}
\forcsvlist{\expandafter\csname \detokenize{#1}aux\endcsname}{#2}
}
\begin{document}
\forcsvlistargs{mycmd}{{{fancy}{empty}},{{plain}{empty}},{{user}{plain}}}
\end{document}
If I'm not wrong, it creates the auxiliary command if not previously defined. I did so in order to use forcsvlistargs
several times in the same document, not having to explicitly declare de function first.
I suppose that \csname \detokenize{#1}\endcsname##1\relax
can be change to something like that #1##1\relax
, but I'm missing something.