ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* test for (negative) number
@ 2012-08-20 16:00 Peter Rolf
  2012-08-20 18:11 ` Sietse Brouwer
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Rolf @ 2012-08-20 16:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

I used '\doifnumberelse' to validate some macro parameters (angle).
Sadly it does not work with negative numbers. Is there a similar macro,
that also supports negative values?

Example:

\doifnumberelse {45}{yes}{no}% yes
\doifnumberelse{-45}{yes}{no}% no


Greetings, Peter
___________________________________________________________________________________
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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: test for (negative) number
  2012-08-20 16:00 test for (negative) number Peter Rolf
@ 2012-08-20 18:11 ` Sietse Brouwer
  2012-08-21  6:32   ` Procházka Lukáš
  2012-08-21 15:13   ` Procházka Lukáš
  0 siblings, 2 replies; 7+ messages in thread
From: Sietse Brouwer @ 2012-08-20 18:11 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Peter,

I recommend using the following handy little idiom:
\ctxlua{commands.doifelse(-45 > 0)}{big}{small} % small

It lets you do all sorts of things that are tricky in TeX:
\ctxlua{ commands.doifelse( string.len( "-45" ) > 5 ) }{long}{short}

Cheers,
Sietse
___________________________________________________________________________________
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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: test for (negative) number
  2012-08-20 18:11 ` Sietse Brouwer
@ 2012-08-21  6:32   ` Procházka Lukáš
  2012-08-21  6:56     ` Wolfgang Schuster
  2012-08-21 15:13   ` Procházka Lukáš
  1 sibling, 1 reply; 7+ messages in thread
From: Procházka Lukáš @ 2012-08-21  6:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users


On Mon, 20 Aug 2012 20:11:32 +0200, Sietse Brouwer <sbbrouwer@gmail.com> wrote:

> Hi Peter,
>
> I recommend using the following handy little idiom:
> \ctxlua{commands.doifelse(-45 > 0)}{big}{small} % small
>
> It lets you do all sorts of things that are tricky in TeX:
> \ctxlua{ commands.doifelse( string.len( "-45" ) > 5 ) }{long}{short}
>
> Cheers,
> Sietse

... Has been wikified -

"http://wiki.contextgarden.net/Command/doif..."

Lukas


___________________________________________________________________________________
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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: test for (negative) number
  2012-08-21  6:32   ` Procházka Lukáš
@ 2012-08-21  6:56     ` Wolfgang Schuster
  2012-08-21  9:24       ` Peter Rolf
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2012-08-21  6:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 21.08.2012 um 08:32 schrieb Procházka Lukáš <LPr@pontex.cz>:

> 
> On Mon, 20 Aug 2012 20:11:32 +0200, Sietse Brouwer <sbbrouwer@gmail.com> wrote:
> 
>> Hi Peter,
>> 
>> I recommend using the following handy little idiom:
>> \ctxlua{commands.doifelse(-45 > 0)}{big}{small} % small
>> 
>> It lets you do all sorts of things that are tricky in TeX:
>> \ctxlua{ commands.doifelse( string.len( "-45" ) > 5 ) }{long}{short}
>> 
>> Cheers,
>> Sietse
> 
> ... Has been wikified -
> 
> "http://wiki.contextgarden.net/Command/doif…"

For functions in the commands namespace you can write e.g. \ctxcommand{doifelse(…)}{…}{…} instead of \ctxlua{commands.doifelse(…)}{…}{…}.

Wolfgang
___________________________________________________________________________________
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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: test for (negative) number
  2012-08-21  6:56     ` Wolfgang Schuster
@ 2012-08-21  9:24       ` Peter Rolf
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Rolf @ 2012-08-21  9:24 UTC (permalink / raw)
  To: ntg-context

Thanks for all the answers so far. The 'doifelse' should do the trick. I
was hoping for a system macro, but if there is none, I have to program
it myself. :-)

Peter

Am 21.08.2012 08:56, schrieb Wolfgang Schuster:
> 
> Am 21.08.2012 um 08:32 schrieb Procházka Lukáš <LPr@pontex.cz>:
> 
>>
>> On Mon, 20 Aug 2012 20:11:32 +0200, Sietse Brouwer <sbbrouwer@gmail.com> wrote:
>>
>>> Hi Peter,
>>>
>>> I recommend using the following handy little idiom:
>>> \ctxlua{commands.doifelse(-45 > 0)}{big}{small} % small
>>>
>>> It lets you do all sorts of things that are tricky in TeX:
>>> \ctxlua{ commands.doifelse( string.len( "-45" ) > 5 ) }{long}{short}
>>>
>>> Cheers,
>>> Sietse
>>
>> ... Has been wikified -
>>
>> "http://wiki.contextgarden.net/Command/doif…"
> 
> For functions in the commands namespace you can write e.g. \ctxcommand{doifelse(…)}{…}{…} instead of \ctxlua{commands.doifelse(…)}{…}{…}.
> 
> Wolfgang
> ___________________________________________________________________________________
> 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  : http://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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: test for (negative) number
  2012-08-20 18:11 ` Sietse Brouwer
  2012-08-21  6:32   ` Procházka Lukáš
@ 2012-08-21 15:13   ` Procházka Lukáš
  2012-08-21 16:42     ` Hans Hagen
  1 sibling, 1 reply; 7+ messages in thread
From: Procházka Lukáš @ 2012-08-21 15:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

... I also found another solution reposter before:

----
\ctxlua{commands.testcase(condition)}
   { If true...}
   {If false}
----

Note that both blocks (if-true and if-false) are mandatory.

Considering Wolfgang's last answer, it would be better to write:

----
\ctxcommand{testcase(condition)}
   { If true...}
   {If false}
----

Lukas



On Mon, 20 Aug 2012 20:11:32 +0200, Sietse Brouwer <sbbrouwer@gmail.com> wrote:

> Hi Peter,
>
> I recommend using the following handy little idiom:
> \ctxlua{commands.doifelse(-45 > 0)}{big}{small} % small
>
> It lets you do all sorts of things that are tricky in TeX:
> \ctxlua{ commands.doifelse( string.len( "-45" ) > 5 ) }{long}{short}
>
> Cheers,
> Sietse
> ___________________________________________________________________________________
> 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  : http://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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: test for (negative) number
  2012-08-21 15:13   ` Procházka Lukáš
@ 2012-08-21 16:42     ` Hans Hagen
  0 siblings, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2012-08-21 16:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 21-8-2012 17:13, Procházka Lukáš wrote:
> .... I also found another solution reposter before:
>
> ----
> \ctxlua{commands.testcase(condition)}
>    { If true...}
>    {If false}

yes, but testcase is an unfortunate name and sort of obsolete (so best 
use doifelse)

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2012-08-21 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-20 16:00 test for (negative) number Peter Rolf
2012-08-20 18:11 ` Sietse Brouwer
2012-08-21  6:32   ` Procházka Lukáš
2012-08-21  6:56     ` Wolfgang Schuster
2012-08-21  9:24       ` Peter Rolf
2012-08-21 15:13   ` Procházka Lukáš
2012-08-21 16:42     ` Hans Hagen

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