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 \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
On Dec 14, 2007, at 5:57 PM, Peter Rolf wrote:
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.
I'm not quite sure I understand what you're trying to do, so this is a shot in the dark: instead of low-level trickery, you could use ConTeXt modes: \startmode[A] \definecolor [mycolor] [g=1] \stopmode \startmode[B] \definecolor [mycolor] [r=1] \stopmode You can then set \enablemode[A] in your file or pass the mode on the commandline: texexec --mode=A HTH Thomas
Thomas A. Schmitz schrieb:
On Dec 14, 2007, at 5:57 PM, Peter Rolf wrote:
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.
I'm not quite sure I understand what you're trying to do, so this is a shot in the dark: instead of low-level trickery, you could use ConTeXt modes:
\startmode[A] \definecolor [mycolor] [g=1] \stopmode
\startmode[B] \definecolor [mycolor] [r=1] \stopmode
You can then set \enablemode[A] in your file or pass the mode on the commandline: texexec --mode=A
Thanks Thomas for your help. I can do this without low-level trickery, but this would mean one or two (fore|backgroundcolor) additional macro(s) per building block (>20) for every graphic style (currently 2; more to come). This makes about 60 stupid little macros..... nope. I think that in some special cases I must do this anyway (where the color is choosen from a combination of states), but most times a general macro will do. I will try to get it run this weekend (have to learn TeX debugging first). But I wouldn't be surprised if this is the easier part of the problem. We will see :) Greetings, Peter
HTH
Thomas ___________________________________________________________________________________ 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 ___________________________________________________________________________________
2007/12/14, Peter Rolf
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
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
Wolfgang Schuster schrieb:
2007/12/14, Peter Rolf
: 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
Hi Peter,
can you try this (untested),
Hi Wolfgang, your idea works pretty good (I haven't thought about \ifcase 'til now). Still the problem is, that - currentstate must be set somehow - the colors and the number of used states vary from macro to macro So I have to define individual variants of \statecolor (with non fixed state=number pairs), or add an entry for every single state (currently 9). The later method is too ugly (imagine the case that you only need states 0 and 8) and will be hard to maintain if new states arise. I end up with 60 macros and that is what I want to avoid. Anyhow thanks for your help. I will try to trace my color macro while listening the right music for such problems (Yo La Tengo - I am not afraid of you and will beat your ass). Hopefully it works. ;) Greetings, Peter
\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 ___________________________________________________________________________________ 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 ___________________________________________________________________________________
2007/12/15, Peter Rolf
Wolfgang Schuster schrieb:
2007/12/14, Peter Rolf
: 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
Hi Peter,
can you try this (untested),
Hi Wolfgang,
your idea works pretty good (I haven't thought about \ifcase 'til now). Still the problem is, that
- currentstate must be set somehow - the colors and the number of used states vary from macro to macro
So I have to define individual variants of \statecolor (with non fixed state=number pairs), or add an entry for every single state (currently 9). The later method is too ugly (imagine the case that you only need states 0 and 8) and will be hard to maintain if new states arise.
It is hard to give a better solution because I don't what do you want to achive and how your interface should look to change the states and colors ...
I end up with 60 macros and that is what I want to avoid. Anyhow thanks for your help. I will try to trace my color macro while listening the right music for such problems (Yo La Tengo - I am not afraid of you and will beat your ass). Hopefully it works. ;)
Greetings, Peter
I wish you good luck to find a better solution, I'm myself a little busy till monday and can't help you for the moment and I run into a few other ConTeXt problems (and bugs, mkii and mkiv) the last two days and wasted to many time with them. Wolfgang
Peter Rolf wrote:
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).
this is what color palets are for .. grep a bit on the base path; it's even in some manuals if you use colorpalets, then you can change the state of many colors at once with one command
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
------------------------------------------------------------------------
___________________________________________________________________________________ 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 ___________________________________________________________________________________
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Peter Rolf wrote:
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.. :)
The problem is that it defines things, and you can't do that inside an argument. Solution: rewrite the macro to define a new macro (like \def\currentStateDependentColor{green}) instead of expanding on the fly. Then you have to do something like this: \StateDependentColor[stateA=green,stateC=blue,whatever=yellow,...] \ color[\currentStateDependentColor] And that should work. Best wishes, Taco
Taco Hoekwater schrieb:
Peter Rolf wrote:
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.. :)
The problem is that it defines things, and you can't do that inside an argument. Solution: rewrite the macro to define a new macro (like \def\currentStateDependentColor{green}) instead of expanding on the fly. Then you have to do something like this:
\StateDependentColor[stateA=green,stateC=blue,whatever=yellow,...] \ color[\currentStateDependentColor]
And that should work.
:)) THANK YOU TACO!!! Best wishes, Peter
Best wishes, Taco ___________________________________________________________________________________ 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 ___________________________________________________________________________________
\setuppagenumber[state=stop] \setupcolors[state=start] \definecolor[colorA] [red] \definecolor[colorB] [green] \definecolor[colorC] [blue] \newconditional\CondA \newconditional\CondB \newconditional\CondC \unprotect \def\CurrentStateDependentColor{} \def\GetStateDependentColor#1% {\bgroup \rawgetparameters[SDC@][A=,B=,C=,#1]% \def\docommand##1% {\doifdefined{Cond##1} % conditional is known.. {\expandafter\ifconditional\csname Cond##1\endcsname % ..AND true.. \doifsomething{\csname SDC@##1\endcsname} % ..AND a color is assigned \donetrue \else\donefalse\fi}% \ifdone\xdef\CurrentStateDependentColor{\csname SDC@##1\endcsname}% \expandafter\quitcommalist\fi}% \processcommacommand[A,B,C]\docommand % raw version does not work! why? \egroup} \protect \starttext %\settrue\CondA \settrue\CondB \settrue\CondC %\tracingonline=1 %\tracingall=1 %\tracingmacros=1 %\tracingcommands=2 \GetStateDependentColor{A=colorA,C=colorC} %\definecolor[testcolor][\TESTcolor] \switchtocolor[\CurrentStateDependentColor] %\tracingmacros=0 %\tracingall=0 THANK YOU TACO!!! \stoptext
participants (5)
-
Hans Hagen
-
Peter Rolf
-
Taco Hoekwater
-
Thomas A. Schmitz
-
Wolfgang Schuster