# Capture the content within an environment

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?

• Without more details of what you really want to do it is difficult to say for sure but I think that you want the environ package. – Andrew Jun 12 '18 at 17:00
• You can use the environ package then do \NewEnviron{some}{Do things with \BODY}. Then when you call \begin{some} stuff \end{some} you get Do things with stuff. – Phelype Oleinik Jun 12 '18 at 17:00
• currently I am experimentating I just need a way to access the "stuff" part and by the sound, environ is it, imma try – Zelos Malum Jun 12 '18 at 17:01
• works dandy, thanks guys! :D anyone wanting the rep just write the answer and I'll accept it – Zelos Malum Jun 12 '18 at 17:04

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.

\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}