My question is similar to the one asked in ASdeL's question, except I am testing a loop variable against a predefined set. It seems that none of the solutions there are working for me because \imgidx is not expanded before the comparison. How can I go about this?
\documentclass{article}
\usepackage{pgffor}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand \IfStringInList {mmmm}
{ \clist_if_in:nnTF {#2} {#1} {#3} {#4} }
\ExplSyntaxOff
\begin{document}
\def \imgperrow {8}
\foreach \x in {0, ..., 4}
{
\pgfmathtruncatemacro{\ymax}{\imgperrow}
\foreach \y in {1, ..., \ymax}
{
\pgfmathtruncatemacro {\imgidx}{\x*\imgperrow + \y}
{\IfStringInList {\imgidx}{1,2,3,4}{img A}{img B}}
}
}
\end{document}
In this example, I should get the first four to be "img A," but all of them show up as "img B."
Thank you for your help.
Vexpects an unbraced argument (we know it also works with braces, but…) – egreg Nov 14 '17 at 23:25