From: Bruce Horrocks <ntg@scorecrow.com>
To: ntg-context mailing list <ntg-context@ntg.nl>
Subject: [NTG-context] Re: LMTX: Command handling, Interface between TeX and Lua
Date: Wed, 13 Dec 2023 20:57:35 +0000 [thread overview]
Message-ID: <F8447B59-256F-4EB4-A627-A8020EA0B2A9@scorecrow.com> (raw)
In-Reply-To: <3270809.44csPzL39Z@falbala>
> On 13 Dec 2023, at 17:13, Gerion Entrup <gerion.entrup@flump.de> wrote:
>
> Is there a simple way to define a new command/environment and handle
> the keyword arguments in Lua? For example defining a frontend command
> like this:
I don't have the answer to your other questions but I do have an example for this one.
It's not mine - I'm fairly sure it came from this list but I can't find who that was any more.
\startluacode
userdata = userdata or { }
function userdata.mycommand(keywords, keyvals, str)
keyword_options = utilities.parsers.settings_to_array(keywords)
named_values = utilities.parsers.settings_to_hash(keyvals)
context('First option = ' .. keyword_options[1])
context('\\par')
context('Color chosen = ' .. named_values['color'])
context('\\par')
context('Curly braces = ' .. str)
context('\\par')
end
\stopluacode
\def\mycommand[#1][#2]#3{\ctxlua{
userdata.mycommand('#1', '#2', [==[#3]==])}}
\starttext
\mycommand[top, inmargin, now][color=green, roof=gabled]{Anne of Green Gables?}
\stoptext
—
Bruce Horrocks
Hampshire, UK
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2023-12-13 21:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 17:13 [NTG-context] " Gerion Entrup
2023-12-13 20:57 ` Bruce Horrocks [this message]
2023-12-14 13:10 ` [NTG-context] " Gerion Entrup
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=F8447B59-256F-4EB4-A627-A8020EA0B2A9@scorecrow.com \
--to=ntg@scorecrow.com \
--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).