Suppressing indentation after surroundings in LaTeX

I am trying to create a new environment in my LaTeX document, where to fall back in the next paragraph after Wednesday.

I was told (the source of TeXbook and LaTeX) that by setting \everypar to {\setbox0\lastbox} , the TeX typesetter would do this at the beginning of the next paragraph and thus remove the indent:

 \everypar{\setbox0\lastbox} 

So this is what I am doing but not working (the following paragraph is still lagging):

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

I studied the insides of LaTeX and was also able to handle it. It seems that the routine \end says at some point \endgroup and \par , which may be the reason that LaTeX is ignoring my \everypar parameter. \global doesn't help either. I know about \noindent , but I want to do this automatically.

An example of a 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. 

The internal routines and switch elements seem to \@endpetrue , \@endparenv and others. Thank you for your help.

+4
source share
9 answers

I couldn't get anything to work without overriding \end , but I'm certainly not an expert.

The following is pretty hacky, but worked in my limited testing. Of course, this will interfere with nested environments (you must override \begin to restore the old \end if you have problems).

 \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 } 
+3
source

Can you avoid this without having an empty line between your environment and the next line?

 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. 
+2
source

Something simple how this works for me:

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

But this does not work before the first section is called \ or \ chapter, in the case of the classes "book" and "report"). I do not know why.

+2
source

I tried Ivan's answer , but it did not work for me. But I got it! Here is what I did:

 \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 

The advantage of this is that it types your block photos very well and removes the indent from the paragraph after the block.

+1
source

You can do this without overriding \end

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

Description

\end modifies \everypar after the extension \endexample . To make things even more complex, he sets \par to restore \everypar{} . The appearance of \@doendpe means that there is no indentation if the paragraph continues after Wednesday, but to restore normal behavior if there is \par (or an empty line) after the environment.

You might want to avoid chaning \end , because it will need to be changed at the beginning of the environment and therefore may interfere with nested environments. Fortunately, the definition of \end contains \expandafter\endgroup\ if@endpe . We can use \ if@endpe as a hook to enter our code into the external area. After automatic recovery \endgroup \ if@endpe .

+1
source

Include \ @afterindentfalse \ @afterheading at the end of your definition.

0
source

I had the same problem. I just used this:

 \noindent \newenvironment 
0
source

You should not bother with a list of tokens \everypar unless you know exactly what you are doing. Use

 \setlength{\parindent}{0pt} 

to get rid of indentation throughout the document.

-1
source

completing your environment with \ noindent can help you

-2
source

Source: https://habr.com/ru/post/1308373/


All Articles