# \end{comment} in \newcommand

I want to define a new command containing \end{comment} (I need it for some conditional compiling). If I do this:

\documentclass{article}

\usepackage{verbatim}

\newcommand{\myendcomment}{\end{comment}}

\begin{document}

\begin{comment}
bla
\myendcomment

\end{document}


I get an error message like this:

Runaway argument?
! File ended while scanning use of \next.
<inserted text>
\par
<*> test.tex
I suspect you have forgotten a }', causing me to read past where you wanted me to stop.


What does this error message mean and how do I get around the problem (without writing \end{comment} directly in the main text?

• The comment environment is defined to gobble everything up to \end{comment}, without interpreting anything in between. Since it does no interpretation, \myendcomment is just the same as any other token, so it won't trigger the end of the comment: only \end{comment} would. So, short answer is: no, you can't. Maybe, if you tell more about your problem, some idea may pop up. Oct 2, 2017 at 7:24
• Thanks @egreg What I want is this: a conditional compilation in which in case a) everything is written and in case b) only certain parts are written (the others are commented out by some means; what I want to avoid is manually putting \end{comment} in case b) I don't specifically need the comment environment, if there is another convenient way to hide text in the output. Oct 2, 2017 at 9:08

## 1 Answer

Try the following two examples:

\documentclass{article}
\usepackage{comment}
\newenvironment{mycomment}{}{}
%\excludecomment{mycomment}
\begin{document}
Text
\begin{mycomment}
Not commented text
\end{mycomment}
\end{document}


and

\documentclass{article}
\usepackage{comment}
\newenvironment{mycomment}{}{}
\excludecomment{mycomment}
\begin{document}
Text
\begin{mycomment}
Commented text
\end{mycomment}
\end{document}