0

I want to use the xsim package to write exercises with may contain multiple hints (short and long version) and maybe also solutions. I.e. something like this:

\documentclass{article}
\usepackage{xsim}

\begin{document}

\section{Problems}
\begin{exercise}[subtitle=Pythagoras]
  This is the first problem.
\end{exercise}
\begin{hintS}
  This is a short hint to the first exercise.
\end{hintS}
\begin{hintL}
  This is a long hint to the first exercise.
\end{hintL}
\begin{solution}
  This is the solution to the first problem.
\end{solution}

\begin{exercise}[subtitle=Another Problem]
  This is the second problem.
\end{exercise}
\begin{hintS}
The second exercise has only a short hint. 
\end{hintS}
\begin{solution}
  This is the solution to the second problem.
\end{solution}


\begin{exercise}[subtitle=Yet Another Problem]
  This is the third problem.
\end{exercise}
\begin{hintL}
The third exercise has only a long hint. 
\end{hintL}
\begin{solution}
  This is the solution to the third problem.
\end{solution}

\begin{exercise}
Another exercise. 
\end{exercise}
\begin{solution}
This exercise has only a solution
\end{solution}


\begin{exercise}
Another exercise. 
\end{exercise}
\begin{hintS}
This exercise has only a short hint but no solution and no long hint.
\end{hintS}

\begin{exercise}
Another exercise. 
\end{exercise}
\begin{hintL}
This exercise has only a long hint but no solution and no short hint. 
\end{hintL}


\begin{exercise}
Another exercise. 
\end{exercise}
\begin{hintS}
Short hint.
\end{hintS}
\begin{hintL}
Long hint. 
\end{hintL}


\section{Short hints}
\printshorthints

\section{Short long hints}
\printlonghints
 
\section{Solutions}
\printsolutions[headings=false]

\end{document}

First I thought just to adapt this this, but it didn't compile for me (! LaTeX Error: Something's wrong--perhaps a missing \item.)

1
  • See my answer to your comment on the linked German thread.
    – cgnieder
    Jan 6, 2021 at 9:52

1 Answer 1

1

Thanks to @cgnieder's hint a solution would look like (though the preamble looks a bit redundant, if you have an idea to make it shorter, please comment).

\documentclass{article}
\usepackage{xsim}
\usepackage{environ,etoolbox}


\DeclareExerciseProperty{hintS}

% we'll use a description list for the hintSs:
\newcommand\printhintSs{%
  \begin{description}
    \ForEachUsedExerciseByType{%
      \def\ExerciseType{##1}%
      \def\ExerciseID{##2}%
      \GetExercisePropertyT{hintS}
        {%
          \item[Short hint to exercise ##3]
           ####1%
        }%
    }%
  \end{description}
}

\NewEnviron{hintS}{\SetExpandedExerciseProperty{hintS}{\expandonce{\BODY}}}


\DeclareExerciseProperty{hintL}

% we'll use a description list for the hintLs:
\newcommand\printhintLs{%
  \begin{description}
    \ForEachUsedExerciseByType{%
      \def\ExerciseType{##1}%
      \def\ExerciseID{##2}%
      \GetExercisePropertyT{hintL}
        {%
          \item[Long hint to exercise ##3]
           ####1%
        }%
    }%
  \end{description}
}

\NewEnviron{hintL}{\SetExpandedExerciseProperty{hintL}{\expandonce{\BODY}}}



\begin{document}

\section{Problems}
\begin{exercise}[subtitle=Pythagoras]
  This is the first problem.
\begin{hintS}
  This is a short hint to the first exercise.
\end{hintS}
\begin{hintL}
  This is a long hint to the first exercise.
\end{hintL}
\end{exercise}
\begin{solution}
  This is the solution to the first problem.
\end{solution}

\begin{exercise}[subtitle=Another Problem]
  This is the second problem.
\begin{hintS}
The second exercise has only a short hint. 
\end{hintS}
\end{exercise}
\begin{solution}
  This is the solution to the second problem.
\end{solution}


\begin{exercise}[subtitle=Yet Another Problem]
  This is the third problem.
\begin{hintL}
The third exercise has only a long hint. 
\end{hintL}
\end{exercise}
\begin{solution}
  This is the solution to the third problem.
\end{solution}

\begin{exercise}
Another exercise. 
\end{exercise}
\begin{solution}
This exercise has only a solution
\end{solution}


\begin{exercise}
Another exercise. 
\begin{hintS}
This exercise has only a short hint but no solution and no long hint.
\end{hintS}
\end{exercise}

\begin{exercise}
Another exercise. 
\begin{hintL}
This exercise has only a long hint but no solution and no short hint. 
\end{hintL}
\end{exercise}


\begin{exercise}
Another exercise. 
\begin{hintS}
Short hint.
\end{hintS}
\begin{hintL}
Long hint.  
\end{hintL}
\end{exercise}

\section{Short hints}
\printhintSs

\section{Short long hints}
\printhintLs
 
\section{Solutions}
\printsolutions[headings=false]

\end{document}

You must log in to answer this question.

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