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{0}{alg:alg}{Algorithm}
18 \localedef{0}{alg:proc}{Procedure}
19 \localedef{0}{alg:in}{Input}
20 \localedef{0}{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~~}}
65 \def\typedalgo#1#2{\algoinit {\bo #1\/} \alg{#2}}
66 \def\algo#1{\typedalgo{\localestr{alg:alg}}{#1}}
67 \def\proc#1{\typedalgo{\localestr{alg:proc}}{#1}}
68 \def\headlessalgo{\algoinit}
70 \def\endalgo{\endlist\endgroup}
74 \ifnum\itemcount=0\par\nobreak\smallskip\fi
75 \algopar\advance\itemcount by 1
76 \algostep{\the\itemcount.}%
77 \futurelet\next\algoitemh
80 \def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\algoitemgo\fi\next}
81 \def\algohang:{\advance\hangindent by \algonestindent \hskip \algonestindent\futurelet\next\algoitemh}
82 \optdef\algoitemgo{\ifx\addid\undefined\else\addid{item}{\the\itemcount}\fi}
84 \def\algin{\par\nobreak{\it \localestr{alg:in}:\/} }
85 \def\algout{\par\nobreak\parindent=0pt{\it \localestr{alg:in}:\/} }
86 \def\alginbreak{\hfil\break\hphantom{\it \localestr{alg:out}:\/} }
87 \def\algalias#1{ (#1)}
89 % Algorithm name in text or in a formula
90 \protected\def\alg#1{\leavevmode\hbox{\csc #1}}
93 \def\algcmt#1{\unskip~~\hfill\fullcmt{#1}\ignorespaces}
94 \def\fullcmt#1{{$\triangleleft$\hskip0.5em\it #1}}