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.

I am having with spacing between paragraphs in my document, and I think I have been able to trace back to a custom environment I have defined.

\makeatletter
\def\remarkname{Remark}
\newcounter{counter@myremarks}
\newenvironment{remark}{\par\vspace{0.2cm}\par\noindent\begingroup\small%
  \addtocounter{counter@myremarks}{1}%
  \textbf{\remarkname~\arabic{counter@myremarks}.}~~\ignorespacesandallpars}{%
  \endgroup\par\vspace{0.2cm}\par\@afterindentfalse\@afterheading}
\newenvironment{remark*}{\par\vspace{0.2cm}\par\noindent\begingroup\small%
  \textbf{\remarkname.}~~\ignorespacesandallpars}{%
  \endgroup\par\vspace{0.2cm}\par\@afterindentfalse\@afterheading}
\makeatother

The \ignorespacesandallpars command is by Martin Scharrer and comes from a previous StackExchange question.

(I know that there are many other ways - packages, or the definitions in amsmath - to get this sort of environment, but I have not yet found something that I'm completely happy with, and it is easier at the moment to use a custom definition.)

After I use this definition, I think I notice spacing being a bit wacky, and requiring additional \smallskip or \medskip commands. I wonder what I am doing wrong.

Is my problem somewhere else, or am I doing something wrong here?

UPDATE: The following snippet illustrates one of the problems (the spacing before the second itemize list is not the same than the first):

enter image description here

\documentclass{article}

\makeatletter
\def\ignorespacesandallpars{%
  \begingroup
  \catcode13=10
  \@ifnextchar\par
    {\endgroup\expandafter\ignorespacesandallpars\@gobble}%
    {\endgroup}%
}
\def\remarkname{Remark}
\newenvironment{remark*}{\par\vspace{0.2cm}\par\noindent\begingroup\small%
  \textbf{\remarkname.}~~\ignorespacesandallpars}{%
  \endgroup\par\vspace{0.2cm}\par\@afterindentfalse\@afterheading}
\makeatother

\begin{document}

Following is an item list
\begin{itemize}
\item One
\item ...
\end{itemize}

\begin{remark*}
  Now a remark.
\end{remark*}

And another item list
\begin{itemize}
\item One
\item ...
\end{itemize}

\end{document}
share|improve this question
1  
Thanks for the code. Why are you using \@afterindentfalse\@afterheading? –  Gonzalo Medina Aug 21 '12 at 19:45
    
@GonzaloMedina: if I recall correctly, what I wanted is to prevent the following paragraph from having indent, and to make it so no amount of spacing would change this (the fact that what follows not be indented). –  Jérémie Aug 21 '12 at 21:37
add comment

1 Answer 1

Well \@afterheading is one of the reasons sectioning commands should never be used in groups ;-)

It gobally sets \@nobreaktrue and then locally sets \everypar to undo it. So after the end of your environment (undoing the \everypar setting) you have \@nobreaktrue sitting there waiting for the next list to catch it...

And \@nobreak makes a list not insert \topsep...

To avoid this mess, you must make sure \@afterheading is called outside your environment.

Replacing \@afterheading with \aftergroup\@afterheading in your definition moves the \@afterheading outside the group defined by your environment and makes \topsep reappear.

share|improve this answer
    
Thank you so much! It works... But I admit I don't exactly understand why (in the same way I didn't understand why the command I pasted above does what I want it to do :-). Could you perhaps elaborate on why using \aftergroup solves my problem? –  Jérémie Aug 21 '12 at 20:19
    
@Jérémie I tried, but I'm afraid I have to suggest if all these @-commands sound greek to you, you should better leave them alone. LaTeX is famous for strange side effects of some internal commands, so they should only be used by those who know exactly what they are doing. –  Stephan Lehmke Aug 21 '12 at 20:25
    
I think I've been using LaTeX for far too long enough to not know about these internal commands, but I can't find a coherent documentations on them! –  Jérémie Aug 21 '12 at 20:28
    
@Jérémie source2e is a good documentation for internal stuff. –  Stephan Lehmke Aug 21 '12 at 20:37
    
@Jérémie I think a lot of people are wondering why you are using \@afterheading in this place. See also Gonzalo Medina's comment. –  Stephan Lehmke Aug 21 '12 at 20:43
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.