From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/113437 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joey McCollum via ntg-context Newsgroups: gmane.comp.tex.context Subject: Checking for a macro in a string without expanding it Date: Tue, 16 Nov 2021 14:22:14 -0500 Message-ID: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5666730209059478761==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21239"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Joey McCollum To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Nov 16 20:23:16 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 1mn431-0005Ia-K3 for gctc-ntg-context-518@m.gmane-mx.org; Tue, 16 Nov 2021 20:23:15 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 90BFD2893E2; Tue, 16 Nov 2021 20:22:32 +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 KpSkUNftBkF6; Tue, 16 Nov 2021 20:22:30 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 1A4062893E7; Tue, 16 Nov 2021 20:22:30 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D7BB42893E3 for ; Tue, 16 Nov 2021 20:22:27 +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 UMOLOfbPdHLi for ; Tue, 16 Nov 2021 20:22:27 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.166.173; helo=mail-il1-f173.google.com; envelope-from=jmccollum20140511@gmail.com; receiver= Original-Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (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 CB7A12893E2 for ; Tue, 16 Nov 2021 20:22:26 +0100 (CET) Original-Received: by mail-il1-f173.google.com with SMTP id l19so325040ilk.0 for ; Tue, 16 Nov 2021 11:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=FGUxc7dZb7bS4RMuwuyhNTpHPRI7bW6N0fD3P4IfqS0=; b=cnhNeyACZ4AJ6YN57i0qRU/hFDdDLhf6ZkE0q9DnZ64zoBdSqdKdJ7LaoX0CDptY+q wGvEP4JYCT2Y+PdSOg8jWLB3q+6iT5AjZbwKsHW7HSrBswLkNVAI6xfqWS7exNXR8s8I TZv2cFPMAgvcQEPrwUZzxNbXOjWAA6Rgp+rP4NxHvjgSIQstz0OkxqIaqbCPB3qlRDae 85aqynb1nMv1ZvZcZoctN7DQYP9pv/klsVteATGIvzXQeGQH47eWchoB2iVFvcjHpXa2 cGd9jUyU3JzKIImuT6bvy3hD1Purj2CyEiD48RNdkqgizSlRhjZG9wSbj7xMk4aH1rkI wn9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=FGUxc7dZb7bS4RMuwuyhNTpHPRI7bW6N0fD3P4IfqS0=; b=yt2yiDz2q0PFm2yDZ0Qm4o+6fudlqd267Ijn3GPeQT36kOOKLjQTsRpqH2JYctk2Ow Oq9JJRNvJsBTU/8NNM6vOin62QLcGVXhNdzDxFx8Ba2doeW8WLvqXWL+CmXhFS379QbD S3LYWAkp3m27i2WZ+wpI+lWvzndk0IA6jSxDsFmWj0ojjtkvJ2B1vnGpf82j/HWxQ1I4 cEltHYssPQYTFkWC4AL1VM6iF+QEcV7xqFUuxrDFiznrHeiWAsgMz++zyMGyuvg/Ymcv kM5zhGTm9e/F360NUraFcRPXFSNbdWHeVP1H3Zg6g7SavloBt/gQOlyViVAxrhUWwQ2u IzJQ== X-Gm-Message-State: AOAM531bPYtWyUGG6oQT/wQLrfLhKWRpAnDYhkcnHGUbD/7GMWrPTV03 Dh35nLlzRML7rnWwOTdbrYV0mwFSlW2fu7+Xd6xLPCmwYUM= X-Google-Smtp-Source: ABdhPJyvTANCEy3y1A5fpJZ+n0084MuD57elA8LCOBQVzDLDamdJDrGCuETYSkmkTSAUjKfqt7J60JJW6/cTkMBBxYQ= X-Received: by 2002:a05:6e02:156b:: with SMTP id k11mr6287305ilu.77.1637090545092; Tue, 16 Nov 2021 11:22:25 -0800 (PST) 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:113437 Archived-At: --===============5666730209059478761== Content-Type: multipart/alternative; boundary="00000000000067ca3905d0ecd882" --00000000000067ca3905d0ecd882 Content-Type: text/plain; charset="UTF-8" As the subject of this question suggests, this is really more of a question about expansion control (a topic that is still a bit obscure to me). Suppose I have a macro \inner that expects a single argument or an assignment of parameters in brackets. For my purposes, I don't want this macro to do anything when it is typeset, so I'll just define it as empty: ``` \def\inner[#1]\empty ``` Now suppose I have another macro \outer that invokes this macro with some specific input and sets some plain text after it: ``` \def\outer{\inner[123] etc.} ``` What I'd like to do is parse the argument of \inner in \outer. I was hoping that a string search in Lua would work, but I'm not having any luck. A minimal (non)-working example is included below: ``` \def\inner[#1]\empty \def\outer{\inner[123] etc.} \startluacode local userdata = userdata or {} function userdata.parseinner(str) local innerparams = "" if string.find(str, "\\inner(%b[])") then i, j = string.find(str, "\\inner(%b[])") innerparams = string.sub(str, i+1, j-1) -- we just want the content inside the brackets end context(innerparams) return end \stopluacode \def\parseinner#1{\ctxlua{userdata.parseinner([==[#1]==])}} \starttext Testing:\blank \parseinner{\outer} \stoptext ``` My problem is that when I pass \outer to the \parseinner macro, it gets fully expanded, so there isn't anything left to match "\\inner%b[]". Is there a way to expand \outer when I pass it to the \parseinner macro without also expanding the \inner macro inside it? Or is there some other preferred way of doing this? Joey --00000000000067ca3905d0ecd882 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
As the subject of this question suggests, this is really m= ore of a question about expansion control (a topic that is still a bit obsc= ure to me). Suppose I have a macro \inner that expects a single argument or= an assignment of parameters in brackets. For my purposes, I don't want= this macro to do anything when it is typeset, so I'll just define it a= s empty:

```
\def\inner[#1]\empty
``= `

Now suppose I have another macro \outer that inv= okes this macro with some specific input and sets some plain text after it:=

```
\def\outer{\inner[123] etc.}
```
What I'd like to do is parse the argument of \inner in \outer. I was h= oping that a string search in Lua would work, but I'm not having any lu= ck. A minimal (non)-working example is included below:

```

\def\inner[#1]\empty

\def\outer{\inner[123] etc.}


\startluacode

local userdata =3D userdat= a or {}

function userdata.parseinn= er(str)

local innerparams =3D = ""

=C2=A0 =C2=A0 if string.fi= nd(str, "\\inner(%b[])") then

=C2=A0 =C2=A0 =C2=A0 i, = j =3D string.find(str, "\\inner(%b[])")

=C2=A0 =C2=A0 =C2=A0 inn= erparams =3D string.sub(str, i+1, j-1) -- we just want the content inside t= he brackets

=C2=A0 =C2=A0 end

=C2=A0 =C2=A0 context(inne= rparams)

=C2=A0 =C2=A0 return

end

\stopluacode

\def\parseinner#1{\ctxlua{user= data.parseinner([=3D=3D[#1]=3D=3D])}}


\starttext

Testing:\blank

\parseinner{\outer}

\stoptext

```

My pro= blem is that when I pass \outer to the \parseinner=C2=A0macro, it gets full= y expanded, so there isn't anything left to match "\\inner%b[]&quo= t;. Is there a way to expand \outer when I pass it to the \parseinner=C2=A0= macro without also expanding the \inner macro inside it? Or is there some o= ther preferred way of doing this?

Joey
--00000000000067ca3905d0ecd882-- --===============5666730209059478761== 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== --===============5666730209059478761==--