In a general setting, you wish to capture the entire environment into a macro, and then pass that macro to another macro as an argument. That is exactly what the environ
package provides:
\documentclass{article}
\usepackage{environ}% http://ctan.org/pkg/environ
\NewEnviron{myenv}[1][\textit]{%
#1{\BODY}%
}
\begin{document}
\begin{myenv}
Hello World!
\end{myenv}
\begin{myenv}[\textbf]
Hello World!
\end{myenv}
\begin{myenv}[\slshape]
Hello World!
\end{myenv}
\begin{myenv}[]
Hello World!
\end{myenv}
\end{document}
environ
allows you to capture the contents of the environment into the macro \BODY
, which is then usable for whatever means. My definition prints it using \textit
by default, but you can modify that using a different macro or font switch.
The above definition of myenv
is general enough to allow for formatting of the environment content using a macro or a switch (as is done in the 3rd example). Supplying an empty (optional) argument removes any formatting.