Difference between revisions of "Command/groupedcommand"

From Wiki
Jump to navigation Jump to search
m
 
Line 3: Line 3:
 
|attributes=
 
|attributes=
 
}}
 
}}
 +
 +
== [[Help:Reference|Syntax]] (autogenerated) ==
 +
<syntax>groupedcommand</syntax>
  
 
== [[Help:Reference|Syntax]] ==
 
== [[Help:Reference|Syntax]] ==

Latest revision as of 16:26, 11 November 2019

\groupedcommand

Syntax (autogenerated)

\groupedcommand{...}{...}
{...}command
{...}command


Syntax

\groupedcommand{...}{...}
{...} before
{...} after

Description

\groupedcommand is used for defining commands that might receive a verbatim environment as their argument, or a block wrapped in \bgroup...\egroup.

\def\dostuff{\groupedcommand{...before...}{...after...}}

is a robust implementation of the more naïve pattern

\def\dostuff#1{...before...#1...after...}

The first problem with the naïve approach: the tokens that form #1 are fixed the the moment the argument is read in. Normally this is no problem, but e.g. verbatim environments adapt the catcodes of characters and therefore are not always happy with already fixed tokens.

Another problem arises when the argument is grouped not by {} but by \bgroup and \egroup. Such an argument fails, because the \bgroup is seen as the argument (which is quite normal).

If you use \groupedcommand, the argument is identified and processed correctly.

Example

% Don't write this
\def\cite#1%
  {\rightquote\rightquote#1\leftquote\leftquote}

% Write this, instead.
\def\cite%
  {\groupedcommand{\rightquote\rightquote}{\leftquote\leftquote}}

Another example, where the item to process is a paragraph:

\def\BoldRaggedCenter%
  {\groupedcommand{\raggedcenter\bf}{\par}}

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: