TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
\ignorespaces after \egroup perhaps. Though the comment package might be better – daleif Jan 27 at 18:25
    
remember that \stepcounter ... works inside savebox – touhami Jan 27 at 19:00
up vote 4 down vote accepted

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

share|improve this answer
    
Thanks! This worked great! – Bart Snapp Jan 28 at 15:01

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

share|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 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 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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