📚 The CoCalc Library - books, templates and other resources
License: OTHER
% ALGORITHMIC STYLE -- Released 8 APRIL 19961% for LaTeX version 2e2% Copyright -- 1994 Peter Williams3% E-mail [email protected]4%5% Modified by Alex Smola (08/2000)6% E-mail [email protected]7%8\NeedsTeXFormat{LaTeX2e}9\ProvidesPackage{algorithmic}10\typeout{Document Style `algorithmic' - environment}11%12\RequirePackage{ifthen}13\RequirePackage{calc}14\newboolean{ALC@noend}15\setboolean{ALC@noend}{false}16\newcounter{ALC@line}17\newcounter{ALC@rem}18\newlength{\ALC@tlm}19%20\DeclareOption{noend}{\setboolean{ALC@noend}{true}}21%22\ProcessOptions23%24% ALGORITHMIC25\newcommand{\algorithmicrequire}{\textbf{Require:}}26\newcommand{\algorithmicensure}{\textbf{Ensure:}}27\newcommand{\algorithmiccomment}[1]{\{#1\}}28\newcommand{\algorithmicend}{\textbf{end}}29\newcommand{\algorithmicif}{\textbf{if}}30\newcommand{\algorithmicthen}{\textbf{then}}31\newcommand{\algorithmicelse}{\textbf{else}}32\newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}33\newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif}34\newcommand{\algorithmicfor}{\textbf{for}}35\newcommand{\algorithmicforall}{\textbf{for all}}36\newcommand{\algorithmicdo}{\textbf{do}}37\newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor}38\newcommand{\algorithmicwhile}{\textbf{while}}39\newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile}40\newcommand{\algorithmicloop}{\textbf{loop}}41\newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop}42\newcommand{\algorithmicrepeat}{\textbf{repeat}}43\newcommand{\algorithmicuntil}{\textbf{until}}4445%changed by alex smola46\newcommand{\algorithmicinput}{\textbf{input}}47\newcommand{\algorithmicoutput}{\textbf{output}}48\newcommand{\algorithmicset}{\textbf{set}}49\newcommand{\algorithmictrue}{\textbf{true}}50\newcommand{\algorithmicfalse}{\textbf{false}}51\newcommand{\algorithmicand}{\textbf{and\ }}52\newcommand{\algorithmicor}{\textbf{or\ }}53\newcommand{\algorithmicfunction}{\textbf{function}}54\newcommand{\algorithmicendfunction}{\algorithmicend\ \algorithmicfunction}55\newcommand{\algorithmicmain}{\textbf{main}}56\newcommand{\algorithmicendmain}{\algorithmicend\ \algorithmicmain}57%end changed by alex smola5859\def\ALC@item[#1]{%60\if@noparitem \@donoparitem61\else \if@inlabel \indent \par \fi62\ifhmode \unskip\unskip \par \fi63\if@newlist \if@nobreak \@nbitem \else64\addpenalty\@beginparpenalty65\addvspace\@topsep \addvspace{-\parskip}\fi66\else \addpenalty\@itempenalty \addvspace\itemsep67\fi68\global\@inlabeltrue69\fi70\everypar{\global\@minipagefalse\global\@newlistfalse71\if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels72\penalty\z@ \fi73\everypar{}}\global\@nobreakfalse74\if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi75\sbox\@tempboxa{\makelabel{#1}}%76\global\setbox\@labels77\hbox{\unhbox\@labels \hskip \itemindent78\hskip -\labelwidth \hskip -\ALC@tlm79\ifdim \wd\@tempboxa >\labelwidth80\box\@tempboxa81\else \hbox to\labelwidth {\unhbox\@tempboxa}\fi82\hskip \ALC@tlm}\ignorespaces}83%84\newenvironment{algorithmic}[1][0]{85\let\@item\ALC@item86\newcommand{\ALC@lno}{%87\ifthenelse{\equal{\arabic{ALC@rem}}{0}}88{{\footnotesize \arabic{ALC@line}:}}{}%89}90\let\@listii\@listi91\let\@listiii\@listi92\let\@listiv\@listi93\let\@listv\@listi94\let\@listvi\@listi95\let\@listvii\@listi96\newenvironment{ALC@g}{97\begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@98\listparindent\z@ \rightmargin\z@99\topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@100\leftmargin 1em101\addtolength{\ALC@tlm}{\leftmargin}102}103}104{\end{list}}105\newcommand{\ALC@it}{\addtocounter{ALC@line}{1}\addtocounter{ALC@rem}{1}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item}106\newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%107{}{\ \algorithmiccomment{##1}}}108\newcommand{\REQUIRE}{\item[\algorithmicrequire]}109\newcommand{\ENSURE}{\item[\algorithmicensure]}110\newcommand{\STATE}{\ALC@it}111\newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}112%changes by alex smola113\newcommand{\INPUT}{\item[\algorithmicinput]}114\newcommand{\OUTPUT}{\item[\algorithmicoutput]}115\newcommand{\SET}{\item[\algorithmicset]}116% \newcommand{\TRUE}{\algorithmictrue}117% \newcommand{\FALSE}{\algorithmicfalse}118\newcommand{\AND}{\algorithmicand}119\newcommand{\OR}{\algorithmicor}120\newenvironment{ALC@func}{\begin{ALC@g}}{\end{ALC@g}}121\newenvironment{ALC@main}{\begin{ALC@g}}{\end{ALC@g}}122%end changes by alex smola123\newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}124\newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}125\newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}126\newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}127\newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}128\renewcommand{\\}{\@centercr}129\newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%130\ALC@com{##1}\begin{ALC@if}}131\newcommand{\SHORTIF}[2]{\ALC@it\algorithmicif\ ##1\132\algorithmicthen\ {##2}}133\newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%134\ALC@com{##1}\begin{ALC@if}}135\newcommand{\ELSIF}[2][default]%136{\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%137\ALC@com{##1}\begin{ALC@if}}138\newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%139\ALC@com{##1}\begin{ALC@for}}140\newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %141\algorithmicdo%142\ALC@com{##1}\begin{ALC@for}}143\newcommand{\SHORTFORALL}[2]{\ALC@it\algorithmicforall\ ##1\ %144\algorithmicdo\ {##2}}145\newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %146\algorithmicdo%147\ALC@com{##1}\begin{ALC@whl}}148\newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%149\ALC@com{##1}\begin{ALC@loop}}150%changed by alex smola151\newcommand{\FUNCTION}[2][default]{\ALC@it\algorithmicfunction\ ##2\ %152\ALC@com{##1}\begin{ALC@func}}153\newcommand{\MAIN}[2][default]{\ALC@it\algorithmicmain\ ##2\ %154\ALC@com{##1}\begin{ALC@main}}155%end changed by alex smola156\newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%157\ALC@com{##1}\begin{ALC@rpt}}158\newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}159\ifthenelse{\boolean{ALC@noend}}{160\newcommand{\ENDIF}{\end{ALC@if}}161\newcommand{\ENDFOR}{\end{ALC@for}}162\newcommand{\ENDWHILE}{\end{ALC@whl}}163\newcommand{\ENDLOOP}{\end{ALC@loop}}164\newcommand{\ENDFUNCTION}{\end{ALC@func}}165\newcommand{\ENDMAIN}{\end{ALC@main}}166}{167\newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}168\newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}169\newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}170\newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}171\newcommand{\ENDFUNCTION}{\end{ALC@func}\ALC@it\algorithmicendfunction}172\newcommand{\ENDMAIN}{\end{ALC@main}\ALC@it\algorithmicendmain}173}174\renewcommand{\@toodeep}{}175\begin{list}{\ALC@lno}{\setcounter{ALC@line}{0}\setcounter{ALC@rem}{0}%176\itemsep\z@ \itemindent\z@ \listparindent\z@%177\partopsep\z@ \parskip\z@ \parsep\z@%178\labelsep 0.5em \topsep 0.2em%179\ifthenelse{\equal{#1}{0}}180{\labelwidth 0.5em }181{\labelwidth 1.2em }182\leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}183\ALC@tlm\labelsep184}185}186{\end{list}}187188189190191192193194195196197198199200201202203