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?

  • \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
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

| improve this answer | |
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

| improve this answer | |
  • 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

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.