% \iffalse meta-comment 
%
% Copyright (C) 2003-2005 by Mathieu Boretti
% 
% This file 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 2003/12/01 or later.
%
% The current Maintainer of this work is Mathieu Boretti
%
% This work consists of the file chapterfolder.ins and
% chapterfolder.dtx and the derived file chapterfolder.sty
% 
% 
% \fi 
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{chapterfolder}[2005/11/24 v2.0 Package for dealing with folder]
%<package>\RequirePackage{ifthen}
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{chapterfolder}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
    \DocInput{chapterfolder.dtx}
\end{document}
%</driver>
% \fi
% \GetFileInfo{chapterfolder.sty}
% \changes{v2.0}{2005-11-24}{First version of chapterfolder that use dtx}
% \title{The \textsf{chapterfolder} package\thanks{This document corresponds to \textsf{chapterfolder}~\fileversion, dated~\filedate.}}
% \author{Mathieu Boretti \\ \texttt{mathieu.boretti@gmail.com}}
%
% \maketitle
%
% \begin{abstract}
% This file describe the \textsf{chapterfolder} package. This package is intended for \LaTeX\ users who must deal with
% complex folder structure. 
% \end{abstract}
% 
% \section{Usage}
% The first command that you need is the |\usepackage{chapterfolder}|. This command include the \textsf{chapterfolder}.
%
% \DescribeMacro{\cfpart} The |\cfpart| command define a part, change the current folder and include a main file for the part. The syntaxe of this command is |\cfpart| \oarg{short name} \marg{name} \marg{folder name} \marg{file name}. 
%
% \DescribeMacro{\cfpart*} This command does the same think as |\cfpart| except that it use a define a part*.
%
% \DescribeMacro{\cfchapter} The |\cfchapter| command define a chapter, change the current folder and include a main file for the chapter. The syntaxe of this command is |\cfchapter| \oarg{short name} \marg{name} \marg{folder name} \marg{file name}.
%
% \DescribeMacro{\cfchapter*} This command does the same think as |\cfchapter| except that it use a define a chapter*.
%
% \DescribeMacro{\cfsection} The |\cfsection| command define a section, change the current folder and include a main file for the section. The syntaxe of this command is |\cfsection| \oarg{short name} \marg{name} \marg{folder name} \marg{file name}.
%
% \DescribeMacro{\cfsection*} This command does the same think as |\cfsection| except that it use a define a section*.
%
% \DescribeMacro{\cfsubsection} The |\cfsubsection| command define a subsection, change the current folder and include a main file for the subsection. The syntaxe of this command is |\cfsubsection| \oarg{short name} \marg{name} \marg{folder name} \marg{file name}.
%
% \DescribeMacro{\cfsubsection*} This command does the same think as |\cfsubsection| except that it use a define a subsection*.
%
% \DescribeMacro{\cfinput} The command |\cfinput| include a file from within the current folder. 
%
% \DescribeMacro{\cfcurrentfolder} The command |\cfcurrentfolder| provide the path to the current folder.
%
% \DescribeMacro{\cfinputfigure} The command |\cfinputfigure| include a file from within the folder {\tt figure} within the current folder.
%
% \DescribeMacro{\cfcurrentfolderfigure} The command |\cfcurrentfolderfigure| provide the path to the current figure folder.
%
% \DescribeMacro{\cfinputlistings} The command |\cfinputlistings| include a file from within the folder {\tt listings} within the current folder.
%
% \DescribeMacro{\cfcurrentfolderlistings} The command |\cfcurrentfolderlistings| provide the path to the current listings folder.
%
% \DescribeMacro{\cfinputalgorithms} The command |\cfinputalgorithms| include a file from within the folder {\tt algorithms} within the current folder.
%
% \DescribeMacro{\cfcurrentfolderalgorithms} The command |\cfcurrentfolderalgorithms| provide the path to the current algorithms folder.
%
% \DescribeMacro{\cffolderfigure} The command |\cffolderfigure| change the current folder and include a main file. The syntaxe of this command is |\cffolderfigure| \marg{folder name} \marg{file name}.
%
% \DescribeMacro{\cfaddFolder} The command |\cfaddFolder| define two command to deal with default folder. The syntaxe of this command is |\cfaddFolder| \marg{command extension} \marg{folder name}.
%
% \section{Compatibility commands}
% The following commands are available for backward compatibility :
%
% \DescribeMacro{\cfpartstar} The command |\cfpartstar| is a alias of |\cfpart*|.
%
% \DescribeMacro{\cfchapterstar} The command |\cfchapterstar| is a alias of |\cfchapter*|.
%
% \DescribeMacro{\cfsectionstar} The command |\cfsectionstar| is a alias of |\cfsection*|.
%
% \DescribeMacro{\cfsubsectionstar} The command |\cfsubsectionstar| is a alias of |\cfsubsection*|.
%
% \section{Implementation}
% \begin{macro}{@cf@currentpos}
% This counter define the top of the stack path
%    \begin{macrocode}
\newcounter{@cf@currentpos}
\setcounter{@cf@currentpos}{0}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\stackFolder<X>}
% These macro contains, when needed the path for the stack
%    \begin{macrocode}
\expandafter\def\csname stackFolder0\endcsname{}
\expandafter\def\csname stackFolder1\endcsname{}
\expandafter\def\csname stackFolder2\endcsname{}
\expandafter\def\csname stackFolder3\endcsname{}
\expandafter\def\csname stackFolder4\endcsname{}
\expandafter\def\csname stackFolder5\endcsname{}
\expandafter\def\csname stackFolder6\endcsname{}
\expandafter\def\csname stackFolder7\endcsname{}
\expandafter\def\csname stackFolder8\endcsname{}
\expandafter\def\csname stackFolder9\endcsname{}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@cfpush}
% This macro push a path onto the stack path
%    \begin{macrocode}
\def\@cfpush#1{%
    \expandafter%
    \def\csname stackFolder\arabic{@cf@currentpos}\endcsname{#1/}%
    \addtocounter{@cf@currentpos}{1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@cfpop}
% This macro pop a path from the stack path
%    \begin{macrocode}
\def\@cfpop{%
    \addtocounter{@cf@currentpos}{-1}
    \expandafter%
    \def\csname stackFolder\arabic{@cf@currentpos}\endcsname{}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfcurrentfolder}
% This marco define the current path
%    \begin{macrocode}
\newcommand{\cfcurrentfolder}{%
\csname stackFolder0\endcsname%
\csname stackFolder1\endcsname%
\csname stackFolder2\endcsname%
\csname stackFolder3\endcsname%
\csname stackFolder4\endcsname%
\csname stackFolder5\endcsname%
\csname stackFolder6\endcsname%
\csname stackFolder7\endcsname%
\csname stackFolder8\endcsname%
\csname stackFolder9\endcsname%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfinput}
% This macro define how to input a file from the current folder
%    \begin{macrocode}
\newcommand{\cfinput}[1]{\input{\cfcurrentfolder#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cffolderinput}
% This macro go into a folder and input a file
%    \begin{macrocode}
\newcommand{\cffolderinput}[2]{%
    \@cfpush{#1}%
    \cfinput{#2}%
    \@cfpop%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfaddFolder}
% This macro define a new default folder for some kind of data
%    \begin{macrocode}
\newcommand{\cfaddFolder}[2]{%
    \expandafter\def\csname cfcurrentfolder#1\endcsname{%
        \cfcurrentfolder/#2/%
    }%
    \expandafter\def\csname cfinput#1\endcsname##1{%
        \input{\csname cfcurrentfolder#1\endcsname##1}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@chapterfolderfigure}
% This macro define the default name of the folder for the figures
%    \begin{macrocode}
\newcommand{\@chapterfolderfigure}{figure}
%    \end{macrocode}
% and then define three macros that access this folder
%    \begin{macrocode}
\cfaddFolder{figure}{\@chapterfolderfigure}
\newcommand{\cfincludegraphics}[2][]{%
    \includegraphics[#1]{\cfcurrentfolderfigure/#2}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@chapterfolderlistings}
% This macro define the default name of the folder for the listings
%    \begin{macrocode}
\newcommand{\@chapterfolderlistings}{listings}
%    \end{macrocode}
% and then define two macros that access this folder
%    \begin{macrocode}
\cfaddFolder{listings}{\@chapterfolderlistings}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@chapterfolderalgorithms}
% This macro define the default name of the folder for the algorithms
%    \begin{macrocode}
\newcommand{\@chapterfolderalgorithms}{algorithms}
%    \end{macrocode}
% and then define two macros that access this folder
%    \begin{macrocode}
\cfaddFolder{algorithms}{\@chapterfolderalgorithms}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfpart}
% This macro is the main macro to include a part from within a folder
%    \begin{macrocode}
\newcommand{\cfpart}{\@ifstar
  \cfpartstar%
  \cfpartstd%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfchapter}
% This macro is the main macro to include a chapter from within a folder
%    \begin{macrocode}
\newcommand{\cfchapter}{\@ifstar
  \cfchapterstar%
  \cfchapterstd%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfsection}
% This macro is the main macro to include a section from within a folder
%    \begin{macrocode}
\newcommand{\cfsection}{\@ifstar
  \cfsectionstar%
  \cfsectionstd%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfsubsection}
% This macro is the main macro to include a subsection from within a folder
%    \begin{macrocode}
\newcommand{\cfsubsection}{\@ifstar
  \cfsubsectionstar%
  \cfsubsectionstd%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfpartstd}
% This macro go in a folder, create a part, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfpartstd}[4][]{%
\ifthenelse{\equal{#1}{}}{\part{#2}}{\part[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfpartstar}
% This macro go in a folder, create a part*, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfpartstar}[4][]{%
\ifthenelse{\equal{#1}{}}{\part*{#2}}{\part[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfchapterstd}
% This macro go in a folder, create a chapter, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfchapterstd}[4][]{%
\ifthenelse{\equal{#1}{}}{\chapter{#2}}{\chapter[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfchapterstar}
% This macro go in a folder, create a chapter*, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfchapterstar}[4][]{%
\ifthenelse{\equal{#1}{}}{\chapter*{#2}}{\chapter*[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfsectionstd}
% This macro go in a folder, create a section, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfsectionstd}[4][]{%
\ifthenelse{\equal{#1}{}}{\section{#2}}{\section[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfsectionstart}
% This macro go in a folder, create a section*, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfsectionstar}[4][]{%
\ifthenelse{\equal{#1}{}}{\section*{#2}}{\section*[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfsubsectionstd}
% This macro go in a folder, create a subsection, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfsubsectionstd}[4][]{%
\ifthenelse{\equal{#1}{}}{\subsection{#2}}{\subsection[#1]{#2}}%
%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cfsubsectionstar}
% This macro go in a folder, create a subsection*, include the default file and go out of the folder 
%    \begin{macrocode}
\newcommand{\cfsubsectionstart}[4][]{%
\ifthenelse{\equal{#1}{}}{\subsection*{#2}}{\subsection*[#1]{#2}}%
\cffolderinput{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
%
% \Finale
\endinput