Verbatim in environ’s \BODY

The environ environments read their content in one go like a macro and are therefore not "real" environments, but rather pseudo-environments (looks like an environment, works like a macro). This does not allow for verbatim content, as with normal macros. The content is read before the verbatim mode can be enabled, so all code is already parsed and categorized.

To get around this, you need to use a normal environment and then replicate the content several times. Usually this can be done by storing the content in a savebox, but your three alternatives do not allow for this because boxing will fix the content. Instead you should write the content to an external file and read it in multiple times. This can be done automatically without the need for manual filecontents environments. An easy way is provided by the listings package as shown by me in Write environment body verbatim to a file.

\documentclass{article}

\makeatletter
\RequirePackage{listings}
\lst@RequireAspects{writefile}

\newcommand{\mlw}[3]{}
\newcommand{\mlwa}[3]{#1}
\newcommand{\mlwb}[3]{#2}
\newcommand{\mlwc}[3]{#3}

\lstnewenvironment{multichaps}{%
  % Write file to given filename
  \lst@BeginWriteFile{\jobname.mul}%
}
{%
  \lst@EndWriteFile% closes output file
  \let\mlw\mlwa
  \input{\jobname.mul}%
  \let\mlw\mlwb
  \input{\jobname.mul}%
  \let\mlw\mlwc
  \input{\jobname.mul}%
}
\makeatother

\begin{document}

\begin{multichaps}
\section{Installation on \mlw{Mac}{Windows}{Linux}}
Now it's time to test the system. Create a file
test.tex with the follwoing content.
\begin{verbatim}
\documentclass{article}

\begin{document}
Hallo World!
\end{document}
\end{verbatim}
Now open your \mlw{Terminal}{(Eingabeaufforderung)}{Terminal}
and call \verb+pdflatex test+
\end{multichaps}

\end{document}

Alternative, you can store the content verbatim in a macro and reevaluate it using e-TeX's \scantokens, which is basically the same as to write it into an external file and rereading it, but more efficient. One issue here seems the handling of end-of-line (EOF) characters. The content can be stored in a macro e.g. using my newverbs package. However, it does not provide an environment variant yet, so you need to use the macro version:

\documentclass{article}

\usepackage{newverbs}

\newcommand{\mlw}[3]{}
\newcommand{\mlwa}[3]{#1}
\newcommand{\mlwb}[3]{#2}
\newcommand{\mlwc}[3]{#3}

\makeatletter
\newcommand{\multichaps}{%
    \begingroup
    \expandafter\Collectverb\expandafter\@multichaps\expandafter
}

% The EOL character must be active to work with 'verbatim'.
% By default it should produce a space.
% This will break implicit paragraphs!
\begingroup
\catcode13=\active%
\gdef\activenl{%
    \catcode13=\active%
    \let^^M\space%
}%
\endgroup%

\newcommand{\@multichaps}[1]{%
  \activenl
  \let\mlw\mlwa
  \scantokens{#1}%
  \let\mlw\mlwb
  \scantokens{#1}%
  \let\mlw\mlwc
  \scantokens{#1}%
  \endgroup
}
\makeatother

\begin{document}

\multichaps=
\section{Installation on \mlw{Mac}{Windows}{Linux}}
Now it's time to test the system. Create a file
test.tex with the follwoing content.
\begin{verbatim}
\documentclass{article}

\begin{document}
Hallo World!
\end{document}
\end{verbatim}
Now open your \mlw{Terminal}{(Eingabeaufforderung)}{Terminal}
and call \verb+pdflatex test+
=

\end{document}

In ConTeXt, the standard way to store and manipulate body environment without storing it as a macro is to use buffers. For example, this is how the same macro could be written in ConTeXt and it works as expected.

\let\mlw\gobblethreearguments

\def\startmultichapters
    {\grabbufferdata[multichapters][startmultichapters][stopmultichapters]}

\def\stopmultichapters
    {\let\mlw\firstofthreearguments
     \getbuffer[multichapters]%
     \let\mlw\secondofthreearguments
     \getbuffer[multichapters]%
     \let\mlw\thirdofthreearguments
     \getbuffer[multichapters]%
     \let\mlw\gobblethreearguments}

\starttext
\startmultichapters
  \startsection[title={\mlw{foo}{bar}{baz}}]
    This is some text in section \mlw{foo}{bar}{baz}
    \starttyping
      Crash
    \stoptyping
  \stopsection
\stopmultichapters
\stoptext

Note: If you are using an older version of ConTeXt (before Feb, 2012), then you need to replace \grabbufferdata with \dostartbuffer.

AFAIK, LaTeX does not have an equivalent of ConTeXt buffers. The closest approximation is to use the filecontents environment to write the contents to an external file (In MkII, ConTeXt buffers also wrote content to external files; but in MkIV, the content is kept in memory). See Taco Hoekwater's answer to LaTeX equivalent of ConTeXt buffers.


Sometime one misses the forest for the trees … I didn’t thougt about putting the contets to an external file an include it three times …

\begin{filecontents}{multichapsbody.tex}
\section{Installation on \mlw{Mac}{Windows}{Linux}}
Now it's time to test the system. Create a file
test.tex with the follwoing content.
\begin{verbatim}
\documentclass{article}

\begin{document}
Hallo World!
\end{document}
\end{verbatim}
Now open your \mlw{Terminal}{(Eingabeaufforderung)}{Terminal}
and call \verb+pdflatex test+
\end{filecontents}

\documentclass{article}

\newcommand{\mlw}[3]{}

\begin{document}
\renewcommand{\mlw}[3]{#1}
\input{multichapsbody}

\renewcommand{\mlw}[3]{#2}
\input{multichapsbody}

\renewcommand{\mlw}[3]{#3}
\input{multichapsbody}
\end{document}