1 % The UCW Macro Collection: Typesetting of algorithms
2 % Written by Martin Mares <mj@ucw.cz> in 2018 and placed into public domain
3 % -------------------------------------------------------------------------
7 % \algo{name of the algorithm}\algalias{a longer name}
8 % \algin input description
10 % \:step \cmt{comment}
11 % \::[identifier]nested step
12 % \:::yet more nested step
13 % \algout output description
17 \localedef{en}{alg:alg}{Algorithm}
18 \localedef{en}{alg:proc}{Procedure}
19 \localedef{en}{alg:in}{Input}
20 \localedef{en}{alg:out}{Output}
26 % Extra indent for nested items
27 \newdimen\algonestindent
31 \newdimen\algolabelwidth
34 % Set up spacing (customizable)
36 \itemnarrow=\itemindent
38 \preitemizeskip=\bigskipamount
39 \postitemizeskip=\dimexpr \bigskipamount - \parskip \relax
42 % Set up paragraph mode for a single step of the algorithm (customizable)
45 \parindent=\algoindent
46 \hangindent=\algoindent
47 \advance\hangindent by \algolabelwidth
52 % Typeset step label (customizable)
53 \def\algostep#1{\hbox to \algolabelwidth{\hss #1~~}}
66 \def\typedalgo#1#2{\algoinit {\bo #1\/} \alg{#2}}
67 \def\algo#1{\typedalgo{\localestr{alg:alg}}{#1}}
68 \def\proc#1{\typedalgo{\localestr{alg:proc}}{#1}}
69 \def\headlessalgo{\algoinit}
71 \def\endalgo{\goodbreak\endlist\endgroup}
75 \ifnum\itemcount=0\par\nobreak\smallskip\fi
76 \algopar\advance\itemcount by 1
77 \algostep{\the\itemcount.}%
78 \futurelet\next\algoitemh
81 \def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\algoitemgo\fi\next}
82 \def\algohang:{\advance\hangindent by \algonestindent \hskip \algonestindent\futurelet\next\algoitemh}
83 \optdef\algoitemgo{\ifx\addid\undefined\else\addid{item}{\the\itemcount}\fi}
85 \def\algin{\par\nobreak{\it \localestr{alg:in}:\/} }
86 \def\algout{\par\nobreak\parindent=0pt{\it \localestr{alg:in}:\/} }
87 \def\alginbreak{\hfil\break\hphantom{\it \localestr{alg:out}:\/} }
88 \def\algalias#1{ (#1)}
90 % Algorithm name in text or in a formula
91 \protected\def\alg#1{\leavevmode\hbox{\csc #1}}
94 \def\algcmt#1{\unskip~~\hfill\fullcmt{#1}\ignorespaces}
95 \def\fullcmt#1{{$\triangleleft$\hskip0.5em\it #1}}