ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Treat last element in a commalist differently
@ 2006-06-02 20:34 Aditya Mahajan
  2006-06-02 20:47 ` Taco Hoekwater
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2006-06-02 20:34 UTC (permalink / raw)


Hi,
  I am trying to write a macro so that

\SEQ X[1,2,3] expands to $X_1, X_2, X_3$
\SEQ X[1-N] expands to $X_1, \dots, X_N$
and
\SEQ X expands to ${\bf X}$.

So far I have

\def\SEQ#1%
   {\dodoubleempty\doSEQ[#1]}

\def\doSEQ[#1][#2]%
{\ifsecondargument \mathematics{\processcommalist[#2]{\dodoSEQ{#1}}}
\else \mathematics{\bold{#1}}\fi}

\def\dodoSEQ#1#2%
   {#1_{#2},}

\starttext
\SEQ X[1,2,3] is part of \SEQ X.
\stoptext

There is an extra comma at the end. That is,

\SEQ X[1,2,3] expands to $X_1,X_2,X_3,$
                                     ^^^

How can I treat the last element of a commalist differently?

Thanks,
Aditya

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

* Re: Treat last element in a commalist differently
  2006-06-02 20:34 Treat last element in a commalist differently Aditya Mahajan
@ 2006-06-02 20:47 ` Taco Hoekwater
  2006-06-02 21:09   ` Aditya Mahajan
  2006-06-03  5:45   ` Aditya Mahajan
  0 siblings, 2 replies; 6+ messages in thread
From: Taco Hoekwater @ 2006-06-02 20:47 UTC (permalink / raw)


Aditya Mahajan wrote:
> There is an extra comma at the end. That is,
> 
> \SEQ X[1,2,3] expands to $X_1,X_2,X_3,$
>                                      ^^^
> 
> How can I treat the last element of a commalist differently?

It is much easier to treat the first element as special:

   \def\doSEQ[#1][#2]%
     {\ifsecondargument
       \donefalse
       \mathematics{\processcommalist[#2]{\dodoSEQ{#1}}}
     \else \mathematics{\bold{#1}}\fi}

   \def\dodoSEQ#1#2%
     {\ifdone ,\else \donetrue\fi#1_{#2}}


Cheers, Taco

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

* Re: Treat last element in a commalist differently
  2006-06-02 20:47 ` Taco Hoekwater
@ 2006-06-02 21:09   ` Aditya Mahajan
  2006-06-02 21:37     ` Taco Hoekwater
  2006-06-03  5:45   ` Aditya Mahajan
  1 sibling, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2006-06-02 21:09 UTC (permalink / raw)


On Fri, 2 Jun 2006, Taco Hoekwater wrote:

> Aditya Mahajan wrote:
>> There is an extra comma at the end. That is,
>>
>> \SEQ X[1,2,3] expands to $X_1,X_2,X_3,$
>>                                      ^^^
>>
>> How can I treat the last element of a commalist differently?
>
> It is much easier to treat the first element as special:
>
>   \def\doSEQ[#1][#2]%
>     {\ifsecondargument
>       \donefalse
>       \mathematics{\processcommalist[#2]{\dodoSEQ{#1}}}
>     \else \mathematics{\bold{#1}}\fi}
>
>   \def\dodoSEQ#1#2%
>     {\ifdone ,\else \donetrue\fi#1_{#2}}
>

Thanks Taco,

  Works like ... er ... magic. Where is \done set to true?

Aditya

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

* Re: Treat last element in a commalist differently
  2006-06-02 21:09   ` Aditya Mahajan
@ 2006-06-02 21:37     ` Taco Hoekwater
  2006-06-03  4:42       ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Taco Hoekwater @ 2006-06-02 21:37 UTC (permalink / raw)


Aditya Mahajan wrote:
>>
>>  \def\dodoSEQ#1#2%
>>    {\ifdone ,\else \donetrue\fi#1_{#2}}
> 
> Thanks Taco,
> 
>   Works like ... er ... magic. Where is \done set to true?

  Right above here, in \dodoSEQ.

Taco

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

* Re: Treat last element in a commalist differently
  2006-06-02 21:37     ` Taco Hoekwater
@ 2006-06-03  4:42       ` Aditya Mahajan
  0 siblings, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2006-06-03  4:42 UTC (permalink / raw)


On Fri, 2 Jun 2006, Taco Hoekwater wrote:

> Aditya Mahajan wrote:
>>>
>>>  \def\dodoSEQ#1#2%
>>>    {\ifdone ,\else \donetrue\fi#1_{#2}}
>>
>> Thanks Taco,
>>
>>   Works like ... er ... magic. Where is \done set to true?
>
>  Right above here, in \dodoSEQ.

Duh... I need to read TeX code more carefully. Thanks.

Aditya

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

* Re: Treat last element in a commalist differently
  2006-06-02 20:47 ` Taco Hoekwater
  2006-06-02 21:09   ` Aditya Mahajan
@ 2006-06-03  5:45   ` Aditya Mahajan
  1 sibling, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2006-06-03  5:45 UTC (permalink / raw)


On Fri, 2 Jun 2006, Aditya Mahajan wrote:

> Hi,
>  I am trying to write a macro so that
>
> \SEQ X[1,2,3] expands to $X_1, X_2, X_3$
> \SEQ X[1-N] expands to $X_1, \dots, X_N$
> and
> \SEQ X expands to ${\bf X}$.
>
> So far I have

On Fri, 2 Jun 2006, Taco Hoekwater wrote:

> It is much easier to treat the first element as special:
>
>   \def\doSEQ[#1][#2]%
>     {\ifsecondargument
>       \donefalse
>       \mathematics{\processcommalist[#2]{\dodoSEQ{#1}}}
>     \else \mathematics{\bold{#1}}\fi}
>
>   \def\dodoSEQ#1#2%
>     {\ifdone ,\else \donetrue\fi#1_{#2}}
>

This is the final macro that I have, incase someone else is 
interested.

\def\SEQ#1%
   {\dodoubleempty\doSEQ[#1]}

\def\doSEQ[#1][#2]%
   {\ifsecondargument
     \donefalse
     \mathematics{\processcommalist[#2]{\dodoSEQ{#1}}}
   \else \mathematics{\bold{#1}}\fi}

\def\dodoSEQ#1#2%
   {\ifdone ,\else \donetrue\fi
     \doifelse{#2}{...}{\dots}{#1_{#2}}}

\starttext

\SEQ X[1,2] is part of \SEQ X[1,2,3,4] and \SEQ X[1,...,10]

\SEQ X[1,2,...,n-1,n,n+1,...,N]

\stoptext

Aditya

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

end of thread, other threads:[~2006-06-03  5:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-02 20:34 Treat last element in a commalist differently Aditya Mahajan
2006-06-02 20:47 ` Taco Hoekwater
2006-06-02 21:09   ` Aditya Mahajan
2006-06-02 21:37     ` Taco Hoekwater
2006-06-03  4:42       ` Aditya Mahajan
2006-06-03  5:45   ` Aditya Mahajan

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