From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/109008 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: need help comparing strings Date: Tue, 13 Oct 2020 11:54:05 -0400 (EDT) Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-1122931962-1602604446=:453286" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2704"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Alpine 2.23 (LNX 453 2020-06-18) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Oct 13 17:54:38 2020 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 1kSMdK-0000cH-SJ for gctc-ntg-context-518@m.gmane-mx.org; Tue, 13 Oct 2020 17:54:38 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id DD71A1A94DD; Tue, 13 Oct 2020 17:54:11 +0200 (CEST) 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 9HyFPcIoJbQa; Tue, 13 Oct 2020 17:54:11 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 033E41A95EB; Tue, 13 Oct 2020 17:54:11 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 2F6B71A94AE for ; Tue, 13 Oct 2020 17:54:10 +0200 (CEST) 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 DXvMMD3xx7kJ for ; Tue, 13 Oct 2020 17:54:09 +0200 (CEST) Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=132.206.73.2; helo=orford.cim.mcgill.ca; envelope-from=adityam@umich.edu; receiver= Original-Received: from orford.cim.mcgill.ca (smtp.cim.mcgill.ca [132.206.73.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 6A4CE1A9486 for ; Tue, 13 Oct 2020 17:54:08 +0200 (CEST) Original-Received: from adi-thinkpad.local (198-84-255-218.cpe.teksavvy.com [198.84.255.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adityam) by orford.cim.mcgill.ca (Postfix) with ESMTPSA id 5448FF5530 for ; Tue, 13 Oct 2020 11:54:06 -0400 (EDT) In-Reply-To: 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:109008 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1122931962-1602604446=:453286 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 13 Oct 2020, Pablo Rodriguez wrote: > Dear list, >=20 > I have the following sample: >=20 > \starttext > \def\numbersfname > {\cldcontext{string.match([[\env{fname}]], "\letterpercent d+")}} > \ctxlua{ c =3D context.getvariable("environment", "fname") or "a" } > \ctxlua{ d =3D [[\env{fname}]] } >=20 > tex: \numbersfname\\ > \doifelse{} > {123}{yes}{no}\\ > c: \cldcontext{c}\\ > \doifelse{\cldcontext{c:match("\letterpercent d+")}} > {123}{yes}{no}\\ > d: \cldcontext{d}\\ > \doifelse{\cldcontext{d:match("\letterpercent d+")}} > {123}{yes}{no} > \stoptext >=20 > For compilation, I run the command: >=20 > context --purgeall --arguments=3Dfname=3D{abc123} test-file.tex >=20 > These things are failing: >=20 > 1. I don=E2=80=99t know how to get \numbersfname equal to "123". I don=E2= =80=99t know > what I=E2=80=99m doing wrong. >=20 > 2. Is there no Lua version of \getvariable{...}{...}? >=20 > 3. I=E2=80=99m trying this on a Linux box, but on Windows I would say tha= t Lua > variable "d" is empty. >=20 > I need to get the number from \env{fname} and I don=E2=80=99t know what I= =E2=80=99m > missing. \doif is the way to test whether it=E2=80=99s right. >=20 > Could anyone explain me what I=E2=80=99m missing here? I find it simpler to write macros where there is clean communicating betwe= en tex and lua. For example: \startluacode userdata =3D userdata or {} function userdata.numbersfname(name) return string.match(name, "%d+") end \stopluacode \define[1]\numbersfname {\cldcontext{userdata.numbersfname([=3D=3D[#1]=3D=3D])}} \starttext \numbersfname{abc123} \numbersfname{\env{fname}} \stoptext Aditya --8323329-1122931962-1602604446=:453286 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== --8323329-1122931962-1602604446=:453286--