我想写一本包含练习、练习答案以及练习提示的书。
我需要帮助来了解如何使用新声明的属性(在本例中是提示)。我知道存储库中的示例,但我仍然对手册中的各种命令感到困惑。
如何打印我刚刚创建的提示的“主体”?也就是说,我想打印以下内容:
梅威瑟:
% !TEX TS-program = xelatex
\documentclass{book}
\usepackage{xsim}
%\xsimsetup{solution/print = false,} % false is the default value, not really needed
\xsimsetup{
exercise/name={Question},
exercises/name={Questions},
solution/name={Solution},
exercise/within = chapter,
exercise/template=myTemplate,
solution/template =myTemplate ,
}
\DeclareExerciseProperty{hint}
\newcommand\hint[1]{\SetExerciseProperty{hint}{#1}} %based on the code in the repo
\DeclareExerciseEnvironmentTemplate{myTemplate}
{%
{\normalfont\bfseries\GetExerciseName~\GetExerciseProperty{counter}~\GetExercisePropertyT{subtitle}{{(\PropertyValue)}}\newline}
}
{%
}
\begin{document}
\chapter{Euclidean Geometry}
\section{Weekly Assignment}
Questions for this week:
\begin{exercise}[subtitle={Proof of the Pythagorean Theorem}]
Prove Pythagoras' theorem.
\hint{The sum of the angles in a triangle is equal to 180 degrees.}
\end{exercise}
\begin{solution}
The theorem can be proved algebraically\ldots
\end{solution}
\section*{Hints}
The body of hint number 〈command for the counter of the hint〉is:
〈command for the body of the hint〉
%% what are the commands?
\printsolutions[headings=true]
\end{document}
我尝试插入\section*{Hints}
以下内容:
\GetExercisePropertyT{hint}{value if true}{value if false}
但它没有打印任何内容。毕竟,此命令出现在手册中的“模板定义中使用的命令”下,但在我链接的示例中,此命令未出现在模板定义中。
此外,自动生成文件中与提示相关的唯一内容xsim
是
\XSIM{hint}{exercise-1=={The sum of the angles in a triangle is equal to 180 degrees.}}
所以我在这儿感到困惑。
答案1
要打印练习本身之外的练习属性,您可以使用命令\ExercisePropertyGet{type}{id}{property}
(请参阅手册第 35 页)。在您的示例中,您没有设置问题的类型或 ID,但默认情况下类型为数字exercise
,ID 为数字。在本例中,它将是:
\ExercisePropertyGet{exercise}{1}{hint}
请注意,此处的 id 1 是硬编码的。您还可以使用各种命令循环遍历练习\ForEachUsedExerciseByXXX
,在循环中您可以访问 id 作为参数#2
。其他参数是类型 ( #1
)、计数器 ( #3
)、标题 ( #4
)、分数和奖励分数 (#5
和#6
)。例如:
\ForEachUsedExerciseByType{%
Exercise id #2 has counter #3 and title #4.\par
The hint for this exercise is: \ExercisePropertyGet{#1}{#2}{hint}\par
}
请注意,手册第 66 页中也包含一个非常相似的示例(附录 F 中的示例 11),但不幸的是,手册中缺少该示例的最后一行,并且语法有点复杂,带有双重和四重参数井号。
MWE 显示所有三个示例:
% !TEX TS-program = xelatex
\documentclass{book}
\usepackage{xsim}
%\xsimsetup{solution/print = false,} % false is the default value, not really needed
\xsimsetup{
exercise/name={Question},
exercises/name={Questions},
solution/name={Solution},
exercise/within = chapter,
exercise/template=myTemplate,
solution/template =myTemplate ,
}
\DeclareExerciseProperty{hint}
\newcommand\hint[1]{\SetExerciseProperty{hint}{#1}} %based on the code in the repo
\DeclareExerciseEnvironmentTemplate{myTemplate}
{%
{\normalfont\bfseries\GetExerciseName~\GetExerciseProperty{counter}~\GetExercisePropertyT{subtitle}{{(\PropertyValue)}}\newline}
}
{%
}
%%% from the manual
\newcommand\printhints{%
\begin{description}
\ForEachUsedExerciseByType{%
\GetExercisePropertyT{hint}
{\item[\XSIMmixedcase{\GetExerciseName}~##3]####1}%
}%
\end{description}
}
\begin{document}
\chapter{Euclidean Geometry}
\section{Weekly Assignment}
Questions for this week:
\begin{exercise}[subtitle={Proof of the Pythagorean Theorem}]
Prove Pythagoras' theorem.
\hint{The sum of the angles in a triangle is equal to 180 degrees.}
\end{exercise}
\begin{solution}
The theorem can be proved algebraically\ldots
\end{solution}
\section*{Hints}
% single property with hardcoded id
The body of hint number 1 is: \ExercisePropertyGet{exercise}{1}{hint}
\subsection*{In a loop}
\ForEachUsedExerciseByType{%
Exercise id #2 has counter #3 and title #4.\par
The hint for this exercise is: \ExercisePropertyGet{#1}{#2}{hint}\par
}
\subsection*{Example from the manual}
\printhints
\printsolutions[headings=true]
\end{document}
结果: