# Hide/Show Solution for Problems

Doing this is a lot of work, and that is why there are, as you say, so many options for "Solution/Answer" packages. You might actually find a package that fits your need pretty easily; maybe exercisebank, xsim, or some of the other alternatives in the exercise and exam topics on CTAN.

That being said, you can as @Levy says, use the comment package to hide your environment. Maybe the \vspace workaround that @Levy suggests could be sufficient, but I couldn't help myself in regards to the automatic height question.

You could use boxes to make sure the height is appropriate. That is, the actual height of the content. Almost.

By defining the \ProcessCutFile to be empty then the comment package won't do anything (it's all in the docs). Further more, we can use the \CommentCutFile to put the content of the environment into a \box, which we can get the height of. Then we just apply \vskip to push this height.

However, if we want it for multiple pages, I came up with a solution that puts \vskip 10pt until it reaches the height of the box. A little hacky, I know.

Only drawbacks are that this height thing would probably not work with verbatim environments like e.g. listings.

\documentclass{article}
\usepackage{comment}
\usepackage{fp}
\usepackage{lipsum}

% Make ourselves a new conditional
\newif\ifDisplaySolutions
% Use \DisplaySolutionstrue to "activate" it
\makeatletter
% Make a solution environment
\generalcomment{solution}{%
\begingroup
\ifDisplaySolutions\else%
% if \DisplaySolutionstrue is not called, then we remove the contents
\def\ProcessCutFile{}\fi%
}{%
\ifDisplaySolutions\else%
% aand,now (also when it's not called), we make a box
% and then we \input the \CommentCutFile.
\setbox1=\vbox{\input{\CommentCutFile}}%
\edef\boxheight{$email protected]\ht1} % Get the height from \ht1 and use \vskip to make appropriate space \newcount\Scount \Scount=0 \FPdiv\boxPartHeight{\boxheight}{10} {\nullfont\loop\vskip 10pt\relax\advance\Scount by 1 \ifnum\Scount<\boxPartHeight\relax\repeat} \fi \endgroup% } \makeatother %Uncomment below to hide solution \DisplaySolutionstrue \begin{document} Some problem text goes here \lipsum[1] \begin{solution} \textbf{SOLUTION}\lipsum \[ \forall\varepsilon>0\exists\delta>0:\dots$
\end{solution}
Some text after solution.

\end{document}


Edit: Made it work across pages

You can put the teacher's section between a block of comment using the package comment.

\begin{comment}
...
text
...
\end{comment}


Then you can compile a version for students. If you want to compile the teacher's version just delete the \begin{comment} and \end{comment}.

You can do exactly what you want using \includecomment{teacher} or \excludecomment{teacher} with the text inside the block teacher.

\documentclass[10pt,a4paper]{report}
\usepackage{comment}

\begin{document}

Text not commented

\includecomment{teacher}
\begin{teacher}
text
\end{teacher}

Text not commented

\end{document}


Now for the reserved space you desire one simple workaround is use the vspace{} command.

\documentclass[10pt,a4paper]{report}
\usepackage{comment}

\begin{document}

Text not commented

\excludecomment{teacher}
\begin{teacher}
text
\end{teacher}
\vspace{3cm}

Text not commented

\end{document}


The reserved space left between the problems are 3cm.

tcolorbox offers lowerbox option to make visible or not their lower parts. This is a little example to show how it works. This option could be combined with recording mechanisms to store and later on show solutions (an example in this answer).

\documentclass{article}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter]{exercise}{+O{}}{%
enhanced, breakable,
coltitle=black,
fonttitle=\bfseries,
title={Exercise~\thetcbcounter:},
#1}

\tcbset{student/.style={lowerbox=invisible}}

\begin{document}

\begin{exercise}
Type some nice problem, not too long.
\tcblower
An this is the solution
\end{exercise}

\begin{exercise}[student]
\lipsum[1]
\tcblower
\lipsum[1]
\end{exercise}

\begin{exercise}[student]
\lipsum[2]
\tcblower
\lipsum[3]
\end{exercise}
\end{document}