ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \doassign variable - updates not picked up
@ 2021-01-22  8:48 Werner Hennrich
  2021-01-22 22:46 ` Wolfgang Schuster
  0 siblings, 1 reply; 3+ messages in thread
From: Werner Hennrich @ 2021-01-22  8:48 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1588 bytes --]

Hello everyone,

I'm using ConTeXt  (ver: 2020.09.20 23:02 LMTX) and have to have
conditional page headers based on specific content criteria. To achive
this I'd like to get some global variables in TeX, change their values
several times throughout the document and have my macro for the header
read them and act accordingly (like skip the header at all, change a
color, etc).

As a basis for this I established the following pattern in an iolated
test case:

    \def\setHeaderVar[#1]{
    \doassign[header][myvar=#1]
    \message{setHEADER: '#1'}
    }
    \def\getHeaderVar{\headermyvar}
    \setupheadertexts[\setups{page:header}]
    \startsetups page:header
    HEADER: myvar=\getHeaderVar
    \stopsetups
    \starttext
    \setHeaderVar[initval]
    page: 1
    \page
    \setHeaderVar[aaaaa]
    page: 2
    \page
    \setHeaderVar[bbbbb]
    page: 3
    \page
    \setHeaderVar[cccc]
    page: 4
    \page
    \setHeaderVar[]
    page: 5
    \stoptext

This works as expected and the header-macro prints the updated value.
But when I put the same pattern in my big environment-file, I can see
the variable being updated with different values (console), but the
header always puts out just the variable's initial value - so the
variable is read but it's updates aren't picked up by the header macro.
Peeking into console, log & tuc didn't raise any idea yet as to what is
going wrong...

Any idea what is happening and how I can fix this?

Any hints on how I can track this down?

Thanks a lot,
Werner Hennrich, Vienna AT



[-- Attachment #1.2: Type: text/html, Size: 3228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: \doassign variable - updates not picked up
  2021-01-22  8:48 \doassign variable - updates not picked up Werner Hennrich
@ 2021-01-22 22:46 ` Wolfgang Schuster
  2021-01-23 19:03   ` Werner Hennrich
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Schuster @ 2021-01-22 22:46 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Werner Hennrich schrieb am 22.01.2021 um 09:48:
> Hello everyone,
> 
> I'm using ConTeXt  (ver: 2020.09.20 23:02 LMTX) and have to have 
> conditional page headers based on specific content criteria. To achive 
> this I'd like to get some global variables in TeX, change their values 
> several times throughout the document and have my macro for the header 
> read them and act accordingly (like skip the header at all, change a 
> color, etc).
> 
> As a basis for this I established the following pattern in an iolated 
> test case:
> 
>     \def\setHeaderVar[#1]{
>     \doassign[header][myvar=#1]
>     \message{setHEADER: '#1'}
>     }
>     \def\getHeaderVar{\headermyvar}
>     \setupheadertexts[\setups{page:header}]
>     \startsetups page:header
>     HEADER: myvar=\getHeaderVar
>     \stopsetups
>     \starttext
>     \setHeaderVar[initval]
>     page: 1
>     \page
>     \setHeaderVar[aaaaa]
>     page: 2
>     \page
>     \setHeaderVar[bbbbb]
>     page: 3
>     \page
>     \setHeaderVar[cccc]
>     page: 4
>     \page
>     \setHeaderVar[]
>     page: 5
>     \stoptext
> 
> This works as expected and the header-macro prints the updated value. 
> But when I put the same pattern in my big environment-file, I can see 
> the variable being updated with different values (console), but the 
> header always puts out just the variable's initial value - so the 
> variable is read but it's updates aren't picked up by the header macro. 
> Peeking into console, log & tuc didn't raise any idea yet as to what is 
> going wrong...
> 
> Any idea what is happening and how I can fix this?

I guess you set the value in a local group and at the end of the group
your setting is forgotten, a simple change you can make is to replace
\doassign with \getgparameters which makes global settings.


A alternative to your current approach is to use the variables mechanism
to set and access values (you still have to ensure all values you set
are global).

\setupheadertexts[\getvariable{header}{text}]

\starttext

\setgvariables[header][text=First page]
Page 1

\page

\setgvariables[header][text=Last page]
Page 2

\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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: \doassign variable - updates not picked up
  2021-01-22 22:46 ` Wolfgang Schuster
@ 2021-01-23 19:03   ` Werner Hennrich
  0 siblings, 0 replies; 3+ messages in thread
From: Werner Hennrich @ 2021-01-23 19:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 22.01.21 um 23:46 schrieb Wolfgang Schuster:
> I guess you set the value in a local group and at the end of the group
> your setting is forgotten, ...

you're right Wolfgang!

I removed a \begingroup-\endgroup pair in the macro that sets the value
by calling my \setHeaderVar and now I get the updates being visible
inside the header code.

> a simple change you can make is to replace
> \doassign with \getgparameters which makes global settings.

I couldn't find any docu on \getgparameters except for its parameter
list (in setup-en.pdf) but what I have now will totally suffice.

> A alternative to your current approach is to use the variables mechanism
> to set and access values (you still have to ensure all values you set
> are global).

I didn't even try the \setvariables approach now,
even though I had checked that one out before I wrote to this list
(w/out checking the begin/endgroup thing though).

Thank you very much and best regards,
Werner


___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2021-01-23 19:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22  8:48 \doassign variable - updates not picked up Werner Hennrich
2021-01-22 22:46 ` Wolfgang Schuster
2021-01-23 19:03   ` Werner Hennrich

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).