1

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?

  • 3
    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. – egreg Oct 2 '17 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. – Jakob Oct 2 '17 at 9:08
1

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.