%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%                impression de hieroglyphes en LaTeX
%                Hieroglyphs Writing in LaTeX  
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%there are two ways for hieroglyphs writing there:
% both of them are based on the
%  " Inventaire des signes hieroglyphiques en vue de leur saisie
%                             informatique "
% Jan Buurman-Nicolas Grimal-Michael Hainsworth-Jochen Hallof-
% Dirk Van Der Plas
%
% Memoires de l'Academie des Inscriptions et Belles Lettres
%
% (the text is in french, english, and german)

% * the first way: Really hard one: make a list of the fonts 
% (with "tex testfonts"), remember the number of the characters
%
% Two signs on the same level are separated by a '-'
% a sign below another one is separated form it by a ':'
% grouping is done by { }
% 
%% Exemples de texte    
%\hieroglyphe{M/17-G/46-A/1-G/19-Y/3-Y/1:Z/2-M/17-{N/29-D/21}:Y/1}
%\hieroglyphe{{Q/3-X/1}:{N/1-N/1-N/1}}
%\hieroglyphe{{Q/3-X/1}:N/1}
%\hieroglyphe{W/26:N/35:V/31}
%\hieroglyphe{W/26:N/35:V/31-A/1-Y/3:Y/1-M/17-N/29:D/21:Y/1}

% An easier way: I am writing now a program to generate hieroglyphic
% texts. It will be an extension of the "manuel de codage" symbolism.

% Fonts definitions (quite a lot !)

% Useful symbols 
\newfont{\EgypS}{Egyp}

  \newfont{\GA}{A scaled \magstep 1}
  \newfont{\GAi}{A}
  \newfont{\GAii}{A scaled 833}
  \newfont{\GAiii}{A scaled 694}
  \newfont{\GAiiii}{A scaled 582}
  \newfont{\GB}{B scaled \magstep 1}
  \newfont{\GBi}{B}
  \newfont{\GBii}{B scaled 833}
  \newfont{\GBiii}{B scaled 694}
  \newfont{\GBiiii}{B scaled 582}
\newfont{\GC}{C scaled \magstep 1}
  \newfont{\GCi}{C}
  \newfont{\GCii}{C scaled 833}
  \newfont{\GCiii}{C scaled 694}
  \newfont{\GCiiii}{C scaled 582}
\newfont{\GD}{D scaled \magstep 1}
  \newfont{\GDi}{D}
  \newfont{\GDii}{D scaled 833}
  \newfont{\GDiii}{D scaled 694}
  \newfont{\GDiiii}{D scaled 582}
\newfont{\GE}{E scaled \magstep 1}
  \newfont{\GEi}{E}
  \newfont{\GEii}{E scaled 833}
  \newfont{\GEiii}{E scaled 694}
  \newfont{\GEiiii}{E scaled 582}
\newfont{\GF}{F scaled \magstep 1}
  \newfont{\GFi}{F}
  \newfont{\GFii}{F scaled 833}
  \newfont{\GFiii}{F scaled 694}
  \newfont{\GFiiii}{F scaled 582}
\newfont{\GG}{G scaled \magstep 1}
  \newfont{\GGi}{G}
  \newfont{\GGii}{G scaled 833}
  \newfont{\GGiii}{G scaled 694}
  \newfont{\GGiiii}{G scaled 582}
\newfont{\GH}{H scaled \magstep 1}
  \newfont{\GHi}{H}
  \newfont{\GHii}{H scaled 833}
  \newfont{\GHiii}{H scaled 694}
  \newfont{\GHiiii}{H scaled 582}
\newfont{\GI}{I scaled \magstep 1}
  \newfont{\GIi}{I}
  \newfont{\GIii}{I scaled 833}
  \newfont{\GIiii}{I scaled 694}
  \newfont{\GIiiii}{I scaled 582}
\newfont{\GK}{K scaled \magstep 1}
  \newfont{\GKi}{K}
  \newfont{\GKii}{K scaled 833}
  \newfont{\GKiii}{K scaled 694}
  \newfont{\GKiiii}{K scaled 582}
\newfont{\GL}{L scaled \magstep 1}
  \newfont{\GLi}{L}
  \newfont{\GLii}{L scaled 833}
  \newfont{\GLiii}{L scaled 694}
  \newfont{\GLiiii}{L scaled 582}
\newfont{\GM}{M scaled \magstep 1}
  \newfont{\GMi}{M}
  \newfont{\GMii}{M scaled 833}
  \newfont{\GMiii}{M scaled 694}
  \newfont{\GMiiii}{M scaled 582}
\newfont{\GN}{N scaled \magstep 1}
  \newfont{\GNi}{N}
  \newfont{\GNii}{N scaled 833}
  \newfont{\GNiii}{N scaled 694}
  \newfont{\GNiiii}{N scaled 582}
\newfont{\GO}{O scaled \magstep 1}
  \newfont{\GOi}{O}
  \newfont{\GOii}{O scaled 833}
  \newfont{\GOiii}{O scaled 694}
  \newfont{\GOiiii}{O scaled 582}
\newfont{\GP}{P scaled \magstep 1}
  \newfont{\GPi}{P}
  \newfont{\GPii}{P scaled 833}
  \newfont{\GPiii}{P scaled 694}
  \newfont{\GPiiii}{P scaled 582}
\newfont{\GQ}{Q scaled \magstep 1}
  \newfont{\GQi}{Q}
  \newfont{\GQii}{Q scaled 833}
  \newfont{\GQiii}{Q scaled 694}
  \newfont{\GQiiii}{Q scaled 582}
\newfont{\GR}{R scaled \magstep 1}
  \newfont{\GRi}{R}
  \newfont{\GRii}{R scaled 833}
  \newfont{\GRiii}{R scaled 694}
  \newfont{\GRiiii}{R scaled 582}
\newfont{\GS}{S scaled \magstep 1}
  \newfont{\GSi}{S}
  \newfont{\GSii}{S scaled 833}
  \newfont{\GSiii}{S scaled 694}
  \newfont{\GSiiii}{S scaled 582}
\newfont{\GT}{T scaled \magstep 1}
  \newfont{\GTi}{T}
  \newfont{\GTii}{T scaled 833}
  \newfont{\GTiii}{T scaled 694}
  \newfont{\GTiiii}{T scaled 582}
\newfont{\GU}{U scaled \magstep 1}
  \newfont{\GUi}{U}
  \newfont{\GUii}{U scaled 833}
  \newfont{\GUiii}{U scaled 694}
  \newfont{\GUiiii}{U scaled 582}
\newfont{\GV}{V scaled \magstep 1}
  \newfont{\GVi}{V}
  \newfont{\GVii}{V scaled 833}         
  \newfont{\GViii}{V scaled 694}
  \newfont{\GViiii}{V scaled 582}
\newfont{\GW}{W scaled \magstep 1}
  \newfont{\GWi}{W}
  \newfont{\GWii}{W scaled 833}
  \newfont{\GWiii}{W scaled 694}
  \newfont{\GWiiii}{W scaled 582}
\newfont{\GX}{X scaled \magstep 1}
  \newfont{\GXi}{X}
  \newfont{\GXii}{X scaled 833}
  \newfont{\GXiii}{X scaled 694}
  \newfont{\GXiiii}{X scaled 582}
\newfont{\GY}{Y scaled \magstep 1}
  \newfont{\GYi}{Y}
  \newfont{\GYii}{Y scaled 833}
  \newfont{\GYiii}{Y scaled 694}
  \newfont{\GYiiii}{Y scaled 582}
\newfont{\GZ}{Z scaled \magstep 1}
  \newfont{\GZi}{Z}
  \newfont{\GZii}{Z scaled 833}
  \newfont{\GZiii}{Z scaled 694}
  \newfont{\GZiiii}{Z scaled 582}
\newfont{\GAa}{Aa scaled \magstep 1}
  \newfont{\GAai}{Aa}
  \newfont{\GAaii}{Aa scaled 833}
  \newfont{\GAaiii}{Aa scaled 694}
  \newfont{\GAaiiii}{Aa scaled 582}

\def\Hta{} % possible values : {} i ii iii iiii

\newif\if@droitegauche
\@droitegauchefalse
\newif\if@xettexon
\@xettexonfalse

\def\leftright{\if@xettexon\endR\fi\beginL\@droitegauchefalse\@xettexontrue}
\def\rightleft{\if@xettexon\endL\fi\beginR\@droitegauchetrue\@xettexontrue}

% \Acv{size}part of font/number\relax => gives you a character
\def\Acv#1#2/#3\relax{%
\count0=#3%
\if@droitegauche%
\advance\count0 by 128\fi%
\hskip 0.2mm{\csname G#2#1\endcsname\char\count0}\hskip 0.2mm}


\def\Aca #1/#2/{\Acv{\Hta}#1/#2\relax}

\newdimen\Htm % maximum height of a quadra (we chosed the size
                    % of the independant pronoun(ink)
\newdimen\Htmi
\newdimen\Htmii
\newdimen\Htmiii
\newdimen\Htmiiii

\setbox0=\vbox{%
\offinterlineskip%
\def\Hta{iiii}%
\hbox{\Acv{\Hta}W/26\relax}%
\hbox{\Acv{\Hta}V/32\relax}%
\hbox{\Acv{\Hta}A/1\relax}}%

% if you want smaller quadra, uncomment the line below.
 \setbox0=\vbox{\hbox{\Acv{\Hta}G/1\relax}}

\Htm=\ht0
\advance\Htm by 0.025mm

\newcount\@Hauteur
\@Hauteur=0

\setbox0=\vbox{\hbox{\Acv{i}G/1\relax}}
\Htmi=\ht0
\setbox0=\vbox{\hbox{\Acv{ii}G/1\relax}}
\Htmii=\ht0
\setbox0=\vbox{\hbox{\Acv{iii}G/1\relax}}
\Htmiii=\ht0
\setbox0=\vbox{\hbox{\Acv{iiii}G/1\relax}}
\Htmiiii=\ht0

\newdimen\@Lower
\@Lower=1.5mm
% Now, the cartouche 

\newdimen\epaisseur
\epaisseur=0.4mm

\def\@debutcart{\if@droitegauche%
\hbox{\vbox to \ht0{\hbox{4}\hbox{\vrule width \epaisseur%
height \dimen0}\hbox{3}}}%
\else%
\hbox{\vbox to \ht0{\hbox{1}\hbox{\vrule width \epaisseur%
height \dimen0}\hbox{2}}}\fi}

\def\@milieucart{\copy0}

\def\@fincart{\if@droitegauche%
\setbox2=\hbox{\hbox{\vbox to \ht0{\hbox{1}\hbox to \wd2{%
\hfil\vrule width \epaisseur height \dimen0}\hbox{2}}}%
\kern-0.9mm\hbox{\vbox to\ht0{\vfil\hbox{5}\vfil}}\hspace{0.5mm}}%
\else%
\setbox2=\hbox{\vbox to \ht0{\hbox{4}\hbox to \wd2{%
\hfil\vrule width \epaisseur height \dimen0}\hbox{3}}%
\hbox{\vbox to\ht0{\vfil\hbox{5}\vfil}}}%
\fi%
\box2}


\def\@initcart#1{%
\offinterlineskip%
\def\strut{}%
\setbox0=\hbox{\vbox{\hrule height
\epaisseur\vskip0.2ex\hbox{\Centrer #1}%
\vskip0.2ex\hrule height \epaisseur}}%
\setbox2=\vbox{\EgypS\hbox{1}\hbox{2}}%
\ifdim\ht0<\ht2%
\setbox0=\hbox{\vbox to\ht2{%
\hrule height \epaisseur\vfill%
\hbox{\Centrer #1}%
\vfill\hrule height \epaisseur}}%
\fi
\EgypS
\dimen0=\ht0%
\advance\dimen0 by -\ht2%
\setbox4=\hbox\bgroup%
}

\def\@endcartouche{%
\egroup%
\dimen0=\@Lower\advance\dimen0 by 0.2ex%
\advance\dimen0 by \epaisseur%
\raise -\dimen0\box4}

\def\cartouche#1{{\@initcart{#1}% On garde le nom, car il n'y en a pas bcp
\@debutcart\@milieucart\@fincart
\@endcartouche}}

\def\debcartouche#1{{%
\@initcart{\raise -\@Lower\hbox{\vbox to \Htm{\ }}}%
\@debutcart\@endcartouche{\Centrer #1}}}

\def\milcartouche#1{{\@initcart{#1}%
\@milieucart\@endcartouche}}

\def\fincartouche#1{{\Centrer #1%
\@initcart{\raise -\@Lower\hbox{\vbox to \Htm{\ }}}%
\@fincart\@endcartouche}}



\def\Hesp{\phantom{\Acv{\Hta}A/1\relax}} % the phantom of
                                                     % a white space

\def\Hqrtesp{\phantom{\Acv{\Hta}X/1\relax}} % the fourth
                                                          % part of a quadra

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pure LaTeX system
%
% you can comment the lines below
%\input EgypUtil.sty
%\def\lignehA#1{\echange{-}{\relax\quadraA}{\Acv{\Hta}#1}}
%\def\ligneh#1{\echange{-}{\relax\quadraA}{\Acv{\Hta}#1}}
%\def\superposeA#1\relax{\hbox{\lignehA{#1}}}
%\def\superpose#1\relax{\vskip 0.1mm plus 1fil\hbox to \dimen0{\hskip 0em
%plus 0.25fil\ligneh{#1}\hskip 0em plus 0.25fil}}
%\def\quadraA#1\relax{\hfil{\setbox0=\vbox{%
%\echange{:}{\relax\superposeA}{\relax:#1\relax}%
%}\hbox{\box0}}}
%\def\quadra#1\relax{{\setbox0=\vbox{\offinterlineskip%
%\echange{:}{\relax\superposeA}{\relax:#1\relax}}\dimen0=\wd0%
%\ifdim\ht0>\Htm%
%\edef\Hta{\Hta i}%
%%\message{\Hta}%
%\quadra#1\relax%
%\else%
%\setbox0=\vbox to \Htm{\offinterlineskip%
%\echange{:}{\relax\vfil\superpose}{\relax\superpose#1\relax}}%
%\hbox{\box0}%
%\fi}}

%{
%\gdef\hieroglyphe#1{{%
%\dimen0=\Htm%
%\advance\dimen0 by 2mm%
%%\hbox\vbox%
%%\vskip 2mm%
%\setbox0=\hbox{%
%\echange{-}{\relax\quadra}{\relax-#1}}%
%\sloppy\unhbox0}}}

%%%%% End of comment-able lines

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For use with sesh

\def\MInEx{iiii} % smaller font size available
\def\negAROBspace{\hskip -0.5ex} % negative space
\def\Hhbt#1{\hbox{\H@Reduction{#1}}} % 
\def\HhbtI#1{\hbox{\H@Reduction{#1}}}

\def\Hrp{\nolinebreak[1]\hskip 0.025ex plus 0.5ex}% espace entre les signes
\def\Hitmts{\linebreak[3]\hskip 0.025ex plus 0.5ex}% espace entre les mots


% Horizontal box.
\def\H@Reduction#1{%  
{\ifx\Hta\MInEx%
#1\else
\setbox0=\hbox{#1}%
\ifdim\wd0>1.3\Htm%      Un quadra, c'est presque carre'
\edef\Hta{\Hta i}%
\advance\@Hauteur by 1%
\H@Reduction{#1}%
\else #1\fi\fi}}

\def\Himbt#1{%
\def\Hhbt##1{\vskip 0ex plus 1fil\hbox 
to \wd0{\hfil \H@Reduction{##1}\hfil}}%
\def\HhbtI##1{\hbox to \wd0{\hfil \H@Reduction{##1}\hfil}}%
\def\Hrpl{\hfill}%
\setbox0=\vbox to \Htm{\offinterlineskip #1}}


%% Boite contenant des hieroglyphes 
\def\Hbt#1{{%
\setbox0=\vbox{\offinterlineskip #1}%
\ifdim\ht0>\Htm%
\ifx\Hta\MInEx%
\Himbt{#1}%
\raise -\@Lower\hbox{\box0}\strut%
\else%
\edef\Hta{\Hta i}%
\advance\@Hauteur by 1%
%\message{\Hta}%
\Hbt{#1}%
\fi%
\else%
\Himbt{#1}%
\raise -\@Lower\hbox{\box0}\strut\fi}}

%% Une boite, a` l'inte'rieur, n'a pas de hauteur fixe 

\def\Hbti#1{{%
\def\Hhbt##1{\hbox{\H@Reduction{##1}}}%
\def\HhbtI##1{\hbox{\H@Reduction{##1}}}%
\ifcase \@Hauteur \or
\Htm\Htmi\or
\Htm\Htmii\or
\Htm\Htmiii\or
\Htm\Htmiiii\else
\message{Too small a sign!}%
\fi
\setbox0=\vbox{\offinterlineskip #1}%
\ifdim\ht0>\Htm
\ifx\Hta\MInEx
\Himbt{#1}\hbox{\box0}%
\else%
\edef\Hta{\Hta i}%
\message{dans boite interne \Hta}%
\Hbti{#1}%
\fi%
\else%
\Himbt{#1}\hbox{\box0}%
\fi}}

%hieroglyphes seuls (centre's ou non)

\def\HunhA#1{{%
\setbox0=\hbox{#1}%
\ifdim\ht0>0.75\Htm%
\raise -\@Lower\box0\strut
\else%
\raise -\@Lower\hbox{\vbox to \Htm{\vfil\box0\vfil}}\strut%
\fi}}

\def\HunhB#1{\raise -\@Lower\hbox{#1}\strut}

\def\Centrer{\def\Hunh{\HunhA}}
\def\SurLigne{\def\Hunh{\HunhB}}
\Centrer

%ligatures Dd et Dt :

\def\ligAROBDd{{\hbox{\vbox{\offinterlineskip%
\hbox{\Acv{\Hta}I/11\relax}%
\ifnum\@Hauteur<2%
\vskip -1ex\hbox{\Acv{\Hta ii}D/48\relax}%
\else
\ifnum\@Hauteur=2%
\vskip -1ex\hbox{\Acv{\Hta i}D/48\relax}%
\else
\vskip -1ex\hbox{\Acv{\Hta}D/48\relax}%
\fi\fi%
}}}}

\def\ligAROBDt{{\hbox{\vbox{\offinterlineskip%
\hbox{\Acv{\Hta}I/11\relax}%
\vskip -1ex\hbox{\Acv{\Hta}X/1\relax}%
}}}}

\def\ligAROBDra{\hbox{\vbox{\offinterlineskip%
\hbox{\Acv{\Hta}I/11\relax}%
\vskip -1.6ex\hbox{\hskip1mm\Acv{\Hta}N/5\relax}%
}}}


%%% A CORRIGER **** PATCH INFAME *****
\def\ligAROBD{\hbox{\vbox{\offinterlineskip%
\hbox{\Acv{\Hta}I/11\relax}%
\hbox{}
}}}

%%% Les nombres
\def\hierCC{\hbox{\Acv{\Hta}V/1\relax\Acv{\Hta}V/1\relax}}
% Hachures ?


\newbox\HachureBoxII
\setbox\HachureBoxII=\hbox{{\offinterlineskip%
\EgypS\vbox{\hbox{C}\hbox{C}}}}

\newbox\HachureBoxIII
\setbox\HachureBoxIII=\hbox{\EgypS CC}



\def\hachure#1{{\leavevmode\setbox0=\hbox{#1}%
\setbox2=\copy\HachureBoxII%
\setbox2=\hbox to 0em{% 
\raise -\@Lower\hbox to\wd0{\cleaders\box2\hfill}\hss}%
\setbox2=\hbox{\box2\box0}%
\box2}}

\def\hachuregaux{\hbox{\copy\HachureBoxII\copy\HachureBoxII}}
\def\hachureg{\raise -\@Lower\hachuregaux}
\def\hachurev{\raise -\@Lower\copy\HachureBoxII}
\def\hachureh{\raise -\@Lower\copy\HachureBoxIII}
\def\hachuret{\raise -\@Lower\hbox{\EgypS C}}

\def\hachurega#1{{\hbox{\hbox to 0ex{\hss\hachuregaux\hss}#1}}}

\def\hachureva#1{{\offinterlineskip\setbox0=\hbox{#1}%
\hbox to \wd0{%
\hbox to 0ex{\vbox to 0ex{\vss\copy\HachureBoxII}\hss}%
\box0%
}}}


\def\hachureha#1{{\offinterlineskip\setbox0=\hbox{#1}%
\hbox to \wd0{\vbox to \ht0{\box0%
\hbox to 0ex{\vbox to 0ex{\vss\copy\HachureBoxIII}\hss}%
}}}}

\def\hachureta#1{{\offinterlineskip\setbox0=\hbox{#1}%
\hbox to \wd0{\vbox to \ht0{\box0%
\hbox to 0ex{\vbox to 0ex{\vss\hbox{\EgypS C}}\hss}%
}}}}

\newif\if@displayhieroglyphes
\@displayhieroglyphesfalse

\newenvironment{hieroglyph}{%
\ifvmode\leavevmode\fi%
\bgroup
\if@displayhieroglyphes%
\setbox\strutbox=\hbox{\vrule height0.9\Htm depth 0.4\Htm
  width\z@}\bgroup%
\else%
\def\strut{}%
\EnPetit\bgroup
\fi%
}{\egroup\egroup}

\def\EnPetit#1{\bgroup\Htm\Htmi\def\Hta{i}#1\egroup}
 
\def\traittexte#1{$\stackrel{\mbox{\rm\tiny #1}}%
{\vrule width 0.05pt height 1ex}$}

\def\enrouge#1{{\setbox0=\hbox{#1}%
\dimen0=\ht0%
\advance\dimen0 by 7pt%
\raise -7pt\hbox{\vbox to \dimen0{\offinterlineskip\box0\vfil\hrule}}}}

\def\nouvLigne{\end{hieroglyph}\begin{hieroglyph}}
\def\nouvPage{\nouvLigne}

\def\EnGros{\@displayhieroglyphestrue}

