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.
liststraitjacket. it's an oversimplification to think that everything is just another form of list. (so many reported bugs foramsthmare simply the result oflistbeing 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. – barbara beeton Apr 08 '15 at 17:19\subsectioninside aquote. It makes no sense. – egreg Apr 08 '15 at 17:36\minisec. Beside this the example should only show that it is dangerous to start one of the environments based on trivlist with a sectioning command. Also I get quite often the request to indent some part of a document and then fight against the additional list spacing and the\@noitemerr. – Ulrike Fischer Apr 08 '15 at 17:38\subsection*. I would define atitledquoteenvironment, with a proper setting for avoiding page breaks (\nopagebreakmight be sufficient). Abusing sectioning commands is wrong to begin with. – egreg Apr 08 '15 at 17:41\trivlist;-). But perhaps this one is more convincing: In this question the internal center environment is the culprit: http://tex.stackexchange.com/questions/237528/tikz-label-over-path-flips. If I redefine center to\renewenvironment{center}{\begin{indentation}{0pt}\centering}{\end{indentation}}the problem disappears. – Ulrike Fischer Apr 08 '15 at 18:02