today i would like to renew some latex environments; so i started with this code snippet:

\documentclass{article}

\newenvironment{foo}{
    \textrm{begin}
}{
    \textrm{end}
}

\let\oldfoo\foo
\let\oldendfoo\endfoo

\renewenvironment{foo}{
    < \oldfoo >
}{
    < \oldendfoo >
}

\begin{document}

\begin{foo}
body
\end{foo}


\end{document}

what happens here is very simple: i defined an environment foo that adds begin and end around a body of text; so the output is something like this:

begin body end

then i renewed this environment to add angle brackets to begin and end; now the output is something like this:

<begin> body <end>

not painful at all; but what if i would like to add another environment foo* that is the same as foo, but displays begin and end in italic?

\newenvironment{foo*}{
    \textit{begin}
}{
    \textit{end}
}

how do i renew this environment foo* to add angle brackets?

round 1

round one, ready go; my very first thought is to very brutally copy renew code for foo and replace all foo with foo*:

\let\oldfoo*\foo*
\let\oldendfoo*\endfoo*

\renewenvironment{foo*}{
    < \oldfoo* >
}{
    < \oldendfoo* >
}

but i was defeated: it doesnt compile;

round 2

gladly, i found this post; i dont know if there are \makestarletter and \makestarother, but directly changing catcodes of *looks promising;

round two, ready go:

\catcode`\*=11
\let\oldfoo*\foo*
\let\oldendfoo*\endfoo*
\catcode`\*=12

\renewenvironment{foo*}{
    < \oldfoo* >
}{
    < \oldendfoo* >
}

guess what: it now compiles; but the output is wrong:

<begin*> body <end*>

so i was defeated again;

round 3

gladly, i found this post; it turns out that * cannot be used for the name of a control sequence; i need to use \csname...\endcsname; this isnt syntactic sugar, is it? syntactically bitter, anyway, round three, ready go:

\catcode`\*=11
\let\oldfoo*\foo*
\let\oldendfoo*\endfoo*
\catcode`\*=12

\renewenvironment{foo*}{
    < \csname oldfoo*\endcsname >
}{
    < \csname oldendfoo*\endcsname >
}

guess what: this time it worked! i won! happy brainf^ck!