[Tex/LaTex] Define a color in a tikz style

tikz-pgftikz-styles

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.

Best Answer

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}