ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Rik Kabel <context@rik.users.panix.com>
To: ntg-context@ntg.nl
Subject: Re: Expansion help needed, getvariable and TABLE
Date: Wed, 31 Jan 2018 09:47:11 -0500	[thread overview]
Message-ID: <1b425461-bb0a-fcbc-68b5-6552fe971dba@rik.users.panix.com> (raw)
In-Reply-To: <5A715C83.3030206@gmail.com>


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

On 2018-01-31 01:04, Wolfgang Schuster wrote:
>
>> Rik Kabel <mailto:context@rik.users.panix.com>
>> 31. Januar 2018 um 03:10
>>
>> 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?
>>
>>
> Natural tables collect the content of all cells to perform the width 
> and height calculations
> and you have to expand the content of the cells to get the current 
> value of \getvariable.
>
> \starttexdefinition unexpanded doTableRow #SET
>     \bTR
>       \expanded{\bTC\getvariable{#SET}{a}\eTC}
>       \expanded{\bTC\getvariable{#SET}{b}\eTC}
>     \eTR
> \stoptexdefinition
>
>
> BTW: You can use the \processcommacommand command when you save your 
> lists in a macro (no need for \expandafter).
>
> \defineexpandable\Sets{one,two}
>
> \processcommacommand[\Sets]\doInlineTextExp
>
>
> Wolfgang

Thank you for the help and the processcommacommand bit. However, the 
problem is still there (and I was just wrong in my own follow-up).

Below is an updated example with and without the \expanded{\bTC...

It does not seem to make a difference here, but perhaps it is needed in 
some situations.

My question is about factoring the \getvariable out of the \bTC rows (in 
this example) and \defining a simpler macro to hold the value. Should it 
be done, and if so, how?

    % macros=mkvi engine=luajittex

    \setvariables      [one]
                        [a=1aaaaaaaa,b=1b,c=1c]
    \setvariables      [two]
                        [a=2a,b=2bbbbbbbbbbbbbbbb,c=2c]

    \defineexpandable  \Sets
                        {one,two}

    \starttexdefinition unexpanded doInlineText #SET
         Direct: \getvariable{#SET}{a} \getvariable{#SET}{b}\
                 \getvariable{#SET}{c}\par
    \stoptexdefinition

    \starttexdefinition unexpanded doTableRow #SET
         \bTR
           \bTC\getvariable{#SET}{a}\eTC
           \bTC\getvariable{#SET}{b}\eTC
           \bTC\getvariable{#SET}{c}\eTC
         \eTR
    \stoptexdefinition

    \starttexdefinition doInlineTextExpA #SET
         \define\A{\getvariable{#SET}{a}}
         \define\B{\getvariable{#SET}{b}}
         \define\C{\getvariable{#SET}{c}}
         Factored A: \A\ \B\ \C\par
    \stoptexdefinition

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

    \starttexdefinition doInlineTextExpB #SET
         \define\A{\getvariable{#SET}{a}}
         \define\B{\getvariable{#SET}{b}}
         \define\C{\getvariable{#SET}{c}}
         Factored B: \A\ \B\ \C\par
    \stoptexdefinition

    \starttexdefinition doTableRowExpB #SET
         \define\A{\getvariable{#SET}{a}}
         \define\B{\getvariable{#SET}{b}}
         \define\C{\getvariable{#SET}{c}}
         \bTR
           \expanded{\bTC\A\eTC}
           \expanded{\bTC\B\eTC}
           \expanded{\bTC\C\eTC}
         \eTR
    \stoptexdefinition

    \starttext

         \processcommacommand[\Sets]\doInlineText

         \bTABLE[frame=off]
           \bTABLEhead
             \bTR[nc=2]
               \bTH Direct\eTH
             \eTR
           \eTABLEhead
           \bTABLEbody
               \processcommacommand[\Sets]\doTableRow
           \eTABLEbody
         \eTABLE

         \processcommacommand[\Sets]\doInlineTextExpA

         \bTABLE[frame=off]
           \bTABLEhead
             \bTR[nc=2]
               \bTH Factored A\eTH
             \eTR
           \eTABLEhead
           \bTABLEbody
             \processcommacommand[\Sets]\doTableRowExpA
           \eTABLEbody
         \eTABLE

         \processcommacommand[\Sets]\doInlineTextExpB

         \bTABLE[frame=off]
           \bTABLEhead
             \bTR[nc=2]
               \bTH Factored B\eTH
             \eTR
           \eTABLEhead
           \bTABLEbody
             \processcommacommand[\Sets]\doTableRowExpB
           \eTABLEbody
         \eTABLE

    \stoptext



-- 
RIk


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

[-- Attachment #2: Type: text/plain, Size: 492 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
___________________________________________________________________________________

  reply	other threads:[~2018-01-31 14:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31  2:10 Rik Kabel
2018-01-31  2:31 ` Rik Kabel
2018-01-31  6:04 ` Wolfgang Schuster
2018-01-31 14:47   ` Rik Kabel [this message]
2018-01-31 14:54     ` Wolfgang Schuster
2018-01-31 15:40       ` Rik Kabel
2018-01-31 16:06         ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b425461-bb0a-fcbc-68b5-6552fe971dba@rik.users.panix.com \
    --to=context@rik.users.panix.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).