Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following two macros, the only difference being that one has the environment inside a group:

\documentclass{article}
\makeatletter
\newcommand\thisworks{%
  {\begin{center}
    $\ast$
    \end{center}}
  \@afterindentfalse
  \@afterheading}

\newcommand\thisdoesnt{%
\begin{center}
  $\ast$
\end{center}
  \@afterindentfalse
  \@afterheading}

\makeatother
\usepackage{lipsum}
\begin{document}
\lipsum[1]

\thisworks

\lipsum[5]

\thisdoesnt

\lipsum[42]
\end{document}

Why does the first suppress the indentation while the second doesn't?

share|improve this question
add comment

2 Answers

up vote 13 down vote accepted

Having a quick look at the definition of \end{center} we see that it just ends a trivlist,

\def\endcenter{\endtrivlist}

now as to why Lamport would use a trivlist to define the centering and indirectly the center macros is a subject for another question, it suffices at this point to just say he was very fond of them, although I am sure he had some valid reasons for doing so.

Changing your code slightly and introducing a trivlist you can observe the effect:

\documentclass{article}
\makeatletter

\newcommand\thisworks{%
   $$\ast$$
  \@afterindentfalse
  \@afterheading}

\newcommand\thisdoesnt{%
  {\begin{trivlist}\item\end{trivlist}}
  $$\ast$$
  \@afterindentfalse
  \@afterheading
}

\makeatother
\usepackage{lipsum}
\begin{document}
\lipsum[1]

\thisworks

\lipsum[5]

\thisdoesnt

\lipsum[42]
\end{document}

If you uncomment the grouping brackets at the \begin{trivlist} line, you will see the effect. The code is all interwoven in the source2e.pdf.

To understand better LaTeX's buggy behaviour here, I will illustrate it with another minimal:

\documentclass{article}
\begin{document}    

This is the normal behavior of a:
\begin{trivlist}\item list\end{trivlist}
trivlist that is not enclosed in a group.

If you enclose the list in a group the lines after the list:
{\begin{center} center\end{center}}
are indented. LaTeX is buggy in this respect. 

\end{document}

This results in:

enter image description here

If you group trivlist or the center commands results in the same buggy behaviour. In your example the latter allows the \@afterindentfalse\@afterheading to take effect as it can apply everypar or indent at the beginning of the paragraph, whereas in the first example above, it can't as the following text is considered the last portion of the previous paragraph.

share|improve this answer
1  
Ah yes, the pain-in-the-neck hat is "let's define everything as a list". –  Joseph Wright Oct 19 '11 at 18:32
1  
@JosephWright it fits nicely with the fact that the only data structure in TeX is (token) lists. The only typesetting structure in LaTeX is (triv) lists. –  Bruno Le Floch Oct 19 '11 at 20:52
2  
But this doesn't answer the question of why an (ungrouped) trivlist stops the suppressing of indentation... –  Seamus Oct 19 '11 at 21:19
    
@Seamus ...Sorry thought it was obvious:). I added some more detail. –  Yiannis Lazarides Oct 20 '11 at 2:54
add comment

\endtrivlist calls \@endparenv which will cause \@doendpe to be executed which "suppress[es] the paragraph indentation in text immediately following a paragraph-making environment" (LaTeX2e sources, p. 227). \@doendpe will override \@afterindentfalse\@afterheading. Note that you can suppress indentation of the following paragraph by adding % (a comment sign) in the line after \thisdoesnt in the document body of your MWE.

See also What exactly does \@doendpe do?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.