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