As mentioned in the comments, there are classes or packages that are probably more suitable solutions (I usually use the exam
class). However, one option is to create an environment that sets the color to be the same as the background. Here's an example in a tcolorbox
, then again by itself. In the latter case you could just use \color{white}
to hide the text.
\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage[math]{blindtext}
\usepackage{mathtools}
\colorlet{mycolor}{blue!20!white}
\tcbset{colback=mycolor}
\newenvironment{mysolution}
{ Solution:\par\color{mycolor} }
{ \color{black} }
\begin{document}
\begin{tcolorbox}
Problem:
Some problem statement.
\tcblower
\begin{mysolution}
The solution
\begin{equation}
x=2
\end{equation}
\blindtext
\end{mysolution}
\end{tcolorbox}
Problem:
A different problem
\begin{mysolution}
\begin{equation}
y=x^{2}
\end{equation}
\blindtext
\end{mysolution}
\end{document}

exam
and its documentation is here: ctan.org/pkg/exam