I am a teacher. When I write an exam, I would like to be able to print the student version of the exam and then print the exam answer key. My students write their answers directly on the exam, so the space I've left them to write their answer will typically be large enough to contain anything I want to have in the answer key. The problem is how to print the two versions of the exam.
Note that I am familiar with the EXAM package (https://ctan.org/pkg/exam?lang=en), and am not currently interested in using it. Looking through other answers, I think what I want is something based on smash (What does \smash do, and where is it documented?).
Shown below is an MWE that has two implementations of \answerkey. Version A is my attempt to do what I want -- optionally include the answer, do it in red, and smash it so that it doesn't take up any space. Unfortunately, for the first use below, the vertical spacing is still changing with and without the answers. For the second use below, it breaks totally because the answer has multiple paragraphs.
The optimal answer is a single \answerkey command that can handle both of the uses below. The goal is that the spacing of the document not change when \answerstrue or \answersfalse is used.
\documentclass[10pt]{article}
\usepackage{xcolor}
\usepackage{tikz}
\newif\ifanswers
\answerstrue
%\answersfalse
\newcommand{\answerkeyA}[1]{%
\ifanswers%
\textcolor{red}{\smash{\textbf{\parbox[t]{\linewidth}{#1}}}}%
\fi%
}
\newcommand{\answerkeyB}[1]{%
\ifanswers%
#1%
\fi%
}
\begin{document}
\begin{enumerate}
\item Answer the following question with words.
\answerkeyA{ I do not like them in a house. I do not like them with
a mouse. I do not like them here or there. I do not like them
anywhere. I do not like green eggs and ham. }
\vspace*{1in}
\item Draw a picture to illustrate the following problem.
\answerkeyB{
Answer:
\begin{tikzpicture}[scale=0.3,font=\sffamily]
\draw [step=1.0, thin, gray!50] (-3, -3) grid (3, 3);
\draw [arrows={latex-latex}] (-3,0) -- coordinate (x axis mid) (3,0);
\draw [arrows={latex-latex}] (0,-3) -- coordinate (y axis mid) (0,3);
\end{tikzpicture}
}
\vspace*{2in}
\item The next problem should be here.
\end{enumerate}
\end{document}


\answer{3cm}{. The spacing error comes fromparboxtreating the size differently from how I realized! It is tied up with the attempt to keep baselines in registration (\noindent...\ignorespaces). Will improve answer. – Donald Arseneau Aug 24 '20 at 02:08