From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Gerion Entrup <gerion.entrup@flump.de>
Subject: [NTG-context] Re: Own command definition breaks with interaction: Use of \do_my_command doesn't match its definition
Date: Mon, 29 Jan 2024 16:31:41 +0100 [thread overview]
Message-ID: <c907f769-d9fe-d894-c1ad-4b8a14130712@gmail.com> (raw)
In-Reply-To: <2780043.ElGaqSPkdT@falbala>
Gerion Entrup schrieb am 25.01.2024 um 09:18:
> 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
\startluacode
function userdata.my_command(keywords, text)
local keywords = utilities.parsers.settings_to_hash(keywords)
if keywords['emph'] then
context.emph(text)
elseif keywords['bold'] then
context.bold(text)
else
context(text)
end
end
\stopluacode
> % without that line there is no problem
> \setupinteraction[state=start]
>
> \defineenumeration[enu][text=Enu]
\defineenumeration[enu][text=Enu,title=yes]
> \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
\tolerant\protected\def\mc[#1]#2%
{\ctxlua{userdata.my_command("#1","#2")}}
Wolfgang
___________________________________________________________________________________
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
___________________________________________________________________________________
prev parent reply other threads:[~2024-01-29 15:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 8:18 [NTG-context] " Gerion Entrup
2024-01-29 8:30 ` [NTG-context] " Taco Hoekwater
2024-01-29 15:31 ` Wolfgang Schuster [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c907f769-d9fe-d894-c1ad-4b8a14130712@gmail.com \
--to=wolfgang.schuster.lists@gmail.com \
--cc=gerion.entrup@flump.de \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).