Peter Flynn wrote:
> Thanks very much. I have managed to solve the problems, with the
> exception of detecting whether or not a list is followed by a blank line.
>
> Anyone ever done that? I know that it makes a difference when
> indentation is in use (no blank line means no indentation on the
> following paragraph)
Blank lines usually are tokenized as \par-tokens.
The \end-macro in the LaTeX2e-kernel is defined as follows:
| \end=macro:
| #1->\csname end#1\endcsname \@checkend {#1}\expandafter
| \endgroup \if@endpe \@doendpe \fi \if@ignore \@ignorefalse
| \ignorespaces \fi
So instead of checking for a blank line after
\end{<environment>}, you probably can detect a \par-token
behind an argument that is delimited by the token-sequence
"\if@ignore\@ignorefalse\ignorespaces\fi" .
In case a \par-token is present, you can have repeated/performed
the assignment-sequence
\@topsepadd\topsep
\advance\@topsepadd\partopsep
which is carried out in case the list started a new paragraph (\ifvmode...)
by the \@trivlist-macro which is called at the beginning of the
trivlist-environment and at the beginning of all list-like environments...
In case no \par-token is present, you can set the \@noparlist-switch
to "true" in order to prevent starting a new paragraph at the end
of the list even in case the list is placed at the beginning of a
paragraph...
If you wish to avoid horizontal indentation in case no blank line/no
\par-token does trail the list-like-environment, you can apply \noindent.
The \endtrivlist-macro executed at the end of all list-like
environments can probably be patched to perform the test.
In the example below I have redefined only the \@listi-macro
in order to keep that example short. You also need to redefine
\@listii ... \@listvi accordingly.
Sincerely
Ulrich
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\renewcommand\@listi{%
\leftmargin \leftmargini
\topsep 0pt
\partopsep\baselineskip
\parsep 0pt
\itemsep 0pt
}%
}%
\long\def\checkpar#1\if@ignore\@ignorefalse\ignorespaces\fi{%
\@ifnextchar\par%
{%
\@topsepadd\topsep
\advance\@topsepadd\partopsep
#1\if@ignore\@ignorefalse\ignorespaces\fi
}%
{%
\@noparlisttrue
#1\if@ignore\@ignorefalse\ignorespaces\fi
%\noindent
}%
}%
\let\savedendtrivlist\endtrivlist
\renewcommand\endtrivlist{\checkpar\savedendtrivlist}
\makeatother
\begin{document}
\vspace*{-1in}%
\parindent=1.5cm
No blank line before environment and no blank line after environment:
Text Text
\begin{itemize}
\item itemize 1
\item itemize 2
\end{itemize}
Text Text
Text Text
\begin{enumerate}
\item enumerate 1
\item enumerate 2
\end{enumerate}
Text Text
\hrulefill
A blank line before environment but no blank line after environment:
Text Text
\begin{itemize}
\item itemize 1
\item itemize 2
\end{itemize}
Text Text
Text Text
\begin{enumerate}
\item enumerate 1
\item enumerate 2
\end{enumerate}
Text Text
\hrulefill
No blank line before environment but a blank line after environment:
Text Text
\begin{itemize}
\item itemize 1
\item itemize 2
\end{itemize}
Text Text
Text Text
\begin{enumerate}
\item enumerate 1
\item enumerate 2
\end{enumerate}
Text Text
\hrulefill
A blank line before environment and a blank line after environment:
Text Text
\begin{itemize}
\item itemize 1
\item itemize 2
\end{itemize}
Text Text
Text Text
\begin{enumerate}
\item enumerate 1
\item enumerate 2
\end{enumerate}
Text Text
\end{document}