ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* color expansion at runtime
@ 2007-12-14 16:57 Peter Rolf
  2007-12-14 17:12 ` Thomas A. Schmitz
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Peter Rolf @ 2007-12-14 16:57 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 728 bytes --]

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
start with). Sigh, still so much to learn.. :)

Any hints are welcome.

Regards, Peter


[-- Attachment #2: statecolor.tex --]
[-- Type: text/plain, Size: 1433 bytes --]

\setuppagenumber[state=stop]
\setupcolors[state=start]

\definecolor[colorA] [red]
\definecolor[colorB] [green]
\definecolor[colorC] [blue]

\newconditional\CondA
\newconditional\CondB
\newconditional\CondC


\unprotect

\def\GetStateDependentColor[#1]%
  {\bgroup
   \rawgetparameters[SDC@][A=,B=,C=,#1]%
   \def\MYdocommand##1%
     {\doifdefined{Cond##1} % conditional is known..
        {\expandafter\ifconditional\csname Cond##1\endcsname % ..AND true..
           \edef\CurrentColor{\csname SDC@##1\endcsname}\else
           \def\CurrentColor{}\fi
         \doifelsenothing\CurrentColor % ..AND a color is assigned
           \donefalse\donetrue}%
      \ifdone\CurrentColor\expandafter\quitcommalist\fi}%
   \processcommacommand[A,B,C]\MYdocommand % raw version does not work! why?
   \egroup}

\protect


\starttext

\setfalse\CondA
\settrue\CondB
\settrue\CondC

\tracingonline=1
%\tracingall=1
%\tracingmacros=1
%\tracingcommands=2
color is -\GetStateDependentColor[A=colorA,C=colorC]- % works so far
%\tracingmacros=0
%\tracingall=0

% crashes

%\tracingall=1
%\tracingmacros=1
%\tracingcommands=2
%\definecolor[testcolor][{\GetStateDependentColor[A=colorA,C=colorC]}]
%\color[testcolor]
%\color[{\GetStateDependentColor[A=colorA,C=colorC]}]
%\expandafter\color\expandafter[\expandafter{\GetStateDependentColor[A=colorA,C=colorC]}]
%\tracingall=0
TEST

\stoptext

[-- Attachment #3: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-12-17 15:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-14 16:57 color expansion at runtime Peter Rolf
2007-12-14 17:12 ` Thomas A. Schmitz
2007-12-14 18:59   ` Peter Rolf
2007-12-15 10:17 ` Wolfgang Schuster
2007-12-15 14:07   ` Peter Rolf
2007-12-15 16:16     ` Wolfgang Schuster
2007-12-17  8:49 ` Hans Hagen
2007-12-17 10:33 ` Taco Hoekwater
2007-12-17 15:01   ` Peter Rolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).