How can I "demux" several features from a mode specification given in a
\foreach?
I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each node, and, in turn, the mode will be used to set several features of the style and position of the node. Since the mode specifies a group of features, I want to "demux" those features from the mode specification, rather than having to list each feature in the \foreach. A minimal not-working example is
\documentclass{standalone}
\usepackage{tikz}
\usepackage{etoolbox}
\begin{document}
\begin{tikzpicture}
\foreach \mode/\loc in {small/{(0,0)}, large/{(2,0)}}
{
\edef\myscale{\ifstrequal{\mode}{large}{1}{0.25}}
\edef\mycolor{\ifstrequal{\mode}{large}{black}{gray}}
\typeout{\meaning\myscale}
\typeout{\meaning\mycolor}
\node [scale=\myscale, color=\mycolor, draw] at \loc {\myscale\mycolor};
}
\end{tikzpicture}
\end{document}
If I try to compile this, I get the error ! Package xcolor Error: Undefined color \ifstrequal{small}{large}{black}{gray}.
It seems that the conditional needs to be expanded before being passed to the style, but I do not know how to do this. Surprisingly (at least to me), if I remove scale=\myscale, color=\mycolor from the style, then I get the following output.

So, for some reason, the node text expands the conditional, but the style does not.
(Aside question: Why do my images in posts always turn out so small?)
Edit: It appears that the \foreach is somewhat of a red herring for the above error message. Specifically, the following simpler code produces the same error:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{etoolbox}
\begin{document}
\def\mode{small}%
\begin{tikzpicture}
\node [scale=\ifstrequal{\mode}{large}{1}{0.25}, draw]
{\ifstrequal{\mode}{large}{1}{0.25}};
\end{tikzpicture}
\end{document}
Although @percusse's answer is best for my particular use, I'm still interested to know why this error occurs. Also, is it possible to force expansion of \ifstrequal?



standaloneclass provides a useful option:convert. – Paul Gaborit Jun 26 '12 at 21:21pgfkeysstyle rather than your "mode"? I mean, that's exactly how it turns out. – Ryan Reich Jun 27 '12 at 04:21#1etc. so that I can give just a short name rather than a full style when I call the command that uses the\foreach. – Henry DeYoung Jun 27 '12 at 17:32