Hel-lo, I am a LaTeX programming newbie.
While formatting my document, I found that it will look nice if I can modify the theorem environment (with amsthm package). So I tried the following code
\makeatletter
\newcount\@envcount
\newcommand{\enclosebox}[2]{%
% Create copies of old environments
\expandafter\let\expandafter\@old\csname #1\endcsname%
\expandafter\let\expandafter\@oldend\csname end#1\endcsname%
% Redefine environment using old ones.
\renewenvironment{#1}[1][]{%
\@nameuse{@old}[##1]%
\begin{#2}%
}{%
\end{#2}%
\@nameuse{@oldend}%
}%
}
\makeatother
This command inserts a new environment (with name #2) to the original environment (with name #1). With this, I can modify theorem environments like this:
\newtheorem{theorem}{Theorem}
\enclosebox{theorem}{<some box environment>}
The problem is, the token \@old
and \@oldend
are overwritten whenever I call \enclosebox
command. For example,
\enclosebox{theorem}{shadebox}
\enclosebox{definition}{shadebox}
\enclosebox{example}{leftbar}
overwrites my old definition and theorem environment, resulting in something like:
So I tried using \csname ~ \endcsname
to assign the name dynamically, but the compiler just spits out a bunch of errors.
Of course I can resolve this problem by pasting multiple copy of the code and modifying each one by hands... but I am doing in this way just to avoid this clumsy solution.
I have no idea how to fix my code. Can you help me?