I thought I had understood at least some aspects of macros, but it turns out I'm as lost as always. Here's my problem: I'm writing a module which will have a \setupcommand. The value is given in a [key=pair] list, so I thought I could use \getvariable. What I have is \def\setupcommand{\setvariables[namespace]} % setting up the namespace \setvariables[namespace][key=value,otherkey=value] % initializing the keys % And now I want to wrap my values up in a conditional statement: \doifelse{\getvariable{namespace}{key}}{value} {do something} {do something else} When I put the \doifelse statement into my source files, the test works; the key is assigned the value that is in the setupcommand. But this doesn't work at runtime: either \getvariable{namespace}{key} always has the value I assign in the line \setvariables[namespace] [key=value,otherkey=value], or if I comment out that line, the variable is empty. I can see why this is the case: the setupcommand is read AFTER the module, so at runtime, the variable is not assigned yet. So my approach seems fundamentally flawed. What could I do instead? Thanks for your help Thomas
Thomas A. Schmitz wrote:
I thought I had understood at least some aspects of macros, but it turns out I'm as lost as always. Here's my problem: I'm writing a module which will have a \setupcommand. The value is given in a [key=pair] list, so I thought I could use \getvariable. What I have is
\def\setupcommand{\setvariables[namespace]} % setting up the namespace \setvariables[namespace][key=value,otherkey=value] % initializing the keys
% And now I want to wrap my values up in a conditional statement: \doifelse{\getvariable{namespace}{key}}{value} {do something} {do something else}
When I put the \doifelse statement into my source files, the test works; the key is assigned the value that is in the setupcommand. But this doesn't work at runtime: either \getvariable{namespace}{key} always has the value I assign in the line \setvariables[namespace] [key=value,otherkey=value], or if I comment out that line, the variable is empty. I can see why this is the case: the setupcommand is read AFTER the module, so at runtime, the variable is not assigned yet. So my approach seems fundamentally flawed. What could I do instead?
I'm not sure what you mean but there is the following mechanism: \startsetups namespace:reset \doifelse{\getvariable{namespace}{key}}{value} {do something} {do something else} \stopsetups \startsetups namespace:set \doifelse{\getvariable{namespace}{key}}{value} {do something} {do something else} \stopsetups \setvariables[namespace][reset=namespace;reset,set=namespace:set] now, when you say: \setvariables[namespace][key=value] first the 'namespace:reset' setups will be executed, then the assignment, and afterwards the 'namespace:set' setups. So, you can have actions before and after assignments. Hans ----------------------------------------------------------------- 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 -----------------------------------------------------------------
Sorry, I was trying to be general instead of specific and was unclear. Here's what I want: \usemodule[MyCrop] \setupcrop[mark=camera,info=yes] % or \setupcrop[mark=cross,info=no] or any combination My idea was to have nested \doifelse statements in the module itself (I got this idea from page-lay.tex): \doifelse{\getvariable{Crop}{mark}{camera} {==> make page background camera-crops} {\doifelse{\getvariable{Crop}{mark}{cross} {==> make page background cross-crops} {do nothing} My problem right now is that the assignment by the user given in the \setup-command is not read before the \doifelse within the module gets executed, so it always defaults to the "do nothing" part because the variables are empty. I hope that's clearer... Thanks for your help! The different backgrounds are working, I just need this last piece to process user input. Best Thomas On Oct 6, 2005, at 9:31 AM, Hans Hagen wrote:
I'm not sure what you mean
Hi Thomas. Thomas A. Schmitz wrote:
Sorry, I was trying to be general instead of specific and was unclear. Here's what I want:
\usemodule[MyCrop] \setupcrop[mark=camera,info=yes] % or \setupcrop[mark=cross,info=no] or any combination
This should work. The only thing that is missing, is a call (at the end of \setupcrop) to a separate routine (based on your \doifelse construct), which sets up the background. Or have i missed something? :) Peter
My idea was to have nested \doifelse statements in the module itself (I got this idea from page-lay.tex):
\doifelse{\getvariable{Crop}{mark}{camera} {==> make page background camera-crops} {\doifelse{\getvariable{Crop}{mark}{cross} {==> make page background cross-crops} {do nothing}
My problem right now is that the assignment by the user given in the \setup-command is not read before the \doifelse within the module gets executed, so it always defaults to the "do nothing" part because the variables are empty. I hope that's clearer...
Thanks for your help! The different backgrounds are working, I just need this last piece to process user input.
Best
Thomas
On Oct 6, 2005, at 9:31 AM, Hans Hagen wrote:
I'm not sure what you mean
_______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Peter, thanks for your help yet again! On Oct 6, 2005, at 12:01 PM, Peter Rolf wrote:
This should work.
OK, so I'm not completely off the mark...
The only thing that is missing, is a call (at the end of \setupcrop) to a separate routine (based on your \doifelse construct), which sets up the background.
Or have i missed something? :)
Actually, this part of the code works. I have defined overlays/layers and a variable PageBackground and in my doifelse want this \let\PageBackground\empty \def\CameraMarks{Camera} \def\CrossMarks{Cross} \doifelse{\getvariable{Crop}{mark}{camera} {\let\PageBackground\CameraMarks} {\doifelse{\getvariable{Crop}{mark}{cross} {\let\PageBackground\CrossMarks} {\relax} For debugging purposes, I just have this \doifelse{\GetMark}{camera} {mark defined as \getvariable{Crop}{mark}} {mark not defined: \getvariable{Crop}{mark}} which will print out a message. \getvariable{Crop}{mark} however, is either empty or has the value I predefine when I initialize it, it does not take the user-supplied value within the module (if I insert this doifelse thing into the document, it does return the correct value because then the \setup-command has been read before.) Thanks, and best Thomas
Thomas A. Schmitz wrote:
Peter, thanks for your help yet again!
On Oct 6, 2005, at 12:01 PM, Peter Rolf wrote:
This should work.
OK, so I'm not completely off the mark...
maybe we're both :)
The only thing that is missing, is a call (at the end of \setupcrop) to a separate routine (based on your \doifelse construct), which sets up the background.
Or have i missed something? :)
Actually, this part of the code works. I have defined overlays/layers and a variable PageBackground and in my doifelse want this
\let\PageBackground\empty \def\CameraMarks{Camera} \def\CrossMarks{Cross}
\doifelse{\getvariable{Crop}{mark}{camera} {\let\PageBackground\CameraMarks} {\doifelse{\getvariable{Crop}{mark}{cross} {\let\PageBackground\CrossMarks} {\relax}
For debugging purposes, I just have this
\doifelse{\GetMark}{camera} {mark defined as \getvariable{Crop}{mark}} {mark not defined: \getvariable{Crop}{mark}}
which will print out a message. \getvariable{Crop}{mark} however, is either empty or has the value I predefine when I initialize it, it does not take the user-supplied value within the module (if I insert this doifelse thing into the document, it does return the correct value because then the \setup-command has been read before.)
Normally there is no magic in setting variables. So double check the code where you set (\setvariables[Crop][...]) the variables. Maybe a typo (lowercase namespace,.. ). Peter
Thanks, and best
Thomas _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Yes, I'm usually prone to making this kind of mistakes. But if I put exactly the same \doifelse in my TeX file (instead of in the module), the correct value is returned. I also thought there was no trickery involved, but it looks like the key is assigned its value only after the module has been read... I have looked at another module I wrote where I have the same situation (font definition), and it just works. I have no clue where both modules differ. Best Thomas On Oct 6, 2005, at 2:45 PM, Peter Rolf wrote:
Normally there is no magic in setting variables. So double check the code where you set (\setvariables[Crop][...]) the variables. Maybe a typo (lowercase namespace,.. ).
Peter
Thomas A. Schmitz wrote:
Yes, I'm usually prone to making this kind of mistakes. But if I put exactly the same \doifelse in my TeX file (instead of in the module), the correct value is returned. I also thought there was no trickery involved, but it looks like the key is assigned its value only after the module has been read... I have looked at another module I wrote where I have the same situation (font definition), and it just works. I have no clue where both modules differ.
I'm just guessing (taken from my own pile of mistakes). Hmm, is it a problem of setting the variable, or it's interpretation? Can you find out, if the variable is set correctly in your \setupcrop macro? Just add \writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}}% right after the \setvariables command and have an eye on the logging. And if this works (I can't imagine why not), try to exchange the \doifelse nesting by \processaction \processaction[\getvariable{Crop}{mark}][ camera =>\def\PageBackground{\CameraMarks}, cross =>\def\PageBackground{\CrossMarks}, default=>\def\PageBackground{}, unknown=>\def\PageBackground{}]% The error can't hide forever ;) Greetings, Peter
Best
Thomas
On Oct 6, 2005, at 2:45 PM, Peter Rolf wrote:
Normally there is no magic in setting variables. So double check the code where you set (\setvariables[Crop][...]) the variables. Maybe a typo (lowercase namespace,.. ).
Peter
_______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Peter, I appreciate your helping me. And I have no clue what's going wrong. On Oct 6, 2005, at 10:08 PM, Peter Rolf wrote:
I'm just guessing (taken from my own pile of mistakes). Hmm, is it a problem of setting the variable, or it's interpretation? Can you find out, if the variable is set correctly in your \setupcrop macro? Just add
\writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}}%
For debugging, I've narrowed the module down to 8 lines: \def\setupcrop{\setvariables[Crop]} \setvariables[Crop][mark=cross,info=yes] \processaction[\getvariable{Crop}{mark}][ camera =>\def\PageBackground{\CameraMarks}, cross =>\def\PageBackground{\CrossMarks}, default=>\def\PageBackground{}, unknown=>\def\PageBackground{}]% \writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}} my testfile: \usemodule[t-crop] \setupcrop[mark=camera,info=yes] \starttext Hello! \stoptext Output in log: (/Users/tas/Library/texmf/tex/t-crop.tex [CROP] : crop mark is: cross If second line of module is commented out, I get: [CROP] : crop mark is: So it's a problem of actually setting the variable.
The error can't hide forever ;)
Maybe it can't hide forever, but it looks like it can run... Thanks for your help. I'll be away tomorrow and will try more on the weekend. Best Thomas
Thomas A. Schmitz wrote:
Peter, I appreciate your helping me. And I have no clue what's going wrong. On Oct 6, 2005, at 10:08 PM, Peter Rolf wrote:
I'm just guessing (taken from my own pile of mistakes). Hmm, is it a problem of setting the variable, or it's interpretation? Can you find out, if the variable is set correctly in your \setupcrop macro? Just add
\writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}}%
For debugging, I've narrowed the module down to 8 lines:
\def\setupcrop{\setvariables[Crop]}
Is that all \setupcrop does? :) It's a bit hard for me to debug your code from parts, without seeing all. But anyway, here is the way I would handle such stuff. Not tested! ... % trigger for printing crop info \newconditional\CropInfo \def\SetupCrop{\dosingleempty\doSetupCrop} \def\doSetupCrop[#1]{% \iffirstargument \getrawparameters[CROP@][{mark=,info=},#1]% \processaction[\CROP@mark][ camera=>{\setvariables[Crop][mark=camera] \def\PageBackground{\CameraMarks}}, cross=>{\setvariables[Crop][mark=cross] \def\PageBackground{\CrossMarks}}, default=>{\setvariables[Crop][mark=] \def\PageBackground{}}, unknown=>{\setvariables[Crop][mark=] \def\PageBackground{}}]% % no need to store this into a variable \processaction[\CROP@info][ no=>\setfalse\CropInfo, default=>\settrue\CropInfo, unknown=>\settrue\CropInfo]% \else % \SetupCrop is called without parameters \setvariables[Crop][mark=] \setfalse\CropInfo \def\PageBackground{}% \fi % just to give the idea... \ifconditional\CropInfo \setlayer[markings][x=.5\paperwidth, y=20mm, location=c]% {\tt \txx "\jobname" - \currentdate [y,/,mm,/,dd]\ - \currenttime\ - \realfolio\ of \lastpage} % \else \fi % for debugging only \writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}}% \writestatus{}{crop info is \ifconditional\CropInfo\ enabled\else\ disabled}% } \SetupCrop % initialisation (or \setups[namespace:reset]) ... I have no experience with the namespace mechanism Hans mentioned (will give it a try/ add it to the wiki). HTH, Peter
\setvariables[Crop][mark=cross,info=yes]
\processaction[\getvariable{Crop}{mark}][ camera =>\def\PageBackground{\CameraMarks}, cross =>\def\PageBackground{\CrossMarks}, default=>\def\PageBackground{}, unknown=>\def\PageBackground{}]%
\writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}}
my testfile:
\usemodule[t-crop] \setupcrop[mark=camera,info=yes]
\starttext
Hello!
\stoptext
Output in log:
(/Users/tas/Library/texmf/tex/t-crop.tex [CROP] : crop mark is: cross
If second line of module is commented out, I get:
[CROP] : crop mark is:
So it's a problem of actually setting the variable.
The error can't hide forever ;)
Maybe it can't hide forever, but it looks like it can run...
Thanks for your help. I'll be away tomorrow and will try more on the weekend.
Best
Thomas _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Peter Rolf wrote:
Thomas A. Schmitz wrote:
Yes, I'm usually prone to making this kind of mistakes. But if I put exactly the same \doifelse in my TeX file (instead of in the module), the correct value is returned. I also thought there was no trickery involved, but it looks like the key is assigned its value only after the module has been read... I have looked at another module I wrote where I have the same situation (font definition), and it just works. I have no clue where both modules differ.
I'm just guessing (taken from my own pile of mistakes). Hmm, is it a problem of setting the variable, or it's interpretation? Can you find out, if the variable is set correctly in your \setupcrop macro? Just add
\writestatus{[CROP]}{crop mark is: \getvariable{Crop}{mark}}%
right after the \setvariables command and have an eye on the logging.
And if this works (I can't imagine why not), try to exchange the \doifelse nesting by \processaction
\processaction[\getvariable{Crop}{mark}][ camera =>\def\PageBackground{\CameraMarks}, cross =>\def\PageBackground{\CrossMarks},
no spaces before the =>
default=>\def\PageBackground{}, unknown=>\def\PageBackground{}]%
----------------------------------------------------------------- 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:
Hi Thomas.
Thomas A. Schmitz wrote:
Sorry, I was trying to be general instead of specific and was unclear. Here's what I want:
\usemodule[MyCrop] \setupcrop[mark=camera,info=yes] % or \setupcrop[mark=cross,info=no] or any combination
This should work. The only thing that is missing, is a call (at the end of \setupcrop) to a separate routine (based on your \doifelse construct), which sets up the background.
Or have i missed something? :)
this is what the \setvariables[blabla][set=whatever-needs-to-be-done-setup] does Hans ----------------------------------------------------------------- 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 -----------------------------------------------------------------
Thomas A. Schmitz wrote:
Sorry, I was trying to be general instead of specific and was unclear. Here's what I want:
\usemodule[MyCrop] \setupcrop[mark=camera,info=yes] % or \setupcrop[mark=cross,info=no] or any combination
My idea was to have nested \doifelse statements in the module itself (I got this idea from page-lay.tex):
\doifelse{\getvariable{Crop}{mark}{camera} {==> make page background camera-crops} {\doifelse{\getvariable{Crop}{mark}{cross} {==> make page background cross-crops} {do nothing}
My problem right now is that the assignment by the user given in the \setup-command is not read before the \doifelse within the module gets executed, so it always defaults to the "do nothing" part because the variables are empty. I hope that's clearer...
ok, so in that case, put the doifelse code in setups and use the 'set' options i mentioned; this is why i built this feature -) Hans ----------------------------------------------------------------- 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 -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Peter Rolf
-
Thomas A. Schmitz