how to define an environment with key=value arguments
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. Hraban
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
Am 08.09.23 um 12:35 schrieb Wolfgang Schuster:
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.
Thank you! You’re right, that might be enough. (Documented only in https://wiki.contextgarden.net/Command/setuphead so far. Even the source browser can’t find anything.) But my “image” consists of a background color (with bleed), a transparent overlay image (with bleed), a tilted image with a shadow on top and a caption (so far) – and pageinjection looks fixed to one image. How can I hook my own placement code in there? Hraban
Henning Hraban Ramm schrieb am 08.09.2023 um 13:09:
Am 08.09.23 um 12:35 schrieb Wolfgang Schuster:
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.
Thank you! You’re right, that might be enough.
(Documented only in https://wiki.contextgarden.net/Command/setuphead so far. Even the source browser can’t find anything.) https://source.contextgarden.net/tex/context/base/mkxl/page-inj.mklx But my “image” consists of a background color (with bleed), a transparent overlay image (with bleed), a tilted image with a shadow on top and a caption (so far) – and pageinjection looks fixed to one image. How can I hook my own placement code in there? We can discuss the details next week and you put the resulting template on the wiki.
Wolfgang
Am 08.09.23 um 16:21 schrieb Wolfgang Schuster:
Henning Hraban Ramm schrieb am 08.09.2023 um 13:09:
Am 08.09.23 um 12:35 schrieb Wolfgang Schuster:
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.
Thank you! You’re right, that might be enough.
(Documented only in https://wiki.contextgarden.net/Command/setuphead so far. Even the source browser can’t find anything.) https://source.contextgarden.net/tex/context/base/mkxl/page-inj.mklx
Seems like I didn’t search right (just “pageinjections“?)
But my “image” consists of a background color (with bleed), a transparent overlay image (with bleed), a tilted image with a shadow on top and a caption (so far) – and pageinjection looks fixed to one image. How can I hook my own placement code in there? We can discuss the details next week and you put the resulting template on the wiki.
Ah, I guess I understand the template mechanism. Yet again glorious setups. Will probably manage. Hraban
Am 08.09.23 um 17:02 schrieb Henning Hraban Ramm:
We can discuss the details next week and you put the resulting template on the wiki.
Ah, I guess I understand the template mechanism. Yet again glorious setups. Will probably manage.
So far: \definepageinjection[chapter:start][ page=left, alternative=setups, setups=frontispiz, color=white, background=color, backgroundcolor=Eifel, ] \startsetups[frontispiz] \starttransparent[tlumi]% \externalfigure[\structureuservariable{image}][ width=\measure{MaxWidth}, ]% \stoptransparent% \stopsetups \setuphead[chapter][ page=right, style=\ChapterFont, beforesection={\pageinjection[chapter:start]}, command=\ChapterStart, before={\startcolumnset[Spalten]}, after={\vskip-\lineheight}, % fix column start inbetween=, aftersection={\stopcolumnset}, ] \startchapter[title={Prolog 2: Reiseführer}][ motto={(quotation.}}, % used in \ChapterStart image={00 Lavakeller Mendig g}, % wrong blank=2, ] Not a MWE, I know. Here’s a screenshot: https://yemaya.fiee.net/s/G2NcwE8qQrLAx8B (Funny, I never needed all of before, after, beforesection and aftersection so far.) The injection is a frame, that’s great, because I can set the background, and \externalfigure starts at (0,0). But it uses its own page size, I don’t understand why. I need the bleed/trim area. If I use \setlayer in the setup, the content gets placed on the next page, i.e. under the text. \structureuservariable{image} in the setup gets the value from the _next_ chapter. Maybe the approach in from the source with \dummyparameter\c!name would work better, but I don’t know how to transfer it. Hraban
Am 08.09.23 um 19:37 schrieb Henning Hraban Ramm:
But it uses its own page size, I don’t understand why. I need the bleed/trim area.
If I use \setlayer in the setup, the content gets placed on the next page, i.e. under the text.
\structureuservariable{image} in the setup gets the value from the _next_ chapter. Maybe the approach in from the source with \dummyparameter\c!name would work better, but I don’t know how to transfer it.
I gave up, ran into too many problems. Tried to avoid injections and put everything in before/beforesection macros, but \structureuservariable there also always picks up the values from the next chapter (while I would expect the current or maybe the previous). So I copy-pasted the whole bunch of ugly commands in front of every chapter, and it works. It’s only for one book with 18 chapters, doesn’t make much sense to spend even more time on a more elegant solution. Hraban
participants (2)
-
Henning Hraban Ramm
-
Wolfgang Schuster