# Double 'evaluate' in one PGF's \foreach

percusse may know if I can do the following with \foreach:

\begin{document}
\foreach [
evaluate=\x as \z using \x*10,
evaluate=\x as \p using \x mm*3
] \x in {1,...,5}{
\endgraf
\hskip\p pt\relax
\textcolor{red!\z!blue}{\x}%
}
\end{document}


Aside

\foreach should help newbie with an intelligent message in a case like the following:

\foreach [
remember=\x % as \lastx (initially A) % n00b forgot the rest.
] \x in {B,C,D,E,F,G,H}{%
$\overrightarrow{\lastx\x}$,
}

• Just came here searching how to use multiple evaluate ! Mar 7 at 12:13

The evaluate keyword invokes the PGF math engine, which always saves its results in units of pt, but without the pt string. So if you use

\hskip\p pt\relax


(adding the pt after the \p), you get the desired result:

\documentclass[10pt]{article}
\usepackage{tikz}
\begin{document}
\foreach [
evaluate=\x as \z using \x*20,
evaluate=\x as \p using \x mm*3
] \x in {1,...,5}{
\endgraf
\hskip\p pt\relax
\textcolor{red!\z!blue}{\x}%
}
\end{document}

• Thanks. Then I just do evaluate=\x as \p using \x*3 with \hskip\p mm\relax. Sep 17, 2012 at 13:36
• @AhmedMusa Thanks for the direct reference. We have a very knowledgable bunch here including yourself so I'm kinda embarrassed :0). Sep 17, 2012 at 14:05
• @AhmedMusa You want "x times 3mm", so use \x*3mm and \hskip\p pt\relax. Later, you can change 3mm to 1em or \baselineskip without any change in your \hskip... command. Sep 17, 2012 at 16:34
• @percusse: Every tikZ expert is called percusse, like every TeX user was called Ben User by Knuth. I chose percusse over Andrew Stacey, Jake, Tom Bombadil, etc., because percusse sounds like a word. Sep 17, 2012 at 17:45
• @PaulGaborit: That makes some sense. Thanks. Sep 17, 2012 at 17:47