Quite a lot environments which change margins (e.g. center, quote, addmargin from KOMA) use internally trivlist
. This has some drawbacks, e.g., when the list is directly between two sectioning commands:
\documentclass{article}
\begin{document}
\section{a section}
%a
\begin{quote}
\subsection*{An important quote}
blalbla
\end{quote}
\end{document}
e.g., gives the well known and feared error:
! LaTeX Error: Something's wrong--perhaps a missing \item.
So I tried to extract from trivlist the code that does the indentation and drop all the label related code and came up with the following code. My question is:
Is there some obvious flaw?
(It looks so simple that I wonder why it doesn't exist yet!)
\documentclass{article}
\usepackage{lipsum}
\makeatletter
\newenvironment{indentation}[2][0pt]%#1=right indentation
{\par
\begingroup
\global\advance\@listdepth\@ne
\leftmargin=#2\relax
\rightmargin=#1\relax
\advance\linewidth -\rightmargin\relax
\advance\linewidth -\leftmargin
\advance \@totalleftmargin \leftmargin
\parshape\@ne \@totalleftmargin \linewidth
\@setpar{{\@@par}}}
{\global\advance\@listdepth\m@ne\endgroup\par}
\makeatother
\begin{document}
\section{abc}
\lipsum[1]
\[a=b\]
\begin{itemize}
\item blabla
\end{itemize}
\section{abc}
\begin{indentation}[\leftmargini]{\leftmargini}
\subsection{abc}
\lipsum[1]
\begin{itemize}
\item blub
\begin{enumerate}
\item Does it work?
\end{enumerate}
\end{itemize}
\[a=b\]
\lipsum[2-3]
\begin{indentation}{0pt}
\centering
\lipsum[1]
\end{indentation}
\end{indentation}
\end{document}
Edit
I take back the "doesn't exist yet". I just found on CTAN http://www.ctan.org/tex-archive/macros/latex209/contrib/misc/indent.sty, which contains an almost identical definition (even with the same name). The only difference is that my code changes \@listdepth
as I wanted to keep the relation of indent for nested lists.
list
straitjacket. it's an oversimplification to think that everything is just another form of list. (so many reported bugs foramsthm
are simply the result oflist
being too restrictive.) i haven't actually tried compiling this, but from reading the code, i didn't see anything obvious either. i will try to find time to give it a workout.\subsection
inside aquote
. It makes no sense.\subsection*
. I would define atitledquote
environment, with a proper setting for avoiding page breaks (\nopagebreak
might be sufficient). Abusing sectioning commands is wrong to begin with.