I've been using latex for all of my typesettings needs for a long time. So, when I need to make exams for classes I wanted a way to make the actual test, as well as an answer key from the same tex source. I stumbled on the following, which makes a new command, \answer{}, with an argument being the answer that is not typeset for the test version, and made red for the key version. There are a few drawbacks, mainly that \phantom can't handle content with line breaks.

%\newcommand{\answer}1\phantom{#1} % for the test \newcommand{\answer}1{\color{red}{#1}\color{black}} % for the key