ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] LMTX: Command handling, Interface between TeX and Lua
@ 2023-12-13 17:13 Gerion Entrup
  2023-12-13 20:57 ` [NTG-context] " Bruce Horrocks
  0 siblings, 1 reply; 3+ messages in thread
From: Gerion Entrup @ 2023-12-13 17:13 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1201 bytes --]

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

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [NTG-context] Re: LMTX: Command handling, Interface between TeX and Lua
  2023-12-13 17:13 [NTG-context] LMTX: Command handling, Interface between TeX and Lua Gerion Entrup
@ 2023-12-13 20:57 ` Bruce Horrocks
  2023-12-14 13:10   ` Gerion Entrup
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce Horrocks @ 2023-12-13 20:57 UTC (permalink / raw)
  To: ntg-context mailing list


> 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [NTG-context] Re: LMTX: Command handling, Interface between TeX and Lua
  2023-12-13 20:57 ` [NTG-context] " Bruce Horrocks
@ 2023-12-14 13:10   ` Gerion Entrup
  0 siblings, 0 replies; 3+ messages in thread
From: Gerion Entrup @ 2023-12-14 13:10 UTC (permalink / raw)
  To: ntg-context mailing list


[-- Attachment #1.1: Type: text/plain, Size: 1242 bytes --]

Am Mittwoch, 13. Dezember 2023, 21:57:35 CET schrieb Bruce Horrocks:
> 
> > 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

Thank you. That helps a lot already!

Gerion

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-14 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-13 17:13 [NTG-context] LMTX: Command handling, Interface between TeX and Lua Gerion Entrup
2023-12-13 20:57 ` [NTG-context] " Bruce Horrocks
2023-12-14 13:10   ` Gerion Entrup

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).