% Modifies smemo2.sty to create an impressive (sic) lined memo.
% Gary Houston.

% Opening of the memo. In order to handle very long lines or multiple
% lines in a single header, vboxes are constructed to precise widths.
% I could not figure out a way to do this with halign, since the
% middle column may contain multiline entries.

\def\opening{%
  \global\@topnum\z@ % Stop figures appearing at top of page.
  \thispagestyle{docnum}%
  % Calculate the width of 1st and 3rd columns.
  \tolerance=10000 % Allow line-breaks in narrow columns.
  \setbox0=\hbox{\bf MEMO TO:\ \ \ }% Widest of the compulsory tags.
  \ifx\empty\@through\relax\else
    \setbox0=\hbox{\bf THROUGH:\ \ \ }% Through is a bit wider.
  \fi
  \dimen1=\wd0
  \def\@done{0}%
  \loop\ifx\@xheadtags\empty\def\@done{1}\fi
    \ifnum\@done=0
      \lop\@xheadtags\to\@headtag
      \setbox0=\hbox{\bf\@headtag{}:\ \ \ }%
      \ifdim\wd0>\dimen1\global\dimen1=\wd0\fi
    \repeat
  \setbox0=\hbox{\hskip 10pt\bf ACTION BY:\hskip 40pt}
  \dimen3=\wd0
  \ifx\@empty\@actionby\relax\else
    \global\setbox0=\hbox{{\bf\hskip 10pt{}ACTION BY: }\ignorespaces\@actionby}%
    \ifdim\wd0>\dimen3\global\dimen3=\wd0\fi
  \fi
  \dimen2=\hsize
  \advance\dimen2 by -\dimen1
  \advance\dimen2 by -\dimen3
  \lineskip=0pt % vboxes are separated with struts.
  \noindent % Do not remove this, or everything will fail.
% To (compulsory) and ActionBy (optional).
% \@actionby is assumed to be reasonably short.
  \hbox to \dimen1{\bf MEMO TO:\hfil}\vtop{\noindent\hsize=\dimen2
    \ignorespaces\strut\@to\strut}\vrule
  \ifx\@empty\@actionby\relax\else
    {\bf\hskip 10pt{}ACTION BY: }\@actionby
  \fi\newline
% cc (optional).
  \ifx\@empty\@cc\relax\else
    \hbox to \dimen1{\bf cc: }\vtop{\noindent\hsize=\dimen2
      \ignorespaces\strut\@cc\strut}\vrule\newline
  \fi
% Through (optional).
  \ifx\@empty\@through\relax\else
    \hbox to \dimen1{\bf THROUGH: }\vtop{\noindent\hsize=\dimen2
      \ignorespaces\strut\@through\strut}\vrule\newline
  \fi
% Extended tags, extracted from token lists.
  \def\@done{0}%
  \loop\ifx\@xheadtags\empty\def\@done{1}\fi
    \ifnum\@done=0
      \lop\@xheadtags\to\@headtag
      \lop\@xheadtext\to\@headtext
      \hbox to \dimen1{\bf\@headtag{}:\hfil}\vtop{\noindent\hsize=\dimen2
        \ignorespaces\strut\@headtext\strut}\vrule\newline
    \repeat
% From (compulsory).
  \hbox to \dimen1{\bf FROM: }\vtop{\noindent\hsize=\dimen2
    \ignorespaces\strut\@from\strut}\vrule\newline
% Date (supplied or imputed).
  \hbox to \dimen1{\bf DATE: }\vtop{\noindent\hsize=\dimen2
    \ignorespaces\strut\@date\strut}\vrule\vadjust{\hrule\vskip 10pt}\newline
% Subject (compulsory).
  \advance\dimen2 by \dimen3 % Can use 3rd column.
  \hbox to \dimen1{\bf SUBJECT: }\vtop{\noindent\hsize=\dimen2
    \ignorespaces\strut\@subject\strut}\vadjust{\vskip 10pt\hrule}\newline
  \par\noindent\ignorespaces
} % End of \opening.
