2

I was trying to write an environment using the environ package. The new environment can be defined without any problem. For some personal reasons, I want to put the start and end of environments to some macros.

See this MWE:

\documentclass{article}

\usepackage{environ}

\makeatletter
\NewEnviron{workpl@n}{\BODY}[\relax]

% The following will not pose any problem
% \newenvironment{workpl@n}{\relax}{\relax}

\def\beginworkplan{\begin{workpl@n}}
\def\endworkplan{\end{workpl@n}}
\makeatother

\begin{document}

% Does not work
% \beginworkplan

\makeatletter
% Works 
\begin{workpl@n}

Plan

% Works 
\end{workpl@n}

% Does not work
% \endworkplan
\makeatother

\end{document}

Strangely, \beginworkplan, \endworkplan command pair fails with the message:

! LaTeX Error: \begin{workpl@n} on input line 14 ended by \end{document}.

However, if the environment is started and finished directly (using \begin{workpl@n} and \end{workpl@n}), it also works.

Moreover, if a new environment is defined using the basic \newenvironment command, putting the start and end of environments to\beginworkplan and \endworkplan does not pose any problem at all.

I need to use \NewEnviron since I have the necessity to collect the environment body.

2

Note that an environment defined with \NewEnviron has to see \end in order to determine the extent of the body.

However, you don't need environ for your purpose, but I surely cannot recommend doing things this way.

\documentclass{article}

\long\def\beginworkplan#1\endworkplan{%
  whatever with #1% #1 here is the same as \BODY with \NewEnviron
}

\begin{document}

\beginworkplan
Plan
\endworkplan
\makeatother

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.