ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* variables
@ 2003-07-15 12:59 Peter Rolf
  2003-07-15 14:22 ` variables Taco Hoekwater
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Rolf @ 2003-07-15 12:59 UTC (permalink / raw)


I want to test, if a given variable is empty or not. I tried the following,
but the test is always false. Is this a bug or a feature ;)
Any help is welcome.


\starttext

\setvariables[test]
  [first=,
   second=something,]

\def\TestVAR#1{\getvariable{test}{#1}}

\if\TestVAR{first}\empty %
  The variable test:first is empty.\else
  The variable test:first contains \TestVAR{first}.\fi

\if\TestVAR{second}\empty %
  The variable test:second is empty.\else
  The variable test:second contains \TestVAR{second}.\fi

\stoptext


Regards,

   Peter

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

* Re: variables
  2003-07-15 12:59 variables Peter Rolf
@ 2003-07-15 14:22 ` Taco Hoekwater
  2003-07-16  9:11   ` variables Peter Rolf
  0 siblings, 1 reply; 3+ messages in thread
From: Taco Hoekwater @ 2003-07-15 14:22 UTC (permalink / raw)
  Cc: peter.rolf

On Tue, 15 Jul 2003 14:59:44 +0200, Peter wrote:

> I want to test, if a given variable is empty or not. I tried the following,
> but the test is always false. Is this a bug or a feature ;)

It is a  feature/bug of TeX itself that "\if" tests perform a conditionality test 
that is not even remotely intuitive ;-) 

The '\if' looks ahead to see if the next two non-expandable tokens have 
the same 'character code' *after* expansion. It will actually compare 's' 
to 'o' in the "second" example (false). The input "second=oops" would have
given a 'true' result, but would also have typeset the extra letters ('ps') as a 
side-effect.

TeX's \if test can be quite confusing and should normally not
be used in a document. It is much better to use one of ConTeXt's
predefined commands, like this one:

	\doifelse 
            {\TestVAR{first}}
            {}
            {The variable test:first is empty.}
            {The variable test:first contains \TestVAR{first}.}

this compares argument #1 to argument #2, executing #3 or #4 depending
on the outcome of the test.

Greetings, Taco

> Any help is welcome.
> 
> 
> \starttext
> 
> \setvariables[test]
>   [first=,
>    second=something,]
> 
> \def\TestVAR#1{\getvariable{test}{#1}}
> 
> \if\TestVAR{first}\empty %
>   The variable test:first is empty.\else
>   The variable test:first contains \TestVAR{first}.\fi
> 
> \if\TestVAR{second}\empty %
>   The variable test:second is empty.\else
>   The variable test:second contains \TestVAR{second}.\fi
> 
> \stoptext
> 
> 
> Regards,
> 
>    Peter
> 
> 
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context


-- 
groeten,

Taco

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

* Re: variables
  2003-07-15 14:22 ` variables Taco Hoekwater
@ 2003-07-16  9:11   ` Peter Rolf
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Rolf @ 2003-07-16  9:11 UTC (permalink / raw)


Thank you Taco for your exact answer. I will use \doifelse instead :)

Regards,

    Peter


Taco Hoekwater wrote:

>On Tue, 15 Jul 2003 14:59:44 +0200, Peter wrote:
>
>  
>
>>I want to test, if a given variable is empty or not. I tried the following,
>>but the test is always false. Is this a bug or a feature ;)
>>    
>>
>
>It is a  feature/bug of TeX itself that "\if" tests perform a conditionality test 
>that is not even remotely intuitive ;-) 
>
>The '\if' looks ahead to see if the next two non-expandable tokens have 
>the same 'character code' *after* expansion. It will actually compare 's' 
>to 'o' in the "second" example (false). The input "second=oops" would have
>given a 'true' result, but would also have typeset the extra letters ('ps') as a 
>side-effect.
>
>TeX's \if test can be quite confusing and should normally not
>be used in a document. It is much better to use one of ConTeXt's
>predefined commands, like this one:
>
>	\doifelse 
>            {\TestVAR{first}}
>            {}
>            {The variable test:first is empty.}
>            {The variable test:first contains \TestVAR{first}.}
>
>this compares argument #1 to argument #2, executing #3 or #4 depending
>on the outcome of the test.
>
>Greetings, Taco
>
>  
>
>>Any help is welcome.
>>
>>
>>\starttext
>>
>>\setvariables[test]
>>  [first=,
>>   second=something,]
>>
>>\def\TestVAR#1{\getvariable{test}{#1}}
>>
>>\if\TestVAR{first}\empty %
>>  The variable test:first is empty.\else
>>  The variable test:first contains \TestVAR{first}.\fi
>>
>>\if\TestVAR{second}\empty %
>>  The variable test:second is empty.\else
>>  The variable test:second contains \TestVAR{second}.\fi
>>
>>\stoptext
>>
>>
>>Regards,
>>
>>   Peter
>>
>>
>>_______________________________________________
>>ntg-context mailing list
>>ntg-context@ntg.nl
>>http://www.ntg.nl/mailman/listinfo/ntg-context
>>    
>>
>
>
>  
>

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

end of thread, other threads:[~2003-07-16  9:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15 12:59 variables Peter Rolf
2003-07-15 14:22 ` variables Taco Hoekwater
2003-07-16  9:11   ` variables Peter Rolf

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