Re: buffer question

Jim Diamond via ntg-context <[email protected]>
Newsgroups gmane.comp.tex.context
Message-ID <[email protected]>
On Thu, Apr 16, 2026 at 11:46 (-0400), Aditya Mahajan wrote:

> On Thu, 16 Apr 2026, Jim via ntg-context wrote:

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

> This is a bit risky with catcodes.

Good point!  (In general... in this specific case, I would imagine that any
simple dimen will not have catcode issues.  But as I type this I have this
feeling someone might educate me on that point.)

> (Quiz: is % inside \startluacode a tex comment or not?)

When I first tried to put your
        %width%
construction into the macro I quickly found out the catcodes issue was a
bit of an issue.

> Better to define a function, say thirddata.definepreamble(width,height)
> at lua end and then call

> \define[1]\makePreamble{\ctxlua(thirddata.definepreamble("#1","100cm")}

Without having done my Lua programming yet, am I correct in assuming that
if someone calls this \makePreamble as follows
        \makePreamble{0.5"}
then Bad Things will happen because of the " in the argument?

                                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
___________________________________________________________________________________
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.