5

我正在尝试在我的 LaTeX 文档中创建一个新环境,在该环境之后的下一段中的缩进被抑制。

有人告诉我(TeXbook 和 LaTeX 源),通过设置\everypar{\setbox0\lastbox},TeX 排字机将在下一段的开头执行此操作,从而删除缩进:

\everypar{\setbox0\lastbox}

所以这就是我所做的,但没有效果(以下段落仍然缩进):

\newenvironment{example}
  {\begin{list}
     {}
     {\setlength\leftmargin{2em}}}
  {\end{list}\everypar{\setbox0\lastbox}}

我已经尽可能地研究了 LaTeX 的内部结构。似乎\end例程在某些时候说\endgroup\par这可能是 LaTeX 忽略我的\everypar设置的原因。\global也无济于事。我知道\noindent但想自动执行此操作。

示例文档片段:

This is paragraph text. This is paragraph text, too.

\begin{example}
  \item This is the first item in the list.
  \item This is the second item in the list.
\end{example}

This is more paragraph text. I don't want this indented, please.

内部例程和感兴趣的开关似乎是\@endpetrue\@endparenv等等。谢谢你的帮助。

4

9 回答 9

3

如果不重新定义,我什么都做不了\end,但我当然不是专家。

以下内容非常hacky,但在我有限的测试中有效。当然这会干扰嵌套环境(如果有问题,您应该能够重新定义\begin以恢复旧环境)。\end

\newenvironment{example}{%
  \bgroup
  \let\oldend=\end
  \def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
                          \csname @afterheading\endcsname}
  \begin{list}{}
    {\setlength\leftmargin{2em}}
  }{%
  \end{list}
  \egroup
}
于 2010-04-30T03:41:17.943 回答
2

您不能通过在您的环境和下一行之间没有空行来避免这种情况吗?

This is paragraph text. This is paragraph text, too.

\begin{example}
  \item This is the first item in the list.
  \item This is the second item in the list.
\end{example}
% (No blank line)
This is more paragraph text. I don't want this indented, please.
于 2010-04-29T20:19:47.427 回答
2

像这样简单的东西对我有用:

\makeatletter
\newenvironment{example}{%
  \bgroup
    \list{}{}
}{%
    \endlist
    \@afterindentfalse
    \@afterheading
  \egroup
}
\makeatother

但是,在调用第一个 \section(或 \chapter,在类“book”和“report”的情况下)之前它不起作用。我不知道为什么。

于 2012-07-02T20:13:18.893 回答
1

我尝试了伊万的答案,但它对我不起作用。但我确实让它工作了!这是我所做的:

\makeatletter
\renewenvironment{quotation}{% 
\bgroup%
\let\oldend=\end%
\def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname%
                        \csname @afterheading\endcsname}%
\list{}{\listparindent 1.5em%
\itemindent    \listparindent%
\leftmargin 1.5em%               This controls the size of the indentation
\rightmargin   \leftmargin
\parsep        \z@ \@plus\p@}%      This line reduces inter-paragraph space to normal values.
\item\relax%
}{%
\endlist%%
\egroup%
}
\makeatother

这样做的好处是它可以很好地排版您的块引用,并从块引用之后的段落中删除缩进。

于 2011-09-05T10:31:44.583 回答
1

您可以在不重新定义的情况下执行此操作\end

\makeatletter
\newenvironment{example}
   {\begin{list}
      {}
      {\setlength\leftmargin{2em}}}
   {\end{list}%
    \def\if@endpe{%
      \@doendpe
      \let\par\@@par
      \iffalse}}
\makeatother

解释

\end展开\everypar 的变化\endexample。为了使事情变得更加复杂,它设置\par为 restore \everypar{}。显然\@doendpe,如果段落在环境之后继续,则确保没有缩进,但如果环境之后有\par(或空行)则恢复正常行为。

您可能希望避免更改\end,因为它必须在环境开始时进行更改,因此可能会干扰嵌套环境。幸运的是\endcontains的定义\expandafter\endgroup\if@endpe。我们可以使用\if@endpe钩子将我们的代码注入到外部作用域。之后\endgroup \if@endpe就自动恢复了。

于 2017-10-16T09:30:49.320 回答
0

在定义的末尾包含 \@afterindentfalse\@afterheading。

于 2010-06-09T22:17:43.633 回答
0

我有同样的问题。我刚用这个:

\noindent \newenvironment
于 2016-04-22T12:40:29.380 回答
-1

你不应该弄乱\everypar令牌列表,除非你确切地知道你在做什么。采用

\setlength{\parindent}{0pt}

摆脱整个文档中的缩进。

于 2010-04-29T15:58:09.280 回答
-2

用 \noindent 结束你的环境可以帮助你

于 2011-08-07T16:00:43.757 回答