I have done something similar; in my experience, it was an environment that has
- a question
- a proof / answer
Here's an example:
\documentclass{article}
\usepackage{amsthm}
\newenvironment{questionanswer}{
\newcommand{\nextpart}{\end{quote}\begin{proof}}
\begin{quote}%
}{%
\end{proof}%
}
\begin{document}
\begin{questionanswer}
Something to be quoted.
\nextpart
Something to be proven.
\end{questionanswer}
\end{document}
To my understanding, this is expanded to exactly
\begin{document}
\begin{quote}
Something to be quoted.
\end{quote}\begin{proof}
Something to be proven.
\end{proof}
\end{document}
Note that by using \renewcommand
, this can be arbitrarily complex:
\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\newenvironment{questionanswer}{%
\newcommand{\nextpart}{\end{quote}\begin{proof}%
\renewcommand{\nextpart}{\end{proof}\begin{itemize}%
\renewcommand{\nextpart}{\end{itemize}\begin{enumerate}%
\renewcommand{\nextpart}{\end{enumerate}\begin{equation}%
}}}}% As you can see, this can be arbitrarily complex
% (just be careful of your braces!)
\begin{quote}%
}{%
\end{equation}%
}
\begin{document}
Some normal text.
\begin{questionanswer}
Something to be quoted.
\nextpart
Something to be proven.
\nextpart
\item one
\item two
\nextpart
\item enum a
\item enum b
\nextpart
\sum_0^\infty a_n := \lim_{n\to\infty}\sum_0^n a_n
\end{questionanswer}
\end{document}

This works by defining \nextpart
to both
- change the environment
- change the definition of
\nextpart
at each invocation. If \nextpart
were defined outside of the questionsanswer
environment, there'd be no way to reset \nextpart
to the value it should have at the beginning of each cycle.
\nextpart
) that will change stuff in your environment (IMO, you do not need to repeat "myenv"). I think that the command\appendix
work like that in the environment "document"...