I want to print on the margin paragraph a \pageref
to the hint of the current exercise.
This is a follow up to a previous question of mine which I rely on, but for some reason my code doesn't work.
I don't understand why I get the error
LaTeX Warning: Reference `hint:1' on page 1 undefined on input line XX.
although I do create a label for each hint, by using this line of code:
\ForEachUsedExerciseByType{\GetExercisePropertyT{hint}{\label{hint:#2}}}
(copied from the linked answer). I expect this line of code to create a label hint:1
for exercise with ID 1, and label hint:2
for exercise with ID 2 etc.
The complete code is:
% !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}