From: Taco Hoekwater <taco@elvenkind.com>
Cc: peter.rolf@arcor.de
Subject: Re: variables
Date: Tue, 15 Jul 2003 16:22:23 +0200 [thread overview]
Message-ID: <20030715162223.5116578c.taco@elvenkind.com> (raw)
In-Reply-To: <3F13FAC0.4040502@arcor.de>
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
next prev parent reply other threads:[~2003-07-15 14:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-15 12:59 variables Peter Rolf
2003-07-15 14:22 ` Taco Hoekwater [this message]
2003-07-16 9:11 ` variables Peter Rolf
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=20030715162223.5116578c.taco@elvenkind.com \
--to=taco@elvenkind.com \
--cc=ntg-context@ntg.nl \
--cc=peter.rolf@arcor.de \
/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).