ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* def with if..else fails in TABLE
@ 2005-10-17 22:06 Henning Hraban Ramm
  2005-10-18  8:23 ` Peter Rolf
  0 siblings, 1 reply; 8+ messages in thread
From: Henning Hraban Ramm @ 2005-10-17 22:06 UTC (permalink / raw)


Salute wizards!

I tried to write a macro for a TABLE line:

\def\TestCmd{\dodoubleempty\doTestCmd}
\def\doTestCmd[#1][#2]#3{\bTR\bTD #3
     \iffirstargument\hfill (#1)\fi
     \eTD \bTD
     \ifsecondargument
         3: #2 and #3
     \else
         2: only #3
     \fi
     \eTD\eTR
}

But it never goes into "else" (if #2 is empty, I get "3: and #3")!
And it's only with the table commands around.
Why? What can I do?


Grüßlis vom Hraban!
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

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

* Re: def with if..else fails in TABLE
  2005-10-17 22:06 def with if..else fails in TABLE Henning Hraban Ramm
@ 2005-10-18  8:23 ` Peter Rolf
  2005-10-18  9:08   ` Henning Hraban Ramm
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Rolf @ 2005-10-18  8:23 UTC (permalink / raw)


Hi Hraban,

Henning Hraban Ramm wrote:
> Salute wizards!
> 
> I tried to write a macro for a TABLE line:
> 
> \def\TestCmd{\dodoubleempty\doTestCmd}
> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>     \iffirstargument\hfill (#1)\fi
>     \eTD \bTD
>     \ifsecondargument
>         3: #2 and #3
>     \else
>         2: only #3
>     \fi
>     \eTD\eTR
> }
> 
> But it never goes into "else" (if #2 is empty, I get "3: and #3")!
> And it's only with the table commands around.
> Why? What can I do?
>
the numbering is not bound to the parameter number; it's just a counter.
calling the macro with two arguments ->
  \iffirstargument  is true
  \ifsecondargument is true
  \ifthirdargument  is false


so simpy start your code with up-down testing of the argument number

\ifthirdargument % [#1][#2]#3
  ...
\else
  \ifsecondargument % [#1 or #2; you must decide which one]#3
    ...
  \else % #3
    ...
  \fi
\fi


Greetings,

Peter

> 
> Grüßlis vom Hraban!
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
> 
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
> 
> 

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

* Re: def with if..else fails in TABLE
  2005-10-18  8:23 ` Peter Rolf
@ 2005-10-18  9:08   ` Henning Hraban Ramm
  2005-10-18 10:18     ` Peter Rolf
  2005-10-18 11:26     ` Peter Rolf
  0 siblings, 2 replies; 8+ messages in thread
From: Henning Hraban Ramm @ 2005-10-18  9:08 UTC (permalink / raw)


Am 2005-10-18 um 10:23 schrieb Peter Rolf:

>> I tried to write a macro for a TABLE line:
>>
>> \def\TestCmd{\dodoubleempty\doTestCmd}
>> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>>     \iffirstargument\hfill (#1)\fi
>>     \eTD \bTD
>>     \ifsecondargument
>>         3: #2 and #3
>>     \else
>>         2: only #3
>>     \fi
>>     \eTD\eTR
>> }
>>
>> But it never goes into "else" (if #2 is empty, I get "3: and #3")!
>> And it's only with the table commands around.
>> Why? What can I do?
>>
> the numbering is not bound to the parameter number; it's just a  
> counter.
> calling the macro with two arguments ->
>   \iffirstargument  is true
>   \ifsecondargument is true
>   \ifthirdargument  is false

But why *does it work* without the TABLE commands??
If it would be true (or at least the reason for my problem) what you  
wrote, the following should work:

\def\TestCmd{\dodoubleempty\doTestCmd}
\def\doTestCmd[#1][#2]#3{\bTR\bTD #3
     \ifsecondargument
         \iffirstargument\hfill (#1)\fi
         \eTD \bTD
         3(#1.#2.#3)
     \else
         \iffirstargument\hfill (#1)\fi
         \eTD \bTD
         2(#1/#2/#3)
     \fi
     \eTD\eTR
}

But there I get only a
! Incomplete \iftrue; all text was ignored after line 63.
<inserted text>
                 \fi



Grüßlis vom Hraban!
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

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

* Re: def with if..else fails in TABLE
  2005-10-18  9:08   ` Henning Hraban Ramm
@ 2005-10-18 10:18     ` Peter Rolf
  2005-10-18 11:26     ` Peter Rolf
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Rolf @ 2005-10-18 10:18 UTC (permalink / raw)


Henning Hraban Ramm wrote:
> Am 2005-10-18 um 10:23 schrieb Peter Rolf:
> 
>>> I tried to write a macro for a TABLE line:
>>>
>>> \def\TestCmd{\dodoubleempty\doTestCmd}
>>> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>>>     \iffirstargument\hfill (#1)\fi
>>>     \eTD \bTD
>>>     \ifsecondargument
>>>         3: #2 and #3
>>>     \else
>>>         2: only #3
>>>     \fi
>>>     \eTD\eTR
>>> }
>>>
>>> But it never goes into "else" (if #2 is empty, I get "3: and #3")!
>>> And it's only with the table commands around.
>>> Why? What can I do?
>>>
>> the numbering is not bound to the parameter number; it's just a  counter.
>> calling the macro with two arguments ->
>>   \iffirstargument  is true
>>   \ifsecondargument is true
>>   \ifthirdargument  is false
> 
> 
sorry, my fault. you are right :)

the numbers are bound to the parameter. and \ifthirdargument is always
true (not an optional parameter).

-----

\def\TestCmd{\dodoubleempty\doTestCmd}
\def\doTestCmd[#1][#2]#3{%
  \ifsecondargument
    \iffirstargument
      3(#1/#2/#3)
    \else
      2a(#1.#2.#3)
    \fi
  \else
    \iffirstargument
      2b(#1/#2/#3)
    \else
      1(#1/#2/#3)
    \fi
  \fi
}


\starttext

\TestCmd{C}

\TestCmd[A]{C}

\TestCmd[][B]{C}

\TestCmd[A][B]{C}

\stoptext

-----
this gives

1(//C)
2b(A//C)
3(/B/C)
3(A/B/C)


thanks for the lesson ;)

Peter

> But why *does it work* without the TABLE commands??

??? maybe an expansion problem. have you tried \expanded{\TestCmd...}

> If it would be true (or at least the reason for my problem) what you 
> wrote, the following should work:
> 
> \def\TestCmd{\dodoubleempty\doTestCmd}
> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>     \ifsecondargument
>         \iffirstargument\hfill (#1)\fi
>         \eTD \bTD
>         3(#1.#2.#3)
>     \else
>         \iffirstargument\hfill (#1)\fi
>         \eTD \bTD
>         2(#1/#2/#3)
>     \fi
>     \eTD\eTR
> }
> 
> But there I get only a
> ! Incomplete \iftrue; all text was ignored after line 63.
> <inserted text>
>                 \fi
> 
> 
> 
> Grüßlis vom Hraban!
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
> 
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
> 
> 

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

* Re: def with if..else fails in TABLE
  2005-10-18  9:08   ` Henning Hraban Ramm
  2005-10-18 10:18     ` Peter Rolf
@ 2005-10-18 11:26     ` Peter Rolf
  2005-10-18 11:39       ` Vit Zyka
  2005-10-18 20:07       ` Henning Hraban Ramm
  1 sibling, 2 replies; 8+ messages in thread
From: Peter Rolf @ 2005-10-18 11:26 UTC (permalink / raw)


Henning Hraban Ramm wrote:
> Am 2005-10-18 um 10:23 schrieb Peter Rolf:
> 
>>> I tried to write a macro for a TABLE line:
>>>
>>> \def\TestCmd{\dodoubleempty\doTestCmd}
>>> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>>>     \iffirstargument\hfill (#1)\fi
>>>     \eTD \bTD
>>>     \ifsecondargument
>>>         3: #2 and #3
>>>     \else
>>>         2: only #3
>>>     \fi
>>>     \eTD\eTR
>>> }
>>>
>>> But it never goes into "else" (if #2 is empty, I get "3: and #3")!
>>> And it's only with the table commands around.
>>> Why? What can I do?
>>>
>> the numbering is not bound to the parameter number; it's just a  counter.
>> calling the macro with two arguments ->
>>   \iffirstargument  is true
>>   \ifsecondargument is true
>>   \ifthirdargument  is false
> 
> 
> But why *does it work* without the TABLE commands??
> If it would be true (or at least the reason for my problem) what you 
> wrote, the following should work:
> 
> \def\TestCmd{\dodoubleempty\doTestCmd}
> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>     \ifsecondargument
>         \iffirstargument\hfill (#1)\fi
>         \eTD \bTD
>         3(#1.#2.#3)
>     \else
>         \iffirstargument\hfill (#1)\fi
>         \eTD \bTD
>         2(#1/#2/#3)
>     \fi
>     \eTD\eTR
> }
> 
> But there I get only a
> ! Incomplete \iftrue; all text was ignored after line 63.
> <inserted text>
>                 \fi
> 
>

The problem is, that the analysis of the \if?argument is not working
here. You always get three arguments inside the TABLE.
The following example shows this in the first three rows. If you use

\doifelsenothing{TEST}
  {NOTHING part}
  {SOMETHING part}%

it works (last three rows). Dunno why ;)

Greetings,

Peter

-----
% interface=en output=pdftex
% Time-stamp: <Dienstag, 18 Oktober 2005 13:01:19; param.tex>
%

\def\TestCmd{\dodoubleempty\doTestCmd}
\def\doTestCmd[#1][#2]#3{\bTR\bTD #3%
  \ifsecondargument
    \hfill (#1) 3: #2 and #3
  \else
    \iffirstargument
      \hfill (#1) 2: #3
    \else
      1: #3
    \fi
  \fi
  \eTD\eTR
}

\def\TestCmdA{\dodoubleempty\doTestCmdA}
\def\doTestCmdA[#1][#2]#3{\bTR\bTD #3%
  \doifelsenothing{#2}
    {\doifelsenothing{#1}
      {1: #3}
      {\hfill (#1) 2: #3}%
    }
    {\doifelsenothing{#1}
      {2: #2 and #3}
      {\hfill (#1) 3: #2 and #3}%
    }%
  \eTD\eTR
}

\starttext

\bTABLE

\TestCmd{C}
\TestCmd[A]{C}
\TestCmd[A][B]{C}

\TestCmdA{Z}
\TestCmdA[Y]{Z}
\TestCmdA[X][Y]{Z}

\eTABLE


\stoptext

%%% Local Variables:
%%% mode: context
%%% TeX-master: ""
%%% End:
-----


> 
> Grüßlis vom Hraban!
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
> 
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
> 
> 

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

* Re: def with if..else fails in TABLE
  2005-10-18 11:26     ` Peter Rolf
@ 2005-10-18 11:39       ` Vit Zyka
  2005-10-18 14:49         ` Hans Hagen
  2005-10-18 20:07       ` Henning Hraban Ramm
  1 sibling, 1 reply; 8+ messages in thread
From: Vit Zyka @ 2005-10-18 11:39 UTC (permalink / raw)


Peter Rolf wrote:
> Henning Hraban Ramm wrote:
> 
>>Am 2005-10-18 um 10:23 schrieb Peter Rolf:
>>
>>
>>>>I tried to write a macro for a TABLE line:
>>>>
>>>>\def\TestCmd{\dodoubleempty\doTestCmd}
>>>>\def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>>>>    \iffirstargument\hfill (#1)\fi
>>>>    \eTD \bTD
>>>>    \ifsecondargument
>>>>        3: #2 and #3
>>>>    \else
>>>>        2: only #3
>>>>    \fi
>>>>    \eTD\eTR
>>>>}
>>>>
>>>>But it never goes into "else" (if #2 is empty, I get "3: and #3")!
>>>>And it's only with the table commands around.
>>>>Why? What can I do?
>>>>
>>>
>>>the numbering is not bound to the parameter number; it's just a  counter.
>>>calling the macro with two arguments ->
>>>  \iffirstargument  is true
>>>  \ifsecondargument is true
>>>  \ifthirdargument  is false
>>
>>
>>But why *does it work* without the TABLE commands??
>>If it would be true (or at least the reason for my problem) what you 
>>wrote, the following should work:
>>
>>\def\TestCmd{\dodoubleempty\doTestCmd}
>>\def\doTestCmd[#1][#2]#3{\bTR\bTD #3
>>    \ifsecondargument
>>        \iffirstargument\hfill (#1)\fi
>>        \eTD \bTD
>>        3(#1.#2.#3)
>>    \else
>>        \iffirstargument\hfill (#1)\fi
>>        \eTD \bTD
>>        2(#1/#2/#3)
>>    \fi
>>    \eTD\eTR
>>}
>>
>>But there I get only a
>>! Incomplete \iftrue; all text was ignored after line 63.
>><inserted text>
>>                \fi
>>
>>
> 
> 
> The problem is, that the analysis of the \if?argument is not working
> here. You always get three arguments inside the TABLE.

I did not test but my opinion is:

- \if*argument is set in the \do*empty

- \bTR, \eTR has optional params so they also use \do*empty

- using test \if*argument AFTER \bTR, \bTD, ... is related to the \bTR, 
... number of arguments not to the \TestCmd.

vit

> The following example shows this in the first three rows. If you use
> 
> \doifelsenothing{TEST}
>   {NOTHING part}
>   {SOMETHING part}%
> 
> it works (last three rows). Dunno why ;)
> 
> Greetings,
> 
> Peter
> 
> -----
> % interface=en output=pdftex
> % Time-stamp: <Dienstag, 18 Oktober 2005 13:01:19; param.tex>
> %
> 
> \def\TestCmd{\dodoubleempty\doTestCmd}
> \def\doTestCmd[#1][#2]#3{\bTR\bTD #3%
>   \ifsecondargument
>     \hfill (#1) 3: #2 and #3
>   \else
>     \iffirstargument
>       \hfill (#1) 2: #3
>     \else
>       1: #3
>     \fi
>   \fi
>   \eTD\eTR
> }
> 
> \def\TestCmdA{\dodoubleempty\doTestCmdA}
> \def\doTestCmdA[#1][#2]#3{\bTR\bTD #3%
>   \doifelsenothing{#2}
>     {\doifelsenothing{#1}
>       {1: #3}
>       {\hfill (#1) 2: #3}%
>     }
>     {\doifelsenothing{#1}
>       {2: #2 and #3}
>       {\hfill (#1) 3: #2 and #3}%
>     }%
>   \eTD\eTR
> }
> 
> \starttext
> 
> \bTABLE
> 
> \TestCmd{C}
> \TestCmd[A]{C}
> \TestCmd[A][B]{C}
> 
> \TestCmdA{Z}
> \TestCmdA[Y]{Z}
> \TestCmdA[X][Y]{Z}
> 
> \eTABLE
> 
> 
> \stoptext
> 
> %%% Local Variables:
> %%% mode: context
> %%% TeX-master: ""
> %%% End:
> -----
> 
> 
> 
>>Grüßlis vom Hraban!
>>---
>>http://www.fiee.net/texnique/
>>http://contextgarden.net
>>http://www.cacert.org (I'm an assurer)
>>
>>_______________________________________________
>>ntg-context mailing list
>>ntg-context@ntg.nl
>>http://www.ntg.nl/mailman/listinfo/ntg-context
>>
>>
> 
> 
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
> 

-- 
=======================================================
Ing. Vít Zýka, Ph.D.                         TYPOkvítek

database publishing              databazove publikovani
data maintaining and typesetting in typographic quality
priprava dat a jejich sazba v typograficke kvalite

tel.: (+420) 777 198 189     www: http://typokvitek.com
=======================================================

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

* Re: def with if..else fails in TABLE
  2005-10-18 11:39       ` Vit Zyka
@ 2005-10-18 14:49         ` Hans Hagen
  0 siblings, 0 replies; 8+ messages in thread
From: Hans Hagen @ 2005-10-18 14:49 UTC (permalink / raw)


Vit Zyka wrote:

>
> I did not test but my opinion is:
>
> - \if*argument is set in the \do*empty
>
> - \bTR, \eTR has optional params so they also use \do*empty
>
> - using test \if*argument AFTER \bTR, \bTD, ... is related to the 
> \bTR, ... number of arguments not to the \TestCmd.

your opinion is right 

also, make sure that the if else fi don't span arguments (unless you know what you're doing), so: 

\bTD \iftrue \eTD \bTD \fi \eTD 

kind of things are tricky for instance when \bTD .. \eTD is defined as 

\def\bTD#1\eTD{...} 

conditionals are parsed in special ways in tex the program (speed optimiziation) 

Hans 



-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: def with if..else fails in TABLE
  2005-10-18 11:26     ` Peter Rolf
  2005-10-18 11:39       ` Vit Zyka
@ 2005-10-18 20:07       ` Henning Hraban Ramm
  1 sibling, 0 replies; 8+ messages in thread
From: Henning Hraban Ramm @ 2005-10-18 20:07 UTC (permalink / raw)


Am 2005-10-18 um 13:26 schrieb Peter Rolf:
> \doifelsenothing{TEST}
>   {NOTHING part}
>   {SOMETHING part}%

Thank you, I could solve it with that.

I already suspected that optional-argument-of-eTX issue, there were  
some error messages in other variants that I tried, that pointed in  
this direction, but I didn't knew how to solve it (thought about some  
\expand magic).
I guess I should finally buy the TeXbook and learn TeX (sigh, another  
old fashioned programming language...)




Grüßlis vom Hraban!
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

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

end of thread, other threads:[~2005-10-18 20:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-17 22:06 def with if..else fails in TABLE Henning Hraban Ramm
2005-10-18  8:23 ` Peter Rolf
2005-10-18  9:08   ` Henning Hraban Ramm
2005-10-18 10:18     ` Peter Rolf
2005-10-18 11:26     ` Peter Rolf
2005-10-18 11:39       ` Vit Zyka
2005-10-18 14:49         ` Hans Hagen
2005-10-18 20:07       ` Henning Hraban Ramm

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