[NTG-context] How to make \def accept block or buffer as part of (long) command argument
Benjamin Buchmuller
benjamin.buchmuller at gmail.com
Sun Jan 2 18:06:36 CET 2022
Uff, this is indeed deep tex. Thanks a lot for the example, Hans! I still need to learn a lot.
After a walk and a bit of fresh air, I found another (much easier) way around my problem. This works since I don't need to deal with #2 in any special way:
\tolerant\def\startMyCommand[#1]%
{
\startallbeautifulcontextcommands
% whatever #1 does
}
\tolerant\def\stopMyCommand%
{
\stopallbeautifulcontextcommands
}
Then one can do in the main files:
\startMyCommand
\beginMyBuffer
bla bla
\endMyBuffer
\stopMycommand
> On Jan 2, 2022, at 14:43, Hans Hagen <j.hagen at xs4all.nl> wrote:
>
> On 1/2/2022 2:14 PM, Benjamin Buchmuller wrote:
>> Thanks, Hans, for the answer, but I'm not sure if I get the point.
>> While this is possible in ConTeXt:
>> \startsection[title={My Title}]
>> \beginMyBlock
>> bla bla
>> \endMyBlock
>> \stopsection
>> The following won't work (end of file error):
>> \startMyCommand[optional={Maybe}]
>> \beginMyBlock
>> bla bla
>> \endMyBlock
>> \stopMyCommand
>> I had hoped for a simple command/modifier like \pleaseacceptblocks\def\startMyCommand[#1]#2\stopMyCommand to have #2 work in a similar way.
>> But maybe, as Wolfgang stated here (https://www.mail-archive.com/ntg-context@ntg.nl/msg73956.html), buffers and blocks can't be used in commands. (To add: Even when passed as arguments during compilation?)
>
> You can bet that WS is right.
>
> You really have to go dirty tex for this kind of magic:
>
> \defineblock[MyBlock]
> \keepblocks[MyBlock]
>
> \starttext
>
> \tolerant\def\startMyCommand[#1]%
> {\begingroup
> \setcatcodetable\notcatcodes
> \dostartMyCommand[#1]}
>
> \let\stopMyCommand\relax
>
> \normalexpanded{\def\noexpand\dostartMyCommand[#1]#2\expandtoken\notcatcodes92 stopMyCommand}%
> {\endgroup
> % whatever #1 does
> \setbuffer[foo]#2\endbuffer
> \typebuffer[foo]
> \getbuffer[foo]}
>
> or
>
> \normalexpanded{\def\noexpand\dostartMyCommand[#1]#2\retokenized\notcatcodes {\stopMyCommand}}%
> {\endgroup
> % whatever #1 does
> \setbuffer[foo]#2\endbuffer
> \typebuffer[foo]
> \getbuffer[foo]}
>
> \startMyCommand[optional={Maybe}]
>
> \beginMyBlock
> bla bla
> \endMyBlock
>
> \stopMyCommand
>
> \stoptext
>
> and then of course further nesting mess ...
>
> Hans
>
> -----------------------------------------------------------------
> Hans Hagen | PRAGMA ADE
> Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
> tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
More information about the ntg-context
mailing list