# Why the renewcommand doesn't work as I expect?

I re-defined two environment

\newtheorem{exmp}{Example}
\newenvironment{examp}{\begin{exmp}}{\renewcommand{\proofname}{Sol.}\end{exmp}}
\newenvironment{pf}{\begin{proof}}{\renewcommand{\proofname}{Proof}\end{proof}}


to make sure that when the proofname which is right after the examp environment should change to Solution, while keep it be Proof for other environment(THEOREM, Lemma and so on).

But it seems that it is not worked as I expected. WHY?

-
Please always post a complete document that demonstrates the problem and all packages used (there are several implementations of \newtheorem for example in different packages.) – David Carlisle Jul 23 '14 at 8:56
I just want to ask the logic part, not the grammar part, so it seems useless to post the whole stuff here. – user19832 Jul 23 '14 at 8:59
every question should have a complete example document if you expect people to actually test their answers. Without knowing how proof is defined (which depends on information you have not supplied) I don't see how it's possible to even guess an answer. – David Carlisle Jul 23 '14 at 9:03

(I assume proof is the environment provided by amsthm.)

This can't work, because every environment forms a group and so \renewcommand{\proofname}{Sol.} is forgotten as soon as \end{exmp} is performed.

You may want to use global redefinitions:

\newtheorem{exmp}{Example}
\newenvironment{examp}
{\begin{exmp}}
{\gdef\proofname{Sol.}\end{exmp}}
\newenvironment{pf}[1][\proofname]
{\begin{proof}[#1]}
{\gdef\proofname{Proof}\end{proof}}


but, of course, you're not safe as a pf environment is mandatory after examp or the next proof after a theorem would be called “Sol.”.

I'd simply prefer using

\begin{exmp}
Something
\end{exmp}
\begin{proof}[Sol.]
The solution
\end{proof}


or also define a sol environment

\newenvironment{sol}
{\begin{proof}[Sol.]}
{\end{proof}}


Since this is a different logical unit than a proof, it deserves its own name.

-
Thanks, I know the point now: because every environment forms a group and so \renewcommand{\proofname}{Sol.} is forgotten as soon as \end{exmp} is performed. – user19832 Jul 23 '14 at 9:06