# TikZ/PGF key filters : overriding color

I'm trying to override the color key within a pic but not within the enclosing scope (That is the path/draw/fill instruction).

My objective is to be able to set the colour for a path and have this affect the pic as well. That is the pic might have a custom shading and I would like this shading to adopt the paths colour as a tint. One should, however, still be allowed to override the local colour for the pic.

The example shows how I think it should be coded based upon the documentation but the filter is not working as I'd expected. Within the example I create a local name space /tikz/example as originally the 'color' style was clobbering the /tikz/color key. Filtering also needs a family to work with.

My understanding of filtering is that one ought to create/register the filter, in this case tikz/example, and then activate it when necessary i.e. before and after pic actions is executed.

The output I expect to see is the backround block in white with a blue line, overlaid by the three smaller blocks each shaded in blue, red and green.

\documentclass[tikz]{standalone}

\usetikzlibrary{calc}

\tikzset{
basis/.initial=1em,
block/.is family,
/tikz/pic actions/.install key filter=block,
block/.pic={
\draw[block/.activate family, pic actions, block/.deactivate family]
let \n{basis}={\pgfkeysvalueof{/tikz/basis}} in
(-\n{basis},-\n{basis}) rectangle  (\n{basis},\n{basis});
},
block/.cd,
colour/.style={/tikz/top color   =#1!50!white,
/tikz/bottom color=#1!50!black},
}

\begin{document}

\begin{tikzpicture}
\draw[color=blue]
( 0, 0) pic               {block}
(-1,-1) pic[color=green]  {block}
rectangle
(1,1)  pic[color=red]    {block};
\end{tikzpicture}

\end{document}


Sorry but I do not understand why you need all this "block family". Inside a picture the pic actions contains the current color settings, that are by default the path's one, but you can overwrite them inside the pic style.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\tikzset{
basis/.initial=1em,
block/.pic={
\draw[pic actions]
let \n{basis}={\pgfkeysvalueof{/tikz/basis}} in
(-\n{basis},-\n{basis}) rectangle  (\n{basis},\n{basis});
},
colour/.style={top color   =#1!50!white,
bottom color=#1!50!black},
}

\begin{document}

\begin{tikzpicture}
\draw[blue]
( 0, 0) pic                         {block}
(-1,-1) pic[colour=green, draw=red] {block}
rectangle
(1,1)  pic[colour=red]              {block};
\end{tikzpicture}

\end{document}


• Thanks for the response, my actual aim is to use the filter mechanism. I suspect one may be able to intercept keys within the /tikz/block family and use them to manipulate those in the /tikz family. This would allow me to do things like intercept certain keys, for example intercepting fill to providing a shaded fill in place of a flat fill. it's a bit of an over complication for a pic but I'm trying more exotic things. I've seen /.search also used in this way but it acts later. – Carel Oct 14 '16 at 15:40
• Sorry but I do not understand what you really want. My be you just want to replace (-1,-1) pic[color=green] {block} by (-1,-1) pic[block\colour=green] {block} in your original code ? – Kpym Oct 15 '16 at 10:25