# Why does the definition of a spy scope imply a change in the foreground color?

I noticed that the foreground color changes when adding a spy scope to my tikzpicture.

Compare:

\documentclass[]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}
\usepackage{lmodern}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}[green!50!black,
%spy using outlines
]
\fill (0,0) rectangle (1,1);
% \spy[size=0.3\linewidth] on (nitscheInit)
%   in node at (1.7,1.7);
\end{tikzpicture}
\end{frame}
\end{document}

This produces a green square as expected. When I include the line

spy using outlines

above, the square turns black! Note that I don't even use the actual \spy command. I would like to use the foreground color for the outline of the spy nodes. I haven't found the default definition for a spy in the docs, perhaps there is a key to override it?

Edit:

I found what could the offending setting in texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryspy.code.tex

\tikzset{
tikz@lib@reset@gs/.style={black,thin,solid,opaque,line cap=butt,line join=miter}
}

If I change black to another color, that color will appear upon invoking the said line. I feel this is a bug, but my knowledge of TeX internals is not sufficient to fix it myself.

• I'm not clear if my edited answer now solves the problem satisfactorily or if there remain outstanding issues. Could you clarify? That would also encourage others to suggest answers which might be more helpful if my workaround isn't suitable for your situation. – cfr Oct 12 '14 at 18:02

I guess that spy using outlines changes the colour. beamer is irrelevant here.

Here is a workaround which I think will do what you want. Note, however, that I've never used this library before and this is not extensively tested. Basically, I think simply not specifying the colour in the definition is probably the right thing to do. When I test this, I get outlines in the foreground colour, regardless of the colour used for the area being spied upon, and an explicit colour request overrides this default as expected. I've used a somewhat different MWE to isolate the issue and to make it clearer what is going on. (At least, to make it clearer to me - I can't speak for others.)

To modify the code you identified in the library, all you do is add

\makeatletter
\tikzset{%
tikz@lib@reset@gs/.style={thin,solid,opaque,line cap=butt,line join=miter}
}
\makeatother

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{spy}
\makeatletter
\tikzset{%
tikz@lib@reset@gs/.style={thin,solid,opaque,line cap=butt,line join=miter}
}
\makeatother
\begin{document}

\begin{tikzpicture}
[
green!50!black,
spy using outlines={magnification=2, connect spies},
]
\fill (0,0) rectangle (1,1);
\spy[size=0.1\linewidth] on (.5,.5) in node at (4,5);
% check with a case where the target area's colour is different from the outline colour
\fill [blue] (10,0) rectangle (9,1);
% check that an explicit colour specification does what we expect
\spy[red,size=0.1\linewidth] on (9.5,.5) in node at (6,5);
% and that we get the expected default again when we don't specify one
\spy[size=0.05\linewidth] on (9.5,.5) in node at (6,3);
\end{tikzpicture}

\end{document}

Please let me know if this is what you wanted. Since I'm not familiar with the library, I might have misunderstood the intent.

• Oh, I see. It is just because you didn't specify a magnification in your MWE! – cfr Oct 2 '14 at 22:14
• thanks for helping, cfr. In my beamer template, I have a custom background and foreground color. I don't want to specify this color inside the tikzpicture environment, because then I can't use it for other documents where I prefer the black/white default. I just want spy not to interfere with the default colors. – Sebastian Oct 3 '14 at 7:24
• @Sebastian Please see my edit. (Actually, it is more a new answer than an edit but some of the letters are probably the same, even if they are arranged in a different order ;).) – cfr Oct 10 '14 at 21:45