質問と回答の環境を定義する方法

質問と回答の環境を定義する方法

生徒のために簡単な質問と回答のシートを作りたいと思っています。次のようなものを作りたいと思っています。

\section{Differential Equations}

    \begin{questions}

         \begin{question}
              ... Question here ...
         \end{question}

         \begin{answer}
              ... Answer here ...
         \end{answer}

    \end{questions}

環境QUESTIONSにenumerateのようなカウンターを持たせたい。つまり、それぞれが次のように\begin{question} ... \end{question}動作する。\item

\begin{question} 
\item 
\end{question}

環境\begin{question} ... \end{question}は「通常の」LaTeX コマンドを実行する必要があります。

可能であれば、回答を文書の最後に印刷するために遅延印刷を希望します。

私はこれを最初に試しました

\makeatletter
\newtoks\answerscollect
\newcounter{question}
\setcounter{question}{0}
\def\thequestion{{\bfseries{Question \arabic{question}. }}\\}

\def\answer#1{%
\protected@edef\answertmp{%
\the\answerscollect\vspace{.5\baselineskip}\noindent\thequestion#1\par}%
\par\answerscollect=\expandafter{\answertmp}}
\def\printanswers{\the\answerscollect\answerscollect={}}
\def\initbox{\answerscollect={\par\noindent Answers:\par}}

\newcommand{\question}[1]{\stepcounter{question}\par\noindent\thequestion#1}
\makeatother

しかし、結果は私が望んでいた通りには動作しません...

答え1

パッケージの簡単な使い方 exam:

\documentclass{exam}
%\printanswers
\begin{document}

\section{Differential Equations}
\begin{questions}
\question ... Short question here ... \answerline[Short answer]
\question ... Question here ... 

\begin{solution}[.2in]
... Answer here ... 
\end{solution}

\question Long descriptive question about everything

\begin{solutionorlines}[2in]
Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
\end{solutionorlines}

\question Draw an arrow showing north direction.

\begin{solutionorbox}[2in]
$\uparrow$
\end{solutionorbox}

\end{questions}

\ifprintanswers
Stuff to appear only when answers \textbf{are} being printed.
\else
Stuff to appear only when answers \textbf{are not} being printed.
\fi

\end{document}

コメント化とコメント解除によって、\printanswers次の 2 つのいずれかが行われます。

1)

質問のみ

2)

答えのある質問

あなたの例と比べて機能不足は見当たりません。

関連情報