ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Gerion Entrup <gerion.entrup@flump.de>
To: ntg-context mailing list <ntg-context@ntg.nl>
Subject: [NTG-context] Re: LMTX: Command handling, Interface between TeX and Lua
Date: Thu, 14 Dec 2023 14:10:10 +0100	[thread overview]
Message-ID: <1951087.PYKUYFuaPT@falbala> (raw)
In-Reply-To: <F8447B59-256F-4EB4-A627-A8020EA0B2A9@scorecrow.com>


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

      reply	other threads:[~2023-12-14 13:15 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 ` [NTG-context] " Bruce Horrocks
2023-12-14 13:10   ` Gerion Entrup [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=1951087.PYKUYFuaPT@falbala \
    --to=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).