LMTX: Command handling, Interface between TeX and Lua
![](https://secure.gravatar.com/avatar/c0cb5820bbd2ff3bd7432ee06e9b39be.jpg?s=120&d=mm&r=g)
Hi, I'd like to understand more of the inner workings of LMTX. When I understand it right, most of the code is now processed in Lua but I was not able to find it. For example, I tried to find out how setupitemgroup is handled (just as an example of a more complex command). The wiki has a (kind of) autogenerated description: https://wiki.contextgarden.net/Command/setupitemgroup I found the data for this (at least this is my guess) here: tex/texmf-context/tex/context/interface/mkiv/i-itemgroup.xml Are these xml files created by hand or somehow generated? Now, when I use `\setupitemgroup[itemize:1][symbol=3,itemalign=middle]`: How are the arguments handled and is this a generic process or specific to each command? 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: \startsomething[firstword={Some},secondword={Text}] Body \stopsomething which I can handle in some lua code like this: function something(firstword, secondword, body) tex.print(firstword) tex.print(secondword) tex.print(body) end Are there any resources beside the context code itself where I can learn that? Gerion
![](https://secure.gravatar.com/avatar/e0f8d84b235b67d60a3c7fd0e326db8d.jpg?s=120&d=mm&r=g)
On 13 Dec 2023, at 17:13, Gerion Entrup
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
![](https://secure.gravatar.com/avatar/c0cb5820bbd2ff3bd7432ee06e9b39be.jpg?s=120&d=mm&r=g)
Am Mittwoch, 13. Dezember 2023, 21:57:35 CET schrieb Bruce Horrocks:
On 13 Dec 2023, at 17:13, Gerion Entrup
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
Thank you. That helps a lot already! Gerion
participants (2)
-
Bruce Horrocks
-
Gerion Entrup