我正在尝试使用该xsim
包对课程 (MAT-1001) 中先前给出的考试进行排序和排序。为了实现这一点,我需要满足以下要求
- 我应该能够按 ID、主题或年份请求考试问题。
- 我希望能够请求问题和子问题。
我尝试使用下面的代码来实现这一点,但我从未遇到过如此奇怪的结果。预期的输出与我的预期相差甚远。完整的代码可以在下面找到,但我想一次解决一个问题。
以下文件是一个示例文件,展示了一些常见的练习。
考试手册
\begin{question}[
year=2017,semester=V,exam=O
ID=MAT-1001-2017-V-H-Problem-1-a,
topic = integral
]
Evaluate the following integrals
\begin{tasks}(3)
\task $\displaystyle \int_0^{\sqrt{\pi/2}} (x+1) \e^{x-1} dx$
\task $\displaystyle \int \frac{a}{x^2 + a^2} dx$
\task $\displaystyle \int \log x dx$.
\end{tasks}
\end{question}
\begin{question}[
year=2017,semester=V,exam=O
ID=MAT-1001-2017-V-H-Problem-1-b,
topic = limit
]
Evaluate the following limits
\begin{tasks}(2)
\task $\displaystyle \lim_{x \to 0} \frac{\sin(x^2)}{x^2}$
\task $\displaystyle \lim_{x \to 0} \frac{\sin(x^2)}{1 + x^2}$.
\end{tasks}
\end{question}
\begin{question}[
year=2017,semester=V,exam=O
ID=MAT-1001-2017-V-H-Problem-1-c,
topic = injective
]
State the definition of an injective function and provle
that the function $f \to \mathbb{R} \to \mathbb{R}$ defined by $\int_0^x
e^{-s^2} dx$ is injective.
\end{question}
\begin{exercise}[year=2017,semester=H,topic={integral,limit,injective},exam=K,
ID=MAT-1001-2017-V-H-Problem-1]
\begin{enumerate}
\item \insertexercise{ID=MAT-1001-2017-V-H-Problem-1-a}
\item \insertexercise{ID=MAT-1001-2017-V-H-Problem-1-b}
\item \insertexercise{ID=MAT-1001-2017-V-H-Problem-1-c}
\end{enumerate}
\end{exercise}
这引出了我的前两个问题
- 我想标记问题并使用这些标签,但上面的代码不起作用。我无法过滤掉每个带有主题的问题
integral
。 - 我怎样才能将问题汇总在一起形成练习(或考试题目)?
我尝试使用代码
\newcommand*\insertexercise[1]{%
\XSIMexpandcode{\printexercise{exercise}{\GetExerciseIdForProperty{ID}{#1}}}%
}
从如何在 xsim 中打印带有 ID 的练习?. 将问题插入到练习中:
\begin{exercise}[year=2017,semester=H,topic={complex,differential},exam=K,
ID=MAT-1001-2017-V-H-Problem-1]
\begin{enumerate}
\item \insertexercise{ID=MAT-1001-2017-V-H-Problem-1-a}
\item \insertexercise{ID=MAT-1001-2017-V-H-Problem-1-b}
\item \insertexercise{ID=MAT-1001-2017-V-H-Problem-1-c}
\end{enumerate}
\end{exercise}
但是这不起作用。如何才能正确地做到这一点?在显示解决方案时,这将如何工作?
在这个问题的剩余部分,我发布了我的 MWE 的片段,分享了我对没有按我预期进行的事情的沮丧。
下面这几行取消注释后编译失败,为什么?
% \collectexercisestype{all} % \input{exam.tex} % \collectexercisesstop{all}
我已经定义了文件exam.tex
但是下面的代码有效
\collectexercisestype{exercise-pool}{exercise}
\input{exam.tex}
\collectexercisesstop{exercise-pool}
% Random exercise
\begin{exercise}
\begin{enumerate}
\item \printrandomexercises[collection=exercise-pool]{2}
\end{enumerate}
\end{exercise}
- 我期望上面的代码能够打印唯一的
Exercise
环境,但exam.tex
它什么也没有打印。为什么?
下面的代码做打印出子问题。但是,为什么它只打印出一无论我输入什么数字?
\collectexercises{subquestions}{subquestion}
\input{exam.tex}
\collectexercisesstop{subquestions}
% Random subquestion
\begin{exercise}
\begin{enumerate}
\item \printrandomexercises[collection=subquestions]{2}
\end{enumerate}
\end{exercise}
我期望以下代码Exercise
从文件中打印出环境,但遗憾的是它什么也没有打印
\insertexercise{ID=MAT-1001-2017-V-H-Problem-1}
类似地,以下代码也不会打印任何内容
\insertexercise{ID=MAT-1001-2017-V-H-Problem-1-a}
此外,我无法打印任何收藏,因为这会导致错误undefined item
。
\section{All}
% \printcollection{all}
\section{Exercises}
% \printcollection{exercise-pool}
\section{Subquestions}
% \printcollection{subquestions}
该文件exam.tex
在问题开始时定义
主文本
\documentclass{article}
\usepackage{amssymb,mathtools}
\usepackage{tasks}
\usepackage{xsim}
% \xsimsetup{
% exercise/name=,
% solution/print=true,
% solution/name=Solution,
% }
\DeclareExerciseTagging{year} % 1992, 2010, etc
\DeclareExerciseTagging{topic}
\DeclareExerciseTagging{semester} % V (Spring), H (Fall)
\DeclareExerciseTagging{exam} % O (ordinary), K (kont / re-sit exam), P (prøveeksamen)
\DeclareExerciseCollection{MAT-1001-Integrals}
\DeclareExerciseType{subquestion}{
exercise-env = question ,
solution-env = answer ,
exercise-name = Question ,
solution-name = Answer ,
exercise-template = item ,
solution-template = item
}
\DeclareExerciseProperty{title}
\DeclareExerciseEnvironmentTemplate{named}
{\subsection*{\GetExercisePropertyTF{title}{#1}{??}}}
{}
\DeclareExerciseEnvironmentTemplate{item}
{\item}
{}
\xsimsetup{
exercise/template = named
}
\DeclareExerciseCollection{all}
\DeclareExerciseCollection{exercise-pool}
\DeclareExerciseCollection{subquestions}
\newcommand{\problemfolder}{exam-problems}
\newcommand*\insertexercise[1]{%
\XSIMexpandcode{\printexercise{exercise}{\GetExerciseIdForProperty{ID}{#1}}}%
}
\begin{document}
% The lines below fails to compile why?
% \collectexercisestype{all}
% \input{exam.tex}
% \collectexercisesstop{all}
% Random subproblem or exercise
% \begin{exercise}[title=Random subproblem or exercise]
% \begin{enumerate}
% \item \printrandomexercises[collection=all]{2}
% \end{enumerate}
% \end{exercise}
% Why does the \printrandomexercises{2} only print 1 instead of two exercises?
% Why does it print the subquestions instead of the exercise?
\collectexercisestype{exercise-pool}{exercise}
\input{exam.tex}
\collectexercisesstop{exercise-pool}
% Random exercise
\begin{exercise}
\begin{enumerate}
\item \printrandomexercises[collection=exercise-pool]{1}
\end{enumerate}
\end{exercise}
% Why does the code below print absolutely nothing?
\collectexercises{subquestions}{subquestion}
\input{exam.tex}
\collectexercisesstop{subquestions}
% Random subquestion
\begin{exercise}
\begin{enumerate}
\item \printrandomexercises[collection=subquestions]{2}
\end{enumerate}
\end{exercise}
% Why does the code below print nothing? Is it possible to nest \insertexercise?
Should print the first problem
\insertexercise{ID=MAT-1001-2017-V-H-Problem-1}
% I can sort of understand why the code above does not work, but why
% can it not print subproblems either?
Should print the first subproblem (problem 1-a)
\insertexercise{ID=MAT-1001-2017-V-H-Problem-1-a}
\section{All}
% \printcollection{all}
\section{Exercises}
% \printcollection{exercise-pool}
\section{Subquestions}
% \printcollection{subquestions}
\end{document}
答案1
这里的问题太多了,很难跟踪。我决定回答你代码中的基本问题。我认为这也可能有助于解决你遇到的其他问题。
exam=0
第一个问题是拼写错误 ——每个s后面都缺少一个逗号question
(在我看来xsim
这里应该会报错,但目前还没有):\begin{question}[ year=2017,semester=V,exam=O % <<<<< HERE ID=MAT-1001-2017-V-H-Problem-1-b, topic = limit ] ... \end{question}
另一个问题是你对 的使用
\insertexercise
。首先,ID=
在参数中省略\insertexercise{ID=MAT-1001-2017-V-H-Problem-1-a}
。它应该是 ID 本身:\insertexercise{MAT-1001-2017-V-H-Problem-1-a}
。- 另一个问题是,您已定义
\insertexercise
仅插入类型为exercise
(\printexercise{exercise}{...}
)的练习,但同时您正尝试插入类型为subquestion
(从您使用的 ID 可以看出\insertexercise
)的练习。 - 另一个问题是
\item
中的重复\item \insertexercise{...}
。您已定义子问题的模板以插入它们\item
自己。
在当前版本的xsim
第二个参数中,\printexercise
可以是id
或者这ID
使得的定义变得\insertexercise
多余。
因此,添加缺失的逗号并定义练习如下:
\begin{exercise}[year=2017,semester=H,topic={integral,limit,injective},exam=K,
ID=MAT-1001-2017-V-H-Problem-1]
\begin{enumerate}
\printexercise{subquestion}{MAT-1001-2017-V-H-Problem-1-a}
\printexercise{subquestion}{MAT-1001-2017-V-H-Problem-1-b}
\printexercise{subquestion}{MAT-1001-2017-V-H-Problem-1-c}
\end{enumerate}
\end{exercise}
应该给出一些合理的东西。确实如此:
\documentclass{article}
\usepackage{amssymb,mathtools}
\usepackage{tasks}
\providecommand*\e{e}
\usepackage{xsim}
\DeclareExerciseTagging{year} % 1992, 2010, etc
\DeclareExerciseTagging{topic}
\DeclareExerciseTagging{semester} % V (Spring), H (Fall)
\DeclareExerciseTagging{exam} % O (ordinary), K (kont / re-sit exam), P (prøveeksamen)
\DeclareExerciseType{subquestion}{
exercise-env = question ,
solution-env = answer ,
exercise-name = Question ,
solution-name = Answer ,
exercise-template = item ,
solution-template = item
}
\DeclareExerciseProperty{title}
\DeclareExerciseEnvironmentTemplate{named}
{\subsection*{\GetExercisePropertyTF{title}{#1}{??}}}
{}
\DeclareExerciseEnvironmentTemplate{item}
{\item}
{}
\xsimsetup{
exercise/template = named
}
\DeclareExerciseCollection{all}
\begin{filecontents}{\jobname-exam.tex}
\begin{question}[
year=2017,semester=V,exam=O,
ID=MAT-1001-2017-V-H-Problem-1-a,
topic = integral
]
Evaluate the following integrals
\begin{tasks}(3)
\task $\displaystyle \int_0^{\sqrt{\pi/2}} (x+1) \e^{x-1} dx$
\task $\displaystyle \int \frac{a}{x^2 + a^2} dx$
\task $\displaystyle \int \log x dx$.
\end{tasks}
\end{question}
\begin{question}[
year=2017,semester=V,exam=O,
ID=MAT-1001-2017-V-H-Problem-1-b,
topic = limit
]
Evaluate the following limits
\begin{tasks}(2)
\task $\displaystyle \lim_{x \to 0} \frac{\sin(x^2)}{x^2}$
\task $\displaystyle \lim_{x \to 0} \frac{\sin(x^2)}{1 + x^2}$.
\end{tasks}
\end{question}
\begin{question}[
year=2017,semester=V,exam=O,
ID=MAT-1001-2017-V-H-Problem-1-c,
topic = injective
]
State the definition of an injective function and provle
that the function $f \to \mathbb{R} \to \mathbb{R}$ defined by $\int_0^x
e^{-s^2} dx$ is injective.
\end{question}
\begin{exercise}[year=2017,semester=H,topic={integral,limit,injective},exam=K,
ID=MAT-1001-2017-V-H-Problem-1]
\begin{enumerate}
\printexercise{subquestion}{MAT-1001-2017-V-H-Problem-1-a}
\printexercise{subquestion}{MAT-1001-2017-V-H-Problem-1-b}
\printexercise{subquestion}{MAT-1001-2017-V-H-Problem-1-c}
\end{enumerate}
\end{exercise}
\end{filecontents}
\begin{document}
\collectexercises{all}
\input{\jobname-exam.tex}
\collectexercisesstop{all}
\printexercise{exercise}{MAT-1001-2017-V-H-Problem-1}
\end{document}