\localedef{en}{alg:in}{Input}
\localedef{en}{alg:out}{Output}
+% Spacing (customizable)
+\def\algospacing{
+ \itemnarrow=\itemindent
+ \interitemskip=1pt
+ \preitemizeskip=\bigskipamount
+ \postitemizeskip=\dimexpr \bigskipamount - \parskip \relax
+}
+
\def\algoinit{
-\goodbreak
-\begingroup
-\itemnarrow=\itemindent
-\interitemskip=1pt
-\preitemizeskip=\bigskipamount
-\postitemizeskip=\dimexpr \bigskipamount - \parskip \relax
-\inititemize
-\let\:=\algoitem
-\def\={\leftarrow}
-\itemcount=0
+ \goodbreak
+ \begingroup
+ \algospacing
+ \inititemize
+ \let\:=\algoitem
+ \def\={\leftarrow}
+ \itemcount=0
}
+
\def\typedalgo#1#2{\algoinit {\bo #1\/} \alg{#2}}
\def\algo#1{\typedalgo{\localestr{alg:alg}}{#1}}
\def\proc#1{\typedalgo{\localestr{alg:proc}}{#1}}
\def\headlessalgo{\algoinit}
+
\def\endalgo{\goodbreak\endlist\endgroup}
\let\endproc=\endalgo
-\def\algopar{\par
-\parindent=2em
-\hangindent=2.5em % \parindent + width of box for the step number
-\hangafter=1
-\leavevmode
+
+\def\algopar{
+ \par
+ \parindent=2em
+ \hangindent=2.5em % \parindent + width of box for the step number
+ \hangafter=1
+ \leavevmode
}
-\def\algoitem{
-\ifnum\itemcount=0\par\nobreak\smallskip\fi
-\algopar\advance\itemcount by 1
-\hbox to 0.5em{\hss \the\itemcount.~~}%
-\futurelet\next\algoitemh}
+
+\def\algoitem{%
+ \ifnum\itemcount=0\par\nobreak\smallskip\fi
+ \algopar\advance\itemcount by 1
+ \hbox to 0.5em{\hss \the\itemcount.~~}%
+ \futurelet\next\algoitemh
+}
+
\def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\algoitemgo\fi\next}
\def\algohang:{\advance\hangindent by 2em \hskip 2em\futurelet\next\algoitemh}
\optdef\algoitemgo{\ifx\addid\undefined\else\addid{item}{\the\itemcount}\fi}
+
\def\algin{\par\nobreak{\it \localestr{alg:in}:\/} }
\def\algout{\par\nobreak\parindent=0pt{\it \localestr{alg:in}:\/} }
\def\alginbreak{\hfil\break\hphantom{\it \localestr{alg:out}:\/} }