ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* xml processing: if elseif else / switch case
@ 2021-12-09  8:19 Denis Maier via ntg-context
  2021-12-09 14:08 ` Joey McCollum via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Denis Maier via ntg-context @ 2021-12-09  8:19 UTC (permalink / raw)
  To: ntg-context; +Cc: denis.maier


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

Hi,

I was wondering whether we have tests similar to <if-else if-else> or <switch case> in context's xml processing. (And even in context more general...) I have found these doifelse tests, but elseif doesn't seem to exist. Is that correct? If yes, could that be added? Of course, you can always just nest doifelse-constructs, but that will become ugly quickly. Being able to specify multiple branches would be handy.

Best,
Denis

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

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09  8:19 xml processing: if elseif else / switch case Denis Maier via ntg-context
@ 2021-12-09 14:08 ` Joey McCollum via ntg-context
  2021-12-09 16:11   ` Wolfgang Schuster via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Joey McCollum via ntg-context @ 2021-12-09 14:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Joey McCollum


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

I believe \orelse might be what you want. It works with most \if... macros,
and it avoids nesting of \doifelse constructs. Here's an example, which I
use in conditionally removing preceding punctuation if any other keys are
defined before a specific one in an assignment:

```
      % If any of the preceding keys was specified, then replace any
preceding punctuation with a space
      % and typeset the number with its CSL abbreviation, followed by a
comma
      \ifdefined\btxsbllocvol
        \removeunwantedspaces\removepunctuation\btxspace
      \orelse\ifdefined\btxsbllocno
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocpt
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocp
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocn
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocfig
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocop
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocbk
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocep
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocchap
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocv
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocfol
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocfrag
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocpl
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsblloccol
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocl
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocsv
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \orelse\ifdefined\btxsbllocsec
        \removeunwantedspaces\removepunctuation\btxspace
      \fi
      \fi
```

Joey

On Thu, Dec 9, 2021, 3:19 AM Denis Maier via ntg-context <ntg-context@ntg.nl>
wrote:

> Hi,
>
>
>
> I was wondering whether we have tests similar to «if-else if-else» or
> «switch case» in context’s xml processing. (And even in context more
> general...) I have found these doifelse tests, but elseif doesn’t seem to
> exist. Is that correct? If yes, could that be added? Of course, you can
> always just nest doifelse-constructs, but that will become ugly quickly.
> Being able to specify multiple branches would be handy.
>
>
>
> Best,
>
> Denis
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

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

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 14:08 ` Joey McCollum via ntg-context
@ 2021-12-09 16:11   ` Wolfgang Schuster via ntg-context
  2021-12-09 16:28     ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2021-12-09 16:11 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Joey McCollum via ntg-context
  Cc: Wolfgang Schuster

Joey McCollum via ntg-context schrieb am 09.12.2021 um 15:08:
> I believe \orelse might be what you want. It works with most \if... 
> macros, and it avoids nesting of \doifelse constructs. Here's an 
> example, which I use in conditionally removing preceding punctuation 
> if any other keys are defined before a specific one in an assignment:
>
> ```
>       % If any of the preceding keys was specified, then replace any 
> preceding punctuation with a space
>     % and typeset the number with its CSL abbreviation, followed by a 
> comma
>       \ifdefined\btxsbllocvol
> \removeunwantedspaces\removepunctuation\btxspace
> \orelse\ifdefined\btxsbllocno
> \removeunwantedspaces\removepunctuation\btxspace
>       \fi
> \orelse\ifdefined\btxsbllocpt
>       [...]
>       \fi
> ```

The \fi at the end of each \orelse branch is wrong.

\ifdefined\btxsbllocvol
     ...
\orelse\ifdefined\btxsbllocno
     ...
\else
     ...
\fi

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 16:11   ` Wolfgang Schuster via ntg-context
@ 2021-12-09 16:28     ` Hans Hagen via ntg-context
  2021-12-09 16:30       ` Joey McCollum via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Hans Hagen via ntg-context @ 2021-12-09 16:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 12/9/2021 5:11 PM, Wolfgang Schuster via ntg-context wrote:
> Joey McCollum via ntg-context schrieb am 09.12.2021 um 15:08:
>> I believe \orelse might be what you want. It works with most \if... 
>> macros, and it avoids nesting of \doifelse constructs. Here's an 
>> example, which I use in conditionally removing preceding punctuation 
>> if any other keys are defined before a specific one in an assignment:
>>
>> ```
>>       % If any of the preceding keys was specified, then replace any 
>> preceding punctuation with a space
>>     % and typeset the number with its CSL abbreviation, followed by a 
>> comma
>>       \ifdefined\btxsbllocvol
>> \removeunwantedspaces\removepunctuation\btxspace
>> \orelse\ifdefined\btxsbllocno
>> \removeunwantedspaces\removepunctuation\btxspace
>>       \fi
>> \orelse\ifdefined\btxsbllocpt
>>       [...]
>>       \fi
>> ```
> 
> The \fi at the end of each \orelse branch is wrong.
> 
> \ifdefined\btxsbllocvol
>      ...
> \orelse\ifdefined\btxsbllocno
>      ...
> \else
>      ...
> \fi
and when 'string' comparison is needed one can do:

\starttext

\def\foo{foo}
\def\ofo{ofo}
\def\oof{oof}

\def\XXX{ofo}

\ifcstok\XXX\foo
     FOO
\orelse\ifcstok\XXX\ofo
     OFO
\orelse\ifcstok\XXX\oof
     OOF
\else
     XXX
\fi

\def\XXX{\ofo}

\iftok{\XXX}{\foo}%
     FOO
\orelse\iftok{\XXX}{\ofo}%
     OFO
\orelse\iftok{\XXX}{\oof}%
     OOF
\else
     XXX
\fi

\ifcstok{\XXX}\foo
     FOO
\orelse\ifcstok{\XXX}\ofo
     OFO
\orelse\ifcstok\XXX}\oof
     OOF
\else
     XXX
\fi

\stoptext

watch the subtle differences. It all makes coding in tex primitives a 
bit more visual appealing and readable. Oone of the objectives of lmtx 
is that users can read the context code without pondering too much about 
the syntax or getting depressed by possibly obscure helper macros and 
expansion trickery.

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 16:28     ` Hans Hagen via ntg-context
@ 2021-12-09 16:30       ` Joey McCollum via ntg-context
  2021-12-09 16:53         ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Joey McCollum via ntg-context @ 2021-12-09 16:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Joey McCollum


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

Thanks for correcting that, Wolfgang. I must have added the other \fi
instances because I was trying to use \orelse in MKIV and couldn't get it
to work. Is it only supported in LMTX?

Joey

On Thu, Dec 9, 2021 at 11:30 AM Hans Hagen via ntg-context <
ntg-context@ntg.nl> wrote:

> On 12/9/2021 5:11 PM, Wolfgang Schuster via ntg-context wrote:
> > Joey McCollum via ntg-context schrieb am 09.12.2021 um 15:08:
> >> I believe \orelse might be what you want. It works with most \if...
> >> macros, and it avoids nesting of \doifelse constructs. Here's an
> >> example, which I use in conditionally removing preceding punctuation
> >> if any other keys are defined before a specific one in an assignment:
> >>
> >> ```
> >>       % If any of the preceding keys was specified, then replace any
> >> preceding punctuation with a space
> >>     % and typeset the number with its CSL abbreviation, followed by a
> >> comma
> >>       \ifdefined\btxsbllocvol
> >> \removeunwantedspaces\removepunctuation\btxspace
> >> \orelse\ifdefined\btxsbllocno
> >> \removeunwantedspaces\removepunctuation\btxspace
> >>       \fi
> >> \orelse\ifdefined\btxsbllocpt
> >>       [...]
> >>       \fi
> >> ```
> >
> > The \fi at the end of each \orelse branch is wrong.
> >
> > \ifdefined\btxsbllocvol
> >      ...
> > \orelse\ifdefined\btxsbllocno
> >      ...
> > \else
> >      ...
> > \fi
> and when 'string' comparison is needed one can do:
>
> \starttext
>
> \def\foo{foo}
> \def\ofo{ofo}
> \def\oof{oof}
>
> \def\XXX{ofo}
>
> \ifcstok\XXX\foo
>      FOO
> \orelse\ifcstok\XXX\ofo
>      OFO
> \orelse\ifcstok\XXX\oof
>      OOF
> \else
>      XXX
> \fi
>
> \def\XXX{\ofo}
>
> \iftok{\XXX}{\foo}%
>      FOO
> \orelse\iftok{\XXX}{\ofo}%
>      OFO
> \orelse\iftok{\XXX}{\oof}%
>      OOF
> \else
>      XXX
> \fi
>
> \ifcstok{\XXX}\foo
>      FOO
> \orelse\ifcstok{\XXX}\ofo
>      OFO
> \orelse\ifcstok\XXX}\oof
>      OOF
> \else
>      XXX
> \fi
>
> \stoptext
>
> watch the subtle differences. It all makes coding in tex primitives a
> bit more visual appealing and readable. Oone of the objectives of lmtx
> is that users can read the context code without pondering too much about
> the syntax or getting depressed by possibly obscure helper macros and
> expansion trickery.
>
> Hans
>
>
> -----------------------------------------------------------------
>                                            Hans Hagen | PRAGMA ADE
>                Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>         tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

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

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 16:30       ` Joey McCollum via ntg-context
@ 2021-12-09 16:53         ` Hans Hagen via ntg-context
  2021-12-09 17:24           ` Denis Maier via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Hans Hagen via ntg-context @ 2021-12-09 16:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 12/9/2021 5:30 PM, Joey McCollum via ntg-context wrote:
> Thanks for correcting that, Wolfgang. I must have added the other \fi 
> instances because I was trying to use \orelse in MKIV and couldn't get 
> it to work. Is it only supported in LMTX?
yes, it's one of the native luametatex features (already there for a while)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 16:53         ` Hans Hagen via ntg-context
@ 2021-12-09 17:24           ` Denis Maier via ntg-context
  2021-12-09 17:32             ` Wolfgang Schuster via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Denis Maier via ntg-context @ 2021-12-09 17:24 UTC (permalink / raw)
  To: ntg-context; +Cc: denis.maier

Thanks for all the answers. That's helpful. But I think that does not work with the xml tests, or does it? I mean, is this a general mechanism?

Denis
________________________________________
Von: ntg-context <ntg-context-bounces@ntg.nl> im Auftrag von Hans Hagen via ntg-context <ntg-context@ntg.nl>
Gesendet: Donnerstag, 9. Dezember 2021 17:53:42
An: mailing list for ConTeXt users
Cc: Hans Hagen
Betreff: Re: [NTG-context] xml processing: if elseif else / switch case

On 12/9/2021 5:30 PM, Joey McCollum via ntg-context wrote:
> Thanks for correcting that, Wolfgang. I must have added the other \fi
> instances because I was trying to use \orelse in MKIV and couldn't get
> it to work. Is it only supported in LMTX?
yes, it's one of the native luametatex features (already there for a while)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 17:24           ` Denis Maier via ntg-context
@ 2021-12-09 17:32             ` Wolfgang Schuster via ntg-context
  2021-12-10 10:25               ` Denis Maier via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2021-12-09 17:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Denis Maier via ntg-context
  Cc: Wolfgang Schuster

Denis Maier via ntg-context schrieb am 09.12.2021 um 18:24:
> Thanks for all the answers. That's helpful. But I think that does not work with the xml tests, or does it? I mean, is this a general mechanism?

Since you didn't provide a example with your problem there is no way to 
tell how to improve it.

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: xml processing: if elseif else / switch case
  2021-12-09 17:32             ` Wolfgang Schuster via ntg-context
@ 2021-12-10 10:25               ` Denis Maier via ntg-context
  0 siblings, 0 replies; 9+ messages in thread
From: Denis Maier via ntg-context @ 2021-12-10 10:25 UTC (permalink / raw)
  To: wolfgang.schuster.lists, ntg-context, ntg-context; +Cc: denis.maier

Well, it was more a question out of curiosity, not a specific problem that needs to be solved. (Or actually, I found another solution for the problem I've had first.)
Anyway, I still think this would be handy as that would be a more maintainble control structure. I'll try to come up with an example next week... 

Denis 

> -----Ursprüngliche Nachricht-----
> Von: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
> Gesendet: Donnerstag, 9. Dezember 2021 18:32
> An: mailing list for ConTeXt users <ntg-context@ntg.nl>; Denis Maier via ntg-
> context <ntg-context@ntg.nl>
> Cc: Maier, Denis Christian (UB) <denis.maier@unibe.ch>
> Betreff: Re: [NTG-context] xml processing: if elseif else / switch case
> 
> Denis Maier via ntg-context schrieb am 09.12.2021 um 18:24:
> > Thanks for all the answers. That's helpful. But I think that does not work
> with the xml tests, or does it? I mean, is this a general mechanism?
> 
> Since you didn't provide a example with your problem there is no way to tell
> how to improve it.
> 
> 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2021-12-10 10:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09  8:19 xml processing: if elseif else / switch case Denis Maier via ntg-context
2021-12-09 14:08 ` Joey McCollum via ntg-context
2021-12-09 16:11   ` Wolfgang Schuster via ntg-context
2021-12-09 16:28     ` Hans Hagen via ntg-context
2021-12-09 16:30       ` Joey McCollum via ntg-context
2021-12-09 16:53         ` Hans Hagen via ntg-context
2021-12-09 17:24           ` Denis Maier via ntg-context
2021-12-09 17:32             ` Wolfgang Schuster via ntg-context
2021-12-10 10:25               ` Denis Maier via ntg-context

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