ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to test the emptyness of a variable?
@ 2013-11-05 21:56 Géry Ogam
  2013-11-07 12:21 ` Procházka Lukáš Ing. - Pontex s. r. o.
  0 siblings, 1 reply; 8+ messages in thread
From: Géry Ogam @ 2013-11-05 21:56 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 791 bytes --]

Any idea for achieving this behaviour?

- When there is a chapter label (\setuplabeltext[chapter=CHAPTER~]), display
:

CHAPTER ONE Cool
CHAPTER 2 Cat
CHAPTER 3 Mouse
etc.

- When there is no chapter label (\setuplabeltext[chapter=]), display:

1 Cool
2 Cat
3 Mouse
etc.


My try achieves the first display, but not the second one since I don’t
know how to test the emptyness of the chapter label. When I remove the
chapter label, it displays:

ONE Cool
2 Cat
3 Mouse

 instead of:

1 Cool
2 Cat
3 Mouse


My code:

\setuplabeltext[chapter=CHAPTER~]
\define[1] \MyCommand{\doifelse{\currentsectioncountervalue}{1}{ONE}{#1}}
\setuphead[chapter][deepnumbercommand=\MyCommand]

\starttext

\chapter{Cool}
\chapter{Cat}
\chapter{Mouse}

\stoptext

[-- Attachment #1.2: Type: text/html, Size: 5040 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

* Re: How to test the emptyness of a variable?
  2013-11-05 21:56 How to test the emptyness of a variable? Géry Ogam
@ 2013-11-07 12:21 ` Procházka Lukáš Ing. - Pontex s. r. o.
  0 siblings, 0 replies; 8+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2013-11-07 12:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]

Hello,

Lua way:

----
\setuplabeltext[chapter=]

\define[1]\MyCommand{\ctxcommand{doifelse(1==\currentsectioncountervalue)}{ONE}{#1}}

\setuphead[chapter][deepnumbercommand=\MyCommand]

\starttext
   \chapter{Cool}
   \chapter{Cat}
   \chapter{Mouse}
\stoptext
----

I'm sure there is also a "cleaner" TeX way, but I'm not experienced enough for that.

Cheers,

Lukas


On Tue, 05 Nov 2013 22:56:54 +0100, Géry Ogam <maggyero@gmail.com> wrote:

> Any idea for achieving this behaviour?
>
> - When there is a chapter label (\setuplabeltext[chapter=CHAPTER~]), display
> :
>
> CHAPTER ONE Cool
> CHAPTER 2 Cat
> CHAPTER 3 Mouse
> etc.
>
> - When there is no chapter label (\setuplabeltext[chapter=]), display:
>
> 1 Cool
> 2 Cat
> 3 Mouse
> etc.
>
>
> My try achieves the first display, but not the second one since I don’t
> know how to test the emptyness of the chapter label. When I remove the
> chapter label, it displays:
>
> ONE Cool
> 2 Cat
> 3 Mouse
>
>  instead of:
>
> 1 Cool
> 2 Cat
> 3 Mouse
>
>
> My code:
>
> \setuplabeltext[chapter=CHAPTER~]
> \define[1] \MyCommand{\doifelse{\currentsectioncountervalue}{1}{ONE}{#1}}
> \setuphead[chapter][deepnumbercommand=\MyCommand]
>
> \starttext
>
> \chapter{Cool}
> \chapter{Cat}
> \chapter{Mouse}
>
> \stoptext
>


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 241 096 751
Fax: +420 244 461 038

[-- Attachment #2: t2.mkiv --]
[-- Type: application/octet-stream, Size: 247 bytes --]

\setuplabeltext[chapter=]

\define[1]\MyCommand{\ctxcommand{doifelse(1==\currentsectioncountervalue)}{ONE}{#1}}

\setuphead[chapter][deepnumbercommand=\MyCommand]

\starttext
  \chapter{Cool}
  \chapter{Cat}
  \chapter{Mouse}
\stoptext

[-- Attachment #3: t2.pdf --]
[-- Type: application/pdf, Size: 8207 bytes --]

[-- Attachment #4: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

* Re: How to test the emptyness of a variable?
@ 2013-11-10 16:32 Géry Ogam
  0 siblings, 0 replies; 8+ messages in thread
From: Géry Ogam @ 2013-11-10 16:32 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 750 bytes --]

Thank you very much Aditya, now it works.

As you said, the trick was to use \doiftextelse{}{}{} function as test of
emptyness function, and \labeltext{chapter} instead of
\currentstructurelabel as variable for the test because the latter was
never found empty, even when it was.

Thus the right code for me is:

\define[1]
\MyConversion{\doifelse{\currentsectioncountervalue}{1}{\doiftextelse{\labeltext{chapter}}{ONE}{#1}}{#1}}
\defineconversion[MyConversion][\MyConversion]
\setuphead[chapter][conversion=MyConversion]

\starttext

\setuplabeltext[chapter=]
    \chapter{Cool}
    \chapter{Cat}
    \chapter{Mouse}

\setuplabeltext[chapter=CHAPTER~]
\setupheadnumber[chapter][0]
    \chapter{Cool}
    \chapter{Cat}
    \chapter{Mouse}

\stoptext

[-- Attachment #1.2: Type: text/html, Size: 1071 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

* Re: How to test the emptyness of a variable?
  2013-11-07 17:45 Géry Ogam
@ 2013-11-09 19:55 ` Aditya Mahajan
  0 siblings, 0 replies; 8+ messages in thread
From: Aditya Mahajan @ 2013-11-09 19:55 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1287 bytes --]

On Thu, 7 Nov 2013, Géry Ogam wrote:

>> I'm sure there is also a "cleaner" TeX way, but I'm not experienced
> enough for that.
>
> I think you misunderstood my issue: your Lua way does the same thing than
> my TeX way: it displays:
>
> ONE Cool
> 2 Cat
> 3 Mouse
>
> but that is NOT what I want. What I want is:
>
> 1 Cool
> 2 Cat
> 3 Mouse
>
> So I need to check if the chapter label has been set empty or not by the
> user, because it is not empty (let's say the user chose the string
> "CHAPTER~" for the chapter label) I want to display this:
>
> CHAPTER ONE Cool
> CHAPTER 2 Cat
> CHAPTER 3 Mouse

> The way to do that is to check if the variable \currentstructurelabel is
> empty, so the code must be:

Why not just check the labeltext?

   \define[1]\MyConversion
       {\doifelse{#1}{1}{ONE}{#1}}

   \define\CheckedConversion % #1 number
       {\doiftextelse{\labeltexts{chapter}}\MyConversion\numbers}

   \defineconversion[CheckedConversion][\CheckedConversion]

   \setuphead[chapter][conversion=CheckedConversion]

   \doifmode{label}{\setuplabeltext[chapter=CHAPTER~]}
   \starttext
         \chapter{Cool}
         \chapter{Cat}
         \chapter{Mouse}
   \stoptext


compile with and without --mode=label.


Aditya

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

* How to test the emptyness of a variable?
@ 2013-11-07 17:45 Géry Ogam
  2013-11-09 19:55 ` Aditya Mahajan
  0 siblings, 1 reply; 8+ messages in thread
From: Géry Ogam @ 2013-11-07 17:45 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1316 bytes --]

> I'm sure there is also a "cleaner" TeX way, but I'm not experienced
enough for that.

I think you misunderstood my issue: your Lua way does the same thing than
my TeX way: it displays:

ONE Cool
2 Cat
3 Mouse

but that is NOT what I want. What I want is:

1 Cool
2 Cat
3 Mouse

So I need to check if the chapter label has been set empty or not by the
user, because it is not empty (let's say the user chose the string
"CHAPTER~" for the chapter label) I want to display this:

CHAPTER ONE Cool
CHAPTER 2 Cat
CHAPTER 3 Mouse

The way to do that is to check if the variable \currentstructurelabel is
empty, so the code must be:

\define[1]
\MyCommand{\doifelse{\currentsectioncountervalue}{1}{\doifnotemptyelse{\currentstructurelabel}{ONE}{#1}}{#1}}
\setuphead[chapter][deepnumbercommand=\MyCommand]

\starttext
    \setuplabeltext[chapter=CHAPTER~]
        \chapter{Cool}
        \chapter{Cat}
        \chapter{Mouse}
\stoptext

\starttext
    \setuplabeltext[chapter=]
        \chapter{Cool}
        \chapter{Cat}
        \chapter{Mouse}
\stoptext

But the problem is that in the second case, even if the chapter label is
set empty the command \doifnotemptyelse{\currentstructurelabel} thinks the
variable \currentstructurelabel is not empty. So there must be something
invisible in it, like a strut or something.

[-- Attachment #1.2: Type: text/html, Size: 1860 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

* How to test the emptyness of a variable?
@ 2013-11-05 12:41 Géry Ogam
  0 siblings, 0 replies; 8+ messages in thread
From: Géry Ogam @ 2013-11-05 12:41 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 737 bytes --]

> you can try
>
> \doifnothing\currentstructurelabel{Do something}


It does not work in my case (even if the currenstructurelabel is empty it
acts as if it not empty). In fact I asked that to get the following
behaviour:

— When there is a chapter label (\setuplabeltext[chapter=CHAPTER~]) I want
that:

CHAPTER ONE Cool
CHAPTER 2 Cat
CHAPTER 3 Mouse
etc.

— When there is no chapter label (\setuplabeltext[chapter=]) I want that:

1 Cool
2 Cat
3 Mouse
etc.


E.g.:

\setuplabeltext[chapter=CHAPTER~]
\define[1] \MyCommand{\doifelse{\currentsectioncountervalue}{1}{ONE}{#1}}
\setuphead[chapter][deepnumbercommand=\MyCommand]

\starttext

\chapter{Cool}
\chapter{Cat}
\chapter{Mouse}

\stoptext

[-- Attachment #1.2: Type: text/html, Size: 1397 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

* Re: How to test the emptyness of a variable?
  2013-11-04 23:42 Géry Ogam
@ 2013-11-05  8:29 ` Hans Hagen
  0 siblings, 0 replies; 8+ messages in thread
From: Hans Hagen @ 2013-11-05  8:29 UTC (permalink / raw)
  To: ntg-context

On 11/5/2013 12:42 AM, Géry Ogam wrote:
> Hello,
>
>
> How to test if the current structure label is empty? The following
> example does not work because I don’t know how to expand the variable
> \currentstructurelabel..
>
> E.g.:
>
> \define \MyCommand{\doifempty{\currentstructurelabel}{Do something}}

you can try

\doifnothing\currentstructurelabel{Do something}


>
> Best regards.
>
>
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>


-- 

-----------------------------------------------------------------
                                           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] 8+ messages in thread

* How to test the emptyness of a variable?
@ 2013-11-04 23:42 Géry Ogam
  2013-11-05  8:29 ` Hans Hagen
  0 siblings, 1 reply; 8+ messages in thread
From: Géry Ogam @ 2013-11-04 23:42 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 278 bytes --]

Hello,


How to test if the current structure label is empty? The following example
does not work because I don’t know how to expand the variable
\currentstructurelabel.

E.g.:

\define \MyCommand{\doifempty{\currentstructurelabel}{Do something}}


Best regards.

[-- Attachment #1.2: Type: text/html, Size: 471 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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] 8+ messages in thread

end of thread, other threads:[~2013-11-10 16:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-05 21:56 How to test the emptyness of a variable? Géry Ogam
2013-11-07 12:21 ` Procházka Lukáš Ing. - Pontex s. r. o.
  -- strict thread matches above, loose matches on Subject: below --
2013-11-10 16:32 Géry Ogam
2013-11-07 17:45 Géry Ogam
2013-11-09 19:55 ` Aditya Mahajan
2013-11-05 12:41 Géry Ogam
2013-11-04 23:42 Géry Ogam
2013-11-05  8:29 ` 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).