summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pseudocode/pseudocode.sty
blob: 3046352df529075d44ba908eefc7533a6181dab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
%%
%% January 14, 2004
%%
%% pseudocode.sty
%%
%%  S O F T W A R E   L I C E N S E
%% =================================
%%
%% The file  pseudocode.sty
%% is referred to as `the pseudocode package'
%% or simply `the package'.
%%
%% The pseudocode package is copyright 1999 D.L. Kreher and D.R. Stinson.
%%
%% The pseudocode package and its drivers may be distributed and/or modified
%% under the conditions of the LaTeX Project Public License, either version
%% 1.3 of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%%
%% The package has the LPPL maintenance status "maintained".
%%
%% The Current Maintainer is Donald L. Kreher.
%%
%% end of software license
%%
%% E-MAIL:   kreher@mtu.edu    dstinson@uwaterloo.ca
%%
%% DESCRIPTION:
%%   pseudocode.sty is a LaTeX style option, consisting of:
%%   the environment pseudocode
%%
%% INSTALLATION:
%%   Put this file where your TeX looks for inputs.
%%
%% DOCUMENTATION:
%%  See pseudocode.tex.
%%
%%  \RETURN altered  Oct 22, 1999
%%  Allowed for two column  formating  Dec 2, 2002
%%  \BREAK for breaking out of loops added Oct 10, 2003
%%  \FORALL  added Oct 10, 2003
%%
%% CODE:
\typeout{**                                           }
\typeout{** Document Style `pseudocode' - environment }
\typeout{** by D.L. Kreher and D.R. Stinson           }
\typeout{**                                           }
\typeout{** The pseudocode environment was originally developed for the book}
\typeout{** Combinatorial Algorithms: Enumeration, Generation, and Search}
\typeout{** CRC Press, 1999. }

%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pseudocode}
%
\if@twocolumn
\newlength{\pcode@width}
\setlength{\pcode@width}{\columnwidth}
\addtolength{\pcode@width}{-40pt}
\else
\newlength{\pcode@width}
\setlength{\pcode@width}{\textwidth}
\addtolength{\pcode@width}{-40pt}
\fi
%
\RequirePackage{fancybox}
\RequirePackage{ifthen}
%
\newcommand{\pcode@AF}[1]{\mbox{\textsc{#1}}} % Algorithm font
\newcounter{pseudocode}[section]
\newcounter{pseudonum}
\renewcommand{\thepseudonum}{\arabic{pseudonum}}
\newcommand{\pcode@tab}[1]{\hspace*{#1ex}}
\renewcommand{\thepseudocode}{\thesection.\arabic{pseudocode}}
%
\newboolean{pcode@plain}
\newboolean{pcode@ruled}
\newboolean{pcode@disp}
\newboolean{pcode@shad}
\newboolean{pcode@dbox}
\newboolean{pcode@obox}
\newboolean{pcode@Obox}
\newboolean{pcode@fbox}
%
\newenvironment{pseudocode}[3][plain]
{%
 \refstepcounter{pseudocode}%
 \ifthenelse{\equal{#1}{plain}}{\setboolean{pcode@plain}{true}}{\setboolean{pcode@plain}{false}}%
 \ifthenelse{\equal{#1}{ruled}}{\setboolean{pcode@ruled}{true}}{\setboolean{pcode@ruled}{false}}%
 \ifthenelse{\equal{#1}{display}}{\setboolean{pcode@disp}{true}}{\setboolean{pcode@disp}{false}}%
 \ifthenelse{\equal{#1}{shadowbox}}{\setboolean{pcode@shad}{true}}{\setboolean{pcode@shad}{false}}%
 \ifthenelse{\equal{#1}{doublebox}}{\setboolean{pcode@dbox}{true}}{\setboolean{pcode@dbox}{false}}%
 \ifthenelse{\equal{#1}{ovalbox}}{\setboolean{pcode@obox}{true}}{\setboolean{pcode@obox}{false}}%
 \ifthenelse{\equal{#1}{Ovalbox}}{\setboolean{pcode@Obox}{true}}{\setboolean{pcode@Obox}{false}}%
 \ifthenelse{\equal{#1}{framebox}}{\setboolean{pcode@fbox}{true}}{\setboolean{pcode@fbox}{false}}%
 \setcounter{pseudonum}{0}%
 \ifthenelse{\boolean{pcode@disp}}%
 {%
  \noindent\begin{math}%
 }%
 {%
  \begin{Sbox}%
  \begin{minipage}{\pcode@width}%
  \ifthenelse{\boolean{pcode@ruled}}
  {
   \noindent\rule{\pcode@width}{1pt}\hfill\\
   {\bfseries Algorithm \thepseudocode:\pcode@tab{1}}\pcode@AF{#2}($#3$)\\
   \noindent\rule{\pcode@width}{1pt}\hfill\\[1ex]
  }
  {
   {\bfseries Algorithm \thepseudocode:\pcode@tab{1}}\pcode@AF{#2}($#3$)\\[2ex]
  }
  \noindent\begin{math}\begin{array}{@{\pcode@tab{1}}lr@{}}%
 }{}%
}%
{%
 \ifthenelse{\boolean{pcode@disp}}%
 {%
  \end{math}
 }%
 {%
  \ifthenelse{\boolean{pcode@ruled}}
  {
   \end{array}\end{math}\\[1ex]
   \noindent\rule{\pcode@width}{1pt}\hfill
   \end{minipage}\end{Sbox}\bigskip\noindent%
  }
  {\end{array}\end{math}\end{minipage}\end{Sbox}\bigskip\noindent}%
  \ifthenelse{\boolean{pcode@plain}}{\TheSbox}{}%
  \ifthenelse{\boolean{pcode@ruled}}{\TheSbox}{}%
  \ifthenelse{\boolean{pcode@shad}}{\shadowbox{\TheSbox}}{}%
  \ifthenelse{\boolean{pcode@dbox}}{\doublebox{\TheSbox}}{}%
  \ifthenelse{\boolean{pcode@obox}}{\cornersize*{4ex}\ovalbox{\TheSbox}}{}%
  \ifthenelse{\boolean{pcode@Obox}}{\cornersize*{4ex}\Ovalbox{\TheSbox}}{}%
  \ifthenelse{\boolean{pcode@fbox}}{\fbox{\TheSbox}}{}%
  \bigskip%
 }%
}%
%
\newcommand{\STMTNUM}[2]{&\refstepcounter{pseudonum}\hspace*{#1}%
\mbox{(\thepseudonum)\label{#2}}}
\newcommand{\LOCAL}[1]{\mbox{\bfseries local}\pcode@tab{1}#1}
\newcommand{\GLOBAL}[1]{\mbox{\bfseries global}\pcode@tab{1}#1}
\newcommand{\EXTERNAL}[1]{\mbox{\bfseries external}\pcode@tab{1}#1}
\newcommand{\COMMENT}[1]%
{%
 \vspace*{1ex}%
 \mbox{\bfseries comment:}\pcode@tab{.5} \mbox{#1}
}
\newcommand{\BEGIN}{\left\{\begin{array}{@{}lr@{}}}
\newcommand{\END}{\end{array}\right.}
\newcommand{\PROCEDURE}[2]%
{%
 \mbox{\bfseries procedure }\pcode@AF{#1}(\ensuremath{#2})\\%
 \begin{array}{@{\pcode@tab{1}}l@{}}%
}
\newcommand{\ENDPROCEDURE}{\vspace*{2ex}\end{array}\\ }
\newcommand{\CALL}[2]{\pcode@AF{#1}(#2)} % 
\newcommand{\MAIN}{\mbox{\bfseries main}\\\begin{array}{@{\pcode@tab{1}}lr@{}}}
\newcommand{\ENDMAIN}{\end{array}}
\newcommand{\RETURN}[1]{\ifthenelse{\equal{#1}{} }%
{\mbox{\bfseries return }}%
{\mbox{\bfseries return }(#1)}}
\newcommand{\OUTPUT}[1]{\mbox{\bfseries output }(#1)}
\newcommand{\EXIT}{\mbox{\bfseries exit }}
\newcommand{\BREAK}{\mbox{\bfseries break }}
\newcommand{\IF}{\mbox{\bfseries if }}
\newcommand{\LET}{\mbox{\bfseries let }}
\newcommand{\CTHEN}{\pcode@tab{1}\mbox{ \bfseries then }}
\newcommand{\CELSE}{\pcode@tab{1}\mbox{ \bfseries else }}
\newcommand{\THEN}{\\\pcode@tab{1}\mbox{ \bfseries then }}
\newcommand{\ELSE}{\\\pcode@tab{1}\mbox{ \bfseries else }}
\newcommand{\ELSEIF}{\\\pcode@tab{1}\mbox{ \bfseries else if }}
\newcommand{\FOREACH}{\mbox{\bfseries for each }}
\newcommand{\FORALL}{\mbox{\bfseries for all }}
\newcommand{\FOR}{\mbox{\bfseries for }}
\newcommand{\TO}{\mbox{ \bfseries to }}
\newcommand{\DOWNTO}{\mbox{ \bfseries downto }}
\newcommand{\CASE}{\mbox{\bfseries case }}
\newcommand{\OF}{\\\pcode@tab{1}\mbox{ \bfseries of }\BEGIN}
\newcommand{\ENDCASE}{\END}
\newcommand{\AND}{\mbox{ \bfseries and }}
\newcommand{\OR}{\mbox{ \bfseries or }}
\newcommand{\NOT}{\mbox{ \bfseries not }}
\newcommand{\SUCCESS}{\mbox{ \bfseries success }}
\newcommand{\FAIL}{\mbox{ \bfseries fail }}
\newcommand{\TRUE}{\mbox{ \bfseries true }}
\newcommand{\FALSE}{\mbox{ \bfseries false }}
\newcommand{\GOTO}{\mbox{\bfseries go to }}
\newcommand{\DO}{\\\pcode@tab{1}\mbox{ \bfseries do }}
\newcommand{\ADO}{\mbox{ \bfseries do }}
\newcommand{\WHILE}{\mbox{\bfseries while }}
\newcommand{\REPEAT}{\mbox{\bfseries repeat }\\\begin{array}{@{\pcode@tab{1}}lr@{}}}
\newcommand{\UNTIL}{\end{array}\\\mbox{\bfseries until }}
\newcommand{\GETS}{\leftarrow}
\endinput
%% END pseudodcode.sty