# [NTG-context] color expansion at runtime

Sat Dec 15 11:17:29 CET 2007

2007/12/14, Peter Rolf <indiego at gmx.net>:
> Hi,
>
> I desperately need runtime defined colors (state dependent) for my
> macros. The macros are used with different graphic styles, which is the
> reason why I want to avoid any style dependent part inside them.
>
> To give you an example. I need something like this
>
> \color[{\StateDependentColor[stateA=green,stateC=blue,whatever=yellow,...]}]
>
> If flag 'stateA' is true at runtime, then color 'green' is used (and so
> on; order is significant).
>
> I have written such a macro, but sadly it crashes when used inside
> \color or \definecolor. Tried to debug it, but this is my first
> experience with the trace commands (probably not the best example to
>
> Any hints are welcome.
>
> Regards, Peter

Hi Peter,

can you try this (untested),

\chardef\stateA\zerocount
\chardef\stateB\plusone
\chardef\stateC\plustwo

\let\currentstate\stateA

\def\statecolor{\ifcase\currentstate red\or green\or blue\fi}

\starttext

\color[\statecolor]{Currentstate}

\let\currentstate\stateB

\color[\statecolor]{Currentstate}

\let\currentstate\stateC

\color[\statecolor]{Currentstate}

\stoptext

Wolfgang