I already had lots of files that use the exam class, so I ended up using the optional package to define a simple environment which shows nothing if option showhints is not used. Here's a basic example:
\documentclass{exam}
\qformat{\textbf{Question \thequestion\hfill}}
% The "optional" package allows the definition of an environment
% hints that will only be printed if the showhints option is passed
\usepackage[dummy]{optional} % document fails to compile if optional has no options ...
\makeatletter
@ifpackagewith{optional}{showhints}{
% environment definition for the case where hints must be shown
\newenvironment{hints}[1][]{\textbf{Hints:} #1}{}
}{
% environment definition for the case where hints must be hidden
\newenvironment{hints}[1][]{\setbox\z@\vbox\bgroup}{\egroup}
}
\makeatother
\begin{document}
\begin{questions}
\question How do you include a package in \LaTeX?
\begin{hints}
Ask around at tex.stackexchange.com if you dare.
\end{hints}
\begin{solution}
Use the \texttt{\textbackslash usepackage} command.
\end{solution}
\end{questions}
\end{document}
Assuming the above is saved to a file named mwe.tex, the following Makefile produces three different outputs:
mwe-base.pdf, which is the intended exercise sheet;
mwe-answers.pdf, which features solutions but no hints;
mwe-hints.pdf, which features hints but no solutions.
SOURCES = $(wildcard *.tex)
TARGETS = $(patsubst %.tex, %, $(SOURCES))
all: $(TARGETS)
%: %.tex
latexmk -jobname=$(basename $<)-base -pdf -pdflatex='pdflatex -shell-escape -interaction=nonstopmode' $<
latexmk -jobname=$(basename $<)-answers -pdf -pdflatex='pdflatex -jobname=$(basename $<)-answers -shell-escape -interaction=nonstopmode "\PassOptionsToClass{answers}{exam}\input{$(basename $<)}"' $<
latexmk -jobname=$(basename $<)-hints -pdf -pdflatex='pdflatex -jobname=$(basename $<)-hints -shell-escape -interaction=nonstopmode "\PassOptionsToPackage{showhints}{optional}\input{$(basename $<)}"' $<
clean:
rm -f .out aux bbl blg log toc .ptb .tod .fls .fdb_latexmk *.lof
There's most probably room for improvement.
xsimsolution can be found in its manual: eample 9 (hints)) – cgnieder Oct 03 '19 at 09:55