* [NTG-context] Re: Why does \setvalue not work inside \startbodymatter?
[not found] ` <265776900.985576.1747583857093@mail.yahoo.com>
@ 2025-05-19 6:46 ` Hans Hagen via ntg-context
2025-05-19 18:28 ` Wolfgang Schuster
1 sibling, 0 replies; 2+ messages in thread
From: Hans Hagen via ntg-context @ 2025-05-19 6:46 UTC (permalink / raw)
To: Joel via ntg-context; +Cc: Hans Hagen
On 5/18/2025 5:57 PM, Joel via ntg-context wrote:
> I have a document setup with:
>
> \starttext
> \startfrontmatter
> (contains all front matter content)
> \stopfrontmatter
>
> \startbodymatter
>
> \stopbodymatter
>
> \startbackmatter
>
> \stopbackmatter
> \stoptext
>
> I was noticing very strange behavior where \setvalue was not showing up
> as \getvalue. I put it in lots of pllaces, but in the main part of the
> document, it wasn't working. Its like it was never set. After a lot of
> testing, I discovered if \setvalue is set inside \startbodymatter, its
> value stays unset. But I can set it in the front matter, backmatter,
> anywhere else. Here is my minimum working example, note that
> \getvalue{B} never appears, it was set within the bodymatter.
>
> \setvalue{A}{this is a test}
>
> \starttext
>
> \startbodymatter
> \setvalue{B}{Why is hits one missing?}
>
> \stopbodymatter
>
> \startbackmatter
>
> \dostepwiserecurse{1}{3}{1}{
>
> \setvalue{C}{this is yet another test}
>
> \getvalue{A}
> \getvalue{B}
> \getvalue{C}
>
> }
>
> \stopbackmatter
>
>
> \stoptext
>
>
>
> What is going on? Should I no longer be using the \startbodymatter, etc.
> items?
\setgvalue (global)
or sometimes you need
\setxvalue (global and expanded)
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* [NTG-context] Re: Why does \setvalue not work inside \startbodymatter?
[not found] ` <265776900.985576.1747583857093@mail.yahoo.com>
2025-05-19 6:46 ` [NTG-context] Re: Why does \setvalue not work inside \startbodymatter? Hans Hagen via ntg-context
@ 2025-05-19 18:28 ` Wolfgang Schuster
1 sibling, 0 replies; 2+ messages in thread
From: Wolfgang Schuster @ 2025-05-19 18:28 UTC (permalink / raw)
To: ntg-context
Am 18.05.2025 um 17:57 schrieb Joel via ntg-context:
> I have a document setup with:
>
> \starttext
> \startfrontmatter
> (contains all front matter content)
> \stopfrontmatter
>
> \startbodymatter
>
> \stopbodymatter
>
> \startbackmatter
>
> \stopbackmatter
> \stoptext
>
> I was noticing very strange behavior where \setvalue was not showing up
> as \getvalue. I put it in lots of pllaces, but in the main part of the
> document, it wasn't working. Its like it was never set. After a lot of
> testing, I discovered if \setvalue is set inside \startbodymatter, its
> value stays unset. But I can set it in the front matter, backmatter,
> anywhere else. Here is my minimum working example, note that
> \getvalue{B} never appears, it was set within the bodymatter.
>
> \setvalue{A}{this is a test}
>
> \starttext
>
> \startbodymatter
> \setvalue{B}{Why is hits one missing?}
>
> \stopbodymatter
>
> \startbackmatter
>
> \dostepwiserecurse{1}{3}{1}{
>
> \setvalue{C}{this is yet another test}
>
> \getvalue{A}
> \getvalue{B}
> \getvalue{C}
>
> }
>
> \stopbackmatter
>
>
> \stoptext
>
>
>
> What is going on? Should I no longer be using the \startbodymatter, etc.
> items?
You already got your answer to the problem by Hans but the example below
shows why you need \setgavlue.
When you use section blocks ConTeXt creates a local group with the
environment where command definitions stay local to the group, e.g. the
\setvalue setting in the block is forgotten at the end of the block and
whatever was set before the block is restored. When you now use
\setgvalue to value is set at a global level and is kept even when we
leave the group which can be seen with the C value.
In your real document you should also avoid short identifiers like A
with \setvalue because when you use \setvalue{A}{...} you're doing the
same as \def\A{...}. To avoud redefining existing commmands use a prefix
for your command names because unlike \def you can use special symbols
like : or _ within \setvalue.
%%%% begin example
\startbuffer[getvalue]
\starttabulate[|T||]
\NC Joel:A \EQ \getvalue{Joel:A} \NC\NR
\NC Joel:B \EQ \getvalue{Joel:B} \NC\NR
\NC Joel:C \EQ \getvalue{Joel:C} \NC\NR
\stoptabulate
\stopbuffer
\setupsectionblock[bodypart][page=no]
\starttext
\setvalue{Joel:A}{First value}
\setvalue{Joel:B}{Second value}
\getbuffer[getvalue]
\startbodymatter
\setvalue {Joel:B}{Local value for B}
\setgvalue{Joel:C}{Global value for C}
\getbuffer[getvalue]
\stopbodymatter
\getbuffer[getvalue]
\stoptext
%%%% end example
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-19 18:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <265776900.985576.1747583857093.ref@mail.yahoo.com>
[not found] ` <265776900.985576.1747583857093@mail.yahoo.com>
2025-05-19 6:46 ` [NTG-context] Re: Why does \setvalue not work inside \startbodymatter? Hans Hagen via ntg-context
2025-05-19 18:28 ` Wolfgang Schuster
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).