サブ質問とそれに対応する回答をタイプセットする方法

サブ質問とそれに対応する回答をタイプセットする方法

コードでは各サブ質問の直後に回答がありますが、出力ではすべての回答が最後に表示されるように、サブ質問を含む演習をタイプセットしたいと思います。また、演習とサブ質問の両方に自動的に番号が付けられるようにしたいと思います。演習のタイプセット用のパッケージがいくつかあることは知っています (たとえば、「answers」、「exercise」、「probsoln」など)。また、「exam」と呼ばれるドキュメント タイプがあることも知っています。

私の質問は、どのパッケージがこれに最も適しており、どのようなコードが結果を生成するのかということです。

次のようなことを書きたいと思います。

\begin{ExerciseList}
  \Exercise{}
    Calculate the following:
    \Question{$7+2$}
      \Answer{$9$}
    \Question{$9-9$}
      \Answer{$0$}
    \Question{$5+5+5$}
      \Answer{$15$}
  \Exercise{}
    Solve the following equations:
    \Question{$x+5=7$}
      \Answer{$x=2$}
    \Question{$x-5=9$}
      \Answer{$x=14$}
    \Question{$5x=20$}
      \Answer{$x=4$}
\end{ExerciseList}

そして、最終的な文書は次のようになります。

練習1
次の計算をしてください。a
) 7+2 b) 9-9 c) 5+5+5

練習2
次の方程式を解きます。a
) x+5=7 b) x-5=9 c) 5x=20

解決策:

練習1
a) 9 b) 0 c) 15

練習2
a) x+5=7 b) x=14 c) x=4

上記のコードは単なる例です。構造が類似していれば、コマンドは私が書いたものとまったく同じである必要はありません。

答え1

パッケージを使用するとprobsoln、問題をドキュメント内、または\loadallproblemsやなどのコマンドを使用して読み込むことができる外部ファイル内に定義できます\loadrandomproblems

ドキュメントで定義されている問題の簡単な例を次に示します。

\documentclass{article}

\usepackage{probsoln}

\begin{defproblem}{prob1}% label
  \begin{onlyproblem}% question
    Calculate the following:%

    \begin{textenum}
    \item $7+2$
    \item $9-9$
    \item $5+5+5$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $9$
    \item $0$
    \item $15$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\begin{defproblem}{prob2}% label
  \begin{onlyproblem}% question
    Solve the following equations:

    \begin{textenum}
    \item $x+5=7$
    \item $x-5=9$
    \item $5x=20$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $x=2$
    \item $x=14$
    \item $x=4$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\begin{document}
\renewcommand{\labelenumii}{\theenumii)}

\begin{enumerate}
\foreachproblem{\item\thisproblem}
\end{enumerate}

\section*{Solutions}

\showanswers
\begin{enumerate}
\foreachsolution{\item\thisproblem}
\end{enumerate}

\end{document}

これにより

問題と解決策を示す文書の画像

書式は変更できます。たとえば、enumitemパッケージ:

\documentclass{article}

\usepackage{probsoln}
\usepackage{enumitem}

\begin{defproblem}{prob1}% label
  \begin{onlyproblem}% question
    Calculate the following:%

    \begin{textenum}
    \item $7+2$
    \item $9-9$
    \item $5+5+5$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $9$
    \item $0$
    \item $15$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\begin{defproblem}{prob2}% label
  \begin{onlyproblem}% question
    Solve the following equations:

    \begin{textenum}
    \item $x+5=7$
    \item $x-5=9$
    \item $5x=20$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $x=2$
    \item $x=14$
    \item $x=4$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\newenvironment{ExerciseList}
{\begin{enumerate}[label={\emph{Exercise \arabic*}},%
   ref={\arabic*},wide]
  \renewcommand{\labelenumii}{\theenumii)}%
}
{\end{enumerate}}

\newcommand{\exercise}{\item\mbox{}\par}

\begin{document}

\begin{ExerciseList}
\foreachproblem{\exercise\thisproblem}
\end{ExerciseList}

\section*{Solutions}

\showanswers
\begin{ExerciseList}
\foreachsolution{\exercise\thisproblem}
\end{ExerciseList}

\end{document}

これにより、次のものが生成されます。

結果のドキュメントの画像

編集:

コード内の質問の横に答えを書く別の方法は次のとおりです。

\documentclass{article}

\usepackage{probsoln}
\usepackage{enumitem}

\newcommand{\QA}[2]{%
  \begin{onlyproblem}#1\end{onlyproblem}%
  \begin{onlysolution}#2\end{onlysolution}}

\begin{defproblem}{prob1}% label
  \begin{onlyproblem}% question
    Calculate the following:%

  \end{onlyproblem}%
  \begin{textenum}
    \item \QA{$7+2$}{$9$}
    \item \QA{$9-9$}{$0$}
    \item \QA{$5+5+5$}{$15$}
  \end{textenum}
\end{defproblem}

\begin{defproblem}{prob2}% label
  \begin{onlyproblem}% question
    Solve the following equations:

  \end{onlyproblem}%
  \begin{textenum}
    \item \QA{$x+5=7$}{$x=2$}
    \item \QA{$x-5=9$}{$x=14$}
    \item \QA{$5x=20$}{$x=4$}
  \end{textenum}
\end{defproblem}

\newenvironment{ExerciseList}
{\begin{enumerate}[label={\emph{Exercise \arabic*}},%
   ref={\arabic*},wide]
  \renewcommand{\labelenumii}{\theenumii)}%
}
{\end{enumerate}}

\newcommand{\exercise}{\item\mbox{}\par}

\begin{document}

\begin{ExerciseList}
\foreachproblem{\exercise\thisproblem}
\end{ExerciseList}

\section*{Solutions}

\showanswers
\begin{ExerciseList}
\foreachsolution{\exercise\thisproblem}
\end{ExerciseList}

\end{document}

結果は前の例と同じになります。

編集2:

問題を定義して表示するメソッドを次に示します。ラベルは自動的に生成されます。

\documentclass{article}

\usepackage{probsoln}
\usepackage{enumitem}

\newcommand{\QA}[2]{%
  \begin{onlyproblem}#1\end{onlyproblem}%
  \begin{onlysolution}#2\end{onlysolution}}

\newenvironment{ExerciseList}
{\begin{enumerate}[label={\emph{Exercise \arabic*}},%
   ref={\arabic*},wide]
  \renewcommand{\labelenumii}{\theenumii)}%
}
{\end{enumerate}}

\newcommand{\exercise}{\item\mbox{}\par}

\newcommand{\Exercise}[2]{\exercise 
 #1\par
 \begin{defproblem}{prob\arabic{enumi}}%
  \begin{textenum}%
  #2%
  \end{textenum}%
 \end{defproblem}%
 \useproblem{prob\arabic{enumi}}%
}

\begin{document}

\begin{ExerciseList}
 \Exercise{Calculate the following:}%
 {%
    \item \QA{$7+2$}{$9$}
    \item \QA{$9-9$}{$0$}
    \item \QA{$5+5+5$}{$15$}
 }%

 \Exercise{Solve the following equations:}
 {%
    \item \QA{$x+5=7$}{$x=2$}
    \item \QA{$x-5=9$}{$x=14$}
    \item \QA{$5x=20$}{$x=4$}
 }
\end{ExerciseList}

\section*{Solutions}

\showanswers
\begin{ExerciseList}
\foreachsolution{\exercise\thisproblem}
\end{ExerciseList}

\end{document}

答え2

パッケージを使用した解決策は次のとおりですanswers。回答のフォーマットを調整できます。

\documentclass[pdftex,12pt]{article}

\usepackage{amsmath}
\usepackage{answers}

\newcommand{\answerFileName}{anexamanswers}
\Newassociation{sol}{Solution}{\answerFileName}
\Opensolutionfile{\answerFileName}

\newenvironment{Exercise}[1]
{\item #1
\begin{enumerate}
}
{
\end{enumerate}
}

\newcommand{\Question}[1]{%
\item #1
}


\begin{document}
\begin{enumerate}

\begin{Exercise}{Calculate the following:}
    \Question{$7+2$}
     \begin{sol}
         $9$
     \end{sol}
    \Question{$9-9$}
      \begin{sol}
          $0$
      \end{sol}
\end{Exercise}

\begin{Exercise}{Solve the following equations:}
    \Question{$x+5=7$}
      \begin{sol}
        $x=2$
     \end{sol}
    \Question{$x-5=9$}
%      \Answer{$x=14$}
    \Question{$5x=20$}
%      \Answer{$x=4$}
\end{Exercise}

\end{enumerate}

\Closesolutionfile{\answerFileName}
\newpage
Answers to Exercises:

\input{\answerFileName}
\end{document}

ここに画像の説明を入力してください

答え3

exsheetsおよびパッケージを使用する提案を次に示しますtasks

\documentclass{article}
\usepackage{exsheets,tasks}
\SetupExSheets{
  solution/name=Exercise ,
  headings-format=\itshape
}
\begin{document}

\begin{question}
  Calculate the following:
  \begin{tasks}(3)
    \task $7+2$
    \task $9-9$
    \task $5+5+5$
  \end{tasks}
\end{question}
\begin{solution}
  \begin{tasks}(3)
    \task $9$
    \task $0$
    \task $15$
  \end{tasks}
\end{solution}

\begin{question}
  Solve the following equations:
  \begin{tasks}(3)
    \task $x+5=7$
    \task $x-5=9$
    \task $5x=20$
  \end{tasks}
\end{question}
\begin{solution}
  \begin{tasks}(3)
    \task $x=2$
    \task $x=14$
    \task $x=4$
  \end{tasks}
\end{solution}

\section*{Solutions}
\printsolutions

\end{document}

ここに画像の説明を入力してください

関連情報