% AlgMacros.tex of January 11, 1984 5:33 pm --- Stolfi
% Macros for algorithms
% Uses counters 3 (to compute useful width), 5 (current nesting
% level), and 9 (loop variable to count bars)
% Things to fix:
% Parameters to be defined by user (in pt unless stated otherwise):
% \algwidth = width of algorithm body (excl. left and right indent.)
% \algindent = indentation of outermost bracket
% \alglevelindent = extra indentation per level
% \algstepindent = indentation of step text (exc. step number)
% relative to innermost bracket
% \algcommindent = indentation of comment text rel. innermost bracket
% \algcontindent = extra indentation of continuation lines
% \algstepnoskip = space between step no and step text
% \algthickness = thickness of block brackets
% \algvskip = extra skip between steps (in ex)
% BODY
% Usage:
% \algbody{
% \comm{We are lost now}
% \step1{If there is any hope, then}
% \begblock
% \step{1A}{\sna{Don't despair yet} Go on.}
% \endblock
% \unstep{Else,}
% \begblock
% \step2{Give up.}
% \endblock
% \step3{Terminate the algorithm.}
% }
\def\algbody#1{\penalty 1000
\vskip1.0ex plus0.5ex\penalty-500
{\parindent 0pt \hangindent 0pt after0
\parskip 0 pt \baselineskip -1pt \lineskip0pt
\setcount5 0
\def\begblock{\algear\algvskip 0 \advcount5 by 1}
\def\endblock{\advcount5 by-1\algear 0 \algvskip}
\begblock
#1
\endblock}
\parindent\stdparindent pt\par
\vskip 1.0ex plus 0.5ex\penalty-600}
% Numbered step
\def\step#1#2{
\unstep{\null\rspose{\hbox{\bf #1.\hfilneg\hskip\algstepnoskip pt}}#2}
} % numbered steps
% Unnumbered step
\def\unstep#1{\par\penalty 600
\hbox
{\algvbars
\hskip \algstepindent pt\advcount3 by -\algstepindent
\vbox{
\vskip \algvskip ex
{\standardsize
\hbox par\count3pt{\hangindent\algcontindent pt after1 #1}}
\vskip \algvskip ex}
\hfil}}
% Step name
\def\sna#1{{[{\it #1\/}]}} % step name and comments.
% Comment
\def\comm#1{\par\penalty 600
\hbox
{\algvbars
\hskip \algcommindent pt\advcount3 by -\algcommindent
\vbox{
{\small
\vskip \algvskip ex
\hbox par \count3pt{\hangindent\algcontindent pt after1 #1}}
\vskip \algvskip ex}
\hfil}}
% INTERNAL MACROS
% No user-serviceable parts below.
\def\algear#1#2{\par\penalty1000
\hbox
{\algvbars \hskip\alglevelindent pt\advcount3 by -\alglevelindent
\vbox{\vskip #1 ex
\hrule height \algthickness pt width 0.4em
\vskip #2ex}\hfil}
\penalty1000}
\def\algvbars{
\hskip \algindent pt \setcount3 \algwidth
\repeat{\count5}{\vrule width\algthickness pt
\hskip-\algthickness pt
\hskip\alglevelindent pt\advcount3 by -\alglevelindent}
\hskip-\alglevelindent pt\advcount3 by \alglevelindent}