% Macros for the Snafu paper document type.
% Copyright (C) 1993, 1994 Gary Houston
% This program may be copied and modified under the terms of the 
% GNU General Public License version 2.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{spaper}[1994/08/26 gf Snafu paper class]

\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}%
}
\ProcessOptions

\LoadClass{article}

\RequirePackage{gftext}
\RequirePackage{gfdisplay}
\RequirePackage{gfhead}
\RequirePackage{gffig}
\RequirePackage{gfstructure}
\RequirePackage{gflink}

\setcounter{secnumdepth}{2}

\regularspacing

% Set up token lists for names and addresses.
% See Texbook section "List macros".
\toksdef\ta=0 \toksdef\tb=2 % Token list registers for temporary use.
\long\def\rightappenditem#1\to#2{\ta={ {#1}}\tb=\expandafter{#2}%
  \edef#2{\the\tb\the\ta}}
\def\lop#1\to#2{\expandafter\lopoff#1\lopoff#1#2}
\long\def\lopoff #1#2\lopoff#3#4{\def#4{#1}\def#3{#2}}

\let\@authors\@empty
\let\@addnums\@empty
\let\@addresses\@empty
\renewcommand{\author}[1]{\rightappenditem#1\to\@authors}
\newcommand{\address}[2]{\rightappenditem#1\to\@addnums
  \rightappenditem#2\to\@addresses}

% Reference to an address.
\newcommand{\addref}[1]{\footnotemark[#1]}

% Command for printing the index.
\newcommand{\printindex}{\InputIfFileExists{\jobname.ind}{}{}}

% Macros for printing title page elements.  These can be redefined
% easily.
\newcommand{\@tptitle}[1]{{\LARGE\bfseries #1\par\vskip 3em}}
\newcommand{\@tpsetupauthor}{\large\lineskip .75em}
\newcommand{\@tpdate}[1]{\vskip 1.5em {\large #1}\par}

% Title page.
\newcommand{\gftitlepage}
{{% Extra group, to keep definitions local.
  \global\@topnum\z@ % Stop figures appearing at top of page.
  \newpage\thispagestyle{docnum}\c@page\z@
  \let\footnotesize\small \let\footnoterule\relax \setcounter{page}{0}
  \null\vfil
  \vskip 60pt
  \begin{center}
    \@tptitle{\@title}
    {\@tpsetupauthor
      \def\@done{0}% Flag for empty list.
      \def\@first{1}% Flag first author.
      \loop\ifx\@authors\empty\def\@done{1}\fi
        \ifnum\@done=0
          \lop\@authors\to\@author
	  \ifnum\@first=0\\ \fi% Add newline before each additional author.
          \@author
	  \def\@first{0}%
        \repeat
	\par
    }% End authors.
    % Insert address information.
    \def\@done{0}% Flag for empty list.
    \def\@first{1}% Flag for first address.
    \loop\ifx\@addresses\empty\def\@done{1}\fi
      \ifnum\@done=0
        \lop\@addresses\to\@address
        \lop\@addnums\to\@addnum
	%Add a newline before each additional address.
	\ifnum\@first=0\\\vskip 1em\fi
        ${}^\@addnum$\@address
	\def\@first{0}%
    \repeat
    \@tpdate{\@date}
  \end{center} \par
  \vfil\null
  \newpage
  \pagenumbering{roman}
  \ifx\@empty\@copyrite\relax\else{%
    \if@twoside\thispagestyle{empty}\c@page\z@\fi
    \null\vfill
    {\small
      \begin{center}
        \@copyrite
      \end{center}
      }
    \cleardoublepage
    }
  \fi
  \ifx\@empty\@thanks\relax\else{%
    \null\vfil
    \begin{center}
      \@thanks
    \end{center}
    \vfil\null
    \cleardoublepage
    }
  \fi
  \ifx\@empty\@abstract\relax\else{%
    \null\vfil
    \begin{center}
      \textbf{Abstract}\par
      \@abstract
    \end{center}}
  \par\vfil\null
  \cleardoublepage
  \fi
  \ifnum\@needtoc=1%
  \tableofcontents
  \cleardoublepage
  \fi
  \ifnum\@needlof=1%
  \listoffigures
  \cleardoublepage
  \fi
  \let\@abstract\@empty
  \let\@copyrite\@empty
  \thispagestyle{plain}
  \pagenumbering{arabic}}
}

\newcommand{\@tnptitle}[1]{\textbf{\large #1}\par}
\newcommand{\@tnpsetupauthor}{\lineskip .5ex}
\newcommand{\@tnpdate}[1]{\vskip 1ex #1\par}

% Title non-page.
\newcommand{\gfmaketitle}
{%
  \global\@topnum\z@ %stop figures going at top of page
  \thispagestyle{docnum}
  \null
  \vskip 2ex
  \begin{center}
    \@tnptitle{\@title}
    \vskip 1ex
    \def\origfn{\c@footnote}
    {\@tnpsetupauthor
      % Extract authors from the token list register.
      \def\@done{0}% Flag for empty list.
      \def\@first{1}% Flag first author.
      \loop\ifx\@authors\empty\def\@done{1}\fi
        \ifnum\@done=0
          \lop\@authors\to\@author
	  \ifnum\@first=0, \fi% Add comma before each additional author.
          \@author
	  \def\@first{0}%
        \repeat
	\par
    }% End authors.
    \@tnpdate{\@date}
  \end{center}
  {\long\def\@makefntext##1{\parindent 1em##1}%
  \ifx\@empty\@thanks\relax
  \else
    \footnotetext{\@thanks}
  \fi
  }%
  % Insert address information, to appear in the footnote.
  \def\@done{0}% Flag for empty list.
  \loop\ifx\@addresses\empty\def\@done{1}\fi
    \ifnum\@done=0
      \lop\@addresses\to\@address
      \lop\@addnums\to\@addnum
      \footnotetext[\@addnum]{\let\\=\relax\@address}
      \advance\c@footnote by 1
  \repeat
  \ifx\@empty\@copyrite\relax\else{%
    {\small
      \begin{center}
        \@copyrite
      \end{center}
      }
    }
  \fi
  \ifx\@empty\@abstract\relax\else
  \begin{center}
    {\bf Abstract}\par
    \@abstract
  \end{center}
  \fi
  \ifnum\@needtoc=1%
  \tableofcontents
  \fi
  \ifnum\@needlof=1%
  \listoffigures
  \fi
  \let\@abstract\@empty
  \let\@copyrite\@empty
}
