答え1
erik が言ったことに加えて、多くのクラスでは、すべての質問のテキストの後に各質問を入力するためのスペースが必要なことが分かりました。私は、質問を 1 回入力してコンパイラを数回実行するだけで、これを自動的に実行できるように試験クラスを拡張しました。
%\NeedsTeXFormat{Latex2e}[1996/06/01]
\ProvidesClass{examExt}[2016/11/09 v1.0]
\LoadClassWithOptions{exam}
\RequirePackage{etex}
\global\newwrite\examfile%
\newcommand\insertQuestions[1][plain]{
\begingroup
\IfFileExists{./\jobname.exm}{\thispagestyle{#1}\input{\jobname.exm}}{\typeout{Class exam Warning: Questions file created. Rerun to get expected output.}}
\endgroup
\immediate\openout\examfile=\jobname.exm
}
\AtEndDocument{
\immediate\closeout\examfile
}
\newcommand\create@environment[1]{
\newenvironment{my#1}{%
\begin{#1}
\immediate\write\examfile{\string\begin{#1}}
}{%
\immediate\write\examfile{\string\end{#1}}
\end{#1}
}
}
\newcommand\create@item[1]{
\expandafter\newcommand\csname my#1\endcsname[2]{%
\if\relax\detokenize{##1}\relax
\csname #1\endcsname ##2
\immediate\write\examfile{\string\csname \space #1\string\endcsname\relax \unexpanded{##2}}%
\else
\csname #1\endcsname[##1] ##2
\immediate\write\examfile{\string\csname \space #1\string\endcsname[##1] \unexpanded{##2}}%
\fi
}
}
\newcommand\create@titleditem[1]{
\expandafter\newcommand\csname my#1\endcsname[3]{%
\if\relax\detokenize{##2}\relax
\csname #1\endcsname{##1} ##3
\immediate\write\examfile{\string\csname \space #1\string\endcsname\unexpanded{\begingroup ##1\endgroup}\relax \unexpanded{##3}}%
\else
\csname #1\endcsname{##1}[##2] ##3
\immediate\write\examfile{\string\csname \space #1\string\endcsname\unexpanded{##1}[##2] \unexpanded{##3}}%
\fi
}
}
\create@environment{questions}
\create@environment{parts}
\create@environment{subparts}
\create@environment{subsubparts}
\create@item{question}
\create@item{part}
\create@item{subpart}
\create@item{subsubpart}
\create@titleditem{titledquestion}
\newcommand\insertClearPage{\immediate\write\examfile{\string\clearpage}}
使用方法を示す MWE を以下に示します。別のファイルを作成し、2 回目のパスで上部に質問をコピーします。
\documentclass{examExt}
\usepackage{amsmath, amssymb}
\begin{document}
\insertQuestions
\clearpage
\begin{myquestions}
\myquestion{2}{This is a question $3\in\mathbb{R}$}
\begin{solutionbox}{3in}
This is a solution
\end{solutionbox}
\begin{myparts}
\mypart{2}{This is a part}
\begin{solutionbox}{3in}
This is a solution
\end{solutionbox}
\end{myparts}
\end{myquestions}
\end{document}
答え2
ここで、\Calculate{}
問題を提示するために を導入し、\Solution{}
答えを提示するために を導入します。 は\Solution
「問題」を最初の行として自動的に再述し、 のオプション引数は[]
通常後に続く改行を抑制します (項目 1 を参照)。
\documentclass[10pt]{amsart}
\usepackage{tabstackengine,enumitem}
\newcommand\Calculate[1]{Calculate $#1$\def\Question{#1}}
\newcommand\Solution[2][\\]{Solution: \Longunderstack[l]{\Question#1#2}}
\stackMath
% TO PROVIDE BLANK SOLUTION
%\renewcommand\Solution[2][\\]{Solution: \setbox0=\hbox{%
% \Longunderstack[l]{\Question#1#2}}\rule[-\dp0]{0pt}{\dimexpr\ht0+\dp0}}
% TO PROVIDE NO SOLUTION
%\renewcommand\Solution[2][\\]{}
\begin{document}
\sffamily
\begin{enumerate}[listparindent=0in,itemsep=5pt]
\item \Calculate{1 + 2}
\Solution[]{=3}
\item \Calculate{1 + 2 + 3}
\Solution{=3+3\\=6}
\item \Calculate{1+2+3+4}
\Solution{=3+3+4\\=6+4\\=10}
\item \Calculate{1+2+3+4+5}
\Solution{=3+3+4+5\\=6+4+5\\=10+5\\=15}
\item
\end{enumerate}
\end{document}
\Solution
解決策を空白にするには、次のように再定義する行のコメントを解除します。
\renewcommand\Solution[2][\\]{Solution: \setbox0=\hbox{%
\Longunderstack[l]{\Question#1#2}}\rule[-\dp0]{0pt}{\dimexpr\ht0+\dp0}}
取得するためいいえ解決策としては、他の行のコメントを外して\Solution
次のように再定義するだけです。
\renewcommand\Solution[2][\\]{}
代わりの
解答の各行の先頭にを入力したくない場合は=
、問題の再述後に改行を抑制するオプションの引数機能を放棄することによってのみ実現できます (項目 1 と比較)。
\documentclass[10pt]{amsart}
\usepackage{tabstackengine,enumitem}
\def\stackalignment{l}
\newcommand\Calculate[1]{Calculate $#1$\def\Question{#1}}
\newcommand\Solution[1]{Solution: \stackunder{\Question}
{\tabbedLongunderstack[l]{#1}}}
\stackMath
\TABstackMath
\TABstackMathstyle{=}
% TO PROVIDE BLANK SOLUTION
%\renewcommand\Solution[1]{Solution: \setbox0=\hbox{\stackunder{\Question}%
% {\tabbedLongunderstack[l]{#1}}}\rule[-\dp0]{0pt}{\dimexpr\ht0+\dp0}}
% TO PROVIDE NO SOLUTION
%\renewcommand\Solution[1]{}
\begin{document}
\sffamily
\begin{enumerate}[listparindent=0in,itemsep=5pt]
\item \Calculate{1 + 2}
\Solution{3}
\item \Calculate{1 + 2 + 3}
\Solution{3+3\\6}
\item \Calculate{1+2+3+4}
\Solution{3+3+4\\6+4\\10}
\item \Calculate{1+2+3+4+5}
\Solution{3+3+4+5\\6+4+5\\10+5\\15}
\item
\end{enumerate}
\end{document}
答え3
クラスを使用するexam
と、解答のためのスペースを残すこともできます。また、質問または質問の一部 (ここでは省略) にポイントを割り当てることもできます。
\documentclass[
answers
]{exam}
\usepackage{mathtools}
\begin{document}
\begin{questions}
\question Calculate \(1 + 2\)
\begin{solution}
\(1 + 2 = 3\)
\end{solution}
\question Calculate \(1 + 2 + 3\)
\begin{solution}
\begin{align*}
& 1 + 2 + 3\\
& = 3 + 3\\
& = 6
\end{align*}
\end{solution}
\end{questions}
\end{document}