% Macro for drawing tableaux, version 2.
% First version by Mark Haiman
% Modified by Anders Buch
%
% Examples:
%
% $\tableau{20}{1&2&3\\4&5\\6,7}$
%
% $\tableau{12}{
%        &        &         & [HLa]3  & [HRa]4  \\
% [LHa]1 & [Ta]2  &  [RHa]3 & [LlTt]4 & [TtRr]5 \\
%        & [LBa]3 & [LlTt]4 & []5     & [RrBb]6 \\
%        &        & [LlBb]5 & [RrBb]6 & [Rrb]7  \\
%        &        &         & [HLa]7  & [Ra]8   \\
%        &        &         &         & [VBa]9
% }$
%
% $\tableau{15}{[a]&&[at]&&[ab]&&[al]&&[ar]&&[ah]&&[av]\\\\
% &[aTT]&&[aBB]&&[aLL]&&[aRR]&&[aHH]&&[aVV]\\\\
% &&[vt]&&[vb]&&[v]&&[hl]&&[hr]}$


\newlength{\tabthinline}
\setlength{\tabthinline}{.4pt}
\newsavebox{\tabcell}
\newcount{\tabcellsz}
\newif\iftabredrawcell
\newcount{\tabtopwidth}
\newcount{\tabbotwidth}
\newcount{\tableftwidth}
\newcount{\tabrightwidth}

\def\tabdrawcell{%
\global\sbox{\tabcell}{\begin{picture}(\tabcellsz,\tabcellsz)
\ifnum\tabtopwidth>0
\linethickness{\tabtopwidth\tabthinline}
\put(0,\tabcellsz){\line(1,0){\tabcellsz}}
\fi
\ifnum\tabbotwidth>0
\linethickness{\tabbotwidth\tabthinline}
\put(0,0){\line(1,0){\tabcellsz}}
\fi
\ifnum\tableftwidth>0
\linethickness{\tableftwidth\tabthinline}
\put(0,0){\line(0,1){\tabcellsz}}
\fi
\ifnum\tabrightwidth>0
\linethickness{\tabrightwidth\tabthinline}
\put(\tabcellsz,0){\line(0,1){\tabcellsz}}
\fi
\end{picture}}%
\global\tabredrawcellfalse
}

\def\tabdocfy#1\tabcellend{%
\iftabredrawcell\tabdrawcell\fi
\hbox to 0pt{\usebox{\tabcell}\hss}%
\vbox to \tabcellsz\unitlength{\vss
\hbox to \tabcellsz\unitlength{\hss$#1$\hss}\vss}}

\def\tabgetopt#1{%
\ifx ]#1\let\next=\tabdocfy\else
\ifx #1\tabcellend\let\next=\relax
\else\let\next=\tabgetopt
\ifx t#1\advance\tabtopwidth by 1\fi
\ifx b#1\advance\tabbotwidth by 1\fi
\ifx l#1\advance\tableftwidth by 1\fi
\ifx r#1\advance\tabrightwidth by 1\fi
\ifx h#1\advance\tabtopwidth by 1\advance\tabbotwidth by 1\fi
\ifx v#1\advance\tableftwidth by 1\advance\tabrightwidth by 1\fi
\ifx a#1\advance\tabtopwidth by 1\advance\tabbotwidth by 1%
\advance\tableftwidth by 1\advance\tabrightwidth by 1\fi
\ifx T#1\advance\tabtopwidth by 2\fi
\ifx B#1\advance\tabbotwidth by 2\fi
\ifx L#1\advance\tableftwidth by 2\fi
\ifx R#1\advance\tabrightwidth by 2\fi
\ifx H#1\advance\tabtopwidth by 2\advance\tabbotwidth by 2\fi
\ifx V#1\advance\tableftwidth by 2\advance\tabrightwidth by 2\fi
\ifx A#1\advance\tabtopwidth by 2\advance\tabbotwidth by 2%
\advance\tableftwidth by 2\advance\tabrightwidth by 2\fi
\fi\fi\next}

\def\tabcfy#1{%
\ifx[#1%
\tabtopwidth=0\tabbotwidth=0\tableftwidth=0\tabrightwidth=0%
\tabredrawcelltrue
\let\run=\tabgetopt
\else\let\run=\tabdocfy
\fi\run#1}

\def\tabcellify#1{%
\def\thearg{#1}\def\nothing{}\ifx\thearg\nothing
\vbox to \tabcellsz\unitlength{\hbox to \tabcellsz\unitlength{\hss}\vss}\else
\tabcfy#1\tabcellend\fi}

\newcommand{\tableau}[2]{
\tabcellsz=#1
\tabtopwidth=1
\tabbotwidth=1
\tableftwidth=1
\tabrightwidth=1
\tabredrawcelltrue
\vcenter{\vbox{\let\\\cr
\baselineskip -16000pt \lineskiplimit 16000pt \lineskip 0pt
\ialign{&\tabcellify{##}\cr#2\crcr}}}}

% end
