From: Benjamin Buchmuller via ntg-context <ntg-context@ntg.nl>
To: Hans Hagen <j.hagen@xs4all.nl>
Cc: Benjamin Buchmuller <benjamin.buchmuller@gmail.com>,
mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: How to make \def accept block or buffer as part of (long) command argument
Date: Sun, 2 Jan 2022 18:06:36 +0100 [thread overview]
Message-ID: <FD0495E5-9D30-4043-820B-303845C2E043@gmail.com> (raw)
In-Reply-To: <63920465-0dd4-f296-5ccc-e9cc8ec9bb4a@xs4all.nl>
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@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
> -----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2022-01-02 17:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.440.1641107345.1172.ntg-context@ntg.nl>
2022-01-02 10:30 ` Dangerous bends symbol in manfnt.afm accidentally chopped by LMTX? Benjamin Buchmuller via ntg-context
2022-01-02 10:47 ` How to make \def accept block or buffer as part of (long) command argument Benjamin Buchmuller via ntg-context
2022-01-02 11:19 ` Hans Hagen via ntg-context
2022-01-02 13:14 ` Benjamin Buchmuller via ntg-context
2022-01-02 13:43 ` Hans Hagen via ntg-context
2022-01-02 17:06 ` Benjamin Buchmuller via ntg-context [this message]
2022-01-02 11:43 ` Dangerous bends symbol in manfnt.afm accidentally chopped by LMTX? Hans Hagen via ntg-context
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FD0495E5-9D30-4043-820B-303845C2E043@gmail.com \
--to=ntg-context@ntg.nl \
--cc=benjamin.buchmuller@gmail.com \
--cc=j.hagen@xs4all.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).