我想排版带有子问题的练习,以便在代码中每个子问题后面立即有一个答案,但在输出中所有答案都会在最后。我还希望练习和子问题都自动编号。我知道有几种排版练习的包(例如“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}