I am writing an exam in LaTeX, and I would like to include the solutions in the text. I'd like there to be one line at the top that I can comment out to remove all solutions from the exam.
In the with-solutions version, the solution text should always appear in red. In the without-solutions version, the solution needs to be replaced with something (a blank line, empty vspace, etc.).
This question got me to something that I think is close: Conditional typesetting / build
This is almost what I need:
\usepackage{xcolor}
\newif\ifsolution
\newcommand\answer{\ifsolution\color{red}}
\let\endanswer\fi
This allows me to put the solutions in \begin{answer}...\end{answer} and easily remove the solutions by commenting out \solutiontrue, but I can't figure out how to replace the solution text with something else.
This doesn't work, but hopefully gives an idea of what I want. When \solutionfalse, I want to replace the solution text with 2cm of blank vspace:
\usepackage{xcolor}
\newif\ifsolution
\newcommand\answer{\ifsolution\color{red}}
\let\endanswer{\else\vspace{2cm}\fi}
