For a study book that I and others are writing, we want to include some exercises. Eventually we want all the exercises to have a solution, but for now, due to limited time, we are able to only include solutions to some exercises. However, we still want to include the exercises for students to try and find answers. For those environments that do not have a solution, we would like to display a text or something else inside the exercise environment to make clear that the solution is not yet available.
The exercises are implemented with an exercise environment, and the solutions are within a solution environment that is created with the answers packages. These solution environments are placed within the specific exercise they belong to.
Now my question; How, if at all, can we detect if a solution environment is present in the exercise environment? And if it is present, how to detect whether it is empty or not?
I think it should be something like this (although this is not proper LaTeX syntax):
\documentclass{scrbook}
\usepackage{etoolbox}
\usepackage{answers}
\Newassociation{sol}{Solution}{solu}
\newenvironment{exercise}{\textit{Exercise}
\begin{small}
}{
\if %exercise environment does contain sol environment
\if sol environment is empty
no solution available %display this text in document
\fi
\else %exercise environment does not contain sol environment
no solution available %display this text in document
\fi
\end{small}
}
\begin{document}
\Opensolutionfile{solu}[SolutionChapter]
\begin{exercise}
Question?
\begin{sol}
Here is a solution
\end{sol}
\end{exercise}
\begin{exercise}
Question?
\begin{sol}
\end{sol}
\textit{No solution available} %should be automatically detected
\end{exercise}
\begin{exercise}
Question?
\textit{No solution available} %should be automatically detected
\end{exercise}
\Closesolutionfile{solu}
\end{document}
If the solutions are available they should be handled as default by the answers package, so that they are put in a separate file. I am not very familiar with conditionals in TeX, so I hope this is possible.
\documentclass
and ending with\end{document}
.