在 LaTeX 中抑制环境后的缩进
我正在尝试在 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
等。感谢您的帮助。
I'm trying to create a new environment in my LaTeX document where indentation in the next paragraph following the environment is suppressed.
I have been told (TeXbook and LaTeX source) that by setting \everypar
to {\setbox0\lastbox}
, the TeX typesetter will execute this at the beginning of the next paragraph and thus remove the indentation:
\everypar{\setbox0\lastbox}
So this is what I do, but to no effect (following paragraph is still indented):
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}\everypar{\setbox0\lastbox}}
I have studied LaTeX's internals as well as I could manage. It seems that the \end
routine says \endgroup
and \par
at some point, which may be the reason LaTeX ignores my \everypar
setting. \global
doesn't help either. I know about \noindent
but want to do this automatically.
Example document fragment:
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.
Internal routines and switches of interest seem to be \@endpetrue
, \@endparenv
and others. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果不重新定义
\end
,我就无法让任何东西发挥作用,但我当然不是专家。以下内容相当hacky,但在我有限的测试中有效。当然,这会干扰嵌套环境(如果遇到问题,您应该能够重新定义
\begin
以恢复旧的\end
)。I couldn't get anything to work without redefining
\end
, but I'm certainly no expert.The following is quite hacky, but worked in my limited testing. Of course this will interfere with nested environments (you should be able to redefine
\begin
to restore the old\end
if you have problems).难道你不能通过在你的环境和下一行之间不留空行来避免这种情况吗?
Can't you avoid this by not having a blank line between your environment and the next line?
像这样简单的事情对我有用:
但是,在调用第一个 \section (或 \chapter,在类“book”和“report”的情况下)之前它不起作用。我不知道为什么。
Something as simple as this works for me:
But, it doesn't work before the first \section (or \chapter, in the case of classes "book" and "report") is called. I don't know why.
我尝试了伊万的答案,但它对我不起作用。但我确实让它工作了!这就是我所做的:
这样做的优点是它可以很好地排版您的块引用,并删除块引用后面段落的缩进。
I tried the Ivan's answer, but it wasn't working for me. But I did get it working! Here's what I did:
The advantage to this is that it typesets your blockquotes very nicely, and removes the indentation from paragraph after the blockquote.
您无需重新定义
\end
即可执行此操作。说明
\end
更改\everypar
after 扩展\endexample< /代码>。为了使事情变得更加复杂,它设置
\par
来恢复\everypar{}
。显然\@doendpe
是为了确保如果段落在环境后面继续,则没有缩进,但如果有\par
(或空),则恢复正常行为线)在环境之后。您可能希望避免更改
\end
因为它必须在环境开始时更改,因此可能会干扰嵌套环境。幸运的是,\end
的定义包含\expandafter\endgroup\if@endpe
。我们可以使用\if@endpe
作为钩子将代码注入外部作用域。\endgroup
之后\if@endpe
自动恢复。You can do this without redefining
\end
Explanation
\end
changes\everypar
after expanding\endexample
. To make things even more complicated it sets\par
to restore\everypar{}
. Appearently\@doendpe
is ment to make sure that there is no indentation if the paragraph continues after the environment, but to restore normal behavior if there is a\par
(or empty line) after the environment.You may want to avoid changing
\end
because it would have to be changed at the begining of the environment and may therefore disturb nested environments. Luckily the definition of\end
contains\expandafter\endgroup\if@endpe
. We can use\if@endpe
as a hook to inject our code to the outer scope. After the\endgroup
\if@endpe
is automatically restored.在定义末尾包含 \@afterindentfalse\@afterheading。
Include \@afterindentfalse\@afterheading at the end of your definition.
我也有同样的问题。我刚刚用过这个:
I had the same problem. I just used this:
你不应该弄乱
\everypar
令牌列表,除非你确切地知道你在做什么。用于消除整个文档中的缩进。
You should not mess with the
\everypar
token list, unless you know exactly what you are doing. Useto get rid of indenting in the whole document.
以 \noindent 结束你的环境可以帮助你
ending your environment with \noindent could help you