github.com/aakash4dev/cometbft@v0.38.2/spec/consensus/consensus-paper/algorithmicplus.sty (about) 1 % ALGORITHMICPLUS STYLE 2 % for LaTeX version 2e 3 % Original ``algorithmic.sty'' by -- 1994 Peter Williams <pwil3058@bigpond.net.au> 4 % Bug fix (13 July 2004) by Arnaud Giersch <giersch@icps.u-strasbg.fr> 5 % Includes ideas from 'algorithmicext' by Martin Biely 6 % <biely@ecs.tuwien.ac.at> and 'distribalgo' by Xavier Defago 7 % Modifications: Martin Hutle <martin.hutle@epfl.ch> 8 % 9 % This style file is free software; you can redistribute it and/or 10 % modify it under the terms of the GNU Lesser General Public 11 % License as published by the Free Software Foundation; either 12 % version 2 of the License, or (at your option) any later version. 13 % 14 % This style file is distributed in the hope that it will be useful, 15 % but WITHOUT ANY WARRANTY; without even the implied warranty of 16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 % Lesser General Public License for more details. 18 % 19 % You should have received a copy of the GNU Lesser General Public 20 % License along with this style file; if not, write to the 21 % Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 % Boston, MA 02111-1307, USA. 23 % 24 \NeedsTeXFormat{LaTeX2e} 25 \ProvidesPackage{algorithmicplus} 26 \typeout{Document Style `algorithmicplus' - environment, replaces `algorithmic'} 27 % 28 \RequirePackage{ifthen} 29 \RequirePackage{calc} 30 \newboolean{ALC@noend} 31 \setboolean{ALC@noend}{false} 32 \newcounter{ALC@line} 33 \newcounter{ALC@rem} 34 \newcounter{ALC@depth} 35 \newcounter{ALCPLUS@lastline} 36 \newlength{\ALC@tlm} 37 % 38 \DeclareOption{noend}{\setboolean{ALC@noend}{true}} 39 % 40 \ProcessOptions 41 % 42 % ALGORITHMIC 43 \newcommand{\algorithmiclnosize}{\small} 44 \newcommand{\algorithmiclnofont}{\tt} 45 \newcommand{\algorithmiclnodelimiter}{:} 46 % 47 \newcommand{\algorithmicrequire}{\textbf{Require:}} 48 \newcommand{\algorithmicensure}{\textbf{Ensure:}} 49 \newcommand{\algorithmiccomment}[1]{\{#1\}} 50 \newcommand{\algorithmicend}{\textbf{end}} 51 \newcommand{\algorithmicif}{\textbf{if}} 52 \newcommand{\algorithmicthen}{\textbf{then}} 53 \newcommand{\algorithmicelse}{\textbf{else}} 54 \newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif} 55 \newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif} 56 \newcommand{\algorithmicfor}{\textbf{for}} 57 \newcommand{\algorithmicforall}{\textbf{for all}} 58 \newcommand{\algorithmicdo}{\textbf{do}} 59 \newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor} 60 \newcommand{\algorithmicwhile}{\textbf{while}} 61 \newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile} 62 \newcommand{\algorithmicloop}{\textbf{loop}} 63 \newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop} 64 \newcommand{\algorithmicrepeat}{\textbf{repeat}} 65 \newcommand{\algorithmicuntil}{\textbf{until}} 66 \def\ALC@item[#1]{% 67 \if@noparitem \@donoparitem 68 \else \if@inlabel \indent \par \fi 69 \ifhmode \unskip\unskip \par \fi 70 \if@newlist \if@nobreak \@nbitem \else 71 \addpenalty\@beginparpenalty 72 \addvspace\@topsep \addvspace{-\parskip}\fi 73 \else \addpenalty\@itempenalty \addvspace\itemsep 74 \fi 75 \global\@inlabeltrue 76 \fi 77 \everypar{\global\@minipagefalse\global\@newlistfalse 78 \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels 79 \penalty\z@ \fi 80 \everypar{}}\global\@nobreakfalse 81 \if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi 82 \sbox\@tempboxa{\makelabel{#1}}% 83 \global\setbox\@labels 84 \hbox{\unhbox\@labels \hskip \itemindent 85 \hskip -\labelwidth \hskip -\ALC@tlm 86 \ifdim \wd\@tempboxa >\labelwidth 87 \box\@tempboxa 88 \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi 89 \hskip \ALC@tlm}\ignorespaces} 90 % 91 \newenvironment{algorithmic}[1][0]{ 92 \setcounter{ALC@depth}{\@listdepth}% 93 \let\@listdepth\c@ALC@depth% 94 \let\@item\ALC@item 95 \newcommand{\ALC@lno}{% 96 \ifthenelse{\equal{\arabic{ALC@rem}}{0}} 97 {{\algorithmiclnosize\algorithmiclnofont \arabic{ALC@line}\algorithmiclnodelimiter}}{}% 98 } 99 \let\@listii\@listi 100 \let\@listiii\@listi 101 \let\@listiv\@listi 102 \let\@listv\@listi 103 \let\@listvi\@listi 104 \let\@listvii\@listi 105 \newenvironment{ALC@g}{ 106 \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@ 107 \listparindent\z@ \rightmargin\z@ 108 \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@ 109 \leftmargin 1em 110 \addtolength{\ALC@tlm}{\leftmargin} 111 } 112 } 113 {\end{list}} 114 \newcommand{\ALC@it}{\refstepcounter{ALC@line}\addtocounter{ALC@rem}{1}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item} 115 \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}% 116 {}{\ \algorithmiccomment{##1}}} 117 \newcommand{\REQUIRE}{\item[\algorithmicrequire]} 118 \newcommand{\ENSURE}{\item[\algorithmicensure]} 119 \newcommand{\STATE}{\ALC@it} 120 \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}} 121 \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}} 122 \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}} 123 \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}} 124 \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}} 125 \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}} 126 \renewcommand{\\}{\@centercr} 127 \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen% 128 \ALC@com{##1}\begin{ALC@if}} 129 \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse% 130 \ALC@com{##1}\begin{ALC@if}} 131 \newcommand{\ELSIF}[2][default]% 132 {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen% 133 \ALC@com{##1}\begin{ALC@if}} 134 \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo% 135 \ALC@com{##1}\begin{ALC@for}} 136 \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ % 137 \algorithmicdo% 138 \ALC@com{##1}\begin{ALC@for}} 139 \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ % 140 \algorithmicdo% 141 \ALC@com{##1}\begin{ALC@whl}} 142 \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop% 143 \ALC@com{##1}\begin{ALC@loop}} 144 \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat% 145 \ALC@com{##1}\begin{ALC@rpt}} 146 \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1} 147 \ifthenelse{\boolean{ALC@noend}}{ 148 \newcommand{\ENDIF}{\end{ALC@if}} 149 \newcommand{\ENDFOR}{\end{ALC@for}} 150 \newcommand{\ENDWHILE}{\end{ALC@whl}} 151 \newcommand{\ENDLOOP}{\end{ALC@loop}} 152 }{ 153 \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif} 154 \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor} 155 \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile} 156 \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop} 157 } 158 \renewcommand{\@toodeep}{} 159 \begin{list}{\ALC@lno}{\setcounter{ALC@line}{0}\setcounter{ALC@rem}{0}% 160 \itemsep\z@ \itemindent\z@ \listparindent\z@% 161 \partopsep\z@ \parskip\z@ \parsep\z@% 162 \labelsep 0.5em \topsep 0.2em% 163 \ifthenelse{\equal{#1}{0}} 164 {\labelwidth 0.5em } 165 {\labelwidth 1.2em } 166 \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep} 167 \ALC@tlm\labelsep 168 } 169 } 170 {% 171 \setcounter{ALCPLUS@lastline}{\value{ALC@line}}% 172 \end{list}} 173 174 \newcommand{\continuecounting}{\setcounter{ALC@line}{\value{ALCPLUS@lastline}}} 175 \newcommand{\startcounting}[1]{\setcounter{ALC@line}{#1}\addtocounter{ALC@line}{-1}} 176 177 \newcommand{\EMPTY}{\item[]} 178 \newcommand{\SPACE}{\vspace{3mm}} 179 \newcommand{\SHORTSPACE}{\vspace{1mm}} 180 \newcommand{\newlinetag}[3]{\newcommand{#1}[#2]{\item[#3]}} 181 \newcommand{\newconstruct}[5]{% 182 \newenvironment{ALC@\string#1}{\begin{ALC@g}}{\end{ALC@g}} 183 \newcommand{#1}[2][default]{\ALC@it#2\ ##2\ #3% 184 \ALC@com{##1}\begin{ALC@\string#1}} 185 \ifthenelse{\boolean{ALC@noend}}{ 186 \newcommand{#4}{\end{ALC@\string#1}} 187 }{ 188 \newcommand{#4}{\end{ALC@\string#1}\ALC@it#5} 189 } 190 } 191 192 \newconstruct{\INDENT}{}{}{\ENDINDENT}{} 193 194 \newcommand{\setlinenosize}[1]{\renewcommand{\algorithmiclnosize}{#1}} 195 \newcommand{\setlinenofont}[1]{\renewcommand{\algorithmiclnofont}{#1}}