# Is there a trick to iterate a set of multidimensional values with \psforeach?

I have, for example, a set of multidimensional values: {{red,1,12pt},{blue,3,10pt},{green,2,15pt}}. With \psforeach I want to iterate the values with 3 variables: \clr, \x, and \size.

Is there a trick to iterate a set of multidimensional values with \psforeach?

Edit: By combining the existing answers, the following is the result.

\documentclass{article}

\usepackage[active,tightpage]{preview}
\PreviewBorder=12pt
\PreviewEnvironment{pspicture}

\def\getValues#1,#2,#3\relax{\def\clr{#1}\def\x{#2}\def\size{#3}}
\makeatletter

\begin{document}
\begin{pspicture}[showgrid=top](-3,-3)(3,3)
\@for\abc:={{red,1,12pt},{blue,3,10pt},{green,2,15pt}}% this percent sign is needed!
\do{\expandafter\getValues\abc\relax
\pscircle[linecolor=\clr,linewidth=\size](0,0){\x}
% other graphics objects go here!
}
\end{pspicture}
\end{document}


-
you can split the argument of psforeach with something like this: \def\tempa#1,#2,#3{\def\clr{#1}\def\x{#2}\def\size{#3}}\tempa\argumentofpsforea‌​ch\relax – Marco Daniel Jun 19 '12 at 17:26
@MarcoDaniel: Could you show the complete solution as an answer? – kiss my armpit Jun 19 '12 at 22:54
@Forgiver: you can simplify it with \do{\expandafter\psCircle\abc\relax} and \def\psCircle#1,#2,#3\relax{\pscircle[linecolor=#1,linewidth=#3]{#2}}  – Herbert Jun 23 '12 at 10:54
@Herbert:But I need \clr, \x, and \size for other usage. – kiss my armpit Jun 23 '12 at 15:50
ok, then you're right. – Herbert Jun 23 '12 at 15:59

only the first argument has to be put into double braces:

\documentclass{minimal}
\usepackage{pstricks}
\def\temp#1{\expandafter\tempB#1\relax}
\def\tempB#1,#2,#3\relax{Colour: #1; X: #2; Size: #3 \par}
\begin{document}
\psforeach{\abc}{{{red,1,12pt}},{blue,3,10pt},{green,2,15pt}}{%
\expandafter\temp\expandafter{\abc}}

\end{document}


\documentclass{minimal}
\def\tempB#1,#2,#3\relax{Colour: #1; X: #2; Size: #3 \par}
\begin{document}
\makeatletter
\@for\abc:={{red,1,12pt},{blue,3,10pt},{green,2,15pt}}%
\do{\expandafter\tempB\abc\relax}
\end{document}

-
Thanks for answering. But why does the first element have to be enclosed by an extra pair of braces? – kiss my armpit Jun 23 '12 at 8:17
the first argument is expanded to see if there is something like 1,..,3. However, you can call it a bug or a feature ... :-) – Herbert Jun 23 '12 at 9:05
Hopefully this bug fix will be announced in the incoming pst-news. :-) – kiss my armpit Jun 23 '12 at 16:35
I'll do my very best ... :-) – Herbert Jun 23 '12 at 16:56

How about using pgffor:

\documentclass{article}
\usepackage{pgffor}
\begin{document}
\def\tempa#1,#2,#3\relax{\def\clr{#1}\def\x{#2}\def\size{#3}}
\foreach \abc in {{red,1,12pt},{blue,3,10pt},{green,2,15pt}}{
\expandafter\tempa\abc\relax%
Colour: \clr; X: \x; Size: \size\par
}%
\end{document}


Each element in \foreach, called \abc is expanded and passed to \tempa, which breaks it up into the three components as \clr, \x, \size.

-

The macro \cptdofunclist doesn't need any delimiter on the last argument of \do. It can see.

\documentclass{article}
\usepackage{catoptions}
\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}
\def\do#1,#2,#3{Colour: #1; X: #2; Size: #3\par}
\cptdofunclist[;]{red, 1, 12pt; blue, 3, 10pt; green, 2, 15pt}

\par\bigskip
\def\do#1,#2,#3,#4{\scalebox{#3}[#4]{\textcolor{#1}{#2}}}
\cptdofunclist[;]{red, Red, 2, 3; blue, Blue, 4, 5; green, Green, 6, 7}
\end{document}


Or, if you insist on using pgffor:

\documentclass{article}
\usepackage{pgffor}
\begin{document}
\def\tempa(#1,#2,#3){Colour: #1; X: #2; Size: #3\par}
\foreach \abc in {(red,1,12pt),(blue,3,10pt),(green,2,15pt)}{%
\expandafter\tempa\abc\relax
}
\end{document}

-