1 % The UCW Macro Collection: Typesetting of algorithms
2 % Written by Martin Mares <mj@ucw.cz> in 2018 and placed into public domain
3 % -------------------------------------------------------------------------
5 % \algo{name of the algorithm}\algalias{a longer name}
6 % \algin input description
9 % \::[identifier]nested step
10 % \:::yet more nested step
11 % \algout output description
14 \def\localealgo{Algorithm}
15 \def\localeproc{Procedure}
16 \def\localeinput{Input}
17 \def\localeoutput{Output}
22 \itemnarrow=\itemindent
24 \preitemizeskip=\bigskipamount
25 \postitemizeskip=\dimexpr \bigskipamount - \parskip \relax
31 \def\typedalgo#1#2{\algoinit {\bo #1\/} \alg{#2}}
32 \def\algo#1{\typedalgo{\localealgo}{#1}}
33 \def\proc#1{\typedalgo{\localeproc}{#1}}
34 \def\headlessalgo{\algoinit}
35 \def\endalgo{\goodbreak\endlist\endgroup}
39 \hangindent=2.5em % \parindent + width of box for the step number
44 \ifnum\itemcount=0\par\nobreak\smallskip\fi
45 \algopar\advance\itemcount by 1
46 \hbox to 0.5em{\hss \the\itemcount.~~}%
47 \futurelet\next\algoitemh}
48 \def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\algoitemgo\fi\next}
49 \def\algohang:{\advance\hangindent by 2em \hskip 2em\futurelet\next\algoitemh}
50 \optdef\algoitemgo{\ifx\addid\undefined\else\addid{item}{\the\itemcount}\fi}
51 \def\algin{\par\nobreak{\it \localeinput:\/} }
52 \def\algout{\par\nobreak\parindent=0pt{\it localeoutput:\/} }
53 \def\alginbreak{\hfil\break\hphantom{\it \localeinput:\/} }
54 \def\algalias#1{ (#1)}
56 % Algorithm name in text or in a formula
57 \protected\def\alg#1{\leavevmode\hbox{\csc #1}}