# Indent text without using trivlist

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
\leftmargin=#2\relax
\rightmargin=#1\relax
\parshape\@ne \@totalleftmargin \linewidth
\@setpar{{\@@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.

• bravo for daring to escape from the list straitjacket. it's an oversimplification to think that everything is just another form of list. (so many reported bugs for amsthm are simply the result of list 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. – barbara beeton Apr 8 '15 at 17:19
• why do you want a subsection heading inside a quote? – David Carlisle Apr 8 '15 at 17:25
• The obvious flaw is having a \subsection inside a quote. It makes no sense. – egreg Apr 8 '15 at 17:36
• Surely not \subsection*. I would define a titledquote environment, with a proper setting for avoiding page breaks (\nopagebreak might be sufficient). Abusing sectioning commands is wrong to begin with. – egreg Apr 8 '15 at 17:41
• I should say starting sections inside a lower level environment should be a non-aim, so while your code looks probably safe enough I'm not sure I agree with the premise that it's needed:-) – David Carlisle Apr 8 '15 at 17:45