I have some environments foo
and bar
that I would like to replace with the environments newfoo
and newbar
with the words "This is a modified foo/bar environment:" added before the environment. I am trying to do it in a loop, like so:
\documentclass{minimal}
\usepackage{amsthm}
\let\bar\relax
\newtheorem{foo}{Foo}
\newtheorem{bar}{Bar}
\newtheorem{newfoo}{New Foo}
\newtheorem{newbar}{New Bar}
\makeatletter
\@for\@env:=foo,bar\do{%
\renewenvironment{\@env}{%
This is a modified \@env environment:
\begin{new\@env}
}{%
\end{new\@env}
}%
}
\makeatother
\begin{document}
\begin{foo}
I want this to be New Foo.
\end{foo}
\begin{bar}
I want this to be New Bar.
\end{bar}
\end{document}
However, this does not work because \begin
does not want to expand the command \@env
. I have unsuccessfully tried to add \expandafter
s there, but I did not manage to make it work. I have also attempted to circumvent it by using
\renewenvironment{\@env}{%
This is a modified \@env environment:
\csname new\@env\endcsname
}{%
\csname endnew\@env\endcsname
}%
but apparently this does not work either (I'm not actually sure why).
Can someone suggest a working solution?