Define a color in a tikz style

How do I do a definecolor in a /.style?

\pgfkeys{/IMMstyle/.style={
inputnode/.style={shape=ellipse,draw,inner sep=2pt,minimum size=5.0mm},
\definecolor{dpred}{rgb}{0.50,0.35,0}
}}


doesn't work.

-
Does this post help: tex.stackexchange.com/questions/19190/… –  cmhughes Sep 25 '11 at 1:48

You can define a /.code (or /.code 2 args, or /.code n args) key that executes your desired code. To define a new color within a style, you could define a key

\tikzset{
define color/.code 2 args={
\definecolor{#1}{rgb}{#2}
}
}


Your example could look like this

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\tikzset{
define color/.code 2 args={
\definecolor{#1}{rgb}{#2}
},
/IMMstyle/.style={
inputnode/.style={
shape=ellipse,
draw,
inner sep=2pt,
minimum size=5mm
},
define color={dpred}{0.80,0.35,0}
}
}

\begin{tikzpicture}
\node [/IMMstyle,inputnode,fill=dpred] {x};
\end{tikzpicture}

\end{document}

-

For future reference, I would guess that most Googlers will arrive here trying to define a style which contains a defined colour (rather than defining the colour within the style itself).

That's easy to do:

\begin{tikzpicture}
\definecolor{dkblue}{rgb} {0.00,0.33,0.68}
\tikzset{
myStyle/.style = {draw=dkblue, very thick, rectangle}
}

\node [myStyle] {x};
\end{tikzpicture}

-