% 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`\@}
\def\chron@sysversion{1.10}
\catcode`\@=11
\catcode`\!=11

\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} %
%
\!chrverif\def\!gobblethree#1#2#3{}
\!chrverif\def\!gobble#1{}
\ifdefined\@ifnextchar \def\:{\let\ifnexttoken\@ifnextchar}\expandafter\:\else 
\ifdefined\doifnextcharelse \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][]}}
\!chr@verif\newif\ifarvirgule

\!chrverif\def\!chrtraitingargvirgule[#1]#2{\def\!tr@itintargvirgule{#2} \!chrtr@itingargvirgule#1,\end}
\!chrverif\def\!chrtr@itingargvirgule#1,{\ifnexttoken\end{\!chrdotraiteargvirgule#1,=\end,\!gobble}{\!chrdotraiteargvirgule#1,=\end,\!chrtr@itingargvirgule}}
\!chrverif\def\!chrdotraiteargvirgule#1=#2,{\ifx\end#2\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}\fi }

\!chrverif\def\startchronology{\!chrtraiteoneargument\dostartchronology}

\!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\!chrdefaultarrowheight{\!chrheight} \!chrverif\def\!chrdefaultcolor{black} \!chrverif\def\!chrdefaultarrowcolor{\!chr@color}
\!chrverif\def\!chrdefaultdatesstyle{} \!chrverif\def\!chrdefaultstartdate{true} \!chrverif\def\!chrdefaultstopdate{true} \!chrverif\def\!chrdefaultdateselevation{20pt}
\!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 \!chrverif\def\!chr@color{black}
\!chrverif\def\!chr@arrowcolor{\!chrdefaultarrowcolor} \!chr@verif\newdimen\!chr!realwidth \!chrverif\def\!chr@datesstyle{} \!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}

\!chrverif\def\dostartchronology[#1]{\begingroup\parindent\z@\par\def\!chr@startyear{\!chrdefaultstartyear}%
\def\!chr@height{\!chrdefaultheight}\def\!chr@stopyear{\!chrdefaultstopyear}\def\!chr@width{\!chrdefaultwidth}\def\!chr@dates{\!chrdefaultdates}%
\def\!chr@arrow{\!chrdefaultarrow}\def\!chr@arrowwidth{\!chrdefaultarrowwidth}\def\!chr@arrowheight{\!chrdefaultarrowheight}\def\!chr@color{\!chrdefaultcolor}%
\def\!chr@arrowcolor{\!chrdefaultarrowcolor}\def\!chr@datesstyle{\!chrdefaultdatesstyle}\def\!chr@startdate{\!chrdefaultstartdate}%
\def\!chr@stopdate{\!chrdefaultstopdate}\def\!chr@dateselevation{\!chrdefaultdateselevation}%
\def\!chr@box{\!chrdefaultbox}\def\!chr@align{\!chrdefaultalign}%
\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 \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% 
% %
\setbox\!chrflechebox\hbox{%
\if!chrdates\if!chrstartdate\raise\dimen@i\relax % %
\hbox to\z@{\hss\!chr@datesstyle{\the\!chrstartyear}\hss}\fi\fi%
\starttikzpicture\filldraw[color=\!chr@color](0,0)--(\!chr!realwidth,0)--(\!chr!realwidth,\!chrheight)--(0,\!chrheight)--cycle;\if!chrbox\draw[color=black](-0.4pt,-0.4pt)--(\!chr!realwidth+0.4pt,-0.4pt)--(\!chr!realwidth+0.4pt,\!chrheight+0.4pt)--(-0.4pt,\!chrheight)--cycle;\fi %
\if!chrarrow\ifx\!chr@color\!chr@arrowcolor\else\draw[color=\!chr!periodeschwarzodergr@u](\!chr!realwidth,0)--(\!chr!realwidth,\!chrheight);\fi\fi\stoptikzpicture %
\if!chrdates\if!chrstopdate\raise\dimen@i\hbox to\z@{\hss\!chr@datesstyle{\the\!chrstopyear}\hss}\fi\fi%
%
\if!chrarrow\raise0.5\dimen@\hbox{\starttikzpicture\filldraw[color=\!chr@arrowcolor](0,0.5\!chrarrowheight)--(\!chrarrowwidth,0)--(0,-0.5\!chrarrowheight)--cycle;\if!chrbox\draw[color=black](-0.4pt,0.5\!chrarrowheight+0.4pt)--(\!chrarrowwidth+0.4pt,0)--(-0.4pt,-0.5\!chrarrowheight-0.4pt)--cycle;\fi \stoptikzpicture}\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}}

\!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 \!chrverif\def\!chrperiodedefaultdates{true}
\!chr@verif\newif\if!chrperiodstartdate \!chr@verif\newif\if!chrperiodstopdate \!chrverif\def\!chrperiodedefaultstartdate{true}
\!chr@verif\newif\if!chrperiodifcolorbox \!chrverif\def\!chrperiodedefaultifcolorbox{true}
\!chrverif\def\!chrperiodedefaultstopdate{true} \!chrverif\def\!chrperiodedefaultcolorbox{white}
\!chr@verif\newdimen\!chrperioddateselevation \!chrverif\def\!chrperiodedefaultdateselevation{0pt}
\!chr@verif\newdimen\!chrperiodeventtextwidth 


%\!chrverif\def\!chr!periodec@lor{\ifcase\!chr!periodecolornum blue\or red\or cyan\or purple\or yellow\fi}
%\!chrverif\def\!chr!periodecolor{\edef\!chrperiodedefaultcolor{\!chr!periodec@lor}\ifx\!chr!periodec@l@r\!chr@color\!chr!periodecoloradvance\!chr!periodecolor %\fi}
%\!chrverif\def\!chr!periodecoloradvance{\global\advance\!chr!periodecolornum\@ne\relax\ifnum\!chr!periodecolornum=5\relax\global\!chr!periodecolornum\z@\fi}
%\!chrverif\def\!chrperiodedefaultdatesstyle{} \!chrverif\def\!chrperiodedefaulttextstyle{} 

\!chrverif\def\!chrperiodedefaultcolor{\chron@periodcolor}
\!chrverif\def\!chrperiodedefa@@ultcolor{\chron@periodcolor}
\!chrverif\def\chron@periodcolor{\ifcase\!chr!periodecolornum blue\or red\or cyan\or purple\or yellow\fi}
\!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=5\relax\global\!chr!periodecolornum\z@\fi}
\!chrverif\def\!chrperiodedefaultdatesstyle{} \!chrverif\def\!chrperiodedefaulttextstyle{} 

\!chrverif\def\chronoperiode{\!chrtraiteoneargument\dochronoperiode}
\!chrverif\def\dochronoperiode[#1]#2#3#4{\def\!chr@periodtextdepth{\!chrperiodedefaulttextdepth}\def\!chr@perioddates{\!chrperiodedefaultdates}%
\def\!chr@periodcolor{\!chrperiodedef@ultcolor}\def\!chr@perioddatesstyle{\!chrperiodedefaultdatesstyle}%
\def\!chr@periodstartdate{\!chrperiodedefaultstartdate}\def\!chr@periodstopdate{\!chrperiodedefaultstopdate}%
\def\!chr@periodtextstyle{\!chrperiodedefaulttextstyle}\def\!chr@perioddates{\!chrperiodedefaultdates}%
\def\!chr@perioddateselevation{\!chrperiodedefaultdateselevation}%
\def\!chr@periodifcolorbox{\!chrperiodedefaultifcolorbox}\def\!chr@periodcolorbox{\!chrperiodedefaultcolorbox}%
\!chr!periodecolor %
\if!chronearg
\!chrtraitingargvirgule[#1]{!chr@period}\fi\!chrperiodtextdepth\!chr@periodtextdepth
\csname !chrperioddates\!chr@perioddates\endcsname \csname !chrperiodstartdate\!chr@periodstartdate\endcsname \csname !chrperiodstopdate\!chr@periodstopdate\endcsname
\csname !chrperiodifcolorbox\!chr@periodifcolorbox\endcsname
\!chrperioddateselevation\!chr@perioddateselevation \advance\!chrperioddateselevation 1.25\!chrheight\relax
\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\ifnum\count@>\z@\relax
\!chr!starttingtraitement\numexpr#2-\!chrstartyear\relax\dimen@\dimexpr\count@\!chr!unitperyear\relax
\!chr!dimentraitement\dimexpr\!chr!starttingtraitement\!chr!unitperyear\relax
% %
\dimen@i\wd\!chrflechebox
\setbox\!chrflechebox\hbox{\unhbox\!chrflechebox\kern-\dimen@i\kern\!chr!dimentraitement\lower\!chrperiodtextdepth\hbox to\z@
{\hbox to\dimen@
{\hss \if!chrperiodifcolorbox\expandafter\!chrperiodcolorbox\fi{\!chr@periodtextstyle{#4}}\hss}\hss}%
\if!chrperioddates\if!chrperiodstartdate\raise\!chrperioddateselevation
\hbox to\z@{\hss\!chr@perioddatesstyle{#2}\hss}\fi\fi 
\starttikzpicture \filldraw [color=\!chr@periodcolor](\z@,\z@)--(\dimen@,\z@)--(\dimen@,\!chrheight)--(\z@,\!chrheight)--cycle;\draw[color=\!chr!periodeschwarzodergr@u](\z@,\z@)--(\z@,\!chrheight);%
\draw [color=\!chr!periodeschwarzodergr@u](\dimen@,\z@)--(\dimen@,\!chrheight);%
\if!chrbox\draw[color=black](\z@,-0.2pt)--(\dimen@,-0.2pt)\fi
\stoptikzpicture
\if!chrperioddates\if!chrperiodstopdate\raise\!chrperioddateselevation \hbox to\z@
{\hss \!chr@perioddatesstyle{#3}\hss}\fi\fi}\!chr!periodecoloradvance\fi\fi\fi\fi\fi}

\!chrverif\def\setupchronoperiode#1{\!chrtraitingargvirgule[#1]{!chrperiodedefault}}

\!chrverif\def\chronoevent{\!chrtraiteoneargument\dochronoevent}
\!chr@verif\newif\if!chreventspecifiedday\!chr@verif\newif\if!chreventspecifiedmonth \!chr@verif\newif\if!chreventbarre \!chrverif\def\!chreventdefaultbarre{true}
\!chrverif\def\!chreventdefaulticon{} \!chr@verif\newdimen\!chreventmarkdepth 
\!chrverif\def\!chreventdefaultmarkdepth{10pt} 
\!chrverif\def\!chreventdefaulttextstyle{} \!chr@verif\newif\if!chreventmark \!chrverif\def\!chreventdefaultmark{true}
\!chr@verif\newif\if!chreventdate \!chrverif\def\!chreventdefaultdate{true} \!chr@verif\let\!chreventdefaultdatesseparation\space
\!chr@verif\newif\if!chreventconversionmonth \!chrverif\def\!chreventdefaultconversionmonth{true}
\!chr@verif\newif\if!chreventifcolorbox \!chrverif\def\!chreventdefaultifcolorbox{true}
\!chrverif\def\!chreventdefaultdatestyle{} \!chrverif\def\!chreventdefaultdatesstyle{} \!chr@verif\newif\if!chreventyear \!chrverif\def\!chreventdefaultyear{true} \!chrverif\def\!chreventdefaulttesttextwidth{\relax}
\!chrverif\def\!chreventdefaulticonheight{0.5\!chrheight} \!chr@verif\newdimen\!chreventiconheight
\!chrverif\def\!chreventdefaultcolorbox{white}

\!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\dochronoevent[#1]#2#3{%
\def\!chr@eventbarre{\!chreventdefaultbarre}\def\!chr@eventicon{\!chreventdefaulticon}\def\!chr@eventmarkdepth{\!chreventdefaultmarkdepth}%
\def\!chr@eventtextstyle{\!chreventdefaulttextstyle}\def\!chr@eventmark{\!chreventdefaultmark}%
\def\!chr@eventdate{\!chreventdefaultdate}\def\!chr@eventdatesseparation{\!chreventdefaultdatesseparation}%
\def\!chr@eventconversionmonth{\!chreventdefaultconversionmonth}\def\!chr@eventdatestyle{\!chreventdefaultdatestyle}%
\def\!chr@eventdatesstyle{\!chreventdefaultdatesstyle}\def\!chr@eventyear{\!chreventdefaultyear}\def\!chr@eventiconheight{\!chreventdefaulticonheight}%
\def\!chr@eventifcolorbox{\!chreventdefaultifcolorbox}\def\!chr@eventcolorbox{\!chreventdefaultcolorbox}%.
\def\!chr@eventtextwidth{\relax}%
\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
%\def\!chr@eventtextwidth{\relax}%
\!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 %
\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
% %
\dimen@i\wd\!chrflechebox
\setbox\!chrflechebox\hbox{\unhbox\!chrflechebox\kern-\dimen@i\kern\!chr!dimentraitement
\if!chreventbarre\starttikzpicture\draw[color=black](0,0)--(0,\!chrheight);\stoptikzpicture\fi\kern-0.4pt\raise\!chreventiconheight\hbox to\z@{\hss\!chr@eventicon\hss}\lower\dimexpr\!chreventmarkdepth+2pt\relax\hbox to\z@{\vbox to\z@{\ifdim\!chreventmarkdepth<0pt\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@ 
\vbox to \z@{
\hbox to\z@{\hss\setbox\z@\hbox{\vbox
{\hsize\!chrperiodeventtextwidth\relax\!chr@eventtextstyle{#3}}}%
\dimen@i\wd\z@
\dimen@ii\dimexpr\ht\z@+\dp\z@\relax
\setbox\z@\hbox to\z@{\hss\starttikzpicture \fill[color=\!chr@eventcolorbox]%
(\z@,\z@)--(\dimen@i,\z@)--(\dimen@i,\dimen@ii)--(\z@,\dimen@ii);\stoptikzpicture\kern-\dimen@i
\box\z@\hss}\box\z@}\vss}
\else \hbox to\z@
{\hss\if!chreventifcolorbox\expandafter\!chreventcolorbox\fi{%
\!chr@eventtextstyle{#3}}\hss}%
\fi \ifdim\!chreventmarkdepth>0pt\relax\vss\fi}}\if!chreventmark\ifdim\!chreventmarkdepth<0pt\starttikzpicture \draw(0,0)--(0,\!chreventmarkdepth+5pt);\stoptikzpicture\else \vrule height0pt depth\!chreventmarkdepth\fi\fi  
\setbox0\vbox{\if!chreventdate\hbox{#2}\fi\hbox{
\ifdim\!chrperiodeventtextwidth > \z@ \vtop {\hsize\!chrperiodeventtextwidth #3}
\else #3\fi }}\lower\dimexpr\dp0+\ht0+\!chreventmarkdepth+2pt\relax\hbox{}
}
\fi\fi\fi}

\!chrverif\def\setupchronoevent#1{\!chrtraitingargvirgule[#1]{!chreventdefault}}

\!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 \moveright\!chrstopwidth\box\!chrflechebox\endgroup\bigskip}
