%%%%%%%%%%%%%%%%%%% Young Tableaux %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                   %%
%%    Macros      \Young     and    \YoungTab                        %%
%%       for drawing arbitrary Young Tableaux   by T.Kugo Aug.5,1998 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%  Usage:  \Young[HEIGHT]{LIST}  e.g.,\Young[-1]{543}         
%%                                                                 
%%    HEIGHT: vertical position in unit of single box size (6.5pt) 
%%            e.g., [-0.5] lowers the Tableau by 0.5 box unit from
%%            the baseline. 
%%            If [HEIGHT] is omitted, it is set equal to 0 so that the
%%            bottom boxes are put just on the baseline.
%%    LIST: numbers of boxes in each row, from the top row to the bottom row.
%%              e.g. {LIST}={532} means Tableaux with   
%%                             5 boxes  BBBBB    (B denotes a box)
%%                             3 boxes  BBB
%%                             2 boxes  BB ______baseline when HEIGHT=0
%% If you write two \Young successively, the Tableauxs connect smoothly.
%%   e.g., \Young[-1]{543}\Young[0]{11}
%%
%% You can change some parameters by putting commands like
%%     \def\YGbox{6.5}     : unit box size in unit [pt]
%%     \def\YGrule{0.4}    : line thickness in unit [pt]
%% These are actually the default values for them.
%%-------------------------------------------------------------------
%% You can also use \YoungTab
%%
%%  Usage:     \YoungTab[HEIGHT][SIZE]{LIST}
%%
%%   e.g., \YoungTab[-1]{ {i_1,i_2,i_3} {j_1,j_2} k }
%%         gives    
%%                      BBB                      i_1 i_2 i_3  
%%            Tableaux  BB       with indices    j_i j_2
%%                      B                         k
%%                                     put in each box
%%  [SIZE]: font size of the indices. If omitted, [SIZE]=[\normalsize]
%%      e.g., \YoungTab[-1][\small]{ {i,j,k} {l,m} }
%%  The empty boxes are allowed:
%%   e.g., \YoungTab{ { , , } { } { } }
%%         gives               ^   ^--- put at least one space
%%                      BBB
%%            Tableaux  B       with no indices put
%%                      B                       
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\YGrule{0.4}   % line thickness in unit of pt
\def\YGbox{6.5}    % box size in unit of pt
% draw symmetric #2 boxes at the height #1 
%   with boxsize=#3 and line thickness=#4
\def\SymBoxes#1#2#3#4{\newdimen\un@t \un@t#3%
\raisebox{#1}{\rule{#2\un@t}{#4}\hskip-#2\un@t% lower horizontal
\@tempdimb\un@t \advance\@tempdimb by-#4\@tempcntb#2\relax%
\@whilenum{\@tempcntb>0}\do{%                         % #2 vertical lines
\rule{#4}{\un@t}\hskip\@tempdimb \advance\@tempcntb by\m@ne}%
\hskip-#2\un@t \rule[\un@t]{#2\un@t}{#4}%
\rule[\un@t]{#4}{#4}\hskip-#4%             % upper horizontal line
\rule{#4}{\un@t}}\hskip-#4}                % rightest vertical line
% \Young
\def\Young{\@ifnextchar[{\@Young}{\@Young[0]}}
\def\@Young[#1]#2{\newdimen\YG@unit \YG@unit\YGbox pt%
\newdimen\h@ight \h@ight#1\YG@unit \@tempcnta-1\relax
\@tfor\c@ount:=#2\do{\advance\@tempcnta by\@ne}% count the number of rows
\@tempdima\@tempcnta\YG@unit%
\advance\h@ight by\@tempdima\relax     % compute the height of the top row
\@tfor\c@ount:=#2\do{\SymBoxes{\h@ight}{\c@ount}{\YG@unit}{\YGrule pt}%
\@tempdima-\c@ount\YG@unit \hskip\@tempdima%
\advance \h@ight by -\YG@unit}         % Draw the Tableaux
\@tempdima\YG@unit \multiply\@tempdima by\@car#2\@nil %
\hskip\@tempdima}                      % hskip by the length of the top row
% \YoungTab
\def\YoungTab{\@ifnextchar[{\@YoungIdx}{\@YoungIdx[0]}}
\def\@YoungIdx[#1]{\@ifnextchar[{\@iYoungIdx[#1]}{\@iYoungIdx[#1][\@empty]}}
\def\@iYoungIdx[#1][#2]#3{%
\newdimen\YG@unit \YG@unit\YGbox pt\newdimen\YG@rule \YG@rule \YGrule pt
\newcount\c@ount \c@ount\z@ \newdimen\skip@wd \unitlength\@ne pt
\newdimen\h@ight \h@ight#1\YG@unit \@tempcnta\m@ne\relax
\@tfor\d@um:=#3\do{\advance\@tempcnta by\@ne}% count the number of rows
\@tempdima\@tempcnta\YG@unit%
\advance\h@ight by\@tempdima\relax%  % compute the height of the top row
\@tfor\@idxlist:=#3\do{%             % routine to draw the indexed Tableaux
\@tempcnta\z@\hskip.5\YG@rule\relax 
\@for\@idx:=\@idxlist\do{%           % place the indices of the row first
\raisebox{\h@ight}{\makebox(\YGbox,\YGbox){#2$\@idx$}}
\advance\@tempcnta by\@ne}\hskip-.5\YG@rule% 
\@tempdima-\@tempcnta\YG@unit \hskip\@tempdima%
\ifnum\c@ount=\z@ \skip@wd-\@tempdima\fi \relax% record the top row width
\SymBoxes{\h@ight}{\@tempcnta}{\YG@unit}{\YG@rule}%
%                                         %(over)draw symmetric boxes next
\hskip\@tempdima \advance\h@ight by -\YG@unit
\advance\c@ount by\@ne}%             % end of the routine
\hskip\skip@wd}                      % hskip by the length of the top row
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
