Nested loops to process groups of pictures
For this particular application, where the outer \foreach
uses a list of lists, you can expand the macro containing the inner list before starting the inner loop.
\documentclass[a4paper,11pt]{article}
\usepackage{etoolbox}
\usepackage[dvipsnames,svgnames,x11names]{xcolor}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[nopanel,screen]{pdfscreen}
\margins{1cm}{1cm}{1cm}{1cm}
\screensize{15.875cm}{20.32cm}
\newcommand*{\SetA}{example-image-a/caption A1,example-image-a/caption A2}
\newcommand*{\SetB}{example-image-b/caption B1,example-image-b/caption B2}
\newcommand*{\MySets}{\SetA,\SetB}
\newcommand{\eforeach}[2]{\expandafter\doeforeach\expandafter{#1}{#2}}
\newcommand{\doeforeach}[2]{\foreach #2 in #1}
\begin{document}
\centering
\foreach \Set in \MySets {
\eforeach{\Set}{\myphoto/\mycaption} {%
\begin{tikzpicture}
\node (a) at (0,0) {\includegraphics[width=0.9\linewidth,height=0.9\textheight]{\myphoto}};
\node[below=3mm] (b) at (a.south) {\mycaption};
\end{tikzpicture}
\clearpage
}
}
\end{document}
If you are consistent in naming your sets, you can loop over the characters (in this case A
and B
) and build a macro with \csname
and \endcsname
. MWE:
\documentclass[a4paper,11pt]{article}
\usepackage{etoolbox}
\usepackage[dvipsnames,svgnames,x11names]{xcolor}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[nopanel,screen]{pdfscreen}
\margins{1cm}{1cm}{1cm}{1cm}
\screensize{15.875cm}{20.32cm}
\newcommand*{\SetA}{example-image-a/caption A1,example-image-a/caption A2}
\newcommand*{\SetB}{example-image-b/caption B1,example-image-b/caption B2}
\newcommand*{\MySets}{\SetA,\SetB}
\begin{document}
\foreach \id in {A,B}{
\edef\Set{\csname Set\id\endcsname}
\foreach \myphoto/\mycaption in \Set {
\centering
\begin{tikzpicture}
\node (a) at (0,0) {\includegraphics[width=0.9\linewidth,height=0.9\textheight]{\myphoto}};
\node[below=3mm] (b) at (a.south) {\mycaption};
\end{tikzpicture}
\clearpage
}
}
\end{document}
There are a two things here:
Firstly, you need to omit the braces around \MySets
in the outer \foreach
.
Secondly, \foreach
is written in such a way that the inner loop is the equivalent of
\foreach \myphoto/\mycaption in {\SetA} {
when you try to loop the way you want to. In your case we can remedy this by expanding everything before the first \foreach
:
\documentclass[a4paper,11pt]{article}
\usepackage{etoolbox}
\usepackage[dvipsnames,svgnames,x11names]{xcolor}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[nopanel,screen]{pdfscreen}
\margins{1cm}{1cm}{1cm}{1cm}
\screensize{15.875cm}{20.32cm}
\newcommand*{\SetA}{example-image-a/caption A1,example-image-a/caption A2}
\newcommand*{\SetB}{example-image-b/caption B1,example-image-b/caption B2}
\edef\MySets{{\SetA},{\SetB}}
\begin{document}
\foreach \Set in \MySets {
\foreach \myphoto/\mycaption in \Set {
\centering
\begin{tikzpicture}
\node (a) at (0,0) {\includegraphics[width=0.9\linewidth,height=0.9\textheight]{\myphoto}};
\node [below=3mm] (b) at (a.south) {\mycaption};
\end{tikzpicture}
\clearpage
}
}
\end{document}
If your use case is not more complex than this, you could also just avoid the nested macro definition in the first place:
\newcommand*\MySets{%
{ example-image-a/caption A1,
example-image-a/caption A2},
{ example-image-b/caption B1,
example-image-b/caption B2}%
}