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
15 \localedef{en}{alg:alg}{Algorithm}
16 \localedef{en}{alg:proc}{Procedure}
17 \localedef{en}{alg:in}{Input}
18 \localedef{en}{alg:out}{Output}
23 \itemnarrow=\itemindent
25 \preitemizeskip=\bigskipamount
26 \postitemizeskip=\dimexpr \bigskipamount - \parskip \relax
32 \def\typedalgo#1#2{\algoinit {\bo #1\/} \alg{#2}}
33 \def\algo#1{\typedalgo{\localestr{alg:alg}}{#1}}
34 \def\proc#1{\typedalgo{\localestr{alg:proc}}{#1}}
35 \def\headlessalgo{\algoinit}
36 \def\endalgo{\goodbreak\endlist\endgroup}
40 \hangindent=2.5em % \parindent + width of box for the step number
45 \ifnum\itemcount=0\par\nobreak\smallskip\fi
46 \algopar\advance\itemcount by 1
47 \hbox to 0.5em{\hss \the\itemcount.~~}%
48 \futurelet\next\algoitemh}
49 \def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\algoitemgo\fi\next}
50 \def\algohang:{\advance\hangindent by 2em \hskip 2em\futurelet\next\algoitemh}
51 \optdef\algoitemgo{\ifx\addid\undefined\else\addid{item}{\the\itemcount}\fi}
52 \def\algin{\par\nobreak{\it \localestr{alg:in}:\/} }
53 \def\algout{\par\nobreak\parindent=0pt{\it \localestr{alg:in}:\/} }
54 \def\alginbreak{\hfil\break\hphantom{\it \localestr{alg:out}:\/} }
55 \def\algalias#1{ (#1)}
57 % Algorithm name in text or in a formula
58 \protected\def\alg#1{\leavevmode\hbox{\csc #1}}