类似注释的环境和间距

类似注释的环境和间距

我经常需要“关闭”环境。下面是我的最小工作示例,其中一种方法是这样做:

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

然而,正如你所见,虚无环境所造的空间

增加了一些空间。我该如何修复?

答案1

你需要\ignorespacesafterend;但你可以考虑这个comment包裹。

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

在此处输入图片描述

答案2

放置\unskip在后面\egroup以使两个调用的行为相同。

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

在此处输入图片描述

相关内容