The following gives me LaTeX Error: Float(s) lost. I saw on Lost float in exam class that this might have to do with the \vbox. Replacing it with an \hbox gives Something's wrong--perhaps a missing \item. How can this be solved?
\documentclass{scrartcl}
\usepackage[american]{babel}
\usepackage{ifthen}
\usepackage{xparse}
\newboolean{sol}
\setboolean{sol}{false}
% solution environment
% see https://tex.stackexchange.com/questions/172404/solution-environment-via-true-false-switch?noredirect=1#172408
\NewDocumentEnvironment{solution}{O{sol}}{%
\ifthenelse{\boolean{#1}}{\par\noindent{\sffamily\bfseries Solution}\par}{\setbox0=\vbox\bgroup}
}{\ifthenelse{\boolean{#1}}{}{\egroup}}
\begin{document}
\begin{solution}
\begin{enumerate}
\item foo
\begin{figure}[!htbp]
\end{figure}
\end{enumerate}
\end{solution}
\end{document}
figurefloat in thesolutionenvironment? If it is to include an image, you can use\includegraphicsas-is without wrapping it inside afigurefloat. – Werner Apr 23 '14 at 21:20