[NTG-context] Expansion help needed, getvariable and TABLE

Rik Kabel context at rik.users.panix.com
Wed Jan 31 03:31:32 CET 2018


On 2018-01-30 21:10, Rik Kabel wrote:
>
> Listers,
>
> I have a problem, and a question on ConTeXt programming efficiency.
>
> In the example below, I have a set of variables. When these are 
> reference directly via \getvariable, everything works as expected in 
> simple text and in TABLEs. When I \define a macro to the \getvariable, 
> that works in simple text, but only the value of the last iteration 
> appears in the TABLE. The macro definition is saved and when it is 
> used, that is the value that it has.
>
> So, how can I \define (or \def, ...) a macro to the expanded value to 
> avoid this? That is the problem.
>
> The question is, Is there is any advantage to be had in doing this? 
> Assume that the value is referenced many (tens of) times. There seems 
> to be an aesthetic value of factoring out the multiple identical 
> instances of the \getvariable syntax and assigning a more semantically 
> informative name, but beyond that, is there any other value?
>

Replying to my own query, I see that I just have to localize the 
definitions by grouping them, as

\starttexdefinition doTableRowExp #SET
    {\define\A{\getvariable{#SET}{a}}
     \define\B{\getvariable{#SET}{b}}
     \bTR
       \bTC\A\eTC
       \bTC\B\eTC
     \eTR}
\stoptexdefinition

Does it matter if I use {}, \bgroup\egroup, or some other mechanism?

My style question is still outstanding.

-- 
Rik


More information about the ntg-context mailing list