ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Henning Hraban Ramm <texml@fiee.net>
Subject: [NTG-context] Re: how to define an environment with key=value arguments
Date: Fri, 8 Sep 2023 12:35:00 +0200	[thread overview]
Message-ID: <c3079fac-0446-515f-735b-1f46bf11c51a@gmail.com> (raw)
In-Reply-To: <dc07763d-d4a8-a0f5-cccc-e7f47b7d1778@fiee.net>

Henning Hraban Ramm schrieb am 08.09.2023 um 12:22:
> Hi,
> for an involved image placement (full page image starting each 
> chapter, several stacked elements), I’d like an environment that 
> accepts key-value arguments, like
>
> \startMyFigure[page=left,title={My caption}]
> \externalfigure[dummy]…
> \stopMyFigure
>
> I don’t think that a real float makes sense, even if the interface 
> looks similar, since it’s always a full page in a fixed place, I need 
> no numbering and can place the caption myself.
>
> Does it make sense to use \definestartstop?
> How would I “plugin“ the argument handling?
>
>
> Or should I better define start and stop separately?
>
> \def\startMyFigure[#1]{
> % e.g. use utilities.parsers.settings_to_hash(#1)
> }
> \def\stopMyFigure{}
>
>
> Probably I’ll need to catch the content (\externalfigure, might become 
> more) and use it in a \setlayer – so perhaps something like
>
> \definebuffer[MyFigure]
> \define\stopMyFigure{%
>  \setlayer[page]{\getMyFigure}}}
> }
>
> ?
> But then I don’t know how to handle the arguments.
>
> Probably it makes most sense to do it in Lua, like
>
> \startluacode
>      interfaces.implement {
>          name      = "startMyFigure",
>          public    = true,
>          arguments = {"hash",},
>          actions   = function(h, a)
>         -- …
>         end, }
> \stopluacode
>
> But I didn’t find how to do environments.

When you just need an environment with a optional argument to pass user 
values you can
use the userdata environment but be aware that you have some limitations 
(like verbatim)
because the mechanism uses a buffer to store the content.

For images (and other content) which are placed on a separate page at 
the start of a chapter
you can use the pageinjection mechanism which was added for this purpose.

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2023-09-08 10:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 10:22 [NTG-context] " Henning Hraban Ramm
2023-09-08 10:35 ` Wolfgang Schuster [this message]
2023-09-08 11:09   ` [NTG-context] " Henning Hraban Ramm
2023-09-08 14:21     ` Wolfgang Schuster
2023-09-08 15:02       ` Henning Hraban Ramm
2023-09-08 17:37         ` Henning Hraban Ramm
2023-09-09 10:56           ` Henning Hraban Ramm

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=c3079fac-0446-515f-735b-1f46bf11c51a@gmail.com \
    --to=wolfgang.schuster.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    --cc=texml@fiee.net \
    /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).