0

As title goes, I want to find a way to get the access of the words inside the environment. To be exactly, given some command \operate with one variable, I want to define an environment foo such that

\begin{foo}
This is the inside words. 
\end{foo}

outputs like \operate{This is the inside words. }. Roughly speaking, I want a command help me get access to the words between \begin{foo} and \end{foo}. This problem is fundamentary in some ways.

  • If the command is empty, it is just what the package comment did. (Note that it is impossible to define \newenvironment{comment}{\iffalse}{\fi}, since the expansion of \fi is later than \iffalse)
  • If the command is \fbox{#1}, it is just what the package mdframed did. This answer explain why it is not easy .

I try to figure out a solution as follow

\newenvironment{foo}{}{\endgroup}
\long\def\foo#1\end{\begingroup\noindent\fbox{\vbox{#1\unskip}}\end}
\begin{foo}
This is the inside words.
\end{foo}

But the problem is that we cannot use other environment inside this environment.

Cubic Bear
  • 101
  • 2
  • 2
    The environ package does this. – schtandard Sep 09 '19 at 15:17
  • Using \NewEnviron (from the environ package), the contents of the argument are contained in \BODY. You can likely, in the environment, say \expandafter\operate\expandafter{\BODY} to get \operate to operate on the contents of \BODY.. – Steven B. Segletes Sep 09 '19 at 15:25
  • Do you want this to handle things like \verb|This is verbatim| also? (That is something the environ-packe does not afaik.) – Ulrich Diez Sep 09 '19 at 19:11
  • And what about the space tokens that due to the \endlinechar-thingie come into being at the ends of lines, e.g., at the end of the line \begin{foo} or at the end of the last line within the environment foo? – Ulrich Diez Sep 09 '19 at 19:17

0 Answers0