Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I made a custom class for homework assignments and I've defined a solution environment as follows:

\def\qed{\ensuremath{\square}} % <-QED Symbol
\newenvironment{solution}{%  <-Solution
  \par\addvspace{1em}
  \itshape{Solution:}}
  {\par\normalfont\hfill\qed\par\addvspace{\medskipamount}}%

This is intended to be a general purpose environment, but I am making a package specifically for use with math typesetting, and I'd like to slightly modify my solution environment when I load that package in this class... but I've tried the following and I get an error:

\let\solution\relax

\newenvironment{solution}{%  <-Solution
  \par\addvspace{1em}
  \itshape{Solution:}\par\addvspace{\medskipamount}}
  {\par\normalfont\hfill\qed\par\addvspace{\medskipamount}}%

The error I get when trying to compile a document is

Command \solution already defined.

share|improve this question
2  
There is \renewenvironment. Otherwise you will need to \let\endsolution\relax. –  Qrrbrbirlbel Feb 27 '13 at 19:21
    
Ah, good - I suppose it would have been nice to try that first. Thanks. –  agent154 Feb 27 '13 at 19:22
    
@Qrrbrbirlbel please post an answer :) –  cmhughes Feb 27 '13 at 21:21
add comment

1 Answer 1

The macro \renewenvironment is there to overwrite a previous defined environment (similar to \renewcommand and \newcommand).

Otherwise you will also need to \let\endsolution\relax.

Code

\documentclass{article}

% \newenvironment{<name>} defines \<name> and \end<name>
% and it checks if both are undefined (= \relax)
\newenvironment{solution}{stuff}{end stuff}

% Solution 1
% \renewenvironment{<name>} checks if both are defined (!= \relax)
\renewenvironment{solution}{other stuff}{end other stuff}

% Solution 2 (just for completeness)
%\let\solution\relax
%\let\endsolution\relax
%\newenvironment{solution}{other stuff}{end other stuff}

\begin{document}
    \begin{solution}
        content
    \end{solution}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.