/pkg/vignettes/algorithmic.sty

https://code.google.com/ · TeX · 232 lines · 189 code · 0 blank · 43 comment · 0 complexity · 7c5e694739a8780710b1924ea3ea5592 MD5 · raw file

  1. %%
  2. %% This is file `algorithmic.sty',
  3. %% generated with the docstrip utility.
  4. %%
  5. %% The original source files were:
  6. %%
  7. %% algorithms.dtx (with options: `algorithmic')
  8. %% This is a generated file.
  9. %%
  10. %% Copyright (C) 1994-2004 Peter Williams <pwil3058@bigpond.net.au>
  11. %% Copyright (C) 2005-2009 Rogério Brito <rbrito@ime.usp.br>
  12. %%
  13. %% This document file is free software; you can redistribute it and/or
  14. %% modify it under the terms of the GNU Lesser General Public License as
  15. %% published by the Free Software Foundation; either version 2 of the
  16. %% License, or (at your option) any later version.
  17. %%
  18. %% This document file is distributed in the hope that it will be useful, but
  19. %% WITHOUT ANY WARRANTY; without even the implied warranty of
  20. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  21. %% General Public License for more details.
  22. %%
  23. %% You should have received a copy of the GNU Lesser General Public License
  24. %% along with this document file; if not, write to the Free Software
  25. %% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  26. %% USA.
  27. %%
  28. \NeedsTeXFormat{LaTeX2e}[1999/12/01]
  29. \ProvidesPackage{algorithmic}
  30. [2009/08/24 v0.1 Document Style `algorithmic']
  31. % The algorithmic.sty package:
  32. \RequirePackage{ifthen}
  33. \RequirePackage{keyval}
  34. \newboolean{ALC@noend}
  35. \setboolean{ALC@noend}{false}
  36. \newcounter{ALC@unique} % new counter to make lines numbers be internally
  37. \setcounter{ALC@unique}{0} % different in different algorithms
  38. \newcounter{ALC@line} % counter for current line
  39. \newcounter{ALC@rem} % counter for lines not printed
  40. \newcounter{ALC@depth}
  41. \newlength{\ALC@tlm}
  42. %
  43. \DeclareOption{noend}{\setboolean{ALC@noend}{true}}
  44. %
  45. \ProcessOptions
  46. %
  47. % For keyval-style options
  48. \def\algsetup{\setkeys{ALG}}
  49. %
  50. % For indentation of algorithms
  51. \newlength{\algorithmicindent}
  52. \setlength{\algorithmicindent}{0pt}
  53. \define@key{ALG}{indent}{\setlength{\algorithmicindent}{#1}}
  54. \ifthenelse{\lengthtest{\algorithmicindent=0pt}}%
  55. {\setlength{\algorithmicindent}{1em}}{}
  56. %
  57. % For line numbers' delimiters
  58. \newcommand{\ALC@linenodelimiter}{:}
  59. \define@key{ALG}{linenodelimiter}{\renewcommand{\ALC@linenodelimiter}{#1}}
  60. %
  61. % For line numbers' size
  62. \newcommand{\ALC@linenosize}{\footnotesize}
  63. \define@key{ALG}{linenosize}{\renewcommand{\ALC@linenosize}{#1}}
  64. %
  65. % ALGORITHMIC
  66. \newcommand{\algorithmicrequire}{\textbf{Require:}}
  67. \newcommand{\algorithmicensure}{\textbf{Ensure:}}
  68. \newcommand{\algorithmiccomment}[1]{\{#1\}}
  69. \newcommand{\algorithmicend}{\textbf{end}}
  70. \newcommand{\algorithmicif}{\textbf{if}}
  71. \newcommand{\algorithmicthen}{\textbf{then}}
  72. \newcommand{\algorithmicelse}{\textbf{else}}
  73. \newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}
  74. \newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif}
  75. \newcommand{\algorithmicfor}{\textbf{for}}
  76. \newcommand{\algorithmicforall}{\textbf{for all}}
  77. \newcommand{\algorithmicdo}{\textbf{do}}
  78. \newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor}
  79. \newcommand{\algorithmicwhile}{\textbf{while}}
  80. \newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile}
  81. \newcommand{\algorithmicloop}{\textbf{loop}}
  82. \newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop}
  83. \newcommand{\algorithmicrepeat}{\textbf{repeat}}
  84. \newcommand{\algorithmicuntil}{\textbf{until}}
  85. \newcommand{\algorithmicprint}{\textbf{print}}
  86. \newcommand{\algorithmicreturn}{\textbf{return}}
  87. \newcommand{\algorithmicand}{\textbf{and}}
  88. \newcommand{\algorithmicor}{\textbf{or}}
  89. \newcommand{\algorithmicxor}{\textbf{xor}}
  90. \newcommand{\algorithmicnot}{\textbf{not}}
  91. \newcommand{\algorithmicto}{\textbf{to}}
  92. \newcommand{\algorithmicinputs}{\textbf{inputs}}
  93. \newcommand{\algorithmicoutputs}{\textbf{outputs}}
  94. \newcommand{\algorithmicglobals}{\textbf{globals}}
  95. \newcommand{\algorithmicbody}{\textbf{do}}
  96. \newcommand{\algorithmictrue}{\textbf{true}}
  97. \newcommand{\algorithmicfalse}{\textbf{false}}
  98. \def\ALC@item[#1]{%
  99. \if@noparitem \@donoparitem
  100. \else \if@inlabel \indent \par \fi
  101. \ifhmode \unskip\unskip \par \fi
  102. \if@newlist \if@nobreak \@nbitem \else
  103. \addpenalty\@beginparpenalty
  104. \addvspace\@topsep \addvspace{-\parskip}\fi
  105. \else \addpenalty\@itempenalty \addvspace\itemsep
  106. \fi
  107. \global\@inlabeltrue
  108. \fi
  109. \everypar{\global\@minipagefalse\global\@newlistfalse
  110. \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels
  111. \penalty\z@ \fi
  112. \everypar{}}\global\@nobreakfalse
  113. \if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi
  114. \sbox\@tempboxa{\makelabel{#1}}%
  115. \global\setbox\@labels
  116. \hbox{\unhbox\@labels \hskip \itemindent
  117. \hskip -\labelwidth \hskip -\ALC@tlm
  118. \ifdim \wd\@tempboxa >\labelwidth
  119. \box\@tempboxa
  120. \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
  121. \hskip \ALC@tlm}\ignorespaces}
  122. %
  123. \newenvironment{algorithmic}[1][0]{
  124. \setcounter{ALC@depth}{\@listdepth}%
  125. \let\@listdepth\c@ALC@depth%
  126. \let\@item\ALC@item%
  127. \newcommand{\ALC@lno}{%
  128. \ifthenelse{\equal{\arabic{ALC@rem}}{0}}
  129. {{\ALC@linenosize \arabic{ALC@line}\ALC@linenodelimiter}}{}%
  130. }
  131. \let\@listii\@listi
  132. \let\@listiii\@listi
  133. \let\@listiv\@listi
  134. \let\@listv\@listi
  135. \let\@listvi\@listi
  136. \let\@listvii\@listi
  137. \newenvironment{ALC@g}{
  138. \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@
  139. \listparindent\z@ \rightmargin\z@
  140. \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@
  141. \leftmargin \algorithmicindent%1em
  142. \addtolength{\ALC@tlm}{\leftmargin}
  143. }
  144. }
  145. {\end{list}}
  146. \newcommand{\ALC@it}{%
  147. \stepcounter{ALC@rem}%
  148. \ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}%
  149. \stepcounter{ALC@line}%
  150. \refstepcounter{ALC@unique}%
  151. \item\def\@currentlabel{\theALC@line}%
  152. }
  153. \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
  154. {}{\ \algorithmiccomment{##1}}}
  155. \newcommand{\REQUIRE}{\item[\algorithmicrequire]}
  156. \newcommand{\ENSURE}{\item[\algorithmicensure]}
  157. \newcommand{\PRINT}{\ALC@it\algorithmicprint{} \ }
  158. \newcommand{\RETURN}{\ALC@it\algorithmicreturn{} \ }
  159. \newcommand{\TRUE}{\algorithmictrue{}}
  160. \newcommand{\FALSE}{\algorithmicfalse{}}
  161. \newcommand{\AND}{\algorithmicand{} }
  162. \newcommand{\OR}{\algorithmicor{} }
  163. \newcommand{\XOR}{\algorithmicxor{} }
  164. \newcommand{\NOT}{\algorithmicnot{} }
  165. \newcommand{\TO}{\algorithmicto{} }
  166. \newcommand{\STATE}{\ALC@it}
  167. \newcommand{\STMT}{\ALC@it}
  168. \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}
  169. \newenvironment{ALC@inputs}{\begin{ALC@g}}{\end{ALC@g}}
  170. \newenvironment{ALC@outputs}{\begin{ALC@g}}{\end{ALC@g}}
  171. \newenvironment{ALC@globals}{\begin{ALC@g}}{\end{ALC@g}}
  172. \newenvironment{ALC@body}{\begin{ALC@g}}{\end{ALC@g}}
  173. \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}
  174. \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}
  175. \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}
  176. \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}
  177. \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}
  178. \renewcommand{\\}{\@centercr}
  179. \newcommand{\INPUTS}[1][default]{\ALC@it\algorithmicinputs\ \ALC@com{##1}\begin{ALC@inputs}}
  180. \newcommand{\ENDINPUTS}{\end{ALC@inputs}}
  181. \newcommand{\OUTPUTS}[1][default]{\ALC@it\algorithmicoutputs\ \ALC@com{##1}\begin{ALC@outputs}}
  182. \newcommand{\ENDOUTPUTS}{\end{ALC@outputs}}
  183. \newcommand{\GLOBALS}{\ALC@it\algorithmicglobals\ }
  184. \newcommand{\BODY}[1][default]{\ALC@it\algorithmicbody\ \ALC@com{##1}\begin{ALC@body}}
  185. \newcommand{\ENDBODY}{\end{ALC@body}}
  186. \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%
  187. \ALC@com{##1}\begin{ALC@if}}
  188. \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%
  189. \ALC@com{##1}\begin{ALC@if}}
  190. \newcommand{\ELSIF}[2][default]%
  191. {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%
  192. \ALC@com{##1}\begin{ALC@if}}
  193. \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%
  194. \ALC@com{##1}\begin{ALC@for}}
  195. \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %
  196. \algorithmicdo%
  197. \ALC@com{##1}\begin{ALC@for}}
  198. \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %
  199. \algorithmicdo%
  200. \ALC@com{##1}\begin{ALC@whl}}
  201. \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%
  202. \ALC@com{##1}\begin{ALC@loop}}
  203. \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%
  204. \ALC@com{##1}\begin{ALC@rpt}}
  205. \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}
  206. \ifthenelse{\boolean{ALC@noend}}{
  207. \newcommand{\ENDIF}{\end{ALC@if}}
  208. \newcommand{\ENDFOR}{\end{ALC@for}}
  209. \newcommand{\ENDWHILE}{\end{ALC@whl}}
  210. \newcommand{\ENDLOOP}{\end{ALC@loop}}
  211. }{
  212. \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}
  213. \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}
  214. \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}
  215. \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}
  216. }
  217. \renewcommand{\@toodeep}{}
  218. \begin{list}{\ALC@lno}{\setcounter{ALC@rem}{0}\setcounter{ALC@line}{0}%
  219. \itemsep\z@ \itemindent\z@ \listparindent\z@%
  220. \partopsep\z@ \parskip\z@ \parsep\z@%
  221. \labelsep 0.5em \topsep 0.2em%
  222. \ifthenelse{\equal{#1}{0}}
  223. {\labelwidth 0.5em }
  224. {\labelwidth 1.2em }
  225. \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}
  226. \ALC@tlm\labelsep
  227. }
  228. }
  229. {\end{list}}
  230. \endinput
  231. %%
  232. %% End of file `algorithmic.sty'.