使用 xsim 的多个提示环境

使用 xsim 的多个提示环境

我想使用该xsim包编写可能包含多个提示(短版和长版)甚至解决方案的练习。例如:

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

首先我以为只是为了适应这个,但它没有为我编译(! LaTeX Error: Something's wrong--perhaps a missing \item.

答案1

感谢@cgnieder 的提示,解决方案看起来像(虽然序言看起来有点多余,但如果你有想法让它更短,请发表评论)。

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

相关内容