# Comment-like environments and spacing

I often need to "turn off" environments. One way I do this is below in my minimal working example:

\documentclass{article}

\newenvironment{nothing}{\setbox0\vbox\bgroup}
{\egroup}

\begin{document}
Hello, this is some text.
\begin{nothing}
This is nothing.
\end{nothing}
More text.

Hello, this is some text.
More text.
\end{document}


However, as you can see,

Some space is added. How do I fix this?

• \ignorespaces after \egroup perhaps. Though the comment package might be better – daleif Jan 27 '16 at 18:25
• remember that \stepcounter ... works inside savebox – touhami Jan 27 '16 at 19:00

You need \ignorespacesafterend; but you can consider the comment package.

\documentclass{article}
\usepackage{comment}

\newenvironment{nothing}
{\setbox0\vbox\bgroup}
{\egroup\ignorespacesafterend}

\begin{document}
Hello, this is some text.
\begin{nothing}
This is nothing.
\end{nothing}
More text.

Hello, this is some text.
More text.

Hello, this is some text.
\begin{comment}
This is nothing.
\end{comment}
More text.

Hello, this is some text.
More text.
\end{document}


Place \unskip after \egroup to make the two invocations behave the same.

\documentclass{article}

\newenvironment{nothing}{\setbox0\vbox\bgroup}
{\egroup\unskip}

\begin{document}
Hello, this is some text.
\begin{nothing}
This is nothing.
\end{nothing}
More text.

Hello, this is some text.
More text.
\end{document}


• Ah - this works for my "minimal example" but apparently it is slightly too minimal... But the other solution below works for me! – Bart Snapp Jan 28 '16 at 15:01
• @BartSnapp I agree that egreg's answer is better. I was the first to upvote it when I saw it appear. – Steven B. Segletes Jan 28 '16 at 15:09