% bold math macros: from http://www.math.fsu.edu/~smith/TeX/boldmath.html
\font\fivebf=cmbx10 scaled 500    % five-point bold
\font\sevenbf=cmbx10 scaled 700   % seven-point bold
\font\tenbf=cmbx10                % ten-point bold
\font\fivemb=cmmib10 scaled 500   % five-point math bold
\font\sevenmb=cmmib10 scaled 700  % seven-point math bold
\font\tenmb=cmmib10               % ten-point math bold
\def\boldmath{\textfont0=\tenbf           \scriptfont0=\sevenbf 
              \scriptscriptfont0=\fivebf  \textfont1=\tenmb
              \scriptfont1=\sevenmb       \scriptscriptfont1=\fivemb}

\newdimen\boxwidth\boxwidth1.5cm
\newdimen\littleboxwidth\littleboxwidth.5cm
\newdimen\marginwidth\marginwidth=.75cm

\def\red{\pdfliteral{1 0 0 rg 1 0 0 RG}}
\def\reset{\pdfliteral{0 0 0 rg 0 0 0 RG}}

\newskip\headerskip\headerskip.1cm
\newskip\optspace\optspace0cm

\def\littlebox#1{%
	\hbox{\vtop{%
		\hbox to \boxwidth{\hfil\vrule\hbox to \littleboxwidth{\hfil\strut$#1\,$}}%
		\hbox to \boxwidth{%
			\dimen0=\boxwidth%
			\advance\dimen0 by -\littleboxwidth\advance\dimen0 by -.4pt\advance\littleboxwidth by .4pt%
			\hskip\dimen0\leaders\hrule\hskip\littleboxwidth%
		}%
	}}%
}
\def\blackbox#1#2{\vbox{\littlebox{#2}\vskip\optspace\hbox to \boxwidth{$\,\boldmath#1$\strut\hfil}}}
\newdimen\boxheight
{
	\setbox0\vbox{\offinterlineskip\hbox{\blackbox{20}{14}}}
	\global\boxheight=\ht0
}

\def\redbox#1#2{\vbox{\littlebox{#2}\vskip\optspace\hbox to \boxwidth{\red\hfil$#1\,$\reset\strut}}}
\def\nobox#1{\vbox to \boxheight{\vfill\hbox to \boxwidth{$\strut\;\boldmath#1$\hfil}}}
\def\leftbox#1{\vbox to \boxheight{\vfil\hbox to \marginwidth{\hfil $#1\;\;$}\vfil}}
\def\rightbox#1{\vbox to \boxheight{\vss\hbox to \marginwidth{$\;\;#1$\hss}\vss}}
\def\headerbox#1{\hbox to \boxwidth{\hfil $#1\strut$\hfil}}

\newdimen\rulelength
\rulelength=5\boxwidth
\advance\rulelength by 2.4pt
\def\smartrule{\hbox{\hskip\marginwidth\leaders\hrule\hskip\rulelength}}

\newdimen\sixrulelength
\sixrulelength=6\boxwidth
\advance\sixrulelength by 2.8pt
\def\sixsmartrule{\hbox{\hskip\marginwidth\leaders\hrule\hskip\sixrulelength}}

\def\tableauheaderhelper#1,#2.{\edef\test{#2}\headerbox{#1}\if\test!\else\tableauheaderhelper#2.\fi}
\def\tableauheader#1{\hbox{\hskip\marginwidth\tableauheaderhelper#1,!.}\smartrule}

\def\sixtableauheaderhelper#1,#2.{\edef\test{#2}\headerbox{#1}\if\test!\else\sixtableauheaderhelper#2.\fi}
\def\sixtableauheader#1{\hbox{\hskip\marginwidth\sixtableauheaderhelper#1,!.}\sixsmartrule}

\def\tableaufooterhelper#1,#2.{\edef\test{#2}\headerbox{#1}\if\test!\else\tableaufooterhelper#2.\fi}
\def\tableaufooter#1{\hbox{\hskip\marginwidth\tableaufooterhelper#1,!.}}

\def\parselittle #1;#2;#3.{\ifx#1l\let\boxybox=\blackbox\else\let\boxybox=\redbox\fi\def\lone{#2}\def\ltwo{#3}}
\def\tableaurowhelper#1 #2.{\edef\test{#2}\vrule\parselittle#1.\boxybox{\lone}{\ltwo}\if\test!\else\tableaurowhelper#2.\fi}
\def\tableaurow left=#1 right=#2 rest=#3.{\hbox{\leftbox{#1}\tableaurowhelper #3 !.\vrule\rightbox{#2}}\smartrule}

\def\tableaublankrowhelper#1,#2.{\edef\test{#2}\vrule\nobox{#1}\if\test!\else\tableaublankrowhelper#2.\fi}
\def\tableaublankrow left=#1 right=#2 rest=#3.{\hbox{\leftbox{#1}\tableaublankrowhelper#3,!.\vrule\rightbox{#2}}\smartrule}

\def\sixtableaublankrowhelper#1,#2.{\edef\test{#2}\vrule\nobox{#1}\if\test!\else\sixtableaublankrowhelper#2.\fi}
\def\sixtableaublankrow left=#1 right=#2 rest=#3.{\hbox{\leftbox{#1}\sixtableaublankrowhelper#3,!.\vrule\rightbox{#2}}\sixsmartrule}

\def\begintableau{\vbox\bgroup\offinterlineskip}
\def\endtableau{\egroup}