%
%
% S-Tables Macro
%
\message{S-Tables Macro v1.0, ACS, TAMU (RANHELP@VENUS.TAMU.EDU)}
%
% Help Text
%
\newhelp\stablestylehelp{You must choose a style between 0 and 3.}%
\newhelp\stablelinehelp{You should not use special hrules when stretching
a table.}%
\newhelp\stablesmultiplehelp{You have tried to place an S-Table inside another
S-Table.  I would recommend not going on.}%
%
% Line Thicknesses (Values)
%
\newdimen\stablesthinline
\stablesthinline=0.4pt
\newdimen\stablesthickline
\stablesthickline=1pt
%
% Border and Internal Line Thicknesses
%
\newif\ifstablesborderthin
\stablesborderthinfalse
\newif\ifstablesinternalthin
\stablesinternalthintrue
\newif\ifstablesomit
\newif\ifstablemode
\newif\ifstablesright
\stablesrightfalse
%
% Save Registers
%
\newdimen\stablesbaselineskip
\newdimen\stableslineskip
\newdimen\stableslineskiplimit
%
% Counters
%
\newcount\stablesmode
\newcount\stableslines
\newcount\stablestemp
\stablestemp=3
\newcount\stablescount
\stablescount=0
\newcount\stableslinet
\stableslinet=0
%
% Table Style Selection
%
% 0 - Centered
% 1 - Left Justified
% 2 - Right Justified
% 3 - Not Justified
%
\newcount\stablestyle
\stablestyle=0
%
% Element Buffering Definitions
%
\def\stablesleft{\quad\hfil}%
\def\stablesright{\hfil\quad}%
%
% Vertical Bar Activation
%
\catcode`\|=\active%
%
% Strut Control
%
\newcount\stablestrutsize
\newbox\stablestrutbox
\setbox\stablestrutbox=\hbox{\vrule height10pt depth5pt width0pt}
\def\stablestrut{\relax\ifmmode%
                         \copy\stablestrutbox%
                       \else%
                         \unhcopy\stablestrutbox%
                       \fi}%
%
% Misc. Internal Stuff
%
\newdimen\stablesborderwidth
\newdimen\stablesinternalwidth
\newdimen\stablesdummy
\newcount\stablesdummyc
\newif\ifstablesin
\stablesinfalse
%
% Table Macros
%
\def\begintable{\stablestart%
  \stablemodetrue%
  \stablesadj%
  \halign%
  \stablesdef}%
\def\begintableto#1{\stablestart%
  \stablemodefalse%
  \stablesadj%
  \halign to #1%
  \stablesdef}%
\def\begintablesp#1{\stablestart%
  \stablemodefalse%
  \stablesadj%
  \halign spread #1%
  \stablesdef}%
\def\stablesadj{%
  \ifcase\stablestyle%
    \hbox to \hsize\bgroup\hss\vbox\bgroup%
  \or%
    \hbox to \hsize\bgroup\vbox\bgroup%
  \or%
    \hbox to \hsize\bgroup\hss\vbox\bgroup%
  \or%
    \hbox\bgroup\vbox\bgroup%
  \else%
    \errhelp=\stablestylehelp%
    \errmessage{Invalid style selected, using default}%
    \hbox to \hsize\bgroup\hss\vbox\bgroup%
  \fi}%
\def\stablesend{\egroup%
  \ifcase\stablestyle%
    \hss\egroup%
  \or%
    \hss\egroup%
  \or%
    \egroup%
  \or%
    \egroup%
  \else%
    \hss\egroup%
  \fi}%
\def\stablestart{%
  \ifstablesin%
    \errhelp=\stablesmultiplehelp%
    \errmessage{An S-Table cannot be placed within an S-Table!}%
  \fi
  \global\stablesintrue%
  \global\advance\stablescount by 1%
  \message{<S-Tables Generating Table \number\stablescount}%
  \begingroup%
  \stablestrutsize=\ht\stablestrutbox%
  \advance\stablestrutsize by \dp\stablestrutbox%
  \ifstablesborderthin%
    \stablesborderwidth=\stablesthinline%
  \else%
    \stablesborderwidth=\stablesthickline%
  \fi%
  \ifstablesinternalthin%
    \stablesinternalwidth=\stablesthinline%
  \else%
    \stablesinternalwidth=\stablesthickline%
  \fi%
  \tabskip=0pt%
  \stablesbaselineskip=\baselineskip%
  \stableslineskip=\lineskip%
  \stableslineskiplimit=\lineskiplimit%
  \offinterlineskip%
  \def\borderrule{\vrule width \stablesborderwidth}%
  \def\internalrule{\vrule width \stablesinternalwidth}%
%
  \def\thinline{\noalign{\hrule height \stablesthinline}}%
  \def\thickline{\noalign{\hrule height \stablesthickline}}%
  \def\trule{\omit\leaders\hrule height \stablesthinline\hfill}%
  \def\ttrule{\omit\leaders\hrule height \stablesthickline\hfill}%
  \def\tttrule##1{\omit\leaders\hrule height ##1\hfill}%
  \def\stablesel{&\omit\global\stablesmode=0%
    \global\advance\stableslines by 1\borderrule\hfil\cr}%
  \def\el{\stablesel&}%
  \def\elt{\stablesel\thinline&}%
  \def\eltt{\stablesel\thickline&}%
  \def\elttt##1{\stablesel\noalign{\hrule height ##1}&}%
  \def\elspec{&\omit\hfil\borderrule\cr\omit\borderrule&%
              \ifstablemode%
              \else%
                \errhelp=\stablelinehelp%
                \errmessage{Special ruling will not display properly}%
              \fi}%
%
  \def\stmultispan##1{\mscount=##1 \loop\ifnum\mscount>3 \stspan\repeat}%
  \def\stspan{\span\omit \advance\mscount by -1}%
%
  \def\multicolumn##1{\omit\multiply\stablestemp by ##1%
     \stmultispan{\stablestemp}%
     \advance\stablesmode by ##1%
     \advance\stablesmode by -1%
     \stablestemp=3}%
  \def\multirow##1{\stablesdummyc=##1\parindent=0pt\setbox0\hbox\bgroup%
    \aftergroup\emultirow\let\temp=}
  \def\emultirow{\setbox1\vbox to\stablesdummyc\stablestrutsize%
    {\hsize\wd0\vfil\box0\vfil}%
    \ht1=\ht\stablestrutbox%
    \dp1=\dp\stablestrutbox%
    \box1}%
%
%  \def\stvcen##1{\vtop{\vfill\hbox{##1}\vfill}}% Currently does not work!
  \def\stpar##1{\vtop\bgroup\hsize ##1%
     \baselineskip=\stablesbaselineskip%
     \lineskip=\stableslineskip%
     \lineskiplimit=\stableslineskiplimit\bgroup\aftergroup\estpar\let\temp=}%
  \def\estpar{\vskip 6pt\egroup}%
  \def\stparrow##1##2{\stablesdummy=##2%
     \setbox0=\vtop to ##1\stablestrutsize\bgroup%
     \hsize\stablesdummy%
     \baselineskip=\stablesbaselineskip%
     \lineskip=\stableslineskip%
     \lineskiplimit=\stableslineskiplimit%
     \bgroup\vfil\aftergroup\estparrow%
     \let\temp=}%
  \def\estparrow{\vfil\egroup%
     \ht0=\ht\stablestrutbox%
     \dp0=\dp\stablestrutbox%
     \wd0=\stablesdummy%
     \box0}%
%
  \def|{\global\advance\stablesmode by 1&&&}%
  \def\|{\global\advance\stablesmode by 1&\omit\vrule width 0pt%
         \hfil&&}%
  \def\vt{\global\advance\stablesmode by 1&\omit\vrule width \stablesthinline%
          \hfil&&}%
  \def\vtt{\global\advance\stablesmode by 1&\omit\vrule width \stablesthickline%
          \hfil&&}%
  \def\vttt##1{\global\advance\stablesmode by 1&\omit\vrule width ##1%
          \hfil&&}%
  \def\vtr{\global\advance\stablesmode by 1&\omit\hfil\vrule width%
           \stablesthinline&&}%
  \def\vttr{\global\advance\stablesmode by 1&\omit\hfil\vrule width%
            \stablesthickline&&}%
  \def\vtttr##1{\global\advance\stablesmode by 1&\omit\hfil\vrule width ##1&&}%
  \stableslines=0%
  \stablesomitfalse}
%
\def\stablesdef{\bgroup\stablestrut\borderrule##\tabskip=0pt plus 1fil%
  &\stablesleft##\stablesright%
  &##\ifstablesright\hfill\fi\internalrule\ifstablesright\else\hfill\fi%
  \tabskip 0pt&&##\hfil\tabskip=0pt plus 1fil%
  &\stablesleft##\stablesright%
  &##\ifstablesright\hfill\fi\internalrule\ifstablesright\else\hfill\fi%
  \tabskip=0pt\cr%
  \ifstablesborderthin%
    \thinline%
  \else%
    \thickline%
  \fi&%
}%
\def\endtable{\advance\stableslines by 1\advance\stablesmode by 1%
   \message{- Rows: \number\stableslines, Columns:  \number\stablesmode>}%
   \stablesel%
   \ifstablesborderthin%
     \thinline%
   \else%
     \thickline%
   \fi%
   \egroup\stablesend%
\endgroup%
\global\stablesinfalse}
%
% end of STABLES.TEX
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

