# Don't do any fills in TikZ

I have a macro that will draw several things in a TikZ picture using some styles I defined, which include fills:

\documentclass{article}
\usepackage{tikz}
\tikzset{%
mystyle1/.style={fill=red,font={\bfseries}},
mystyle2/.style={fill=yellow,draw=blue}
}
\newcommand{\doit}{%
\begin{tikzpicture}
\node[mystyle1,circle]at(0,0){Text1};
\node[mystyle2,rectangle] at (3,0){Text2};
\end{tikzpicture}
}
\begin{document}
Foo

\doit

bar
\end{document}


Which looks like

How can I tell TikZ, before or after the \tikzset, to

don't do the fills but everything else

without redefining all the styles? (Here it's only two, but in my real applications it's many and they may change.)

So, the result should look like this:

I thought, that something like

\tikzset{every node/.append style={fill=none}}


should work, but it doesn't.

-

I would recommend you allow for an optional Parameter to the \doit macro with which you can specify other options.. So \doit produces the first image and \doit[fill=none] produces the second:

If you want more flexibility you can have two optional parameters to control the options for the circle and rectangle separately. So the third option below was produced with:

\doit[fill=orange, draw=blue, ultra thick][fill=green!50, draw=magenta, ultra thick]


## Notes:

• I used the xparse package to provide the macro that allows for two optional parameters. If you do not want to include an additional package, there are probably other ways to accomplish this.

## Code: One Optional Parameter

\documentclass{article}
\usepackage{tikz}
\tikzset{%
mystyle1/.style={fill=red,font={\bfseries}},
mystyle2/.style={fill=yellow,draw=blue}
}

\newcommand{\doit}[1][]{%
\begin{tikzpicture}
\node[mystyle1, circle, #1] at (0,0){Text1};
\node[mystyle2, rectangle, #1] at (3,0){Text2};
\end{tikzpicture}
}
\begin{document}
Foo

\doit

\doit[fill=none]

bar
\end{document}


## Code: Two Optional Parameters

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}

\tikzset{%
mystyle1/.style={fill=red,font={\bfseries}},
mystyle2/.style={fill=yellow,draw=blue}
}

\NewDocumentCommand{\doit}{O{} O{}}{%
\begin{tikzpicture}
\node[mystyle1, circle, #1] at (0,0){Text1};
\node[mystyle2, rectangle, #2] at (3,0){Text2};
\end{tikzpicture}
}
\begin{document}
Foo

\doit

\doit[fill=none][fill=none]

\doit[fill=orange, draw=blue, ultra thick][fill=green!50, draw=magenta, ultra thick]

bar
\end{document}

-
Thanks. But I wanted a solution without redefining the styles. –  Toscho Jan 20 '14 at 18:51
Perhaps I am not fully understanding your comment, but I am not redefining the styles, just adding to them as needed. Your complete style is applied then only what you specify in the optional parameter is overwritten. –  Peter Grill Jan 20 '14 at 18:53
I have made no changes to mystyle1 and mystyle2. –  Peter Grill Jan 20 '14 at 19:49
Ah, sorry, confused the lines. –  Toscho Jan 21 '14 at 16:42

One solution could be to define a style myfill which can be switched on and off.

\documentclass{article}
\usepackage{tikz}
\tikzset{myfill/.style={fill=#1}}

\tikzset{%
mystyle1/.style={myfill=red,font={\bfseries}},
mystyle2/.style={myfill=yellow,draw=blue}
}
\newcommand{\doit}{%
\begin{tikzpicture}
\node[mystyle1,circle]at(0,0){Text1};
\node[mystyle2,rectangle] at (3,0){Text2};
\end{tikzpicture}
}
\begin{document}
Foo

\doit

bar

\tikzset{myfill/.style=}
\doit

off
\end{document}


-

Thanks to inspiration from Thomas F. Sturm and Peter Grill I have found a nice solution for myself:

Just redefine the fill-style:

\tikzset{fill/.style={}}


Please comment, if this is an acceptable way or should be put into l2tabu.

-