30

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.

9
  • 6
    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
  • 2
    why do you want a subsection heading inside a quote? – David Carlisle Apr 8 '15 at 17:25
  • 1
    The obvious flaw is having a \subsection inside a quote. It makes no sense. – egreg Apr 8 '15 at 17:36
  • 1
    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
  • 4
    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
1

If you remove the % from line number 4 of your code, the error goes away. A \section always has to contain some text.

5
  • 1
    Sorry but this is not an answer. I know that the error goes away if I uncomment the "a". But the point of my question it to avoid the error in the other case. – Ulrike Fischer May 23 '17 at 9:33
  • If you want to have an empty \section, put something like ~\\ in it: \begin{document} \section{a section} ~\\ \begin{quote} ... It won't appear int the pdf. – Sweidán Omár May 23 '17 at 9:35
  • My question is not about document based work arounds but about a general solution. Please check my reputation before continuing to give me such advices. – Ulrike Fischer May 23 '17 at 9:45
  • Sorry for the misunderstanding. Then you should define your own section command: \documentclass{article} \newcommand\mysection[2][\DefaultOpt]{% \def\DefaultOpt{#2}% \section[#1]{#2}% } \begin{document} \mysection[Empty section]{ %a \begin{quote} \subsection*{An important quote} blalbla \end{quote} } \end{document} – Sweidán Omár May 23 '17 at 11:09
  • You are again offering a solution for one document. And I certainly don't want to put the whole section text in an argument. – Ulrike Fischer May 23 '17 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.