I have a macro that requires some setup code before being called :
\documentclass{minimal}
\usepackage{color}
\begin{document}
% some setup code
\colorbox{green}{This is green.}
% some cleanup code
\end{document}
All is good, but I don't like duplicating the setup/cleanup code.
How can I get a similar result using Environments? That way I could place the setup code in the "begin" section and the cleanup in the "end" section.
I tried the following, but obviously that's not how it works :
\documentclass{minimal}
\usepackage{color}
% % % % THIS DOES NOT WORK % % % %
\newenvironment{green}{\colorbox{green}\begingroup}{\endgroup}
% % % % THIS DOES NOT WORK % % % %
\begin{document}
\begin{green}
This should be green as well.
\end{green}
\end{document}
This gives the error ! Extra }, or forgotten \endgroup. I tought that \begingroup and \endgroup were specifically for using in unbalanced situations.
What are my options?



\begingroupand\endgrouponly help if you want a group. To get unbalanced braces, one technique is to use\bgroupand\egroup, which are\letto{and}, but this doesn't help with macro arguments. It does help with (most) boxes, but that's special. – Ryan Reich Aug 27 '13 at 19:08