|
| 1 | +% ALGORITHMIC STYLE -- Released 8 APRIL 1996 |
| 2 | +% for LaTeX version 2e |
| 3 | +% Copyright -- 1994 Peter Williams |
| 4 | +% E-mail PeterWilliams@dsto.defence.gov.au |
| 5 | +% |
| 6 | +% Modified by Alex Smola (08/2000) |
| 7 | +% E-mail Alex.Smola@anu.edu.au |
| 8 | +% |
| 9 | +\NeedsTeXFormat{LaTeX2e} |
| 10 | +\ProvidesPackage{algorithmic} |
| 11 | +\typeout{Document Style `algorithmic' - environment} |
| 12 | +% |
| 13 | +\RequirePackage{ifthen} |
| 14 | +\RequirePackage{calc} |
| 15 | +\newboolean{ALC@noend} |
| 16 | +\setboolean{ALC@noend}{false} |
| 17 | +\newcounter{ALC@line} |
| 18 | +\newcounter{ALC@rem} |
| 19 | +\newlength{\ALC@tlm} |
| 20 | +% |
| 21 | +\DeclareOption{noend}{\setboolean{ALC@noend}{true}} |
| 22 | +% |
| 23 | +\ProcessOptions |
| 24 | +% |
| 25 | +% ALGORITHMIC |
| 26 | +\newcommand{\algorithmicrequire}{\textbf{Require:}} |
| 27 | +\newcommand{\algorithmicensure}{\textbf{Ensure:}} |
| 28 | +\newcommand{\algorithmiccomment}[1]{\{#1\}} |
| 29 | +\newcommand{\algorithmicend}{\textbf{end}} |
| 30 | +\newcommand{\algorithmicif}{\textbf{if}} |
| 31 | +\newcommand{\algorithmicthen}{\textbf{then}} |
| 32 | +\newcommand{\algorithmicelse}{\textbf{else}} |
| 33 | +\newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif} |
| 34 | +\newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif} |
| 35 | +\newcommand{\algorithmicfor}{\textbf{for}} |
| 36 | +\newcommand{\algorithmicforall}{\textbf{for all}} |
| 37 | +\newcommand{\algorithmicdo}{\textbf{do}} |
| 38 | +\newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor} |
| 39 | +\newcommand{\algorithmicwhile}{\textbf{while}} |
| 40 | +\newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile} |
| 41 | +\newcommand{\algorithmicloop}{\textbf{loop}} |
| 42 | +\newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop} |
| 43 | +\newcommand{\algorithmicrepeat}{\textbf{repeat}} |
| 44 | +\newcommand{\algorithmicuntil}{\textbf{until}} |
| 45 | + |
| 46 | +%changed by alex smola |
| 47 | +\newcommand{\algorithmicinput}{\textbf{input}} |
| 48 | +\newcommand{\algorithmicoutput}{\textbf{output}} |
| 49 | +\newcommand{\algorithmicset}{\textbf{set}} |
| 50 | +\newcommand{\algorithmictrue}{\textbf{true}} |
| 51 | +\newcommand{\algorithmicfalse}{\textbf{false}} |
| 52 | +\newcommand{\algorithmicand}{\textbf{and\ }} |
| 53 | +\newcommand{\algorithmicor}{\textbf{or\ }} |
| 54 | +\newcommand{\algorithmicfunction}{\textbf{function}} |
| 55 | +\newcommand{\algorithmicendfunction}{\algorithmicend\ \algorithmicfunction} |
| 56 | +\newcommand{\algorithmicmain}{\textbf{main}} |
| 57 | +\newcommand{\algorithmicendmain}{\algorithmicend\ \algorithmicmain} |
| 58 | +%end changed by alex smola |
| 59 | + |
| 60 | +\def\ALC@item[#1]{% |
| 61 | +\if@noparitem \@donoparitem |
| 62 | + \else \if@inlabel \indent \par \fi |
| 63 | + \ifhmode \unskip\unskip \par \fi |
| 64 | + \if@newlist \if@nobreak \@nbitem \else |
| 65 | + \addpenalty\@beginparpenalty |
| 66 | + \addvspace\@topsep \addvspace{-\parskip}\fi |
| 67 | + \else \addpenalty\@itempenalty \addvspace\itemsep |
| 68 | + \fi |
| 69 | + \global\@inlabeltrue |
| 70 | +\fi |
| 71 | +\everypar{\global\@minipagefalse\global\@newlistfalse |
| 72 | + \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels |
| 73 | + \penalty\z@ \fi |
| 74 | + \everypar{}}\global\@nobreakfalse |
| 75 | +\if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi |
| 76 | +\sbox\@tempboxa{\makelabel{#1}}% |
| 77 | +\global\setbox\@labels |
| 78 | + \hbox{\unhbox\@labels \hskip \itemindent |
| 79 | + \hskip -\labelwidth \hskip -\ALC@tlm |
| 80 | + \ifdim \wd\@tempboxa >\labelwidth |
| 81 | + \box\@tempboxa |
| 82 | + \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi |
| 83 | + \hskip \ALC@tlm}\ignorespaces} |
| 84 | +% |
| 85 | +\newenvironment{algorithmic}[1][0]{ |
| 86 | +\let\@item\ALC@item |
| 87 | + \newcommand{\ALC@lno}{% |
| 88 | +\ifthenelse{\equal{\arabic{ALC@rem}}{0}} |
| 89 | +{{\footnotesize \arabic{ALC@line}:}}{}% |
| 90 | +} |
| 91 | +\let\@listii\@listi |
| 92 | +\let\@listiii\@listi |
| 93 | +\let\@listiv\@listi |
| 94 | +\let\@listv\@listi |
| 95 | +\let\@listvi\@listi |
| 96 | +\let\@listvii\@listi |
| 97 | + \newenvironment{ALC@g}{ |
| 98 | + \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@ |
| 99 | + \listparindent\z@ \rightmargin\z@ |
| 100 | + \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@ |
| 101 | + \leftmargin 1em |
| 102 | + \addtolength{\ALC@tlm}{\leftmargin} |
| 103 | + } |
| 104 | + } |
| 105 | + {\end{list}} |
| 106 | + \newcommand{\ALC@it}{\addtocounter{ALC@line}{1}\addtocounter{ALC@rem}{1}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item} |
| 107 | + \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}% |
| 108 | +{}{\ \algorithmiccomment{##1}}} |
| 109 | + \newcommand{\REQUIRE}{\item[\algorithmicrequire]} |
| 110 | + \newcommand{\ENSURE}{\item[\algorithmicensure]} |
| 111 | + \newcommand{\STATE}{\ALC@it} |
| 112 | + \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}} |
| 113 | +%changes by alex smola |
| 114 | + \newcommand{\INPUT}{\item[\algorithmicinput]} |
| 115 | + \newcommand{\OUTPUT}{\item[\algorithmicoutput]} |
| 116 | + \newcommand{\SET}{\item[\algorithmicset]} |
| 117 | +% \newcommand{\TRUE}{\algorithmictrue} |
| 118 | +% \newcommand{\FALSE}{\algorithmicfalse} |
| 119 | + \newcommand{\AND}{\algorithmicand} |
| 120 | + \newcommand{\OR}{\algorithmicor} |
| 121 | + \newenvironment{ALC@func}{\begin{ALC@g}}{\end{ALC@g}} |
| 122 | + \newenvironment{ALC@main}{\begin{ALC@g}}{\end{ALC@g}} |
| 123 | +%end changes by alex smola |
| 124 | + \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}} |
| 125 | + \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}} |
| 126 | + \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}} |
| 127 | + \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}} |
| 128 | + \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}} |
| 129 | + \renewcommand{\\}{\@centercr} |
| 130 | + \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen% |
| 131 | +\ALC@com{##1}\begin{ALC@if}} |
| 132 | + \newcommand{\SHORTIF}[2]{\ALC@it\algorithmicif\ ##1\ |
| 133 | + \algorithmicthen\ {##2}} |
| 134 | + \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse% |
| 135 | +\ALC@com{##1}\begin{ALC@if}} |
| 136 | + \newcommand{\ELSIF}[2][default]% |
| 137 | +{\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen% |
| 138 | +\ALC@com{##1}\begin{ALC@if}} |
| 139 | + \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo% |
| 140 | +\ALC@com{##1}\begin{ALC@for}} |
| 141 | + \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ % |
| 142 | +\algorithmicdo% |
| 143 | +\ALC@com{##1}\begin{ALC@for}} |
| 144 | + \newcommand{\SHORTFORALL}[2]{\ALC@it\algorithmicforall\ ##1\ % |
| 145 | + \algorithmicdo\ {##2}} |
| 146 | + \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ % |
| 147 | +\algorithmicdo% |
| 148 | +\ALC@com{##1}\begin{ALC@whl}} |
| 149 | + \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop% |
| 150 | +\ALC@com{##1}\begin{ALC@loop}} |
| 151 | +%changed by alex smola |
| 152 | + \newcommand{\FUNCTION}[2][default]{\ALC@it\algorithmicfunction\ ##2\ % |
| 153 | + \ALC@com{##1}\begin{ALC@func}} |
| 154 | + \newcommand{\MAIN}[2][default]{\ALC@it\algorithmicmain\ ##2\ % |
| 155 | + \ALC@com{##1}\begin{ALC@main}} |
| 156 | +%end changed by alex smola |
| 157 | + \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat% |
| 158 | + \ALC@com{##1}\begin{ALC@rpt}} |
| 159 | + \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1} |
| 160 | + \ifthenelse{\boolean{ALC@noend}}{ |
| 161 | + \newcommand{\ENDIF}{\end{ALC@if}} |
| 162 | + \newcommand{\ENDFOR}{\end{ALC@for}} |
| 163 | + \newcommand{\ENDWHILE}{\end{ALC@whl}} |
| 164 | + \newcommand{\ENDLOOP}{\end{ALC@loop}} |
| 165 | + \newcommand{\ENDFUNCTION}{\end{ALC@func}} |
| 166 | + \newcommand{\ENDMAIN}{\end{ALC@main}} |
| 167 | + }{ |
| 168 | + \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif} |
| 169 | + \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor} |
| 170 | + \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile} |
| 171 | + \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop} |
| 172 | + \newcommand{\ENDFUNCTION}{\end{ALC@func}\ALC@it\algorithmicendfunction} |
| 173 | + \newcommand{\ENDMAIN}{\end{ALC@main}\ALC@it\algorithmicendmain} |
| 174 | + } |
| 175 | + \renewcommand{\@toodeep}{} |
| 176 | + \begin{list}{\ALC@lno}{\setcounter{ALC@line}{0}\setcounter{ALC@rem}{0}% |
| 177 | + \itemsep\z@ \itemindent\z@ \listparindent\z@% |
| 178 | + \partopsep\z@ \parskip\z@ \parsep\z@% |
| 179 | + \labelsep 0.5em \topsep 0.2em% |
| 180 | + \ifthenelse{\equal{#1}{0}} |
| 181 | + {\labelwidth 0.5em } |
| 182 | + {\labelwidth 1.2em } |
| 183 | + \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep} |
| 184 | + \ALC@tlm\labelsep |
| 185 | + } |
| 186 | + } |
| 187 | + {\end{list}} |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
0 commit comments