[Tex/LaTex] Controlling parindent in enumerate inside customized list environment

#enumerateenumitemenvironmentsspacing

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}%
    \addtolength{\itemindent}{\labelsep}%  
    \setlength{\labelwidth}{\exlabelwidth}% 
    \addtolength{\labelwidth}{\exsymbolwidth}%     
    \addtolength{\labelwidth}{\exlabelsep}%   
    \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.

Thanks for any advice.

Best Answer

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}%
    \addtolength{\itemindent}{\labelsep}%  
    \setlength{\labelwidth}{\exlabelwidth}% 
    \addtolength{\labelwidth}{\exsymbolwidth}%     
    \addtolength{\labelwidth}{\exlabelsep}%   
    \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.