Re: buffer question
Jim via ntg-context <[email protected]>
| Newsgroups | gmane.comp.tex.context |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Apr 16, 2026 at 10:22 (-0400), Aditya Mahajan wrote:
> On Thu, 16 Apr 2026, Jim via ntg-context wrote:
>> So... is there some way to get a parameter value (pageHeight in this
>> example) into the buffer contents?
>> (I realize I can create Yet Another buffer MyPrePreamble which defines a
>> macro (or sets a dimen) to the desired value and call
>> \typesetbuffer[MyPrePreamble,MyPreamble,content]
>> but I was wondering if there was something a bit more elegant.)
> Just do everything in lua:
> \starttext
> \startluacode
> local preamble = [[
> \definepapersize[ShowAndTypeset]
> [width=%width%, height=%height%];
> \setuppapersize[ShowAndTypeSet]
> ]]
> local options={width="5cm", height="10cm"}
> local parsed = utilities.templates.replace(preamble, options)
> context.tobuffer("MyPreamble", parsed)
> \stopluacode
> \typebuffer[MyPreamble]
> \stoptext
Aditya,
too easy! Thanks.
(Is the ';' after "%height%]" really desired here, or did you pull yourself
away from a Algol/C/C++/Java program to answer this?)
Aditya presciently anticipated (is that redundant?) Question 3 of
International Buffer Day, which was going to be
Q3: How to create a buffer from inside a macro?
Given Aditya's answer to Q2, the solution is pretty simple:
\def\makeMyPreamble #1
{
\startluacode
local preamble3 = [[
\definepapersize[ShowAndTypeset]
[width=100mm, height=#1]
\setuppapersize[ShowAndTypeset]
]]
context.tobuffer("MyPreamble", preamble3)
\stopluacode
}
How to specify both width and height is left as an exercise to the diligent
student. ;-)
Jim
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : [email protected] / 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
___________________________________________________________________________________