# Controlling parindent in enumerate inside customized list environment

I'm trying to control the indentation of paragraphs in an enumerated list that is inside a customized list environment. I find that changing \parindent in the inner list has no effect.

Here's an example that reproduces the problem:

\documentclass{report}
\usepackage{lipsum}
\usepackage{enumitem}

\newlength{\exlabelwidth}
\settowidth{\exlabelwidth}{\small 99.99}
\newlength{\exlabelsep}
\setlength{\exlabelsep}{0.5em}
\newlength{\exsymbolwidth}
\settowidth{\exsymbolwidth}{\small\ensuremath{*}}

\newcounter{exercise}[chapter]
\renewcommand{\theexercise}{\thechapter.\arabic{exercise}}
\newcommand{\exitem}{}
\newenvironment{exercises}%
{\begin{list}{\exitem}{%
\usecounter{exercise}%
\small%
\setlength{\itemindent}{\exlabelwidth}%
\setlength{\labelwidth}{\exlabelwidth}%
\setlength{\leftmargin}{0.0cm}%
\setlength{\itemsep}{0.0cm}%
\setlength{\parsep}{0.0cm}%
\setlength{\listparindent}{\parindent}%
}%
}%
{\end{list}%
}
\newcommand{\ex}[1][]{%
\renewcommand{\exitem}{%
\makebox[\exsymbolwidth][r]{#1}\hspace{\exlabelsep}%
\makebox[\exlabelwidth][r]{\bfseries\theexercise}}\item%
}

\begin{document}
\begin{exercises}
\ex
\lipsum[1]
\lipsum[2]
\ex
\lipsum[3]
\begin{enumerate}[parsep=0pt,listparindent=\parindent]
\item
\lipsum[1]
\lipsum[2]
\end{enumerate}
\end{exercises}
\end{document}


The environment is based on advice I received on tex.stackexchange. I tried to make the code shorter, but I get errors. What I would like to be able to do is to have the second paragraph in the enumerate environment indented. Right now, it starts flush left regardless of whether I use the enumitem package and set parsep to zero or not.

-
Use listparindent=15pt explicitly (which is the default \parindent outside the enumerate environment) rather than setting it to \parindent. Does that help? –  Werner Mar 16 '13 at 15:08
Setting \setlength{\listparindent}{15pt} in \newenvironment{exercises} has no effect. –  user1362373 Mar 16 '13 at 15:38
Frank has provided the location where you need to supply listparindent=15pt; not in exercises, but as the option to enumerate. –  Werner Mar 16 '13 at 16:20

Your problem is due to the fact that on one hand you use the enumitem package but then you also define your own lists via the list environment of LaTeX. The enumitem package doesn't know about your new list and gets confused.

Basically what happens is that the following code in \enit@preset makes the wrong choice:

   \ifnum\@listdepth=\@ne
\enit@outerparindent\parindent
\else
\parindent\enit@outerparindent
\fi


The idea of this code is to save the outer \parindent value in \enit@outerparindent when we enter the first level of lists and if we enter a nested list reuse the saved value instead. Now unfortunately your new list doesn't know about this so nothing gets saved. But if the enumerate is entered it is in fact already on level 2 and therefore \parindent gets the current value of \enit@outerparindent which is, of course, still zero.

So either you simply give listparindent and explicit value when you call enumarate, e.g.

\begin{enumerate}[parsep=0pt,listparindent=15pt]


or, if you like this properly fixed you could set \enit@outerparindent in your definition of exercises if it exists (i.e., if enumitem was loaded), e.g.,

\makeatletter
\newenvironment{exercises}%
{\begin{list}{\exitem}{%
\@ifundefined{enit@outerparindent}{}%  if this command exists set it, otherwise do nothing
{\ifnum\@listdepth=\@ne
\enit@outerparindent\parindent
\else
\parindent\enit@outerparindent
\fi
}%
\usecounter{exercise}%
\small%
\setlength{\itemindent}{\exlabelwidth}%
\setlength{\labelwidth}{\exlabelwidth}%
\setlength{\leftmargin}{0.0cm}%
\setlength{\itemsep}{0.0cm}%
\setlength{\parsep}{0.0cm}%
\setlength{\listparindent}{\parindent}%
}%
}%
{\end{list}}
\makeatother


Because of the @ signs you need \makeatletter ...\makeatother.

-
That did the trick, thank you very much. –  user1362373 Mar 16 '13 at 16:17
@JavierBezos perhaps enumitem should patch the list environment to properly set this for manually constructed lists. –  Frank Mittelbach Mar 16 '13 at 16:21
I have a follow-up question: I find that the fix proposed by Frank only works if I set \enit@outerparindent and keep \begin{enumerate}[parsep=0pt,listparindent=15pt]. But his reply suggests that either I do this or I set \enit@outerparindent. Did I misunderstand his reply? –  user1362373 Mar 16 '13 at 19:53
it shoud be enough to do one or the other (and it works here just changing your exercise env as indicated). –  Frank Mittelbach Mar 16 '13 at 22:15
I find I have to do both (i.e., add your code segment and add [parsep=0pt,listparindent=15pt]) otherwise nothing changes. [I'm using pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012). The log file shows also that I'm using enumitem 2011/09/28 v3.5.2.] –  user1362373 Mar 17 '13 at 8:56
show 1 more comment