From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/113690 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joey McCollum via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: xml processing: if elseif else / switch case Date: Thu, 9 Dec 2021 11:30:45 -0500 Message-ID: References: <5a99613cd1254cf296a97aa479ee740b@unibe.ch> <9a9e1b91-9c28-1eab-0748-3ead0ded72ad@gmail.com> <62b08e5c-4ef8-fd93-63ba-90095f2626e9@xs4all.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1013386746553669985==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37371"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Joey McCollum To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Dec 09 17:39:34 2021 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvMSC-0009Sy-Ba for gctc-ntg-context-518@m.gmane-mx.org; Thu, 09 Dec 2021 17:39:32 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D5FEE2A1ED8; Thu, 9 Dec 2021 17:33:15 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F_xJykN0NUHC; Thu, 9 Dec 2021 17:33:14 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id E5CF52A1ED9; Thu, 9 Dec 2021 17:33:13 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id BA9442A1ED1 for ; Thu, 9 Dec 2021 17:33:11 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id txTZsPzo2THn for ; Thu, 9 Dec 2021 17:33:10 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.166.182; helo=mail-il1-f182.google.com; envelope-from=jmccollum20140511@gmail.com; receiver= Original-Received: from mail-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id EE6A22A1E5D for ; Thu, 9 Dec 2021 17:33:09 +0100 (CET) Original-Received: by mail-il1-f182.google.com with SMTP id t8so5831184ilu.8 for ; Thu, 09 Dec 2021 08:33:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=g9Gv2Vq3TLkwwkgyXKaYgVFNjTttd2c13WBrW4ZJpXQ=; b=TUf54Ek9OrTsdcehOUge2HKNsHhVjOikuTNjbSdhQUcjhpAcJZRC9mXKxh570dULSL WxuLuH2+Xl9pcxD4PuWUAl+IGoDSGPDiKA3CSwh/jCZQmprgyi91Nz8pNq4v9VUVwE3X Qk2400WH4nXIuu9Ol8LNWRzdcO8WLmKKVTHcGXPwRqcETlzDLtqzY9b6Qc7WbVkuLCow k6hEDo6hGxhLNGYc2O/IgdNtT7x2AFbPfqlfz83JhmwZ9alpsN/Mq/k3JZs0L3yv26d/ 0Gt6JfvwmKVoYOSs4FUKoW2cRtyENv0ckgjQE1GbIfPgV9yEkBBv9MCSI1f3L4eggdnA +KPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=g9Gv2Vq3TLkwwkgyXKaYgVFNjTttd2c13WBrW4ZJpXQ=; b=SPJUuxYyN7F8Yj21winY5/jAbKDk7ULXYNjS/pPaD54B03qNyCEl0dG1f1IwhIbpfQ kWfOmuaIyezN+dvsN7rwYPdAvI6d+k022u2ewkiMOEJa3CedbN/A1kgmiWLdU8NPVq1Z 2uX/ZWTGBbojiOUQP40v3ChNrC8nHQf8+aJgha1QIgLgWURfDx526VZTbSjeUxHtUu85 gIpsmqOxngYxVldeu/r6N8srWMrmm+piDtrzoN+r7NwhVUpLVLXmIvbxyEm1KnYgDeqt +PIKJMVbdmMjJGkljzYNwaHcfmzYtlo6mRY/5l/PCb1lQ8lcFNQJwOyVdaQx6G3oTzY6 ivmw== X-Gm-Message-State: AOAM533p/MPHNbBgvWjkCrAyIvs0vEIVFyqqVpARNsRPYg+JwfFDf5ha dy86Rqwah3gaPVCrS0FvDbxJCPP/OZIPLE/+6Vo9Dlsj X-Google-Smtp-Source: ABdhPJzSDg0Sx5pJZPeI+T6PVjWXl3tKaQKDuzewuxpxRis5VyIsqvhkrh5/yeR6Mxzzp2CvcVcpUhT22SfIahjy87g= X-Received: by 2002:a05:6e02:c94:: with SMTP id b20mr14901693ile.257.1639067588024; Thu, 09 Dec 2021 08:33:08 -0800 (PST) In-Reply-To: <62b08e5c-4ef8-fd93-63ba-90095f2626e9@xs4all.nl> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:113690 Archived-At: --===============1013386746553669985== Content-Type: multipart/alternative; boundary="00000000000058dc9f05d2b92901" --00000000000058dc9f05d2b92901 Content-Type: text/plain; charset="UTF-8" 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 > > ___________________________________________________________________________________ > --00000000000058dc9f05d2b92901 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for correcting that, Wolfgang. I must have added th= e other \fi instances because I was trying to use \orelse in MKIV and could= n't get it to work. Is it only supported in LMTX?

Jo= ey

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, W= olfgang 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 punctuati= on
>> if any other keys are defined before a specific one in an assignme= nt:
>>
>> ```
>> =C2=A0 =C2=A0 =C2=A0 % If any of the preceding keys was specified,= then replace any
>> preceding punctuation with a space
>> =C2=A0 =C2=A0 % and typeset the number with its CSL abbreviation, = followed by a
>> comma
>> =C2=A0 =C2=A0 =C2=A0 \ifdefined\btxsbllocvol
>> \removeunwantedspaces\removepunctuation\btxspace
>> \orelse\ifdefined\btxsbllocno
>> \removeunwantedspaces\removepunctuation\btxspace
>> =C2=A0 =C2=A0 =C2=A0 \fi
>> \orelse\ifdefined\btxsbllocpt
>> =C2=A0 =C2=A0 =C2=A0 [...]
>> =C2=A0 =C2=A0 =C2=A0 \fi
>> ```
>
> The \fi at the end of each \orelse branch is wrong.
>
> \ifdefined\btxsbllocvol
>=C2=A0 =C2=A0=C2=A0=C2=A0 ...
> \orelse\ifdefined\btxsbllocno
>=C2=A0 =C2=A0=C2=A0=C2=A0 ...
> \else
>=C2=A0 =C2=A0=C2=A0=C2=A0 ...
> \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
=C2=A0 =C2=A0 =C2=A0FOO
\orelse\ifcstok\XXX\ofo
=C2=A0 =C2=A0 =C2=A0OFO
\orelse\ifcstok\XXX\oof
=C2=A0 =C2=A0 =C2=A0OOF
\else
=C2=A0 =C2=A0 =C2=A0XXX
\fi

\def\XXX{\ofo}

\iftok{\XXX}{\foo}%
=C2=A0 =C2=A0 =C2=A0FOO
\orelse\iftok{\XXX}{\ofo}%
=C2=A0 =C2=A0 =C2=A0OFO
\orelse\iftok{\XXX}{\oof}%
=C2=A0 =C2=A0 =C2=A0OOF
\else
=C2=A0 =C2=A0 =C2=A0XXX
\fi

\ifcstok{\XXX}\foo
=C2=A0 =C2=A0 =C2=A0FOO
\orelse\ifcstok{\XXX}\ofo
=C2=A0 =C2=A0 =C2=A0OFO
\orelse\ifcstok\XXX}\oof
=C2=A0 =C2=A0 =C2=A0OOF
\else
=C2=A0 =C2=A0 =C2=A0XXX
\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


-----------------------------------------------------------------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Hans Hagen | PRAGMA ADE
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ridderstraat 27 | 80= 61 GH Hasselt | The Netherlands
=C2=A0 =C2=A0 =C2=A0 =C2=A0 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 t= he Wiki!

maillist : ntg-cont= ext@ntg.nl / http://www.ntg.nl/mailman/listinfo/nt= g-context
webpage=C2=A0 : http://www.pragma-ade.nl / http://context.aanhet.net=
archive=C2=A0 : https://bitbucket.org/phg/context-m= irror/commits/
wiki=C2=A0 =C2=A0 =C2=A0: http://contextgarden.net
___________________________________________________________________________= ________
--00000000000058dc9f05d2b92901-- --===============1013386746553669985== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============1013386746553669985==--