From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from cgl.ntg.nl (Cgl.ntg.nl [5.39.185.202]) by inbox.vuxu.org (Postfix) with ESMTP id 4A2CC212C1 for ; Thu, 25 Jan 2024 09:24:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id A29DC483F58 for ; Thu, 25 Jan 2024 09:21:41 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d24S7zljYWgN for ; Thu, 25 Jan 2024 09:21:41 +0100 (CET) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id BD622484306 for ; Thu, 25 Jan 2024 09:19:56 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 9D833483DC9 for ; Thu, 25 Jan 2024 09:19:05 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XjEw9jZf2yY8 for ; Thu, 25 Jan 2024 09:19:04 +0100 (CET) Received: from flump.de (flump.de [185.163.118.210]) (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) by cgl.ntg.nl (Postfix) with ESMTPS id 57366483DC4 for ; Thu, 25 Jan 2024 09:19:04 +0100 (CET) Received: from falbala.localnet (ip4d1692dd.dynamic.kabel-deutschland.de [77.22.146.221]) by flump.de (Postfix) with ESMTPSA id EA75770213A for ; Thu, 25 Jan 2024 09:19:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flump.de; s=mail; t=1706170744; bh=ODfMp6j6uTu5bq2TQjvL4wvicW2UdtaJEpgV9w2Z+mE=; h=From:To:Subject:Date; b=4FJ8kPE1BGrqcnuL4GgltEAKehBg5Hj41X5Wh3GTE2ELlAmezKTdvLHlZKfF4HLk2 ONwvJUrjiEzxyiJTyAeOv267LhYgd63jF7gefKCyKgTXDlCtqK/2w4WTLcPQMBZSIu fUqc1JIiZAV2LVOa54Z1rb/ATZZrCUHWFExNUb4g= From: Gerion Entrup To: ntg-context@ntg.nl Date: Thu, 25 Jan 2024 09:18:57 +0100 Message-ID: <2780043.ElGaqSPkdT@falbala> MIME-Version: 1.0 Message-ID-Hash: XLQT5CIHWKPCHFZ4EHCLCNI5EU67ENQT X-Message-ID-Hash: XLQT5CIHWKPCHFZ4EHCLCNI5EU67ENQT X-MailFrom: gerion.entrup@flump.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list Reply-To: mailing list for ConTeXt users Subject: [NTG-context] Own command definition breaks with interaction: Use of \do_my_command doesn't match its definition List-Id: mailing list for ConTeXt users Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: multipart/mixed; boundary="===============8113076181235323531==" --===============8113076181235323531== Content-Type: multipart/signed; boundary="nextPart2344141.tdWV9SEqCh"; micalg="pgp-sha256"; protocol="application/pgp-signature" --nextPart2344141.tdWV9SEqCh Content-Type: multipart/mixed; boundary="nextPart5332172.GXAFRqVoOG"; protected-headers="v1" Content-Transfer-Encoding: 7Bit From: Gerion Entrup To: ntg-context@ntg.nl Date: Thu, 25 Jan 2024 09:18:57 +0100 Message-ID: <2780043.ElGaqSPkdT@falbala> MIME-Version: 1.0 This is a multi-part message in MIME format. --nextPart5332172.GXAFRqVoOG Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, I want to make a proper definition of a new command to be able to process it in Lua. I found something on StackOverflow [1] but that breaks in enumeration _and_ when interaction is enabled and I do not understand why? Can you give me some help here? I want to make commands like \foo{bla} and \foo[b]{bla} possible at the same time. Here is a minimal example (also attached): ``` \startluacode function userdata.my_command(keywords, text) commands.writestatus("test", string.format("text: %s, config: %s", text, keywords)) local cfg = utilities.parsers.settings_to_hash(keywords) if cfg['emph'] ~= nil then context("\\emph{" .. text .. "}") elseif cfg['bold'] ~= nil then context("\\bold{" .. text .. "}") else context(text) end end \stopluacode % without that line there is no problem \setupinteraction[state=start] \defineenumeration[enu][text=Enu] \unprotect \def\mc{\dosingleempty\do_my_command} \def\do_my_command[#1]#2{% \iffirstargument{% \ctxlua{userdata.my_command('#1', [==[#2]==])}% }\else {% \ctxlua{userdata.my_command('', [==[#2]==])}% }\fi } \protect \starttext % all the following works \mc{foo} \mc[bold]{foo} \mc[emph]{foo} \startenu[title=Some] \stopenu % this breaks \startenu[title=Some \mc{foo}] \stopenu \stoptext ``` The compilation fails with: ``` tex error > tex error on line 41 in file ./test.tex: Use of \do_my_command doesn't match its definition ``` Best, Gerion [1] https://tex.stackexchange.com/a/55778 --nextPart5332172.GXAFRqVoOG Content-Disposition: attachment; filename="test.tex" Content-Transfer-Encoding: 7Bit Content-Type: text/x-tex; charset="x-UTF_8J"; name="test.tex" \startluacode function userdata.my_command(keywords, text) commands.writestatus("test", string.format("text: %s, config: %s", text, keywords)) local cfg = utilities.parsers.settings_to_hash(keywords) if cfg['emph'] ~= nil then context("\\emph{" .. text .. "}") elseif cfg['bold'] ~= nil then context("\\bold{" .. text .. "}") else context(text) end end \stopluacode % without that line there is no problem \setupinteraction[state=start] \defineenumeration[enu][text=Enu] \unprotect \def\mc{\dosingleempty\do_my_command} \def\do_my_command[#1]#2{% \iffirstargument{% \ctxlua{userdata.my_command('#1', [==[#2]==])}% }\else {% \ctxlua{userdata.my_command('', [==[#2]==])}% }\fi } \protect \starttext % all the following works \mc{foo} \mc[bold]{foo} \mc[emph]{foo} \startenu[title=Some] \stopenu % this breaks \startenu[title=Some \mc{foo}] \stopenu \stoptext --nextPart5332172.GXAFRqVoOG-- --nextPart2344141.tdWV9SEqCh Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQGzBAABCAAdFiEEM/tVN9WpYYHnPZHxloeAdSYJHeoFAmWyGXEACgkQloeAdSYJ HepYlQv7BhWydG5YW09996qp1boyLBNzBrOF11e4jGIi/MFMuy9DgowmEHAsXaeA YdR4C+7z/G0beRHe2FE+Yj0LZfqPD6MMP0JoYaxCHICPdcONbv+blf/JP44MnaEZ WJ4QdHYOwwwGt5ZSCBHMYo4WxjjiiCnDgDWid3PBV+p0YORqJDUvhyHI5G4WOj1A 9k03kr+OJkqIQHivCupUX4R7sBQY+LKxG9rc01zeKLBcz7KQ9xIg/2jd7akd2xJc 5CTWrTswoCisPH9wr9EoMU85hoOIslAvJ5nuPWb1QNOgmiVlXujst5mgz7HRZSaA 6lzIWIDTY7jgkD0TbVgeWOprwe5OOlX4BG6zVEcavTjeV0pNScCO0mof8qIwT4C6 IKNbDgiNLUjfHtnf6s3BLp9pAI6NFPUbas53x4O/20e1vKHnbniNuumtTVKu0MgK uXPn440Qz4AaWzxQyfkXAzbeIBU8rYjnNGSfHYUi/Hlcv2R3SJDKcfNes186ITLD KTLsyFPq =3U2+ -----END PGP SIGNATURE----- --nextPart2344141.tdWV9SEqCh-- --===============8113076181235323531== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________ --===============8113076181235323531==--