我想在边缘段落 a 上打印\pageref
当前练习的提示。
这是上一个问题我所依赖的,但由于某种原因,我的代码不起作用。
我不明白为什么我会收到错误
LaTeX Warning: Reference `hint:1' on page 1 undefined on input line XX.
尽管我确实为每个提示创建了一个标签,但使用以下代码行:
\ForEachUsedExerciseByType{\GetExercisePropertyT{hint}{\label{hint:#2}}}
(从链接的答案中复制)。我希望这行代码为 ID 为 1 的练习创建一个标签hint:1
,hint:2
为 ID 为 2 的练习创建一个标签,等等。
完整代码如下:
% !TEX TS-program = xelatex
\synctex=0
\documentclass[openany,oneside]{book}
\usepackage{xsim,geometry,hyperref}
\geometry{left=20mm,textwidth=130mm,marginparsep=10mm,marginparwidth=50mm}
\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}}
\ForEachUsedExerciseByType{\GetExercisePropertyT{hint}{\label{hint:##2}}} %<<-- Apparently creates a label
\DeclareExerciseEnvironmentTemplate{myTemplate}
{%
\IfInsideSolutionTF
{\label{sol:\ExerciseID}}
{\label{ex:\ExerciseID}}%
{\par\normalfont\bfseries\GetExerciseName~\GetExerciseProperty{counter}~\GetExercisePropertyT{subtitle}{{(\PropertyValue)}}\newline}
\IfInsideSolutionF{\marginpar{%
\IfExercisePropertySetT{hint}{hint on page \pageref{hint:\ExerciseID}} %<<-- This label is undefined
}}
}
{\par
}
\begin{document}
\chapter{Euclidean Geometry}
Questions for this week:
\section{Questions}
\begin{exercise}
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}
\begin{exercise}[subtitle={Proof of Thales's Theorem}]
Prove Thales's theorem.
\hint{the base angles of an isosceles triangle are equal. }
\end{exercise}
\begin{solution}
Let $\alpha=\angle BAO$ and $\beta=\angle OBC$\ldots
\end{solution}
\begin{exercise}
Prove the angle bisector theorem.
% no hint for this exercise
\end{exercise}
\begin{solution}
Consider triangles $ABD$ and $ACD$\ldots
\end{solution}
\section*{Hints}
\ForEachUsedExerciseByType{%
{\normalfont\bfseries Hint #3\par}
\ExercisePropertyGet{#1}{#2}{hint}\par%
}
\section*{Solutions}
\printsolutions[headings=false]
\end{document}
答案1
标签将当前区域单位的编号分配给键,并且在您希望创建标签的命令附近没有区域单位。
您必须将其附加\label{hint:#1}
到列表环境的项目中(例如描述),就像您链接到的答案中所做的那样。