Obtaining the argument information for an environment is much the same as that for a command, as described earlier, except that the argument is delimited by $On$C instead of $OPn$CP. Suppose you have an environment called, say, exercise which will typeset an exercise for the reader. Each exercise has an argument--the exercise title--which will be typeset in bold at the start of the environment. The LaTeX code might look something like:
\newenvironment{exercise}[1]% {\begin{quote}\textbf{Exercise : #1}\par} {\end{quote}}The Perl code will then look something like:
sub do_env_exercise{ local($_) = @_; local($title); $title = &missing_braces unless (s/$next_pair_rx/$title=$2,''/eo); "<BLOCKQUOTE><B>Exercise : $title</B><P>" . $_ . "</BLOCKQUOTE>"; }Note the use of $next_pair_rxname=$next_pair_rx,sort=nextpairrx,description=Regular expression used to extract the group at the start of $_ delimited by $On$C. The contents of the group is given by $2, the unique identifier belonging to that group is given by $1.$next_pair_rx instead of $next_pair_pr_rxname=$next_pair_pr_rx,sort=nextpairprrx,description=Regular expression used to extract the group at the start of $_ delimited by $OPn$CP. The contents of the group is given by $2, the unique identifier belonging to that group is given by $1.$next_pair_pr_rx.
Optional arguments are dealt with in the same way as described earlier For example, suppose the exercise environment above should have an optional argument instead. If the argument is present it is used as a title, e.g. Exercise : The Title, but if it is not present, the title is simply Exercise. The LaTeX code will look something like2:
\newenvironment{exercise}[1][]% {\begin{quote} \textbf{Exercise\ifthenelse{\equal{#1}{}}{}{ : #1}}\par} {\end{quote}}and the Perl code should look something like:
sub do_env_exercise{ local($_) = @_; local($title,$pat); ($title, $pat) = &get_next_optional_argument; if ($title ne '') { $title = " : $title"; } "<BLOCKQUOTE><B>Exercise$title</B><P>" . $_ . "</BLOCKQUOTE>"; }