I am writing exercises along my book and I am using xsim
for this.
For some of the exercise there will be a hint that should appear at the end of the chapter (under "Hints to exercises" section).
Just as well, for some of the exercises there will also be a corresponding solution. Same - I want them to appear at the end of the chapter under a section "Solutions To exercises".
How do I that?
I tried to follow the example in the repository for hints and for cross referencing, but I don't know how to fully implement it.
- First would be to declare a new template, called
myTemplate
, for which the first thing would be to create a label for the exercises and the solutions, but how do I also create a label for the hints?
\DeclareExerciseEnvironmentTemplate{myTemplate}
{%
\IfInsideSolutionTF
{\label{sol:\ExerciseID}}
{\label{ex:\ExerciseID}}
% how to create a label for the hints??
- I also need help with creating a command that prints the hints at the end of the chapter. I want the hints to appear as
Hint for exercise 3
Use the fact that $x=1$.
Hint for exercise 5
Recall that $x=y$.
etc.
A MWE for the document as I have it now is this:
%!TEX TS-program = xelatex
\documentclass[openany,oneside]{book}
\usepackage{xsim,xcolor}
\newcommand{\marginRef}[1]{%
\marginpar{\colorbox{lightgray}{\parbox{\dimexpr\marginparwidth-2\fboxsep}{#1}}}
}
\xsimsetup{solution/print = false,}
\xsimsetup{
exercise/name={Problem},
exercises/name={Problems},
solution/name={Solution},
solutions/name={Solutions},
exercise/within = chapter,
exercise/template=myTemplate,
solution/template =myTemplate ,
print-solutions/headings-template = myTemplate
}
\DeclareExerciseProperty{hint}
\newcommand\hint[1]{\SetExerciseProperty{hint}{#1}}
\DeclareExerciseHeadingTemplate{myTemplate}{%
\chapter{Solutions to Problems in chapter \thechapter}%
}
\DeclareExerciseEnvironmentTemplate{myTemplate}
{%
\IfInsideSolutionTF
{\label{sol:\ExerciseID}}
{\label{ex:\ExerciseID}}
% how to create a label for the hints??
\GetExerciseHeadingF{\subsection*}%
{%
\XSIMmixedcase{\arial% <- font changed
\GetExerciseName}\nobreakspace
\GetExerciseProperty{counter}%
\IfInsideSolutionF
{%
\GetExercisePropertyT{subtitle}
{ {\large\itshape\PropertyValue}}%
}%
}\marginpar{% how to print the hint page ref here?
}%
\marginRef{solution in page \pageref{ex:\ExerciseID} }
% \marginpar{\colorbox{lightgray}{\parbox{\dimexpr\marginparwidth-2\fboxsep}{solution in page \pageref{ex:\ExerciseID}}}}
}
{\par}
% lang package
\usepackage{polyglossia}
\setdefaultlanguage{english}
\newfontfamily\arial{Arial}[Script=Latin,Language=English]
\begin{document}
\chapter{Geometry}
\section{Introduction}
\begin{exercise}[subtitle={Pythagoras' theorem}]
Prove that the area of the square whose side is the hypotenuse is equal to the sum of the areas of the squares on the other two sides.
\hint{Draw the altitude from point C, and call H its intersection with the side AB. }
\end{exercise}
\begin{solution}
The proof is easy.
\end{solution}
\printsolutions[headings=true,headings-template=myTemplate]
\end{document}
Output: