# LaTeX error trying to close comment environment

I'm trying to create a document in which answers could be shown or not shown depending on the inclusion of \includecomment{answer}. I decided to use the comment package because the examples I found here seemed really simple, but it is stumping me nonetheless. I also need for individuals to be able to select which questions/answers are relevant for their projects.

I'm trying to use the answer environment, but it doesn't seem to work within an if/then. Here is a little bit of the sample that I think should run. I know that \end{answer} needs to be on its own line. There are no blank spaces before or after it. The code will compile if (a) I comment out the \begin and \end{answer}, or if (b) I comment out the if/then lines before and after the item. If I try to compile with both, I get the following error:

Runaway argument?

! File ended while scanning use of \next.

< inserted text >

           \par


< * > example.tex

\documentclass{article}
\usepackage{ifthen}
\usepackage{comment}

\newcommand{\usetwo}{1} %Use Q2? 1 for yes, 2 for no.

\begin{document}

\begin{enumerate}
\item Question 1
\ifthenelse{\equal{\usetwo}{1}}{
\item Question 2\\
}%
{}% if not set to 1
\end{enumerate}

\end{document}


## migrated from stackoverflow.comOct 10 '16 at 16:49

This question came from our site for professional and enthusiast programmers.

• Welcome to TeX.SE! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Oct 10 '16 at 17:01

You cannot pass comment-like environments as arguments to other macros. Instead, use a \if construction like below:

\documentclass{article}

\usepackage{comment}

\newif\ifquestiontwo
\questiontwofalse% \questiontwotrue

\begin{document}

\begin{enumerate}
\item Question 1

\ifquestiontwo
\item Question 2

\fi
\end{enumerate}

\end{document}


You can switch between using Question 2 or not via \questiontwotrue/\questiontwofalse.