4

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, space made by nothing environment

Some space is added. How do I fix this?

Bart Snapp
  • 1,339

2 Answers2

7

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}

enter image description here

4

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}

enter image description here

egreg
  • 1,121,712