代码之家  ›  专栏  ›  技术社区  ›  glts

抑制胶乳环境后的压痕

  •  4
  • glts  · 技术社区  · 14 年前

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

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

    \everypar{\setbox0\lastbox}
    

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

    我已经尽我所能研究了乳胶的内部结构。看来 \end \endgroup \par \每个人 设置。 \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 和其他人。谢谢你的帮助。

    9 回复  |  直到 12 年前
        1
  •  3
  •   Ivan Andrus    14 年前

    \end

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

    \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
    }
    
        2
  •  2
  •   Geoff    14 年前

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

    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.
    
        3
  •  2
  •   josé    12 年前

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

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

        4
  •  1
  •   Community Mike Causer    7 年前

    Ivan's answer

    \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
    

    这样做的好处是,它可以很好地排版块引号,并删除块引号后面段落的缩进。

        5
  •  1
  •   Leonard Michlmayr    6 年前

    \end

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

    解释

    \结束 变化 \everypar 之后 \endexample . 使事情变得更加复杂 \par 恢复 \everypar{} . 表面上 \@doendpe 如果段落在环境之后继续,则确保没有缩进,但是如果出现缩进,则恢复正常行为 \标准杆 (或空行)在环境之后。

    你可能想避免改变 因为它必须在环境开始时更改,因此可能会干扰嵌套环境。幸运的是 \结束 包含 \expandafter\endgroup\if@endpe \if@endpe 作为一个钩子,将我们的代码注入外部作用域。之后 \endgroup 自动恢复。

        6
  •  0
  •   Peter Flynn Peter Flynn    14 年前

        7
  •  0
  •   Undo ptrk    8 年前

    我也有同样的问题。我只是用了这个:

    \noindent \newenvironment
    
        8
  •  -1
  •   topskip    14 年前

    你不应该弄乱这个房间 \everypar 令牌列表,除非你知道你在做什么。使用

    \setlength{\parindent}{0pt}
    

    以消除整个文件中的缩进。

        9
  •  -2
  •   Peter Pall    13 年前

    用indent结束您的环境\n对您有帮助