Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm not having any luck using the TikZ let operation inside a foreach loop. Is there anything I'm missing?

Sample code (that doesn't work):

  \foreach \y in {1,2,3}
     {\draw (0,0) -- (3,\y);
      \draw let 
        \p1 = (3,\y),
        \n1 = {atan2(\x1,\y1)} in
      (\y,0) arc [start angle = 0, end angle = \n1, radius=\y];
share|improve this question

1 Answer 1

up vote 10 down vote accepted

The let synax is perfectly valid inside a \foreach. You do however have a clash of variable names: The \y from the loop conflicts with the \y⟨n⟩ from let. Simply renaming the loop counter solves the problem:


  \foreach \a in {1,2,3}
     {\draw (0,0) -- (3,\a);
      \draw let 
        \p1 = (3,\a),
        \n1 = {atan2(\x1,\y1)} in
      (\a,0) arc [start angle = 0, end angle = \n1, radius=\a];

The underlying problem is that TeX macro names cannot contain numbers. So let has to define a macro called \y that reads the 1 (or other number) as a parameter and then redirects to the correct value. This of course overrides the \y coming from the loop. So you (presumably) get an error on (\y,0), because the new \y (inside the let) expects to be followed by a number, not a ,.

share|improve this answer
Brilliant, thanks! –  Simon Byrne Aug 8 '11 at 17:05
This also made me suffer! This incompatibility should be mentioned in TikZ manual. –  Gonzalo Jan 8 '13 at 2:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.