0

I want to write a book with exercises, solutions to exercises and some hints to those exercises.

I need help with understanding how to work with a new declared property (hint, in this case). I am aware of the example in the repository, but still I got lost with the various commands in the manual.

How do I print the "body" of the hint I just created? That is, I want to print the following:

enter image description here

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}
}
{%
}

\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}

I tried to insert after \section*{Hints} the following:

\GetExercisePropertyT{hint}{value if true}{value if false}

But it doesn't print anything. After all, this command appears in the manual under "Commands for Usage in Template Definitions", yet in the example I linked to, this command appears not inside a template definition.

Moreover, the only thing related to the hint in the auto-generated xsim file is

\XSIM{hint}{exercise-1=={The sum of the angles in a triangle is equal to 180 degrees.}}

So I am confused here.

1 Answer 1

2

To print an exercise property outside of the exercise itself you can use the command \ExercisePropertyGet{type}{id}{property} (see page 35 of the manual). In your example you did not set the type or id of the question, but by default the type will be exercise and the id is numeric. In this case it would be:

\ExercisePropertyGet{exercise}{1}{hint}

Note that here the id 1 is hardcoded. You can also loop over the exercises using various \ForEachUsedExerciseByXXX commands, where you get access to the ids within the loop as argument #2. The other arguments are the type (#1), the counter (#3), the title (#4), the points and bonus points (#5 and #6). For example:

\ForEachUsedExerciseByType{%
Exercise id #2 has counter #3 and title #4.\par
The hint for this exercise is: \ExercisePropertyGet{#1}{#2}{hint}\par
}

Note that a very similar example is also contained in the manual on page 66 (example 11 in Appendix F), however unfortunately the last line of that example is missing from the manual and the syntax is a bit complex with double and quadruple argument hash marks.

MWE showing all three examples:

% !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}

Result:

enter image description here

6
  • I never mentioned it in the original question, but can you show me how to \ref{} to a hint of a specific exercise?
    – tush
    Commented Dec 29, 2022 at 22:57
  • @tush referencing a hint is a somewhat different question I guess, it would be better to ask a new question about that. However, I'm not sure what you would like to achieve with such a reference, let's say you put \ref{pythagorashint} somewhere, what should that print? Note that a hint does not have its own id or counter, it is a property of an exercise which is stored using the exercise id (and therefore you can only have one hint per exercise).
    – Marijn
    Commented Dec 30, 2022 at 8:49
  • @tush I noticed you have deleted the new question, did you solve it yourself?
    – Marijn
    Commented Dec 30, 2022 at 17:54
  • Marijn see tex.stackexchange.com/a/648136/264024
    – Udi Fogiel
    Commented Dec 30, 2022 at 18:17
  • @Marijn yes, I realized that the solution is in the link given in Udi Fogiel's comment.
    – tush
    Commented Dec 30, 2022 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .