% Authors: Anna Shipunova and Alexey Shipunov, dactylorhiza@gmail.com

\ProvidesPackage{autolist}%
        [2010/10/24 v0.4 Various lists]

\ProvidesPackage{autolist}
\RequirePackage{calc}

\newcounter{TMC@a}

\newdimen\Subleftmargini
\newdimen\Subleftmarginii
\newdimen\Subleftmarginiii
\newdimen\Subleftmarginiv
\newdimen\Subleftmarginv
\newdimen\Subleftmarginvi
\newdimen\Subleftmarginvii
\newdimen\Subleftmarginviii
\newdimen\Subleftmarginix
\newdimen\Subleftmarginx

\newcount\@Subnumdepth \@Subnumdepth = 0
\@definecounter{Subnumi}
\@definecounter{Subnumii}
\@definecounter{Subnumiii}
\@definecounter{Subnumiv}
\@definecounter{Subnumv}
\@definecounter{Subnumvi}
\@definecounter{Subnumvii}
\@definecounter{Subnumviii}
\@definecounter{Subnumix}
\@definecounter{Subnumx}

% Lists with up to 10 levels

% "List" analog
\def\Sublist#1#2{\ifnum \@listdepth >9\relax \@toodeep
     \else \global\advance\@listdepth\@ne \fi
  \rightmargin \z@ \listparindent\z@ \itemindent\z@
  \csname @slist\romannumeral\the\@listdepth\endcsname
  \def\@itemlabel{#1}\let\makelabel\@mklab \@nmbrlistfalse #2\relax
  \@trivlist
  \parskip\parsep \parindent\listparindent
  \advance\linewidth -\rightmargin \advance\linewidth -\leftmargin
  \advance\@totalleftmargin \leftmargin
  \parshape \@ne \@totalleftmargin \linewidth
  \ignorespaces}
\let\endSublist=\endlist

% Size decrease
\setlength\Subleftmargini  {\parindent}
\setlength\Subleftmarginii {1em}
\setlength\Subleftmarginiii{1em}
\setlength\Subleftmarginiv {1em}
\setlength\Subleftmarginv  {1em}
\setlength\Subleftmarginvi {1em}
\setlength\Subleftmarginvii{1em}
\setlength\Subleftmarginviii{1em}
\setlength\Subleftmarginix {1em}
\setlength\Subleftmarginx  {1em}

\def\@slistI{\leftmargin\Subleftmargini
             \topsep0pt \parsep0pt \itemsep0pt}
\let\@slisti\@slistI
\@slisti
\def\@slistii {\leftmargin\Subleftmarginii
              \labelwidth\Subleftmarginii
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listiii{\leftmargin\Subleftmarginiii
              \labelwidth\Subleftmarginiii
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listiv {\leftmargin\Subleftmarginiv
              \labelwidth\Subleftmarginiv
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listv  {\leftmargin\Subleftmarginv
              \labelwidth\Subleftmarginv
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listvi {\leftmargin\Subleftmarginvi
              \labelwidth\Subleftmarginvi
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listvii{\leftmargin\Subleftmarginvii
              \labelwidth\Subleftmarginvii
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listviii{\leftmargin\Subleftmarginviii
              \labelwidth\Subleftmarginviii
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listix {\leftmargin\Subleftmarginix
              \labelwidth\Subleftmarginix
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}
\def\@listx  {\leftmargin\Subleftmarginx
              \labelwidth\Subleftmarginx
              \advance\labelwidth-\labelsep
              \topsep0pt \parsep0pt \itemsep0pt}

% "Enumerate" analog with hierarchical numeration
\def\Subnum{\ifnum \@Subnumdepth >9 \@toodeep\else
        \advance\@Subnumdepth \@ne
        \edef\@Subnumctr{Subnum\romannumeral\the\@Subnumdepth}\Sublist
        {\csname label\@Subnumctr\endcsname}{\usecounter
          {\@Subnumctr}\def\makelabel##1{\hss\llap{##1}}}\fi}
\let\endSubnum=\endlist

\def\theSubnumi{\arabic{Subnumi}}
\def\theSubnumii{\arabic{Subnumii}}
\def\theSubnumiii{\arabic{Subnumiii}}
\def\theSubnumiv{\arabic{Subnumiv}}
\def\theSubnumv{\arabic{Subnumv}}
\def\theSubnumvi{\arabic{Subnumvi}}
\def\theSubnumvii{\arabic{Subnumvii}}
\def\theSubnumviii{\arabic{Subnumviii}}
\def\theSubnumix{\arabic{Subnumix}}
\def\theSubnumx{\arabic{Subnumx}}
\def\labelSubnumi{\theSubnumi.}
\def\labelSubnumii{\theSubnumi.\theSubnumii.}
\def\labelSubnumiii{\theSubnumi.\theSubnumii.\theSubnumiii.}
\def\labelSubnumiv{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.}
\def\labelSubnumv{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.}
\def\labelSubnumvi{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.}
\def\labelSubnumvii{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.}
\def\labelSubnumviii{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.\theSubnumviii.}
\def\labelSubnumix{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.\theSubnumviii.\theSubnumix.}
\def\labelSubnumx{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.\theSubnumviii.\theSubnumix.\theSubnumx.}
\def\p@Subnumi{}
\def\p@Subnumii{\theSubnumi.}
\def\p@Subnumiii{\theSubnumi.\theSubnumii.}
\def\p@Subnumiv{\theSubnumi.\theSubnumii.\theSubnumiii.}
\def\p@Subnumv{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.}
\def\p@Subnumvi{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.}
\def\p@Subnumvii{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.}
\def\p@Subnumviii{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.}
\def\p@Subnumix{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.\theSubnumviii.}
\def\p@Subnumx{\theSubnumi.\theSubnumii.\theSubnumiii.\theSubnumiv.\theSubnumv.\theSubnumvi.\theSubnumvii.\theSubnumviii.\theSubnumix.}

% Lists with changing indent(LaTeX Companion 1st ed., p. 51--66)

% Ragged left
\newenvironment{Lautolist}[1][\quad]%
        {\begin{list}{}{\renewcommand{\makelabel}[1]{{##1}\hfil}%
                \settowidth{\labelwidth}{{#1}}%
                \setlength{\leftmargin}{\labelwidth+\labelsep}%
                \itemsep=.5pt\parsep=2pt\topsep=5pt}}
        {\end{list}}

% Ragged right
\newenvironment{Rautolist}[1][\quad]%
        {\begin{list}{}{\renewcommand{\makelabel}[1]{\hfil{##1}}%
                \settowidth{\labelwidth}{{#1}}%
                \setlength{\leftmargin}{\labelwidth+\labelsep}%
                \itemsep=.5pt\parsep=2pt\topsep=5pt}}
        {\end{list}}

% Items for several lines
\newcommand{\Lplabel}[1]
        {\raisebox{0pt}[1ex][0pt]{\makebox[\labelwidth][l]%
        {\parbox[t]{\labelwidth}{\raggedright\hspace{0pt}#1}}}}

\newcommand{\Rplabel}[1]
       {\raisebox{0pt}[1ex][0pt]{\makebox[\labelwidth][l]%
       {\parbox[t]{\labelwidth}{\raggedleft\hspace{0pt}#1}}}}

\newenvironment{Rpolylist}[1][\quad]%
       {\begin{list}{}{%
               \renewcommand{\makelabel}[1]{\Rplabel{##1}}%
               \settowidth{\labelwidth}{{#1}}%
               \setlength{\leftmargin}{\labelwidth+\labelsep}%
               \itemsep=.5pt\parsep=2pt\topsep=5pt}}
               {\end{list}}

\newenvironment{Lpolylist}[1][\quad]%
        {\begin{list}{}{%
                \renewcommand{\makelabel}[1]{\Lplabel{##1}}%
                \settowidth{\labelwidth}{{#1}}%
                \setlength{\leftmargin}{\labelwidth+\labelsep}%
                \itemsep=.5pt\parsep=2pt\topsep=5pt}}
        {\end{list}}

% Description-like, but also number items
\def\L@bl#1{\hspace{\labelsep}\refstepcounter{TMC@a}%
        \arabic{TMC@a}.\ \textit{#1}}
\newenvironment{characters}{\begin{list}{}
        {\renewcommand{\makelabel}{\L@bl}}}
{\setcounter{TMC@a}{0}\end{list}}

\endinput
