From: Peter Rolf <indiego@gmx.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Test whether variable has been set
Date: Sun, 27 May 2007 20:15:47 +0200 [thread overview]
Message-ID: <4659CAD3.90500@gmx.net> (raw)
In-Reply-To: <e65d34bf0705270758le3e64cfq4c4eda52ee88017e@mail.gmail.com>
Elliot Clifton schrieb:
> Hi Peter,
>
> Thanks for your reply. I think I may have misunderstood the variable
> section on the wiki. I been using \setvariable to both declare and
> assign variables from my component files. When I should have been
> declaring them in the environment file first, right?
As long as you can garantee, that your variables are declared *before*
they are read, things are ok. But an environment or extra file is IMO
the cleanest way.
Reading an undefined variable results in the \empty token. This can be
problematic, if you expect a number; e.g.
\dimexpr\getvariable{foo}{width}\relax.
Anyway, it's no good idea to use something that is not defined.
So you have to
- define a variable, before you use it or
- use the \doifnotvariable,\doifvariable and \doifelsevariable macros
before you try to read a (maybe undefined) variable.
I can't say much about the second one. Search the ConTeXt sources to get
an idea.
The \doifnothing,\doifsomething and \doifelsenothing macros just test,
if the variable is empty or not.
A variable can be defined with an empty value (\setvariable[foo][bar=]).
I use this for automatic size calculations. If no default value is
given, then the size is calculated in my macro.
> \setvariable[namespace][key=DefaultValue], right? So how do I test for
> a (Default)Value?
\doifsamestring{\getvariable{foo}{bar}} {your_default_value}
{equal}%
\doifsamestringelse{\getvariable{foo}{bar}} {your_default_value}
{equal}
{unequal}%
probably not the fastest variant. If I remember it right, I had some
problems with \doif comparison (catcodes?).
> Sorry, I'm just beginning TeX programming I don't understand how to do this.
>
No problem. If it's not in the WIKI, this is the place to ask.
Best, Peter
> Elliot
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive : https://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2007-05-27 18:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-27 14:58 Elliot Clifton
2007-05-27 15:55 ` Aditya Mahajan
2007-05-27 16:15 ` Hans Hagen
2007-05-27 18:15 ` Peter Rolf [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-05-27 11:15 Elliot Clifton
2007-05-27 13:26 ` 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=4659CAD3.90500@gmx.net \
--to=indiego@gmx.net \
--cc=ntg-context@ntg.nl \
/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).