# Does a scope propagate through a foreach loop? [closed]

I wanted to draw a bunch of circles using a \foreach using the even odd fill rule.

If I do:

\documentclass{standalone}\input tikz\begin{document}\tikz{

\begin{scope}[red,even odd rule]
\fill(1,1)circle(1);
\fill(2,2)circle(2);
\end{scope}

}\end{document}


I get the desired effect, however if I do

\documentclass{standalone}\input tikz\begin{document}\tikz{

\begin{scope}[fill=red,even odd rule]
\foreach\i in {1,2}{
\fill(\i,\i)circle(\i);
}
\end{scope}

}\end{document}


The properties of the scope no longer effect my \draw. Is there someway to get the scope to propagate through the \foreach loop?

• While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Mar 12 '17 at 7:38
• @MöbiusStripMall: Please make sure they actually compile. In the second one, you are using \i as the loop variable and then atte,pting to access \x. Also, please include the image that you get form the two versions. Mar 12 '17 at 8:05
• The even odd rule only has an effect on a single path. Ex: \fill[even odd rule] (1,1) circle(1) (2,2) circle(2); Mar 12 '17 at 8:40
• The first snippet does not produce the claimed output. Mar 12 '17 at 8:43
• @AndrewSwann That is correct. I must have made a mistake at some point causing it to appear that it was outputting that image. The question is ultimately founded on the preconception that the mistake was proper behavior and should probably be closed. Mar 12 '17 at 8:46

You can achieve the desired result using a loop as follows:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\begin{scope}[red,even odd rule]
\fill
\foreach\i in {1,2}{
(\i,\i) circle(\i)}
;
\end{scope}
\end{tikzpicture}

\end{document}


I am getting identical results:

## Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{scope}[draw=blue, ultra thick, fill=red!20,even odd rule]
\filldraw (1,1) circle(1);
\filldraw (2,2) circle(2);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[draw=blue, ultra thick, fill=red!20,even odd rule]
\foreach \i in {1,2} {
\filldraw (\i,\i) circle(\i);
}
\end{scope}
\end{tikzpicture}
\end{document}

• Hm... Something very strange is going on for me. I will delete the question until I understand what exactly is happening. Thank you. Mar 12 '17 at 8:12
• @MöbiusStripMall: There must be some version problem. Add \listfiles and include the output that lists the version of each package. Mar 12 '17 at 8:14
• I don't think it is. I get the same output as you now but 5 minutes ago when I compiled the images for this question I got different results. I am really confused right now. I think however that my question is ultimately founded on some misconception or error on my part. Mar 12 '17 at 8:24