2

When working in latex I can do an environment like

\begin{some}
stuff
\end{some}

and stuff happen and I can define my own environments, I am working on something and what I want to do is essentially to grab everything that was "stuff" in the example and do something to it during the end part of the definition, how would I go about that?

Bernard
  • 271,350

1 Answers1

4

For this you can use the environ package's \NewEnviron{<env>} definition. The environment contents is captured inside \BODY that you can set as-is, or manipulate however you want.

enter image description here

\documentclass{article}

\usepackage{environ}

\NewEnviron{some}{%
  \BODY% Print the body of the some environment

  \renewcommand{\thisorthat}{that}% Update
  \BODY% Print the body of the some environment
}

\newcommand{\thisorthat}{this}

\begin{document}

\begin{some}
  It's either \thisorthat, or \thisorthat.
\end{some}

\end{document}
Werner
  • 603,163