Re: [NTG-context] How to make \def accept block or buffer as part of (long) command argument

2022-01-02 Thread Benjamin Buchmuller via ntg-context
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  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
> -

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

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


Re: [NTG-context] How to make \def accept block or buffer as part of (long) command argument

2022-01-02 Thread Hans Hagen via ntg-context

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
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] How to make \def accept block or buffer as part of (long) command argument

2022-01-02 Thread Benjamin Buchmuller via ntg-context
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?)

Many Thanks again!


Benjamin

> On Jan 2, 2022, at 12:19, Hans Hagen  wrote:
> 
> On 1/2/2022 11:47 AM, Benjamin Buchmuller via ntg-context wrote:
>> Hi list,
>> I'm playing around with blocks and buffers again, realizing that I cannot 
>> use them inbetween a \start...\stop that I defined myself. Apparently, they 
>> work between \startsection...\stopsection and the like, so I was wondering 
>> how I should define or expand #2 in the MWE below to make TeX happily accept 
>> these useful features?
> buffers are stored as-is so no catcode magic stored, contrary to macros
> 
> you can use \setbuffer but that doesn't solve the argument passing
> 
> however, you can nest buffers so you can make other \start\stop commands 
> buffers too and then do some at the start and (look for \defiebuffer) but it 
> quickly becomes messy i think
> 
> 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
> -

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

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


Re: [NTG-context] How to make \def accept block or buffer as part of (long) command argument

2022-01-02 Thread Hans Hagen via ntg-context

On 1/2/2022 11:47 AM, Benjamin Buchmuller via ntg-context wrote:

Hi list,

I'm playing around with blocks and buffers again, realizing that I cannot use 
them inbetween a \start...\stop that I defined myself. Apparently, they work 
between \startsection...\stopsection and the like, so I was wondering how I 
should define or expand #2 in the MWE below to make TeX happily accept these 
useful features?

buffers are stored as-is so no catcode magic stored, contrary to macros

you can use \setbuffer but that doesn't solve the argument passing

however, you can nest buffers so you can make other \start\stop commands 
buffers too and then do some at the start and (look for \defiebuffer) 
but it quickly becomes messy i think


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
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


[NTG-context] How to make \def accept block or buffer as part of (long) command argument

2022-01-02 Thread Benjamin Buchmuller via ntg-context
Hi list,

I'm playing around with blocks and buffers again, realizing that I cannot use 
them inbetween a \start...\stop that I defined myself. Apparently, they work 
between \startsection...\stopsection and the like, so I was wondering how I 
should define or expand #2 in the MWE below to make TeX happily accept these 
useful features?

Thanks a lot


Benjamin


\starttext

\let\stopMyCommand\relax

\tolerant\protected\def\startMyCommand[#1]#2\stopMyCommand{

Optional argument #1

Content #2

}

\bf Here we test the command: Works \tf

\startMyCommand[is optional]
gets processed!
\stopMyCommand

\bf Here we test the block: Works \tf

\defineblock[MyBlock]

\beginMyBlock
Block for something else.
\endMyBlock

\useblocks[MyBlock][criterium=text]

\bf Here we test the block inside command: Fails \tf

% UNCOMMENT BELOW FAILS: tex error > runaway error: end of file encountered
%
% \startMyCommand[is optional]
% Still?
%
% \beginMyBlock
% Block for something else.
% \endMyBlock
% \stopMyCommand

\definebuffer[MyBuffer]

\bf Here we test the buffer: Works \tf

\startbuffer[MyBuffer]
Buffer for something else.
\stopbuffer

\getbuffer[MyBuffer]

\bf Here we test the buffer inside command: Fails \tf

% UNCOMMENT BELOW FAILS: tex error > runaway error: end of file encountered
%
% \startMyCommand[is optional]
% Still?
%
% \startbuffer[MyBuffer]
% Buffer for something else.
% \endbuffer
% \stopMyCommand

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

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