%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% outlines.sty - Provides an "outline" environment for mixed-level
% outline lists
%
% Charles Pecheur, UCL, 2005 -- 2012
% charles.pecheur@uclouvain.be
%
% Note: this package has no connection with outline.sty or outliner.sty, 
% that are available on CTAN
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Usage: 
%
% \usepackage{outlines}
%
% \begin{outline}[<list-style>] 
%   \1 <level 1 text>
%   \1[<label>] <level 1 text>
%      \2 <level 2 text>
%         \3 <level 3 text>
%            \4 <level 4 text>
% \0 <normal paragraph>
%   ...
% \end{outline}
%
% where:
% + <list-style> is an optional list environment name 
%   (e.g. itemize, enumerate, ...).  The default is itemize.
%   The same style is used for all levels that have not been overridden.
% + <label> is an optional label, as in \item[<label>].
% + Levels may be mixed freely, except that a \1 must come before
%   the first \2, a \2 before the first \3, etc. 
%   (this restriction is inherited from list environments).
% + \0 gives a normal, non-list paragraph.
% + List styles for each level can be overridden by re-defining
%   \outlinei, ..., \outlineiiii, either globally or inside an outline block.
%
% Do not nest outlines inside outlines or other lists.  Lists inside outlines
% should work fine.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ProvidesPackage{outlines}[2012/1/23 1.1 Ch. Pecheur]
\RequirePackage{ifthen}

\makeatletter
% \ol@type stores the default list style
\newcommand{\ol@type}{itemize}
% \ol@typei ... store the (list) environment names used in outlines
\newcommand{\outlinei}{\ol@type}
\newcommand{\outlineii}{\ol@type}
\newcommand{\outlineiii}{\ol@type}
\newcommand{\outlineiiii}{\ol@type}
% \ol@inci ..., \ol@deci ... increase/decrease the indentation level
\newcommand{\ol@inci}{\begin{\outlinei}}
\newcommand{\ol@deci}{\end{\outlinei}}
\newcommand{\ol@incii}{\begin{\outlineii}}
\newcommand{\ol@decii}{\end{\outlineii}}
\newcommand{\ol@inciii}{\begin{\outlineiii}}
\newcommand{\ol@deciii}{\end{\outlineiii}}
\newcommand{\ol@inciiii}{\begin{\outlineiiii}}
\newcommand{\ol@deciiii}{\end{\outlineiiii}}

% \ol@toz, \ol@toi ... "transition" to indentation level 0..4 by opening or
% closing nested list levels as needed.
% They are dynamically modified according to the current level.
\newcommand{\ol@toz}{}
\newcommand{\ol@toi}{}
\newcommand{\ol@toii}{}
\newcommand{\ol@toiii}{}
\newcommand{\ol@toiiii}{}

% \ol@commands{C0}{C1}{C2}{C3}{C4} set the level transition commands 
% above to C0..C4
\newcommand{\ol@commands}[5]{%
  \renewcommand{\ol@toz}{#1}%
  \renewcommand{\ol@toi}{#2}%
  \renewcommand{\ol@toii}{#3}%
  \renewcommand{\ol@toiii}{#4}%
  \renewcommand{\ol@toiiii}{#5}%
}

% \ol@exit resets transition commands.  This is not mandatory, just cleaner.
\newcommand{\ol@exit}{%
  \ol@commands{}{}{}{}{}}
% \ol@z, \ol@i ... update all transitions for level 0..4
\newcommand{\ol@z}{%
  \ol@commands%
    {}%
  	{\ol@inci}%
	{\ol@inci\ol@incii}%
    {\ol@inci\ol@incii\ol@inciii}%
    {\ol@inci\ol@incii\ol@inciii\ol@inciiii}}
\newcommand{\ol@i}{%
  \ol@commands%
    {\ol@deci}%
    {}%
    {\ol@incii}%
    {\ol@incii\ol@inciii}%
    {\ol@incii\ol@inciii\ol@inciiii}}
\newcommand{\ol@ii}{%
  \ol@commands%
    {\ol@decii\ol@deci}%
    {\ol@decii}%
    {}%
    {\ol@inciii}%
    {\ol@inciii\ol@inciiii}}
\newcommand{\ol@iii}{%
  \ol@commands%
    {\ol@deciii\ol@decii\ol@deci}%
    {\ol@deciii\ol@decii}%
    {\ol@deciii}%
    {}%
    {\ol@inciiii}}
\newcommand{\ol@iiii}{%
  \ol@commands%
    {\ol@deciiii\ol@deciii\ol@decii\ol@deci}%
    {\ol@deciiii\ol@deciii\ol@decii}%
	{\ol@deciiii\ol@deciii}%
	{\ol@deciiii}%
	{}}


% the outline environment provides commands \1..\4 for 
% introducing items at level 1..4, and \0 for normal paragraphs 
% within the outline section.
\newenvironment{outline}[1][]{%
  \ifthenelse{\equal{#1}{}}{}{\renewcommand{\ol@type}{#1}}%
  \ol@z%
  \newcommand{\0}{\ol@toz\ol@z}%
  \newcommand{\1}{\ol@toi\ol@i\item}%
  \newcommand{\2}{\ol@toii\ol@ii\item}%
  \newcommand{\3}{\ol@toiii\ol@iii\item}%  
  \newcommand{\4}{\ol@toiiii\ol@iiii\item}%  
}{%
  \ol@toz\ol@exit%
}

\makeatother