% This is is the main file of the `chronosys' package, with all the principal code.
%
% The maintener of this work is Mathieu Long.
% email : mlong.tex@hotmail.fr
% the `chronosys' package consists in the 9 files :
%  -- `docchronosys_en.tex' and `docchronosys_en.pdf' (english manual)
%  -- `docchronosys_fr.tex' and `docchronosys_fr.pdf' (french manual)
%  -- README
%  -- `chronosys.tex' (file for plain TeX)
%  -- `chronosyschr.tex' (main file of the `chronosys' package)
%  -- `chronosys.sty' (file for LaTeX)
%  -- `x-chronosys.tex' (file for ConTeXt)
%
% 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.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Mathieu Long.
%
\expandafter\ifx\csname chronosys @\endcsname\relax\else\immediate\write16{Le fichier a deja ete charge}\endinput\fi
\ifx\numexpr\UNDEFINED\immediate\write16{Desole, mais ce fichier utilise les primitives E-TeX, vous ne pouvez pas utiliser le moteur TeX.}\endinput\fi
\expandafter\edef\csname chronosys @\endcsname{\the\catcode`\@}%
\catcode`\@=11%
\catcode`\!=11%
\def\chron@sysversion{1.2}%
%
\newhelp\chrhelpmessage{Contactez l'auteur par mail.}%
\newhelp\chrerrormessage{La commande a deja ete definie.}%
\def\error!message{\errhelp{\the\chrhelpmessage}\errmessage{\the\chrerrormessage}} %
%
\def\!chrverif#1#2{\ifdefined#2\expandafter\error!message \fi #1#2}%
%
%Commandes utilis\'ees 
%
%
\def\!gobblethree#1#2#3{}%
\def\!gobble#1{}%
\ifdefined\@ifnextchar %LATEX
  \def\:{\let\ifnexttoken\@ifnextchar}\expandafter\:
\else 
  \ifdefined\doifnextcharelse %CONTEXT
    \def\:{\let\ifnexttoken\doifnextcharelse}\expandafter\:
  \else 
    \long\def\@ifnextchar#1#2#3{%
      \let\reserved@d=#1%
      \def\reserved@a{#2}%
      \def\reserved@b{#3}%
      \futurelet\@let@token\@ifnch}%
      \let\kernel@ifnextchar\@ifnextchar
      \def\@ifnch{%
        \ifx\@let@token\@sptoken
          \let\reserved@c\@xifnch
        \else
          \ifx\@let@token\reserved@d
            \let\reserved@c\reserved@a
          \else
            \let\reserved@c\reserved@b
          \fi
        \fi
    \reserved@c}%
\def\:{\let\@sptoken= }\: % this makes \@sptoken a space token
\def\:{\@xifnch}\expandafter\def\: {\futurelet\@let@token\@ifnch}%
\let\ifnexttoken\@ifnextchar
\fi\fi
%
\newif\if!chronearg \newif\if!chrtwoarg 
\!chrverif\def\!chrtraiteoneargument#1{\ifnexttoken[{\!chroneargtrue#1}{\!chroneargfalse#1[]}}%
%
\!chrverif\def\!chrtraitetwoargument#1{\let\todoafterarg#1%
\ifnexttoken[{\!chroneargtrue\savefirsttwoarg}{\!chroneargfalse\!chrtwoargfalse#1[][]}}%
\!chrverif\def\savefirsttwoarg[#1]{\ifnexttoken[{\!chrtwoargtrue \todoafterarg[#1]}{\!chrtwoargfalse \todoafterarg[#1][]}}%
%
\!chrverif\def\!chrtraitingargvirgule#1#2{\def\!tr@itintargvirgule{#2}\!chrtr@itingargvirgule#1,\end}%
\!chrverif\def\!chrtr@itingargvirgule#1,{%
\!chrdotraiteargvirgule#1,=\end,\ifnexttoken\end \!gobble \!chrtr@itingargvirgule}%
\!chrverif\def\!chrdotraiteargvirgule#1=#2,{%
\ifx \end#2\relax
\else \!chrdotr@iteargvirgule#1=#2,\expandafter\!gobblethree
\fi}%
\!chrverif\def\!chrdotr@iteargvirgule#1=#2,{%
\ifcsname \!tr@itintargvirgule#1\endcsname
 \expandafter\def\csname \!tr@itintargvirgule#1\endcsname{#2}%
\else \immediate\write16{chronosys : option #1 ligne \number\inputlineno\space non reconnue, impossible de lui affecter la valeur #2}%
\fi }%
%
%STARTCHRONOLOGY
%
\!chrverif\def\startchronology{\!chrtraiteoneargument\dostartchronology}%
%
%OPTIONS DE STARTCHRONOLOGY
%
\!chrverif\def\!chrdefaultstartyear{0}\!chrverif\def\!chrdefaultstopyear{\the\year}\!chrverif\def\!chrdefaultwidth{\the\hsize}%
\!chrverif\def\!chrdefaultheight{0.7pc}\!chrverif\def\!chrdefaultdates{true}\!chrverif\def\!chrdefaultarrow{true}% 
\!chrverif\def\!chrdefaultarrowwidth{0.1\!chrwidth}\!chrverif\def\!chrdefaultdateselevation{20pt}%
\!chrverif\def\!chrdefaultarrowheight{\!chrheight}\!chrverif\def\!chrdefaultcolor{black}\!chrverif\def\!chrdefaultarrowcolor{\!chr@color}%
\!chrverif\def\!chrdefaultdatesstyle{}\!chrverif\def\!chrdefaultstartdate{true}\!chrverif\def\!chrdefaultstopdate{true}% 
\!chrverif\def\!chrdefaultbox{false}\!chrverif\def\!chrdefaultalign{center}%
%
\!chr@verif\newdimen\!chrheight \!chr@verif\newif\if!chrdates \!chr@verif\newif\if!chrarrow \!chr@verif\newcount\!chrstartyear
\!chr@verif\newcount\!chrstopyear \!chr@verif\newdimen\!chrwidth \!chr@verif\newdimen\!chrarrowwidth \!chr@verif\newdimen\!chrarrowheight 
\!chr@verif\newbox\!chrflechebox 
\!chr@verif\newdimen\!chr!realwidth \!chr@verif\newdimen\!chr!unitperyear
\!chr@verif\newif\if!chrstartdate \!chr@verif\newif\if!chrstopdate \!chr@verif\newdimen\!chrdateselevation \!chr@verif\newif\if!chrbox
%
\!chrverif\def\!chr!periodeschwarzodergrau{\def\!chr!stringtest{black}%
\ifx\!chr@color\!chrstringtest
  \def\!chr!periodeschwarzodergr@u{gray}%
\else
  \def\!chr!periodeschwarzodergr@u{black}%
\fi}%
%
%
\!chr@verif\newdimen\!chrskipbefore
\!chr@verif\newdimen\!chrskipafter
%
\!chrverif\def\!chrdefaultoptions{startyear=\!chrdefaultstartyear, stopyear=\!chrdefaultstopyear,
startdate=\!chrdefaultstartdate, stopdate=\!chrdefaultstopdate,
height=\!chrdefaultheight, width=\!chrdefaultwidth, dates=\!chrdefaultdates, arrow=\!chrdefaultarrow,
arrowwidth=\!chrdefaultarrowwidth, arrowheight=\!chrdefaultarrowheight, color=\!chrdefaultcolor,
arrowcolor=\!chrdefaultarrowcolor, datesstyle=\!chrdefaultdatesstyle, dateselevation=\!chrdefaultdateselevation,
box=\!chrdefaultbox, align=\!chrdefaultalign}%
%
\!chrverif\def\!chr@startyear{}\!chrverif\def\!chr@startdate{}%
\!chrverif\def\!chr@stopyear{}\!chrverif\def\!chr@stopdate{}%
\!chrverif\def\!chr@height{}\!chrverif\def\!chr@width{}%
\!chrverif\def\!chr@dates{true}%
\!chrverif\def\!chr@arrow{}\!chrverif\def\!chr@arrowwidth{}\!chrverif\def\!chr@arrowheight{}% 
\!chrverif\def\!chr@color{}% 
\!chrverif\def\!chr@arrowcolor{}\!chrverif\def\!chr@datesstyle{}% 
\!chrverif\def\!chr@dateselevation{}%
\!chrverif\def\!chr@box{}\!chrverif\def\!chr@align{}%
%
%DOSTARTCHRONOLOGY
%
\!chrverif\def\dostartchronology[#1]{\begingroup\parindent\z@\par
\global\!chrskipafter\z@
\global\!chrskipbefore\z@
\expandafter\expandafter\expandafter\!chrtraitingargvirgule\expandafter{\!chrdefaultoptions}{!chr@}%
\if!chronearg \!chrtraitingargvirgule{#1}{!chr@}\fi 
\!chrheight\!chr@height   \!chrstartyear\!chr@startyear 
\!chrstopyear\!chr@stopyear    \!chrwidth\!chr@width %
\csname !chrdates\!chr@dates\endcsname \csname !chrarrow\!chr@arrow\endcsname 
\csname !chrstartdate\!chr@startdate\endcsname  \csname !chrbox\!chr@box\endcsname 
\csname !chrstopdate\!chr@stopdate\endcsname \!chrarrowwidth\!chr@arrowwidth 
\!chrarrowheight\!chr@arrowheight \!chrdateselevation\!chr@dateselevation%
\!chr!periodeschwarzodergrau%
\dostartchronologyfinal}%
%
\!chrverif\def\dostartchronologyfinal{%
\unless\if!chrarrow
  \!chrarrowwidth\z@\relax \!chrarrowheight\z@
\fi
\!chr!realwidth\dimexpr\!chrwidth-\!chrarrowwidth\relax
\ifdim\!chr!realwidth<0pt\relax
  \advance\!chrwidth\dimen@ 
  \advance\!chrarrowwidth-\!chr!realwidth 
  \!chr!realwidth\z@
\fi 
\dimen@\dimexpr\!chrheight-\!chrarrowheight\relax  
\dimen@ii\dimen@\relax
\ifdim\dimen@ii>0pt\relax
  \dimen@ii\z@
\fi
\dimen@i\dimexpr\!chrheight-\dimen@ii+\!chrdateselevation\relax
% % %AFFICHAGE DE LA FRISE
\setbox\!chrflechebox\hbox{%
  \if!chrdates
    \if!chrstartdate\raise\dimen@i\relax % %
      \hbox to\z@{\hss\!chr@datesstyle{\the\!chrstartyear}\hss}%
    \fi
  \fi%
%  \!chrstarttikzpicture\!chrfilldraw[color=\!chr@color](0,0)--(\the\!chr!realwidth,0)--(\the\!chr!realwidth,\the\!chrheight)--(0,\the\!chrheight)--cycle;
%  \if!chrbox
%    \!chrdraw[color=black](-0.4pt,-0.4pt)--(\the\!chr!realwidth+0.4pt,-0.4pt)--(\the\!chr!realwidth+0.4pt,\the\!chrheight+0.4pt)--(-0.4pt,\the\!chrheight)--cycle;
%  \fi %
%  \if!chrarrow
%    \ifx\!chr@color\!chr@arrowcolor
%    \else \!chrdraw[color=\!chr!periodeschwarzodergr@u](\the\!chr!realwidth,0)--(\the\!chr!realwidth,\the\!chrheight);
%    \fi
%  \fi
%  \!chrstoptikzpicture %
  \begingroup{%
  \!chrusecolor{\!chr@color}%
  \vrule width\!chr!realwidth height\!chrheight depth\z@\relax \kern-\!chr!realwidth\relax
  \if!chrbox
    \!chrusecolor{black}%
    \hbox to\z@{\vrule width\!chr!realwidth height0.4pt\relax\hss}%
    \raise\!chrheight\hbox to\z@{\vrule width\!chr!realwidth height0.4pt\relax\hss}%
    \vrule height\!chrheight depth\z@\relax\kern-0.4pt\relax
    \kern\!chr!realwidth \vrule height\!chrheight\relax\kern-0.4pt\relax
    \kern-\!chr!realwidth
  \fi
  %\if!chrarrow
  %\fi
  \kern\!chr!realwidth
  }%
  \endgroup
  \if!chrdates
    \if!chrstopdate
      \raise\dimen@i\hbox to\z@{\hss\!chr@datesstyle{\the\!chrstopyear}\hss}%
    \fi
  \fi%
%
  \if!chrarrow
    \raise0.5\dimen@\hbox{%
      \!chrstarttikzpicture
      \!chrfilldraw[color=\!chr@arrowcolor](0,0.5*\the\!chrarrowheight-0.4pt)--(\the\!chrarrowwidth,0)--(0,-0.5*\the\!chrarrowheight)--cycle;
      \if!chrbox
        \!chrdraw[color=black](-0.4pt,0.5*\the\!chrarrowheight+0.4pt)--(\the\!chrarrowwidth+0.4pt,0)--(-0.4pt,-0.5*\the\!chrarrowheight-0.4pt)--cycle;
      \fi
      \!chrstoptikzpicture
      \edef\@@string@a{\!chr@color}%
      \edef\@@string@b{\!chr@arrowcolor}%
      \ifx\@@string@a\@@string@b
      \else
        {\!chrusecolor{\!chr!periodeschwarzodergr@u}%
        \kern-\!chrarrowwidth\kern-0.2pt\relax \hbox to\z@{\vrule height\dimexpr(\!chrarrowheight-\!chrheight)/2 + \!chrheight\relax depth\dimexpr(\!chrheight-\!chrarrowheight)/2\relax\hss}% 
        \kern\!chrarrowwidth\kern-0.2pt\relax}%
      \fi
    }%
  \fi}%
  \count@\numexpr\!chrstopyear-\!chrstartyear\relax
  \ifnum\count@<0\relax
    \immediate\write16{Erreur avec les dates donn\'ees}%
  \fi 
  \!chr!unitperyear\dimexpr\!chr!realwidth/\count@\relax}%
%
%
\!chrverif\def\setupchronology#1{\!chrtraitingargvirgule{#1}{!chrdefault}}%
%
%PERIODES
%
\!chr@verif\newcount\!chr!periodecolornum\!chr@verif\newcount\!chr!starttingtraitement \!chr@verif\newdimen\!chr!dimentraitement
\!chr@verif\newdimen\!chrperiodtextdepth \!chrverif\def\!chrperiodedefaulttextdepth{15pt}% 
\!chr@verif\newif\if!chrperioddates  \!chr@verif\newif\if!chrperiodbox
\!chr@verif\newif\if!chrperiodstartdate \!chr@verif\newif\if!chrperiodstopdate \!chrverif\def\!chrperiodedefaultstartdate{true}
\!chr@verif\newif\if!chrperiodifcolorbox 
\!chr@verif\newdimen\!chrperioddateselevation 
\!chr@verif\newdimen\!chrperiodeventtextwidth 
\!chr@verif\newdimen\!chrperiodbottomdepth \!chr@verif\newdimen\!chrperiodtopheight
%
%alternance des couleurs
\!chr@verif\newcount\!chrperiodecoloralternancetotalnum
\!chrverif\def\!chrperiodedefaultcolor{\chronoperiodcolor}%
\!chrverif\def\!chrperiodedefa@@ultcolor{\chronoperiodcolor}%
\!chrverif\def\!chrperiodedef@ultcolor{\!chrperiodedefaultcolor}%
\!chrverif\def\chronoperiodcolor{\ifcase\!chr!periodecolornum blue\or red\or cyan\or purple\or yellow\fi}%
\!chrperiodecoloralternancetotalnum5%
\!chrverif\def\!chr!periodecolor{\edef\!chrperiodedef@ultcolor{\!chrperiodedefaultcolor}%
  \ifx\!chrperiodedefaultcolor\!chrperiodedefa@@ultcolor
    \ifx\!chrperiodedef@ultcolor\!chr@color
      \!chr!periodecoloradvance\!chr!periodecolor 
    \fi
  \fi}%
\!chrverif\def\!chr!periodecoloradvance{\global\advance\!chr!periodecolornum\@ne\relax
\ifnum\!chr!periodecolornum=\!chrperiodecoloralternancetotalnum\relax\global\!chr!periodecolornum\z@\fi}%
%
\!chrverif\def\restartchronoperiodecolor{\!chrtraiteoneargument\dorestartchronoperiodecolor}%
\!chrverif\def\dorestartchronoperiodecolor[#1]{%
\if!chronearg 
  \def\@@string@a{#1}%
  \!chr!periodecolornum\z@ %
  \dorestartchronoperiodecolor@ux
\else
  \!chr!periodecolornum\z@
\fi}%
\!chrverif\def\dorestartchronoperiodecolor@ux{\edef\@@string@b{\chronoperiodcolor}%
\ifnum\!chr!periodecolornum<\!chrperiodecoloralternancetotalnum
  \unless\ifx\@@string@a\@@string@b
    \global\advance\!chr!periodecolornum\@ne 
    \dorestartchronoperiodecolor@ux
  \fi
\else\global\!chr!periodecolornum\z@\fi}%
%
\!chrverif\def\chronoperiodecoloralternation#1{%
\def\@@string@s{\ifcase\!chr!periodecolornum}%
\!chrperiodecoloralternancetotalnum\z@\!chr!chronoperiodecoloralternance#1,\end \let\chronoperiodcolor\@@string@s
\!chr!periodecolornum\z@}%
%
\!chrverif\def\!chr!chronoperiodecoloralternance#1,{\advance\!chrperiodecoloralternancetotalnum\@ne
\expandafter\def\expandafter\@@string@s\expandafter{\@@string@s#1}%
\ifnexttoken\end {\expandafter\def\expandafter\@@string@s\expandafter{\@@string@s\fi}\!gobble}%
{\expandafter\def\expandafter\@@string@s\expandafter{\@@string@s\or}\!chr!chronoperiodecoloralternance}}%
%
%
\!chrverif\def\!chr@periodtextdepth{}\!chrverif\def\!chr@perioddates{}%
\!chrverif\def\!chr@periodcolor{}\!chrverif\def\!chr@perioddatesstyle{}%
\!chrverif\def\!chr@periodstartdate{}\!chrverif\def\!chr@periodstopdate{}%
\!chrverif\def\!chr@periodtextstyle{}%
\!chrverif\def\!chr@perioddateselevation{}%
\!chrverif\def\!chr@periodifcolorbox{}\!chrverif\def\!chr@periodcolorbox{}%
\!chrverif\def\!chr@periodbottomdepth{}\!chrverif\def\!chr@periodtopheight{}%
\!chrverif\def\!chr@periodbox{}\!chrverif\def\!chr@periodtextwidth{}%
%
\!chrverif\def\!chreventdefaulttesttextwidth{\relax}%
%
%DOCHRONOPERIODE
%
%
\!chrverif\def\dochronoperiode[#1]#2#3#4{%
\!chr!periodecolor %alternance automqatique des couleurs
\if!chronearg \!chrtraitingargvirgule{#1}{!chr@period}\fi
% % %
\!chrperiodtextdepth\!chr@periodtextdepth \!chrperiodtopheight\!chr@periodtopheight
\!chrperiodbottomdepth\!chr@periodbottomdepth
\csname !chrperioddates\!chr@perioddates\endcsname \csname !chrperiodstartdate\!chr@periodstartdate\endcsname 
\csname !chrperiodstopdate\!chr@periodstopdate\endcsname \csname !chrperiodifcolorbox\!chr@periodifcolorbox\endcsname
\csname !chrperiodbox\!chr@periodbox\endcsname
\ifx\!chr@periodtextwidth\!chreventdefaulttesttextwidth
	\!chrperiodeventtextwidth=-1pt%
\else
	\!chrperiodeventtextwidth=\!chr@periodtextwidth%
\fi
\!chrperioddateselevation\!chr@perioddateselevation 
\advance\!chrperioddateselevation 1.25\!chrheight\relax
% % %On s'assure que les dates sont biebn dans l'intervalle
\ifnum#2>\numexpr\!chrstartyear-1\relax
\ifnum#2<\numexpr\!chrstopyear+1\relax
\ifnum#3<\numexpr\!chrstopyear+1\relax 
\ifnum#3>\numexpr\!chrstartyear-1\relax
\count@\numexpr#3-#2\relax
% % %Et que la seconde est post\'erieure \`a la pr\'emi\`ere
\ifnum\count@>\z@\relax
% %
\!chr!starttingtraitement\numexpr#2-\!chrstartyear\relax\dimen@\dimexpr\count@\!chr!unitperyear\relax
\!chr!dimentraitement\dimexpr\!chr!starttingtraitement\!chr!unitperyear\relax
% %AFFICHAGE
\dimen@i\wd\!chrflechebox
\setbox\!chrflechebox\hbox{%
  \unhbox\!chrflechebox\kern-\dimen@i\kern\!chr!dimentraitement
  \lower\dimexpr\!chrperiodtextdepth-\!chrperiodbottomdepth\relax\hbox to\z@{%
    \ifdim\!chrperiodeventtextwidth < \z@ \hbox to\dimen@{%
      	\hss \if!chrperiodifcolorbox\expandafter\!chrperiodcolorbox\fi{\!chr@periodtextstyle{#4}}\hss
    	}%
    \else
       \setbox\z@\hbox to\dimen@{\hss\vbox{%
       \hsize\!chrperiodeventtextwidth {\!chr@periodtextstyle{#4}}
       }\hss}%
       \dimen@i\wd\z@
       \dimen@ii\dimexpr\ht\z@+\dp\z@\relax
       \lower\dimexpr\dimen@ii-10pt\relax\hbox to\dimen@{%
          \hss\setbox\z@\hbox{%
           \vbox{%
            \hsize\!chrperiodeventtextwidth\relax\!chr@periodtextstyle{#4}%
            \vskip1pt
           }%
          }%
          \dimen@i\dimexpr\wd\z@+4pt\relax
          \dimen@ii\dimexpr\ht\z@+\dp\z@+2pt\relax
          \setbox\z@\hbox to\z@{%
          \hss\begingroup{\!chrusecolor{\!chr@periodcolorbox}\vrule height\dimen@ii width\dimen@i depth2pt}\endgroup\kern-\dimen@i\kern2pt\relax%
                     \box\z@\hss
          }%
          \box\z@\hss
       }%
    \fi
    \hss
  }%
  \if!chrperioddates
    \if!chrperiodstartdate
      \raise\dimexpr\!chrperioddateselevation +(\!chrperiodtopheight-\!chrheight)\relax 
      \hbox to\z@{%
        \hss\!chr@perioddatesstyle{#2}\hss
      }%
    \fi
  \fi 
  \raise\!chrperiodbottomdepth \hbox{%
    \begingroup {\!chrusecolor{\!chr@periodcolor}%
       \dimen@i\dimexpr\!chrperiodtopheight-\!chrperiodbottomdepth\relax%
       \vrule width\dimen@ height\dimen@i depth\z@\kern-\dimen@%
%       \!chrusecolor{black}%
%       \raise\dimen@i\hbox to\z@{\vrule height0.1pt depth0.3pt width\dimen@\hss}%
%       \hbox to\z@{\vrule height0.1pt depth0.3pt width\dimen@\hss}%
    }\endgroup%%
    \begingroup{%
    \dimen@i\dimexpr\!chrperiodtopheight-\!chrperiodbottomdepth\relax%
    \!chrusecolor{\!chr!periodeschwarzodergr@u}%
    \kern-0.2pt\relax\vrule height\dimen@i width0.4pt\relax  \kern-0.2pt\relax%
    \kern\dimen@\relax
    \kern-0.2pt\relax\vrule height\dimen@i width0.4pt\relax  \kern-0.2pt\relax
    \kern-\dimen@\relax
    }%
    \endgroup
    \begingroup{%
    \!chrusecolor{black}
    \if!chrbox
      \lower 0.2pt\hbox to\z@{\vrule width\dimen@\hss}%
    \fi
    \if!chrperiodbox
      \raise \!chrperiodbottomdepth \hbox to\z@{\vrule width\dimen@\hss}%
      \raise \!chrperiodtopheight \hbox to\z@{\vrule width\dimen@\hss}%
    \fi
    }%
    \endgroup
    \kern\dimen@\relax
  }%
  \if!chrperioddates
    \if!chrperiodstopdate
      \raise\dimexpr\!chrperioddateselevation+(\!chrperiodtopheight-\!chrheight)\relax
      \hbox to\z@{%
        \hss \!chr@perioddatesstyle{#3}\hss
      }%
    \fi
  \fi
}%
\!chr!periodecoloradvance
\fi\fi\fi\fi\fi}%
%
%
\!chrverif\def\setupchronoperiode{\def\@@string@a{periode}\!chrtraiteoneargument\dosetupchronoeventandperiode}%
%
%EVENTS
%
%
\!chr@verif\newif\if!chreventspecifiedday\!chr@verif\newif\if!chreventspecifiedmonth \!chr@verif\newif\if!chreventbarre
\!chr@verif\newif\if!chreventdate  \!chr@verif\newif\if!chreventmark
\!chr@verif\newif\if!chreventifcolorbox \!chr@verif\newif\if!chreventconversionmonth 
\!chr@verif\newdimen\!chreventmarkdepth \!chr@verif\newif\if!chreventyear \!chr@verif\newdimen\!chreventiconheight
 \!chrverif\def\!chreventdefaultbarre{true}%
\!chrverif\def\!chreventdefaulticon{}%
\!chrverif\def\!chreventdefaultmarkdepth{10pt}%
\!chrverif\def\!chreventdefaulttextstyle{}%
%
%
%
\!chrverif\def\!chreventevalspecification#1{\count@\z@\relax\!chreventev@lspecification#1/\end}%
\!chrverif\def\!chreventev@lspecification#1/{\advance\count@\@ne\relax\expandafter\def\csname
!chreventspecifiedargument\number\count@\endcsname{#1}\ifnexttoken\end \!gobble \!chreventev@lspecification}%
%
\!chrverif\def\chron@selectmonth#1{\ifcase#1\or janvier\or f\'evrier\or mars\or avril\or mai\or juin\or juillet\or ao\^ut\or septembre\or octobre\or novembre\or d\'ecembre\fi}%
%
\!chrverif\def\!chr@eventbarre{}\!chrverif\def\!chr@eventicon{}\!chrverif\def\!chr@eventmarkdepth{}%
\!chrverif\def\!chr@eventtextstyle{}\!chrverif\def\!chr@eventmark{}%
\!chrverif\def\!chr@eventdate{}\!chrverif\def\!chr@eventdatesseparation{}%
\!chrverif\def\!chr@eventconversionmonth{}\!chrverif\def\!chr@eventdatestyle{}%
\!chrverif\def\!chr@eventdatesstyle{}\!chrverif\def\!chr@eventyear{}\!chrverif\def\!chr@eventiconheight{}%
\!chrverif\def\!chr@eventifcolorbox{}\!chrverif\def\!chr@eventcolorbox{}%.
\!chrverif\def\!chr@eventtextwidth{}%
% 
\!chr@verif\newif\if!chreventlocationup
%
%
%DOCHRONOEVENT
%
%
\!chrverif\def\dochronoevent[#1]#2#3{%
\if!chronearg \!chrtraitingargvirgule{#1}{!chr@event}\fi
% % %
\csname !chreventbarre\!chr@eventbarre\endcsname 
\csname !chreventmark\!chr@eventmark\endcsname 
\csname !chreventdate\!chr@eventdate\endcsname
\csname !chreventconversionmonth\!chr@eventconversionmonth\endcsname 
\csname !chreventyear\!chr@eventyear\endcsname
\csname !chreventifcolorbox\!chr@eventifcolorbox\endcsname
\!chreventmarkdepth\!chr@eventmarkdepth 
\!chreventiconheight\!chr@eventiconheight
\ifx\!chr@eventtextwidth\!chreventdefaulttesttextwidth 
   \!chrperiodeventtextwidth=-1pt%
\else \!chrperiodeventtextwidth\!chr@eventtextwidth
\fi
\ifdim\!chreventmarkdepth<\z@\relax
  \!chreventlocationuptrue
\else
  \!chreventlocationupfalse
\fi
% % % Evaluation de la precision de la date de l'evenement
\!chreventevalspecification{#2}%
\ifnum\count@<4\relax
  \ifcase\count@
    \or \!chreventspecifieddayfalse\!chreventspecifiedmonthfalse 
        \edef\!chreventyear{\csname !chreventspecifiedargument1\endcsname}%
    \or \!chreventspecifieddayfalse\!chreventspecifiedmonthtrue
        \edef\!chreventyear{\csname !chreventspecifiedargument2\endcsname}%
        \edef\!chreventmonth{\csname !chreventspecifiedargument1\endcsname}%
    \or \!chreventspecifieddaytrue\!chreventspecifiedmonthtrue
        \edef\!chreventyear{\csname !chreventspecifiedargument3\endcsname}%
        \edef\!chreventmonth{\csname !chreventspecifiedargument2\endcsname}%
        \edef\!chreventday{\csname !chreventspecifiedargument1\endcsname}%
  \fi %
% %On s'assure que les dates sont bien comprises dans les bornes
\ifnum\!chreventyear>\numexpr\!chrstartyear-1\relax
\ifnum\!chreventyear<\numexpr\!chrstopyear+1\relax
      \if!chreventspecifiedmonth
        \if!chreventspecifiedday 
          \count@\numexpr\!chreventday+\!chreventmonth*30\relax
        \else %
          \count@\numexpr\!chreventmonth*30\relax
        \fi
      \else \count@\z@
      \fi %
      \!chr!dimentraitement\dimexpr(\!chr!unitperyear)/365*\count@\relax%
     \count@\numexpr\!chreventyear-\!chrstartyear\relax 
     \advance\!chr!dimentraitement\dimexpr\count@\!chr!unitperyear\relax
% % % Affichage
     \dimen@i\wd\!chrflechebox
     \setbox\!chrflechebox\hbox{%
       \unhbox\!chrflechebox\kern-\dimen@i\kern\!chr!dimentraitement
       \if!chreventbarre
        \begingroup{%
        \!chrusecolor{black}%
        \kern-0.4pt\relax\vrule width0.4pt height\!chrheight depth\z@\relax
        }%
        \endgroup
       \fi
       \kern-0.4pt\raise\!chreventiconheight \hbox to\z@{\hss\!chr@eventicon\hss}%
       \lower\dimexpr\!chreventmarkdepth+2pt\relax
       \hbox to\z@{%
         \vbox to\z@{%
           \if!chreventlocationup\relax\vss\fi
           \if!chreventdate\hbox to\z@{%
             \hss \if!chreventifcolorbox \expandafter\!chreventcolorbox\fi
             {\!chr@eventdatestyle{%
               \if!chreventspecifiedday %
                 {\!chr@eventdatesstyle{\!chreventday}}\!chr@eventdatesseparation
               \fi
             {\!chr@eventdatesstyle{%
               \if!chreventspecifiedmonth 
                 \if!chreventconversionmonth\expandafter \chron@selectmonth
                 \fi 
                 \!chreventmonth
               \fi
               }%
             }%
             \if!chreventspecifiedmonth\if!chreventyear \!chr@eventdatesseparation\fi\fi 
             \if!chreventyear{\!chr@eventdatesstyle{\!chreventyear}}\fi%
             }}%
             \hss
           }%
           \fi
           \ifdim\!chrperiodeventtextwidth > \z@ 
             \hbox to\z@{%
               \hss\setbox\z@\hbox{%
                 \vbox{%
                   \hsize\!chrperiodeventtextwidth\relax\!chr@eventtextstyle{#3}%
                   \vskip1pt\relax
                 }%
               }%
               \dimen@i\dimexpr\wd\z@+4pt\relax
               \dimen@ii\dimexpr\ht\z@+\dp\z@+2pt\relax
               \setbox\z@\hbox to\z@{%
                 \hss\begingroup{\!chrusecolor{\!chr@eventcolorbox}\vrule height\dimen@ii width\dimen@i depth2pt\relax}\endgroup \kern-\dimen@i\kern2pt\relax%
                 \box\z@\hss
               }%
               \box\z@
             }%
           \else 
             \hbox to\z@{%
               \hss\if!chreventifcolorbox\expandafter\!chreventcolorbox\fi{%
               \!chr@eventtextstyle{#3}}\hss
             }%
           \fi 
           \unless\if!chreventlocationup\relax\vss\fi
         }%
       }%
       \if!chreventmark
         \if!chreventlocationup\relax
         %\!chrstarttikzpicture \!chrdraw(0,0)--(0,\the\!chreventmarkdepth+5pt);\!chrstoptikzpicture
           \vrule height\dimexpr-\!chreventmarkdepth-5pt\relax depth\z@ \kern-0.4pt\relax
         \else \vrule height\z@ depth\!chreventmarkdepth
         \fi
         \kern-0.4pt\relax
       \fi  
       \setbox0\vbox{%
         \if!chreventdate
           \hbox{#2}%
         \fi
         \hbox{%
          \ifdim\!chrperiodeventtextwidth > \z@ 
            \vbox {%
             \hsize\!chrperiodeventtextwidth #3%
            }%
          \else #3%
          \fi 
         }%
       }%
      \begingroup\dimen@\dimexpr\dp0+\ht0+2pt\relax
      \dimen@i\dimexpr\dimen@-\!chreventmarkdepth\relax
      \if!chreventlocationup
        \ifdim \dimen@i >\!chrskipbefore \global\!chrskipbefore\dimen@i \fi
      \else
        \ifdim \dimen@ >\!chrskipafter \global\!chrskipafter\dimen@ \fi
      \fi
      \endgroup
    }%
\fi\fi\fi}%
%
%
%
%
%
%
%
\!chrverif\def\setupchronoevent{\def\@@string@a{event}\!chrtraiteoneargument\dosetupchronoeventandperiode}%
\!chrverif\def\dosetupchronoeventandperiode[#1]#2{\if!chronearg
\def\@@string@a{#1}\fi \!chr@parcoursoptions#2,\end}%
%
%STOPCHRONOLOGY
%
%
\!chr@verif\newdimen\!chrstopwidth
\!chrverif\def\!chrstopcenteralign{\!chrstopwidth\dimexpr(\hsize-\!chrwidth)/2\relax}%
\!chrverif\def\!chrstopleftalign{\!chrstopwidth\z@}%
\!chrverif\def\!chrstoprightalign{\!chrstopwidth\dimexpr\hsize-\!chrwidth\relax}%
%
\!chrverif\def\stopchronology{\goodbreak
\ifcsname !chrstop\!chr@align align\endcsname
  \csname !chrstop\!chr@align align\endcsname
\else\!chrstopwidth\z@
\fi 
\vskip\!chrskipbefore
\moveright\!chrstopwidth\box\!chrflechebox
\vskip\!chrskipafter
\endgroup\bigskip}%
%
\!chr@verif\newif\if!chrverifdefines
\!chrverif\def\!chrverifdefines{%
 \ifcsname chrono\@@string@a\endcsname
   \!chrverifdefinesfalse \immediate\write16{Attention : macro \expandafter\noexpand\csname chrono\@@string@a\endcsname deja definie.}%
   \expandafter\!gobble 
 \else
   \!chrverifdefinestrue
   \expandafter\!chrverifdefines@ux
 \fi}%
\!chrverif\def\!chrverifdefines@ux{\expandafter\def\csname chrono\@@string@a\endcsname}%
%
%
%DEFINECHRONOEVENT
%
%
\!chrverif\def\definechronoevent#1{%
\def\@@string@a{#1}%
\!chrverifdefines{%
\expandafter\expandafter\expandafter\!chrtraitingargvirgule\expandafter\expandafter\expandafter{\csname !chr#1defaultoptions\endcsname}{!chr@event}%
\!chrtraiteoneargument\dochronoevent}%
\if!chrverifdefines
  \expandafter\def\csname !chr#1defaultoptions\endcsname{barre=true, icon=\relax,%
  markdepth=10pt, textstyle=\relax, mark=true,%
  date=true, datesseparation=\space, conversionmonth=true,%
  datestyle=\relax, datesstyle=\relax, year=true,%
  iconheight=0.5\!chrheight, ifcolorbox=true, colorbox=white,%
  textwidth=\relax}%
\fi
\ifnexttoken[{\!chr@defineorsetupoptions}{}}%
%
%
%DEFINECHRONOPERIODE
%
%
\!chrverif\def\definechronoperiode#1{%
\def\@@string@a{#1}%
\!chrverifdefines{%
\expandafter\expandafter\expandafter\!chrtraitingargvirgule\expandafter\expandafter\expandafter{\csname !chr#1defaultoptions\endcsname}{!chr@period}%
\!chrtraiteoneargument\dochronoperiode}%
\if!chrverifdefines
  \expandafter\def\csname !chr#1defaultoptions\endcsname{textdepth=15pt, dates=true,%
  color=\!chrperiodedef@ultcolor, datesstyle=\relax,%
  startdate=true, stopdate=true, textstyle=\relax,%
  dateselevation=0pt, ifcolorbox=true,%
  colorbox=white, bottomdepth=0pt, topheight=\!chrheight, box=false,%
  textwidth=\relax}%
\fi
\ifnexttoken[{\!chr@defineorsetupoptions}{}}%
%
%pour modifier les valeurs par d\'efaut
%
\!chrverif\def\!chr@defineorsetupoptions[#1]{%
\!chr@parcoursoptions#1,\end
}%
%
\!chrverif\def\!chr@parcoursoptions#1,{\!chr@replaceoptions#1,=\end,\ifnexttoken\end \!gobble \!chr@parcoursoptions}%
\!chrverif\def\!chr@replaceoptions#1=#2,{%
\ifx#2\end\relax
\else
  \def\@@string@f{}%
  \def\@@string@c{#1}\def\@@string@d{#2}%
  \expandafter\let\expandafter\@@string@@b\csname !chr\@@string@a defaultoptions\endcsname
  \expandafter\!chr@replaceoptionsaux\@@string@@b,\end%
  \expandafter\let\csname !chr\@@string@a defaultoptions\endcsname\@@string@f
  \expandafter\!gobblethree
\fi}%
%
\!chrverif\def\!chr@replaceoptionsaux#1,{\!chr@replaceoptions@ux#1,=\end,\ifnexttoken\end\!gobble\!chr@replaceoptionsaux}%
\!chrverif\def\!chr@replaceoptions@ux#1=#2,{%
\ifx#2\end\relax
\else
  \def\@@string@e{#1}% 
  \ifx\@@string@c\@@string@e
    \expandafter\def\expandafter\@@string@f\expandafter{\@@string@f , #1=}%
    \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\@@string@f\expandafter\expandafter\expandafter{\expandafter\@@string@f\@@string@d}%
  \else 
    \expandafter\def\expandafter\@@string@f\expandafter{\@@string@f , #1=#2}%
  \fi
  \expandafter\!gobblethree
\fi
}%
%
%
\!chr@verif\newcount\!chrgraduationcount
\!chr@verif\newcount\!chrgraduationcount@ux
\newif\if!chrgradu@tionevent \!chrgradu@tioneventtrue
\!chrverif\def\chronograduation{\!chrtraitetwoargument\dochronograduation}%
\!chrverif\def\dochronograduation[#1][#2]#3{%
\if!chrtwoarg
  \def\@@string@a{#2}%
  \def\@@string@b{#1}\def\@@string@c{event}%
  \def\@@string@d{periode}%
  \ifx\@@string@b\@@string@c 
    \!chrgradu@tioneventtrue 
  \else
    \ifx\@@string@b\@@string@d 
      \!chrgradu@tioneventfalse
    \else 
    	\def\@@string@e{}\unless\ifx\@@string@b\@@string@e\immediate\write16{chronosys : style #1 non défini ligne \number\inputlineno}\fi
    \fi
  \fi 
\else \def\@@string@a{#1}%
\fi
\!chrgraduationcount\!chrstartyear
\if!chrgradu@tionevent
  \loop
    \advance\!chrgraduationcount#3%
    \ifnum\!chrgraduationcount<\!chrstopyear 
      \expandafter\chrono!!eventgradu@tion
      \expandafter[\@@string@a]{\number\!chrgraduationcount}{}%
  \repeat
\else 
  \def\@@string@e{startdate=true,}%
  \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\@@string@e\expandafter\expandafter\expandafter{\expandafter\@@string@e\@@string@a}%
  \expandafter\chrono!!periodegradu@tion\expandafter[\@@string@e]{\number\!chrgraduationcount}{#3}{}%
  \restartchronoperiodecolor
  \loop 
    \advance\!chrgraduationcount#3%
    \ifnum\!chrgraduationcount<\!chrstopyear
       \!chrgraduationcount@ux\numexpr\!chrgraduationcount-#3\relax \expandafter\chrono!!periodegradu@tion\expandafter[\@@string@a]{\number\!chrgraduationcount@ux}{\number\!chrgraduationcount}{}%
  \repeat
\fi}%
%
\!chrverif\def\setupchronograduation{\!chrtraiteoneargument\dosetupchronograduation}%
\!chrverif\def\dosetupchronograduation[#1]{%
\if!chronearg
  \def\@@string@b{#1}\def\@@string@c{event}\def\@@string@d{periode}%
  \ifx\@@string@b\@@string@c 
    \!chrgradu@tioneventtrue 
  \else
    \ifx\@@string@b\@@string@d 
      \!chrgradu@tioneventfalse
    \fi
  \fi 
\fi
\if!chrgradu@tionevent 
  \def\@@string@a{[!!eventgradu@tion]}%
\else \def\@@string@a{[!!periodegradu@tion]}%
\fi
\expandafter\setupchronoevent\@@string@a}%
%
\definechronoevent{event}%
\definechronoevent{!!eventgradu@tion}[markdepth=5pt,barre=false, ifcolorbox=false]%
\definechronoperiode{periode}%
\definechronoperiode{!!periodegradu@tion}[dateselevation=-10pt,%
startdate=false, ifcolorbox=false]%
%
\endinput
%
%