我想定义一个包含两部分的环境,即
\begin{myenv}
some text
\nextpart{myenv}
some more
\end{myenv}
\begin
我想我可以通过探索、\end
和的定义来做到这一点\newenvironment
,但我想知道是否有人已经这样做了。
答案1
我也做过类似的事情;根据我的经验,那是一个
- 一个问题
- 证明/答案
以下是一个例子:
\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}
据我理解,这完全扩展为
\begin{document}
\begin{quote}
Something to be quoted.
\end{quote}\begin{proof}
Something to be proven.
\end{proof}
\end{document}
请注意,通过使用\renewcommand
,这可以任意复杂:
\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}
这通过定义\nextpart
两者来实现
- 改变环境
- 改变定义
\nextpart
每次调用时。如果\nextpart
定义外部环境questionsanswer
,没有办法重置\nextpart
它的价值应该在每个周期的开始处都有。