[comp.text] TABLES macro for TeX and LaTeX

akk2@ur-tut (Atul Kacker) (06/24/88)

The following is a shar file that contains the TABLES macro.
TeX users should use them with a \input tables somewhere
before they first use them and LaTeX users should have
\documentstyle[tables]{article} for example.
To extract the files, delete everything until the #! bin/sh line
and then type sh <filename> on the resulting file.

-rw-rw----  1 akk2        11250 Jun 22 16:30 tabledoc.tex
-rw-r--r--  1 akk2        20758 Jun 24 12:22 tables.sty
-rw-rw----  1 akk2        20461 Jun 22 16:30 tables.tex


#!/bin/sh
# to extract, remove the header and type "sh filename"
if `test ! -s ./tabledoc.tex`
then
echo "writting ./tabledoc.tex"
cat > ./tabledoc.tex << '\Rogue\Monster\'
\documentstyle[tables]{article}
% Note : This is not the original document TABLEDOC.TEX.  It has been 
%        re-typed using a hardcopy of the original by Atul Kacker
%        at the University of Rochester.
\def\bs{\char'134}
\def\vbar{\char'174}
\def\and{\char'046}
\def\tc#1{\hbox{\tt \bs #1}}
\def\ctr#1{\quad #1 \hfil}
\font\sl=cmsl10
\setlength{\textwidth}{433pt}
\setlength{\oddsidemargin}{0pt}
\setlength{\marginparwidth}{72pt}
\setlength{\topmargin}{0pt}
\setlength{\textheight}{555pt}
%
\begin{document}
\centerline{\framebox{\large Making Tables with Macros}}
\vbox{\vskip 0.5in}
\centerline{Ray F. Cowan}
\centerline{22 February 1985}
\vbox{\vskip 0.5in}
Tables have traditionally been difficult to make using \TeX\ -- especially
ruled tables.  The file {\tt \hbox{TABLES.TEX}} contains macros designed to
prepare both ruled and unruled tables with considerably less effort.  Note that
\hbox{\tt TABLES.TEX} can be used with any macro set; it does not depend on
prior loading of \hbox{\tt PHYZZX} or any other macro set, for example. One of
the main advantages of this macro set is that you no longer need to design a
preamble for the table; the macros will scan your table entries and construct a
suitable preamble for you.  To access the macros, say \hbox{\tt `\bs input
TABLES'} in your \TeX\ file, somewhere before you first use them.  The macros
available are listed in Table~\ref{tab:one} and Table~\ref{tab:two}.

\vbox{\vskip 0.5in}
\begin{table}[h]
\begintable
{\sl Macro name} | {\sl Description} \cr
\tc{begintable} | \para{Indicates the start of a new table} \cr
\tc{endtable}   | \para{Ends the current table.  Must be used in
                        the place of the last \tc{cr}.}\cr 
\tc{cr}         | \para{Ends the current row, and starts the next 
                        one.  The completed row will be separated 
                        from the next with a thin horizontal rule.}\cr 
\tc{crthick}    | \para{Similar to \tc{cr}, but the rows will be 
                         separated with a thick horizontal rule.} \cr 
\tc{crnorule} or \tc{nr}
                | \para{Similar to \tc{cr}, but the rows will not be 
                        separated by any rule.}\cr 
{\tt \hbox{\vbar}} (vertical bar) or \tc{vb} 
                | \para{Separates one column from the next, and 
                        puts a vertical rule between them.} \cr 
{\tt \hbox{\and}} or \tc{novb} 
                | \para{Same as {\tt \hbox{\vbar}}, but does not 
                        put in the vertical rule between the columns.} \cr
{\tt \hbox{\vbar}} 
                | \para{Same as {\tt \hbox{\vbar}}, but puts in a 
                        thick vertical rule.} 
\endtable
\caption{Description of simple table macros}\label{tab:one}
\end{table}
\clearpage
\begin{table}[h]
\begintable
\tc{thicksize}={\em dimen}
                | \para{This dimension specifies the thickness of the thick 
                        rules in the table.  The default size is 1.5 
                        points.} \cr
\tc{thinsize}={\em dimen}
                | \para{This dimension specifies the thickness of thin rules
                        in the table.  The default size is 0.8 points.} \cr
\tc{tablewidth}={\em dimen}
                | \para{Specifies how wide to make the next table.  If not
                        specified, the table is made to its natural width.  
                        This value is reset following the construction of
                        each table.} \cr
\tc{multispan}{\tt \{}{\em n}{\tt \}}
                | \para{Makes the next entry span the next {\em n} columns,
                        where {\em n} is an integer, {\em n} $>$ 0.  See other
                        notes on \tc{multispan} below.} \cr
\tc{omit}       | \para{This \TeX\ primitive causes the normal template for
                        its entry to be omitted, allowing the user to do
                        something else with this entry.} \cr
\tc{para}{\tt \{}{\em paragraph text}{\tt \}}
                | \para{Turns an entry into a neat little paragraph like this 
                        one.  The width of the paragraph is determined by the
                        dimension \tc{parasize}.  The default is 4 inches.} \cr
\tc{parasize}={\em dimen}
                | \para{Sets the width of paragraphs produced with the \tc{para}
                        macro.} \cr
\tc{ctr}{\tt \{\#\}} 
                | \para{Used in the standard template, this macro centers 
                        its argument in the column.  The user can redefine it 
                        for special effects.  The default definition is}
                        \crnorule
                | \qquad\tc{def}\tc{ctr}{\tt \#1\{}\tc{hfil}{\tt \bs\ \#1\bs\ }\tc{hfil}{\tt \}}\cr
\tc{vctr}{\tt \{\#\}}
                | \para{Centers an entry vertically.  The vertical center of the
                        entry is placed on the baseline of the row containing
                        it.  The intended use is to center an entry between two
                        rows.} \cr
\tc{centeredtables}
                | \para{Turns table centering on.  Each table will be centered 
                        left-to-right on the page.  This is the default.} \cr
\tc{noncenteredtables}
                | \para{Turns table centering off. Each table is returned as an
                        \tc{hbox}, and it is up to the user to place it as 
                        desired.} \cr
\tc{tableinfotrue}
                | \para{Turns on the diagnostic message telling you how many
                        rows and columns were found in the table.  This is the
                        default.} \cr
\tc{tableinfofalse}
                | \para{Turns off the diagnostic messages concerning rows and 
                        columns.}
\endtable
\caption{Description of extended table macros}\label{tab:two}
\end{table}
\clearpage
The general idea is that you start your table with the command \tc{begintable},
type your entries in one row at a time, then finish with the command
\tc{endtable}.  To specify a row, enter the individual entries into your \TeX\
file, separating each column entry with a {\tt \hbox{\vbar}}, an {\tt
\hbox{\and}}, or a {\tt \hbox{\bs\vbar}}.  A {\tt \hbox{\vbar}} will separate
the adjoining columns with a thin vertical rule, an {\tt \hbox{\and}} will
leave out the vertical rule, and a {\tt \hbox{\bs\vbar}} will separate the
columns with a thick vertical rule.  To end one row and start another, use
either a \tc{cr}, a \tc{crnorule}, or a \tc{crthick}.  A \tc{cr} separates the
rows with a thin horizontal rule; a \tc{crnorule} leaves out the horizontal
rule, while \tc{crthick} inserts a thick horizontal rule.  Then end the last
row with an \tc{endtable}. 

Each row of the table must contain the same number of columns, otherwise 
unpredictable things will happen.  Again the {\em last row} must {\em not} 
end with \tc{cr...}, but {\em must} end with an \tc{endtable}.  If you put a 
\tc{cr} and an \tc{endtable} both on the last row, you won't like what 
happens.

Each entry will be centered in it's column (unless you use \tc{omit}, a 
\TeX\ primitive, or \tc{multispan}.  See notes below).  The table will be 
centered in a \tc{hbox} of width \tc{hsize}, unless you have turned table 
centering off (see the commands \tc{centeredtables} and 
\tc{noncenteredtables}).

Each time a new table is encountered, a message similar to {\tt `[Nrows=xx,
Ncols=yy]'} is printed on your terminal, where {\tt xx} is the number of rows
and {\tt yy} the number of columns discovered in your table.  If you think they
are incorrect, you may have left out some {\tt \hbox{\vbar}}'s or {\tt
\hbox{\and}}'s or \tc{cr}'s.  This diagnostic feature can be disabled by saying
\tc{tableinfofalse} (and restarted by saying \tc{tableinfotrue}).

\vbox{\vskip 0.3truein}
{\em An example}

A simple 3-row, 2-column table with a header spanning two columns could be 
specified as (see notes 3 and 4 below on the use of \tc{multispan}):
\begin{verbatim}
       \begintable
       \multispan{2}\tstrut\hfil The Top Line\hfil\crthick
       Entry 1 | Entry 2 \cr
       Entry 3 | Entry 4 \endtable
\end{verbatim}
These commands produce Table~\ref{tab:three}.
\begin{table}[h]
       \begintable
		\multispan{2}\tstrut\hfill The Top Line\hfill\crthick
		Entry 1 | Entry 2 \cr
		Entry 3 | Entry 4 \endtable
\caption{A sample table}\label{tab:three}
\end{table}
\clearpage

\vbox{\vskip 0.3truein}
{\em An example of non-centered tables}

Two or more tables can be placed side-by-side by using the
\tc{noncenteredtables} command.  Consider the two tables here
(Table~\ref{tab:four}): 

\begin{table}[h]
       \noncenteredtables
       \tableline{
       \begintable
       Item ABC | Item DEF \cr
       Item GHI | Item JKL \endtable
       \hfil
       \begintable
       Data 111 | Data 222 \cr
       Data 333 | Data 444 \cr
       Data 555 | Data 666 \endtable
       }
\caption{Two non-centered tables aligned side-by-side}\label{tab:four}
\end{table}

These were produced by saying
\begin{verbatim}
       \noncenteredtables
       \line{
       \begintable
       Item ABC | Item DEF \cr
       Item GHI | Item JKL \endtable
       \hfil
       \begintable
       Data 111 | Data 222 \cr
       Data 333 | Data 444 \cr
       Data 555 | Data 666 \endtable
       }
\end{verbatim}
Notice that tables of unequal height are aligned at the bottom.

\vbox{\vskip 0.5truein}
{\large Usage notes:}

\begin{enumerate}
\item[1.] Vertical spacing is done with a strut, called \tc{tstrut}, which 
is initially defined as 3.1ex high and 1.2ex deep.  If you don't like the 
way it looks, you can redefine \tc{tstrut} to your own liking:
\begin{verbatim}
       \def\tstrut{\vrule height hh depth dd width 0pt}
\end{verbatim}
where you specify your desired height {\tt hh} and depth {\tt dd}.
\item[2.] You can control the thickness of the thin and thick rules through
the use of \tc{thicksize} and \tc{thinsize}.  You can turn off the rules 
entirely by saying
\begin{verbatim}
       \thinsize=0pt
       \thicksize=0pt
\end{verbatim}
for example
\item[3.] If you use a \tc{multispan} or an \tc{omit} in the first column of 
a row, you will lose the effect of the \tc{tstrut} within that row and must 
specify it yourself.  See the example above.
\item[4.] Use of \tc{multispan} and \tc{omit} will cause the default 
centering of the entry to be lost; if you want it centered, put an \tc{hfil} 
on each side of the entry, as in the example above.
\item[5.] To override the default centering action, include an \tc{hfill} on 
the left or right as desired; the \tc{hfill} will override the default 
\tc{hfil}.
\end{enumerate}

\vbox{\vskip 0.3truein}
{\large Local modifications for use with \LaTeX :}

\vbox{\vskip 0.1truein}
This macro package was originally written for use with plain \TeX.  Bob Taylor
has made changes for it to be used as a style option in \LaTeX.  The plain
\TeX\ command \tc{line} has been replaced with \tc{tableline}, with 
\tc{tableline} being defined as 
\begin{verbatim}
       \def\tableline{\hbox to \hsize}
\end{verbatim}

The \tc{documentstyle} command in your \LaTeX\ file should look something like:
\begin{verbatim}
       \documentstyle[tables]{article}
\end{verbatim}

\end{document}
\Rogue\Monster\
else
  echo "will not over write ./tabledoc.tex"
fi
if [ `wc -c ./tabledoc.tex | awk '{printf $1}'` -ne 11250 ]
then
echo `wc -c ./tabledoc.tex | awk '{print "Got " $1 ", Expected " 11250}'`
fi
if `test ! -s ./tables.sty`
then
echo "writting ./tables.sty"
cat > ./tables.sty << '\Rogue\Monster\'
%  modified by Bob Taylor for University of Rochester 20-Mar-87:
%  \line macro in Cowan's code is disabled by LaTeX, so I've
%  changed all instances of \line in Cowan's code to the new
%  definition \tableline as defined right after this comment.
%
   \def\tableline{\hbox to \hsize}
%
% +--------------------------------------------------------------------+
% ]                                                                    ]
% ]                           TABLES.TEX                               ]
% ]                                                                    ]
% ]                     Ray F. Cowan  15-Feb-85                        ]
% ]                                                                    ]
% ]                       Princeton University                         ]
% ]                                                                    ]
% ]                     Last Revision: 21-Nov-85                       ]
% ]                                                                    ]
% ]   Macros I find handy for making tables.  See TABLEDOC TEX for     ]
% ]   a longer description.  The token-counting macros are straight    ]
% ]   from the TeXbook's "Dirty Tricks" appendix.                      ]
% ]                                                                    ]
% +--------------------------------------------------------------------+
%
\newbox\hdbox%
\newcount\hdrows%
\newcount\multispancount%
\newcount\ncase%
\newcount\ncols% This is the number of primary text columns in the table.
\newcount\nrows%
\newcount\nspan%
\newcount\ntemp%
\newdimen\hdsize%
\newdimen\newhdsize%
\newdimen\parasize%
\newdimen\spreadwidth%
\newdimen\thicksize%
\newdimen\thinsize%
\newdimen\tablewidth%
\newif\ifcentertables%
\newif\ifendsize%
\newif\iffirstrow%
\newif\iftableinfo%
\newtoks\dbt%
\newtoks\hdtks%
\newtoks\savetks%
\newtoks\tableLETtokens%
\newtoks\tabletokens%
\newtoks\widthspec%
%
%  Book-keeping stuff--see how often these macros are called.
%
%\immediate\write15{%
%CP SMSG GJMSINK TEXTABLE --> TABLE MACROS V. 851121 JOB = \jobname%
%}%
%
%  Turn on table diagnostics.
%
\tableinfotrue%
\catcode`\@=11%  Allows use of "@" in macro names, like PLAIN.TEX does.
\def\out#1{\immediate\write16{#1}}%  Debugging aid.  Writes #1 on the
%                                    user's terminal and in the log file.
%
%  Define the \tstrut height, depth in terms of the x_height parameter.
%
\def\tstrut{\vrule height3.1ex depth1.2ex width0pt}%
\def\and{\char`\&}%  Allows us to get an `&' in the text.  This is the
%                    same as using the PLAIN TeX macro \&.
\def\tablerule{\noalign{\hrule height\thinsize depth0pt}}%
\thicksize=1.5pt%  Default thickness for fat rules.  The user should feel
%                  free to change this to his preference.
\thinsize=0.6pt%   Default thickness for thin rules.
\def\thickrule{\noalign{\hrule height\thicksize depth0pt}}%
\def\hrulefill{\leaders\hrule\hfill}%
\def\bigrulefill{\leaders\hrule height\thicksize depth0pt \hfill}%
\def\ctr#1{\hfil\ #1\hfil}%
\def\altctr#1{\hfil #1\hfil}%
\def\vctr#1{\hfil\vbox to0pt{\vss\hbox{#1}\vss}\hfil}%
%
%  Here are things for controlling the width of the finished table.
%
\tablewidth=-\maxdimen%
\spreadwidth=-\maxdimen%
\def\tabskipglue{0pt plus 1fil minus 1fil}%
%
%  Stuff for centering or not.
%
\centertablestrue%
\def\centeredtables{%
   \centertablestrue%
}%
\def\noncenteredtables{%
   \centertablesfalse%
}%
%
%  \vctr vertically centers its argument in the row.
%
\parasize=4in%
\long\def\para#1{%  Used to make little paragraphs out of one entry.
   {%
      \vtop{%
         \hsize=\parasize%
         \baselineskip14pt%
         \lineskip1pt%
         \lineskiplimit1pt%
         \noindent #1%
         \vrule width0pt depth6pt%
      }%
   }%
}%
%
\gdef\ARGS{########}%  Produces the correct number of #'s in the preamble
%                      by the time eveything is expanded and \halign sees
%                      it.
\gdef\headerARGS{####}%  Same as \ARGS, but used in \header macros.
\def\@mpersand{&}%  Allows us to get alignment tab characters later
%                   when we have made the character "&" an active macro.
{\catcode`\|=13%  Make |'s locally active.
\gdef\letbarzero{\let|0}%  Globally define a macro that allows us to
%                          keep active |'s from being expanded in edef's.
\gdef\letbartab{\def|{&&}}%
\gdef\letvbbar{\let\vb|}%
%  This \def will cause active |'s read by
%                            \ruledtable to be converted into double
%                            alignment tabs.
}%  End of locally active |'s.
%
{\catcode`\&=4%  Make these alignment tabs.
\def\ampskip{&\omit\hfil&}%  This local macro skips a vertical rule.
\catcode`\&=13%  Now make &'s into active macros.
\let&0%  This allows us to expand \ampskip in the next \xdef without
%        attempting to expand the & and getting an "undefined control
%        sequence" error.
\xdef\letampskip{\def&{\ampskip}}%
\gdef\letnovbamp{\let\novb&\let\tab&}
%  This will cause active &'s read by
%                                   \ruledtable to be converted into
%                                   double tabs and an \omit'ted \vrule.
}%  End of locally active &'s.
%
\def\begintable{%  Here we make |'s and &'s active characters so we can
%                  interpret them as macros.  Note that this action is
%                  true only until we encounter the matching \endgroup
%                  token later at the end of the \ruledtable macro.
   \begingroup%
   \catcode`\|=13\letbartab\letvbbar%
   \catcode`\&=13\letampskip\letnovbamp%
   \def\multispan##1{%  We must redefine \multispan to count the number
%                       of primary columns, not physical columns.
      \omit \mscount##1%
      \multiply\mscount\tw@\advance\mscount\m@ne%
      \loop\ifnum\mscount>\@ne \sp@n\repeat%
   }%  End of \multispan macro.
   \def\|{%
      &\omit\widevline&%
   }%
   \ruledtable%  Now we call \ruledtable to do the real work.
}%  End of \begintable macro.
%
\long\def\ruledtable#1\endtable{%
%
%  This macro reads in the user's data entries
%  and converts them into a ruled table.
%
%  Important note:  Many macros and parameters are re-defined here, and
%  these must be kept local to the table macros to avoid conflict with
%  their use outside of tables.  This is done by the \begingroup token
%  macro \begintable and the \endgroup token at the end of
%  this macro.
%
   \offinterlineskip%  Needed to make rules touch each other.
   \tabskip 0pt%  Needed for same reason as \offinterlineskip.
   \def\widevline{\vrule width\thicksize}%  Make outer \vrule's wider.
   \def\endrow{\@mpersand\omit\hfil\crnorm\@mpersand}%
   \def\crthick{\@mpersand\crnorm\thickrule\@mpersand}%
   \def\crnorule{\@mpersand\crnorm\@mpersand}%
   \let\nr=\crnorule%  A shorter abbreviation.
   \def\endtable{\@mpersand\crnorm\thickrule}%
%
   \let\crnorm=\cr%  Allows us to use \cr for our own purposes.
%
%  Cause user-typed \cr's to follow a row with a \tablerule.
%
   \edef\cr{\@mpersand\crnorm\tablerule\@mpersand}%
%
   \the\tableLETtokens%  Get the user's extra \let's, if any.
%
%  Put the data entries into a token register so we can scan through them
%  and see what the user is asking us to do.
%
   \tabletokens={&#1}%  We add an extra alignment tab to the beginning
%                       of the first row to allow for the first \vrule.
%
%  Now count how many rows are in the table and return the result in
%  count register \nrows; do the same for columns, and return that
%  in register \ncols.
%
   \countROWS\tabletokens\into\nrows%
   \countCOLS\tabletokens\into\ncols%
%
%  Now do a little arithmetic to convert the number of primary columns
%  into the number of physical columns that the alignment preamble must
%  prepare for;  similarly for rows.
%
   \advance\ncols by -1%
   \divide\ncols by 2%
   \advance\nrows by 1%
%
%  Tell the user how many rows and columns we found in his data, if he
%  wants to know.
%
   \iftableinfo %
      \immediate\write16{[Nrows=\the\nrows, Ncols=\the\ncols]}%
   \fi%
%
%  Now we actually go ahead and produce the table.
%
   \ifcentertables
      \ifhmode \par\fi%  Make sure we are in vertical mode.
      \tableline{%  The final table comes out as an \hbox of width the \hsize.
      \hss%  The final table will be centered left-to-right.
   \else %
      \hbox{%
   \fi
      \vbox{%
         \makePREAMBLE{\the\ncols}%  Generate the preamble.
         \edef\next{\preamble}%  This line and the next line force the
         \let\preamble=\next%    expansion of all \ARGS tokens into the
%                                appropriate number of #'s.
         \makeTABLE{\preamble}{\tabletokens}%  Go do the \halign here.
      }%  End of \vbox.
      \ifcentertables \hss}\else }\fi%  Finish the centering effect.
%                                       It is important that no spaces
%                                       follow the two `}' here.
%  }%  End of \tableline
   \endgroup%  Return all local macros and parameters to their outside
%              values.
   \tablewidth=-\maxdimen%  Reset \tablewidth to normal.
   \spreadwidth=-\maxdimen% Same for \spreadwidth.
}%  End of macro \ruledtable.
%
\def\makeTABLE#1#2{%  Does an \halign for the \ruledtable macro.
   {%  Start of local parameter values.
%
   \let\ifmath0%     These macros would cause trouble if they were to be
   \let\header0%     expanded in the following \xdef; we \let them be
   \let\multispan0%  equal to a digit, because digits can't be expanded.
%
%  Set up the width specification here.
%
   \ncase=0%
   \ifdim\tablewidth>-\maxdimen \ncase=1\fi%
   \ifdim\spreadwidth>-\maxdimen \ncase=2\fi%
   \relax%  This \relax is absolutely necessary, without it the following
%           \ifcase will always take \ncase=0.
%
   \ifcase\ncase %
      \widthspec={}%
   \or %
      \widthspec=\expandafter{\expandafter t\expandafter o%
                 \the\tablewidth}%
   \else %
      \widthspec=\expandafter{\expandafter s\expandafter p\expandafter r%
                 \expandafter e\expandafter a\expandafter d%
                 \the\spreadwidth}%
   \fi %
%\out{Widthspec=O\the\widthspecE}%
%\out{Preamble=O\preambleE}%
   \xdef\next{%  We must force the preamble to be expanded BEFORE the
      \halign\the\widthspec{%
%        \halign is done;  this \edef\next{...}\next construction
%                does the trick.
      #1%  This is the preamble text.
%
      \noalign{\hrule height\thicksize depth0pt}%  Makes the top \hrule.
%
      \the#2\endtable%  This is the main body.
%
%     \noalign{\hrule height0.7pt depth0pt}%  Makes the last \hrule.
      }%  End of \halign.
   }%  End of \next.
   }%  End of local values.
   \next%  This \next must be outside of the local values, because now
%          we want those troublesome macros in the \let's above to have
%          their normal actions.
}%  End of macro \makeTABLE.
%
\def\makePREAMBLE#1{%  This macro generates the necessary preamble for a
%                      ruled table with #1 primary columns.
%                      (Primary columns means the number of columns NOT
%                       counting those used for vertical rules.)
   \ncols=#1%  Get the number of columns desired.
   \begingroup%  Start local parameter definitions.
   \let\ARGS=0%  This is the key to the whole thing; it prevents \ARGS
%                from being expanded in the following \edef's.
   \edef\xtp{\widevline\ARGS\tabskip\tabskipglue%
   &\ctr{\ARGS}\tstrut}%  A 1-column preamble.  Gets the sizing right.
   \advance\ncols by -1%  One column has been generated; decrement the
%                         counter.
   \loop%  Append as many further columns as needed to the preamble.
      \ifnum\ncols>0 %
      \advance\ncols by -1%
      \edef\xtp{\xtp&\vrule width\thinsize\ARGS&\ctr{\ARGS}}%
   \repeat
   \xdef\preamble{\xtp&\widevline\ARGS\tabskip0pt%
   \crnorm}%  Adds the last \vrule.
   \endgroup%  End of local parameters.
}%  End of macro \makePREAMBLE.
%
\def\countROWS#1\into#2{%  This counts the number of rows in #1 by
%                          looking for control sequences that end a row,
%                          e.g., \cr, \crthick, etc., and puts the result
%                          into count register #2.
   \let\countREGISTER=#2%
   \countREGISTER=0%
%  \out{In countROWS:  tokens are O\the#1E}%
   \expandafter\ROWcount\the#1\endcount%
}%
%
\def\ROWcount{%
   \afterassignment\subROWcount\let\next= %
}%
\def\subROWcount{%
%  \out{In subROWcount:  next is O\meaning\nextE}%  Debugging aid.
   \ifx\next\endcount %
      \let\next=\relax%
   \else%
      \ncase=0%
      \ifx\next\cr %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\endrow %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crthick %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crnorule %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\header %
%     \out{In subROWcount:  next=header, ncase set=1}%
         \ncase=1%
      \fi%
%     \out{In subROWcount:  ncase is O\the\ncaseE}%
      \relax%
      \ifcase\ncase %
         \let\next\ROWcount%
%        \out{subROWcount---> ncase=\the\ncase}%
      \or %
         \let\next\argROWskip%
%        \out{subROWcount---> ncase=\the\ncase}%
      \else %
      \fi%
   \fi%
%  \out{subROWcount---> NEXT=\meaning\next}%
   \next%
}%  End of macro \subROWcount.
%
\def\counthdROWS#1\into#2{%
\dvr{10}%
   \let\countREGISTER=#2%
   \countREGISTER=0%
\dvr{11}%
%  \out{In counthdROWS:  tokens are O\the#1E}%
\dvr{13}%
   \expandafter\hdROWcount\the#1\endcount%
\dvr{12}%
}%
%
\def\hdROWcount{%
   \afterassignment\subhdROWcount\let\next= %
}%
\def\subhdROWcount{%
%\out{In subhdROWcount:  next is O\meaning\nextE}%
   \ifx\next\endcount %
      \let\next=\relax%
   \else%
      \ncase=0%
      \ifx\next\cr %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\endrow %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crthick %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crnorule %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\header %
%\out{In subhdROWcount:  next=header, ncase set=1}%
         \ncase=1%
      \fi%
%\out{In subhdROWcount:  ncase is O\the\ncaseE}%
\relax%
      \ifcase\ncase %
         \let\next\hdROWcount%
%\out{subhdROWcount---> ncase=\the\ncase}%
      \or%
         \let\next\arghdROWskip%
%\out{subhdROWcount---> ncase=\the\ncase}%
      \else %
      \fi%
   \fi%
%\out{subhdROWcount---> NEXT=\meaning\next}%
   \next%
}%
%
{\catcode`\|=13\letbartab
\gdef\countCOLS#1\into#2{%
%  \out{In countCOLS:  tokens are O\the#1E}
   \let\countREGISTER=#2%
   \global\countREGISTER=0%
   \global\multispancount=0%
   \global\firstrowtrue
   \expandafter\COLcount\the#1\endcount%
   \global\advance\countREGISTER by 3%
   \global\advance\countREGISTER by -\multispancount
%  \out{countCOLS-->O\the\countREGISTERE}
}%
%
\gdef\COLcount{%
   \afterassignment\subCOLcount\let\next= %
}%
{\catcode`\&=13%
\gdef\subCOLcount{%
%\out{In subCOLcount: next is O\meaning\nextE}
   \ifx\next\endcount %
      \let\next=\relax%
   \else%
      \ncase=0%
      \iffirstrow
         \ifx\next& %
            \global\advance\countREGISTER by 2%
            \ncase=0%
         \fi%
         \ifx\next\span %
            \global\advance\countREGISTER by 1%
            \ncase=0%
         \fi%
         \ifx\next| %
            \global\advance\countREGISTER by 2%
            \ncase=0%
         \fi
         \ifx\next\|
            \global\advance\countREGISTER by 2%
            \ncase=0%
         \fi
         \ifx\next\multispan
            \ncase=1%
            \global\advance\multispancount by 1%
         \fi
         \ifx\next\header
            \ncase=2%
         \fi
         \ifx\next\cr       \global\firstrowfalse \fi
         \ifx\next\endrow   \global\firstrowfalse \fi
         \ifx\next\crthick  \global\firstrowfalse \fi
         \ifx\next\crnorule \global\firstrowfalse \fi
      \fi%  End of \iffirstrow.
\relax%\out{subCOL-->  ncase=O\the\ncaseE}
% \out{subCOL-->  next=\meaning\next}
      \ifcase\ncase %
         \let\next\COLcount%
      \or %
         \let\next\spancount%
      \or %
         \let\next\argCOLskip%
      \else %
      \fi %
   \fi%
%  \out{subCOL-->  countREGISTER=O\the\countREGISTERE}
   \next%
}%
\gdef\argROWskip#1{%
%  Deletes the next balanced, undelimited argument from a
%                 token list.
% \out{---> Entering argROWskip <---}
% \out{In argROWskip:  deleted arg is O#1E}%
   \let\next\ROWcount \next%
}%  End of macro \argskip.
\gdef\arghdROWskip#1{%
%  Deletes the next balanced, undelimited argument from a
%                 token list.
% \out{---> Entering arghdROWskip <---}
% \out{In arghdROWskip:  deleted arg is O#1E}%
   \let\next\ROWcount \next%
}%  End of macro \arghdROWskip.
\gdef\argCOLskip#1{%
%  Deletes the next balanced, undelimited argument from a
%                 token list.
% \out{---> Entering argCOLskip <---}
% \out{In argCOLskip:  deleted arg is O#1E}%
   \let\next\COLcount \next%
}%  End of macro \argskip.
}%  End of active &'s.
}%  End of active |'s.
\def\spancount#1{%\out{spancount--->\meaning#1}
   \nspan=#1\multiply\nspan by 2\advance\nspan by -1%
   \global\advance \countREGISTER by \nspan
%  \out{number spancount--->\the\nspan; \the\countREGISTER}
   \let\next\COLcount \next}%
%
%\def\dvr#1{\vrule width 1.0pt depth 0pt height 12pt$_{#1}$}
\def\dvr#1{\relax}%
% \omit\hfil%
% \parindent=0pt\hsize=1.1in\valign{%
% \vfil#\vfil&\vfil#\vfil\cr\hfil\hbox{\ Added to\ }\hfil&%
% \hfil\hbox{\ empty events\ }\hfil\cr}\hfil%
\def\header#1{%
\dvr{1}{\let\cr=\@mpersand%
\hdtks={#1}%
%\out{In header:  hdtks=O\the\hdtksE}%
\counthdROWS\hdtks\into\hdrows%
\advance\hdrows by 1%
\ifnum\hdrows=0 \hdrows=1 \fi%
%\out{In header:  Nhdrows=O\the\hdrowsE}%
\dvr{5}\makehdPREAMBLE{\the\hdrows}%
%\out{In header:  headerpreamble=O\headerpreambleE}%
\dvr{6}\getHDdimen{#1}%
%\out{In header:  hdsize=O\the\hdsizeE}%
%\striplastCR{#1}%
{\parindent=0pt\hsize=\hdsize{\let\ifmath0%
\xdef\next{\valign{\headerpreamble #1\crnorm}}}\dvr{7}\next\dvr{8}%
}%
}\dvr{2}}%  End of macro \header.
%\def\striplastCR#1\cr{\xdef\headerbody{#1}}%
\def\makehdPREAMBLE#1{%This macro generates the necessary preamble for a
\dvr{3}%
%                      ruled table with \ncols primary columns.
%                      (Primary columns means the number of columns NOT
%                       counting those used for vertical rules.
\hdrows=#1%  Get the number of columns desired.
{%  Start local parameter definitions.
\let\headerARGS=0%
%  This is the key to the whole thing; it prevents \ARGS
\let\cr=\crnorm%
%                from being expanded in the followin \edef's.
\edef\xtp{\vfil\hfil\hbox{\headerARGS}\hfil\vfil}%
\advance\hdrows by -1%  One row has been generated; decrement the
%                         counter.
\loop%  Append as many further rows as needed to the preamble.
\ifnum\hdrows>0%
\advance\hdrows by -1%
\edef\xtp{\xtp&\vfil\hfil\hbox{\headerARGS}\hfil\vfil}%
\repeat%
\xdef\headerpreamble{\xtp\crcr}%
}%  End of local parameters.
\dvr{4}}%  End of \makehdPREAMBLE.
%
\def\getHDdimen#1{%
%\out{In getHDdimen:  Arg 1=O#1E}%
\hdsize=0pt%
\getsize#1\cr\end\cr%
}%  End of macro getHDdimen.
\def\getsize#1\cr{%
%\out{In getsize:  Arg 1=O#1E}%
%  Here we have to check arg#1 and see if the first token in #1 is an
%    \end; if so, we stop, else we check the width of arg#1.
%  We recall that each arg#1 will be terminated with a \cr token.
\endsizefalse\savetks={#1}%
%\out{In getsize:  the savetks = O\the\savetksE}%
\expandafter\lookend\the\savetks\cr%
%\out{In getsize:  ifendsize = O\meaning\ifendsizeE}%
\relax \ifendsize \let\next\relax \else%
\setbox\hdbox=\hbox{#1}\newhdsize=1.0\wd\hdbox%
\ifdim\newhdsize>\hdsize \hdsize=\newhdsize \fi%
%\out{In getsize:  hdsize=O\the\hdsizeE}%
%\out{In getsize:  newhdsize=O\the\newhdsizeE}%
\let\next\getsize \fi%
\next%
}%
\def\lookend{\afterassignment\sublookend\let\looknext= }%
\def\sublookend{\relax%
%\out{In sublookend:  looknext = O\looknextE}%
\ifx\looknext\cr %
%\out{In sublooknext:  looknext=cr}%
\let\looknext\relax \else %
%\out{In sublooknext:  looknext/=cr}%
   \relax
   \ifx\looknext\end \global\endsizetrue \fi%
   \let\looknext=\lookend%
    \fi \looknext%
}%
%
%  Allow the user to make his own names for crthick, etc.
%
\def\tablelet#1{%
   \tableLETtokens=\expandafter{\the\tableLETtokens #1}%
}%
\catcode`\@=12%  Change @'s back to their normal category code.
%
\Rogue\Monster\
else
  echo "will not over write ./tables.sty"
fi
if [ `wc -c ./tables.sty | awk '{printf $1}'` -ne 20758 ]
then
echo `wc -c ./tables.sty | awk '{print "Got " $1 ", Expected " 20758}'`
fi
if `test ! -s ./tables.tex`
then
echo "writting ./tables.tex"
cat > ./tables.tex << '\Rogue\Monster\'
% +--------------------------------------------------------------------+
% ]                                                                    ]
% ]                           TABLES.TEX                               ]
% ]                                                                    ]
% ]                     Ray F. Cowan  15-Feb-85                        ]
% ]                                                                    ]
% ]                       Princeton University                         ]
% ]                                                                    ]
% ]                     Last Revision: 21-Nov-85                       ]
% ]                                                                    ]
% ]   Macros I find handy for making tables.  See TABLEDOC TEX for     ]
% ]   a longer description.  The token-counting macros are straight    ]
% ]   from the TeXbook's "Dirty Tricks" appendix.                      ]
% ]                                                                    ]
% +--------------------------------------------------------------------+
%
\newbox\hdbox%
\newcount\hdrows%
\newcount\multispancount%
\newcount\ncase%
\newcount\ncols% This is the number of primary text columns in the table.
\newcount\nrows%
\newcount\nspan%
\newcount\ntemp%
\newdimen\hdsize%
\newdimen\newhdsize%
\newdimen\parasize%
\newdimen\spreadwidth%
\newdimen\thicksize%
\newdimen\thinsize%
\newdimen\tablewidth%
\newif\ifcentertables%
\newif\ifendsize%
\newif\iffirstrow%
\newif\iftableinfo%
\newtoks\dbt%
\newtoks\hdtks%
\newtoks\savetks%
\newtoks\tableLETtokens%
\newtoks\tabletokens%
\newtoks\widthspec%
%
%  Book-keeping stuff--see how often these macros are called.
%
%\immediate\write15{%
%CP SMSG GJMSINK TEXTABLE --> TABLE MACROS V. 851121 JOB = \jobname%
%}%
%
%  Turn on table diagnostics.
%
\tableinfotrue%
\catcode`\@=11%  Allows use of "@" in macro names, like PLAIN.TEX does.
\def\out#1{\immediate\write16{#1}}%  Debugging aid.  Writes #1 on the
%                                    user's terminal and in the log file.
%
%  Define the \tstrut height, depth in terms of the x_height parameter.
%
\def\tstrut{\vrule height3.1ex depth1.2ex width0pt}%
\def\and{\char`\&}%  Allows us to get an `&' in the text.  This is the
%                    same as using the PLAIN TeX macro \&.
\def\tablerule{\noalign{\hrule height\thinsize depth0pt}}%
\thicksize=1.5pt%  Default thickness for fat rules.  The user should feel
%                  free to change this to his preference.
\thinsize=0.6pt%   Default thickness for thin rules.
\def\thickrule{\noalign{\hrule height\thicksize depth0pt}}%
\def\hrulefill{\leaders\hrule\hfill}%
\def\bigrulefill{\leaders\hrule height\thicksize depth0pt \hfill}%
\def\ctr#1{\hfil\ #1\hfil}%
\def\altctr#1{\hfil #1\hfil}%
\def\vctr#1{\hfil\vbox to0pt{\vss\hbox{#1}\vss}\hfil}%
%
%  Here are things for controlling the width of the finished table.
%
\tablewidth=-\maxdimen%
\spreadwidth=-\maxdimen%
\def\tabskipglue{0pt plus 1fil minus 1fil}%
%
%  Stuff for centering or not.
%
\centertablestrue%
\def\centeredtables{%
   \centertablestrue%
}%
\def\noncenteredtables{%
   \centertablesfalse%
}%
%
%  \vctr vertically centers its argument in the row.
%
\parasize=4in%
\long\def\para#1{%  Used to make little paragraphs out of one entry.
   {%
      \vtop{%
         \hsize=\parasize%
         \baselineskip14pt%
         \lineskip1pt%
         \lineskiplimit1pt%
         \noindent #1%
         \vrule width0pt depth6pt%
      }%
   }%
}%
%
\gdef\ARGS{########}%  Produces the correct number of #'s in the preamble
%                      by the time eveything is expanded and \halign sees
%                      it.
\gdef\headerARGS{####}%  Same as \ARGS, but used in \header macros.
\def\@mpersand{&}%  Allows us to get alignment tab characters later
%                   when we have made the character "&" an active macro.
{\catcode`\|=13%  Make |'s locally active.
\gdef\letbarzero{\let|0}%  Globally define a macro that allows us to
%                          keep active |'s from being expanded in edef's.
\gdef\letbartab{\def|{&&}}%
\gdef\letvbbar{\let\vb|}%
%  This \def will cause active |'s read by
%                            \ruledtable to be converted into double
%                            alignment tabs.
}%  End of locally active |'s.
%
{\catcode`\&=4%  Make these alignment tabs.
\def\ampskip{&\omit\hfil&}%  This local macro skips a vertical rule.
\catcode`\&=13%  Now make &'s into active macros.
\let&0%  This allows us to expand \ampskip in the next \xdef without
%        attempting to expand the & and getting an "undefined control
%        sequence" error.
\xdef\letampskip{\def&{\ampskip}}%
\gdef\letnovbamp{\let\novb&\let\tab&}
%  This will cause active &'s read by
%                                   \ruledtable to be converted into
%                                   double tabs and an \omit'ted \vrule.
}%  End of locally active &'s.
%
\def\begintable{%  Here we make |'s and &'s active characters so we can
%                  interpret them as macros.  Note that this action is
%                  true only until we encounter the matching \endgroup
%                  token later at the end of the \ruledtable macro.
   \begingroup%
   \catcode`\|=13\letbartab\letvbbar%
   \catcode`\&=13\letampskip\letnovbamp%
   \def\multispan##1{%  We must redefine \multispan to count the number
%                       of primary columns, not physical columns.
      \omit \mscount##1%
      \multiply\mscount\tw@\advance\mscount\m@ne%
      \loop\ifnum\mscount>\@ne \sp@n\repeat%
   }%  End of \multispan macro.
   \def\|{%
      &\omit\widevline&%
   }%
   \ruledtable%  Now we call \ruledtable to do the real work.
}%  End of \begintable macro.
%
\long\def\ruledtable#1\endtable{%
%
%  This macro reads in the user's data entries
%  and converts them into a ruled table.
%
%  Important note:  Many macros and parameters are re-defined here, and
%  these must be kept local to the table macros to avoid conflict with
%  their use outside of tables.  This is done by the \begingroup token
%  macro \begintable and the \endgroup token at the end of
%  this macro.
%
   \offinterlineskip%  Needed to make rules touch each other.
   \tabskip 0pt%  Needed for same reason as \offinterlineskip.
   \def\widevline{\vrule width\thicksize}%  Make outer \vrule's wider.
   \def\endrow{\@mpersand\omit\hfil\crnorm\@mpersand}%
   \def\crthick{\@mpersand\crnorm\thickrule\@mpersand}%
   \def\crnorule{\@mpersand\crnorm\@mpersand}%
   \let\nr=\crnorule%  A shorter abbreviation.
   \def\endtable{\@mpersand\crnorm\thickrule}%
%
   \let\crnorm=\cr%  Allows us to use \cr for our own purposes.
%
%  Cause user-typed \cr's to follow a row with a \tablerule.
%
   \edef\cr{\@mpersand\crnorm\tablerule\@mpersand}%
%
   \the\tableLETtokens%  Get the user's extra \let's, if any.
%
%  Put the data entries into a token register so we can scan through them
%  and see what the user is asking us to do.
%
   \tabletokens={&#1}%  We add an extra alignment tab to the beginning
%                       of the first row to allow for the first \vrule.
%
%  Now count how many rows are in the table and return the result in
%  count register \nrows; do the same for columns, and return that
%  in register \ncols.
%
   \countROWS\tabletokens\into\nrows%
   \countCOLS\tabletokens\into\ncols%
%
%  Now do a little arithmetic to convert the number of primary columns
%  into the number of physical columns that the alignment preamble must
%  prepare for;  similarly for rows.
%
   \advance\ncols by -1%
   \divide\ncols by 2%
   \advance\nrows by 1%
%
%  Tell the user how many rows and columns we found in his data, if he
%  wants to know.
%
   \iftableinfo %
      \immediate\write16{[Nrows=\the\nrows, Ncols=\the\ncols]}%
   \fi%
%
%  Now we actually go ahead and produce the table.
%
   \ifcentertables
      \ifhmode \par\fi%  Make sure we are in vertical mode.
      \line{%  The final table comes out as an \hbox of width the \hsize.
      \hss%  The final table will be centered left-to-right.
   \else %
      \hbox{%
   \fi
      \vbox{%
         \makePREAMBLE{\the\ncols}%  Generate the preamble.
         \edef\next{\preamble}%  This line and the next line force the
         \let\preamble=\next%    expansion of all \ARGS tokens into the
%                                appropriate number of #'s.
         \makeTABLE{\preamble}{\tabletokens}%  Go do the \halign here.
      }%  End of \vbox.
      \ifcentertables \hss}\else }\fi%  Finish the centering effect.
%                                       It is important that no spaces
%                                       follow the two `}' here.
%  }%  End of \line.
   \endgroup%  Return all local macros and parameters to their outside
%              values.
   \tablewidth=-\maxdimen%  Reset \tablewidth to normal.
   \spreadwidth=-\maxdimen% Same for \spreadwidth.
}%  End of macro \ruledtable.
%
\def\makeTABLE#1#2{%  Does an \halign for the \ruledtable macro.
   {%  Start of local parameter values.
%
   \let\ifmath0%     These macros would cause trouble if they were to be
   \let\header0%     expanded in the following \xdef; we \let them be
   \let\multispan0%  equal to a digit, because digits can't be expanded.
%
%  Set up the width specification here.
%
   \ncase=0%
   \ifdim\tablewidth>-\maxdimen \ncase=1\fi%
   \ifdim\spreadwidth>-\maxdimen \ncase=2\fi%
   \relax%  This \relax is absolutely necessary, without it the following
%           \ifcase will always take \ncase=0.
%
   \ifcase\ncase %
      \widthspec={}%
   \or %
      \widthspec=\expandafter{\expandafter t\expandafter o%
                 \the\tablewidth}%
   \else %
      \widthspec=\expandafter{\expandafter s\expandafter p\expandafter r%
                 \expandafter e\expandafter a\expandafter d%
                 \the\spreadwidth}%
   \fi %
%\out{Widthspec=O\the\widthspecE}%
%\out{Preamble=O\preambleE}%
   \xdef\next{%  We must force the preamble to be expanded BEFORE the
      \halign\the\widthspec{%
%        \halign is done;  this \edef\next{...}\next construction
%                does the trick.
      #1%  This is the preamble text.
%
      \noalign{\hrule height\thicksize depth0pt}%  Makes the top \hrule.
%
      \the#2\endtable%  This is the main body.
%
%     \noalign{\hrule height0.7pt depth0pt}%  Makes the last \hrule.
      }%  End of \halign.
   }%  End of \next.
   }%  End of local values.
   \next%  This \next must be outside of the local values, because now
%          we want those troublesome macros in the \let's above to have
%          their normal actions.
}%  End of macro \makeTABLE.
%
\def\makePREAMBLE#1{%  This macro generates the necessary preamble for a
%                      ruled table with #1 primary columns.
%                      (Primary columns means the number of columns NOT
%                       counting those used for vertical rules.)
   \ncols=#1%  Get the number of columns desired.
   \begingroup%  Start local parameter definitions.
   \let\ARGS=0%  This is the key to the whole thing; it prevents \ARGS
%                from being expanded in the following \edef's.
   \edef\xtp{\widevline\ARGS\tabskip\tabskipglue%
   &\ctr{\ARGS}\tstrut}%  A 1-column preamble.  Gets the sizing right.
   \advance\ncols by -1%  One column has been generated; decrement the
%                         counter.
   \loop%  Append as many further columns as needed to the preamble.
      \ifnum\ncols>0 %
      \advance\ncols by -1%
      \edef\xtp{\xtp&\vrule width\thinsize\ARGS&\ctr{\ARGS}}%
   \repeat
   \xdef\preamble{\xtp&\widevline\ARGS\tabskip0pt%
   \crnorm}%  Adds the last \vrule.
   \endgroup%  End of local parameters.
}%  End of macro \makePREAMBLE.
%
\def\countROWS#1\into#2{%  This counts the number of rows in #1 by
%                          looking for control sequences that end a row,
%                          e.g., \cr, \crthick, etc., and puts the result
%                          into count register #2.
   \let\countREGISTER=#2%
   \countREGISTER=0%
%  \out{In countROWS:  tokens are O\the#1E}%
   \expandafter\ROWcount\the#1\endcount%
}%
%
\def\ROWcount{%
   \afterassignment\subROWcount\let\next= %
}%
\def\subROWcount{%
%  \out{In subROWcount:  next is O\meaning\nextE}%  Debugging aid.
   \ifx\next\endcount %
      \let\next=\relax%
   \else%
      \ncase=0%
      \ifx\next\cr %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\endrow %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crthick %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crnorule %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\header %
%     \out{In subROWcount:  next=header, ncase set=1}%
         \ncase=1%
      \fi%
%     \out{In subROWcount:  ncase is O\the\ncaseE}%
      \relax%
      \ifcase\ncase %
         \let\next\ROWcount%
%        \out{subROWcount---> ncase=\the\ncase}%
      \or %
         \let\next\argROWskip%
%        \out{subROWcount---> ncase=\the\ncase}%
      \else %
      \fi%
   \fi%
%  \out{subROWcount---> NEXT=\meaning\next}%
   \next%
}%  End of macro \subROWcount.
%
\def\counthdROWS#1\into#2{%
\dvr{10}%
   \let\countREGISTER=#2%
   \countREGISTER=0%
\dvr{11}%
%  \out{In counthdROWS:  tokens are O\the#1E}%
\dvr{13}%
   \expandafter\hdROWcount\the#1\endcount%
\dvr{12}%
}%
%
\def\hdROWcount{%
   \afterassignment\subhdROWcount\let\next= %
}%
\def\subhdROWcount{%
%\out{In subhdROWcount:  next is O\meaning\nextE}%
   \ifx\next\endcount %
      \let\next=\relax%
   \else%
      \ncase=0%
      \ifx\next\cr %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\endrow %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crthick %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\crnorule %
         \global\advance\countREGISTER by 1%
         \ncase=0%
      \fi%
      \ifx\next\header %
%\out{In subhdROWcount:  next=header, ncase set=1}%
         \ncase=1%
      \fi%
%\out{In subhdROWcount:  ncase is O\the\ncaseE}%
\relax%
      \ifcase\ncase %
         \let\next\hdROWcount%
%\out{subhdROWcount---> ncase=\the\ncase}%
      \or%
         \let\next\arghdROWskip%
%\out{subhdROWcount---> ncase=\the\ncase}%
      \else %
      \fi%
   \fi%
%\out{subhdROWcount---> NEXT=\meaning\next}%
   \next%
}%
%
{\catcode`\|=13\letbartab
\gdef\countCOLS#1\into#2{%
%  \out{In countCOLS:  tokens are O\the#1E}
   \let\countREGISTER=#2%
   \global\countREGISTER=0%
   \global\multispancount=0%
   \global\firstrowtrue
   \expandafter\COLcount\the#1\endcount%
   \global\advance\countREGISTER by 3%
   \global\advance\countREGISTER by -\multispancount
%  \out{countCOLS-->O\the\countREGISTERE}
}%
%
\gdef\COLcount{%
   \afterassignment\subCOLcount\let\next= %
}%
{\catcode`\&=13%
\gdef\subCOLcount{%
%\out{In subCOLcount: next is O\meaning\nextE}
   \ifx\next\endcount %
      \let\next=\relax%
   \else%
      \ncase=0%
      \iffirstrow
         \ifx\next& %
            \global\advance\countREGISTER by 2%
            \ncase=0%
         \fi%
         \ifx\next\span %
            \global\advance\countREGISTER by 1%
            \ncase=0%
         \fi%
         \ifx\next| %
            \global\advance\countREGISTER by 2%
            \ncase=0%
         \fi
         \ifx\next\|
            \global\advance\countREGISTER by 2%
            \ncase=0%
         \fi
         \ifx\next\multispan
            \ncase=1%
            \global\advance\multispancount by 1%
         \fi
         \ifx\next\header
            \ncase=2%
         \fi
         \ifx\next\cr       \global\firstrowfalse \fi
         \ifx\next\endrow   \global\firstrowfalse \fi
         \ifx\next\crthick  \global\firstrowfalse \fi
         \ifx\next\crnorule \global\firstrowfalse \fi
      \fi%  End of \iffirstrow.
\relax%\out{subCOL-->  ncase=O\the\ncaseE}
% \out{subCOL-->  next=\meaning\next}
      \ifcase\ncase %
         \let\next\COLcount%
      \or %
         \let\next\spancount%
      \or %
         \let\next\argCOLskip%
      \else %
      \fi %
   \fi%
%  \out{subCOL-->  countREGISTER=O\the\countREGISTERE}
   \next%
}%
\gdef\argROWskip#1{%
%  Deletes the next balanced, undelimited argument from a
%                 token list.
% \out{---> Entering argROWskip <---}
% \out{In argROWskip:  deleted arg is O#1E}%
   \let\next\ROWcount \next%
}%  End of macro \argskip.
\gdef\arghdROWskip#1{%
%  Deletes the next balanced, undelimited argument from a
%                 token list.
% \out{---> Entering arghdROWskip <---}
% \out{In arghdROWskip:  deleted arg is O#1E}%
   \let\next\ROWcount \next%
}%  End of macro \arghdROWskip.
\gdef\argCOLskip#1{%
%  Deletes the next balanced, undelimited argument from a
%                 token list.
% \out{---> Entering argCOLskip <---}
% \out{In argCOLskip:  deleted arg is O#1E}%
   \let\next\COLcount \next%
}%  End of macro \argskip.
}%  End of active &'s.
}%  End of active |'s.
\def\spancount#1{%\out{spancount--->\meaning#1}
   \nspan=#1\multiply\nspan by 2\advance\nspan by -1%
   \global\advance \countREGISTER by \nspan
%  \out{number spancount--->\the\nspan; \the\countREGISTER}
   \let\next\COLcount \next}%
%
%\def\dvr#1{\vrule width 1.0pt depth 0pt height 12pt$_{#1}$}
\def\dvr#1{\relax}%
% \omit\hfil%
% \parindent=0pt\hsize=1.1in\valign{%
% \vfil#\vfil&\vfil#\vfil\cr\hfil\hbox{\ Added to\ }\hfil&%
% \hfil\hbox{\ empty events\ }\hfil\cr}\hfil%
\def\header#1{%
\dvr{1}{\let\cr=\@mpersand%
\hdtks={#1}%
%\out{In header:  hdtks=O\the\hdtksE}%
\counthdROWS\hdtks\into\hdrows%
\advance\hdrows by 1%
\ifnum\hdrows=0 \hdrows=1 \fi%
%\out{In header:  Nhdrows=O\the\hdrowsE}%
\dvr{5}\makehdPREAMBLE{\the\hdrows}%
%\out{In header:  headerpreamble=O\headerpreambleE}%
\dvr{6}\getHDdimen{#1}%
%\out{In header:  hdsize=O\the\hdsizeE}%
%\striplastCR{#1}%
{\parindent=0pt\hsize=\hdsize{\let\ifmath0%
\xdef\next{\valign{\headerpreamble #1\crnorm}}}\dvr{7}\next\dvr{8}%
}%
}\dvr{2}}%  End of macro \header.
%\def\striplastCR#1\cr{\xdef\headerbody{#1}}%
\def\makehdPREAMBLE#1{%This macro generates the necessary preamble for a
\dvr{3}%
%                      ruled table with \ncols primary columns.
%                      (Primary columns means the number of columns NOT
%                       counting those used for vertical rules.
\hdrows=#1%  Get the number of columns desired.
{%  Start local parameter definitions.
\let\headerARGS=0%
%  This is the key to the whole thing; it prevents \ARGS
\let\cr=\crnorm%
%                from being expanded in the followin \edef's.
\edef\xtp{\vfil\hfil\hbox{\headerARGS}\hfil\vfil}%
\advance\hdrows by -1%  One row has been generated; decrement the
%                         counter.
\loop%  Append as many further rows as needed to the preamble.
\ifnum\hdrows>0%
\advance\hdrows by -1%
\edef\xtp{\xtp&\vfil\hfil\hbox{\headerARGS}\hfil\vfil}%
\repeat%
\xdef\headerpreamble{\xtp\crcr}%
}%  End of local parameters.
\dvr{4}}%  End of \makehdPREAMBLE.
%
\def\getHDdimen#1{%
%\out{In getHDdimen:  Arg 1=O#1E}%
\hdsize=0pt%
\getsize#1\cr\end\cr%
}%  End of macro getHDdimen.
\def\getsize#1\cr{%
%\out{In getsize:  Arg 1=O#1E}%
%  Here we have to check arg#1 and see if the first token in #1 is an
%    \end; if so, we stop, else we check the width of arg#1.
%  We recall that each arg#1 will be terminated with a \cr token.
\endsizefalse\savetks={#1}%
%\out{In getsize:  the savetks = O\the\savetksE}%
\expandafter\lookend\the\savetks\cr%
%\out{In getsize:  ifendsize = O\meaning\ifendsizeE}%
\relax \ifendsize \let\next\relax \else%
\setbox\hdbox=\hbox{#1}\newhdsize=1.0\wd\hdbox%
\ifdim\newhdsize>\hdsize \hdsize=\newhdsize \fi%
%\out{In getsize:  hdsize=O\the\hdsizeE}%
%\out{In getsize:  newhdsize=O\the\newhdsizeE}%
\let\next\getsize \fi%
\next%
}%
\def\lookend{\afterassignment\sublookend\let\looknext= }%
\def\sublookend{\relax%
%\out{In sublookend:  looknext = O\looknextE}%
\ifx\looknext\cr %
%\out{In sublooknext:  looknext=cr}%
\let\looknext\relax \else %
%\out{In sublooknext:  looknext/=cr}%
   \relax
   \ifx\looknext\end \global\endsizetrue \fi%
   \let\looknext=\lookend%
    \fi \looknext%
}%
%
%  Allow the user to make his own names for crthick, etc.
%
\def\tablelet#1{%
   \tableLETtokens=\expandafter{\the\tableLETtokens #1}%
}%
\catcode`\@=12%  Change @'s back to their normal category code.
%
\Rogue\Monster\
else
  echo "will not over write ./tables.tex"
fi
if [ `wc -c ./tables.tex | awk '{printf $1}'` -ne 20461 ]
then
echo `wc -c ./tables.tex | awk '{print "Got " $1 ", Expected " 20461}'`
fi
echo "Finished archive 1 of 1"
exit
-- 
Atul Kacker  |     Internet: akk2@tut.cc.rochester.edu
             |     UUCP: {ames,cmcl2,decvax,rutgers}!rochester!ur-tut!akk2
-------------------------------------------------------------------------------