1 %%%%%% ************** line 192
4 %%--------------------------------------------------------------------------------------------------------------
6 %%--------------------------------------------------------------------------------------------------------------
7 %% Quoi de neuf depuis Algorithm 1.0 / What's new since Algorithm 1.0
9 %% Meilleure boîte de cadrage
10 %% Meilleure gestion des largeurs, permettant l'utilisation du mode multicolonnes, et permettant la césure
11 %% automatique des longues lignes de pseudo-instructions.
12 %% Widths are better handled, allowing the use of multicolumn mode, and also allowing auto line splitting into
13 %% long lines of pseudo-code.
14 %%--------------------------------------------------------------------------------------------------------------
16 %% Copyleft Pierre Chatelier
17 %% e-mail: pierre.chatelier@club-internet.fr
18 %% page perso: http://perso.club-internet.fr/ktd
20 %%Un package pour ecrire du code algorithmique
21 %%Il propose, dans l'environnement "algorithme", d'utiliser
22 %% -Des remarques, pour commenter le code ( \Rem{Remarque} )
23 %% -Des blocs, pour indenter le code ( \Block{code} )
24 %% -Des boucles "Tant Que...faire...Fait" ( \While{condition}{code} )
25 %% -Des boucles "Repeter...jusqu'a" ( \Repeat{code}{condition} ou \RepeatUntil{}{} )
26 %% -Des boucles "Pour...de...a...faire...Fin Pour" ( \ForFromTo{variable}{valeur début}{valeur fin}{code} )
27 %% -Des boucles "Pour...faire...Fin Pour" ( \For{controle de boucle}{code} )
28 %% -Des Si...Alors...Fin Si ( \If{condition}{code} ou \IfThen{condition}{code} )
29 %% -Des Si...Alors...Sinon...Fin Si ( \IfThenElse{condition}{code de alors}{code de sinon} )
30 %% -Des Selon que ... Fin Selon que ( \Switch{code} )
31 %% -Des fonctions ( \Function{parametres}{type de retour}{code} )
32 %% -Des procédures ( \Procedure{parametres}{code} )
33 %% -Une instruction de declaration de type ( \Type{nom ou liste de variable}{nom de type} )
34 %% -Quelques mots-clefs d'usage courant : \True, \False, \And, \Or et \Not
35 %% Les versions étoilées des commandes (\WhileDo*{}, \IfThen*{}, ... ; toutes sauf \Rem, \Block \Switch,
36 %% \Function et \Procedure) font tout sur la meme ligne
38 %% Une table des algorithmes est disponible via \listofalgorithms.
39 %% Pour introduire un algorithme dans cette table, il faut taper la commande "\caption{texte...}" dans un
40 %% environnemment "algorithme"
42 %% On peut passer une option au package : [french] ou [english] pour la langue des mots-clef
44 %%---------------------------------------------------------------------------------------------------------------
45 %%This is a package to write some algorithms.
46 %%It provides, within an "algorithm" environment, to use
47 %% -Comments ( \Rem{text} )
48 %% -Blocks, to indent code ( \Block{text} )
49 %% -While ... do ... done ( \While{condition}{code} )
50 %% -Repeat ... until ( \Repeat{code}{condition} or \RepeatUntil{}{} )
51 %% -Repeat ... until ( \RepeatUntil{code}{condition} )
52 %% -For...from...to...do...done ( \ForFromTo{variable}{initial value}{final value}{code} )
53 %% -For...do...done ( \For{loop control}{code} )
54 %% -If...then...end if ( \If{condition}{code} or \IfThen{condition}{code} )
55 %% -If...then...else...end if ( \IfThenElse{condition}{then code}{else code} )
56 %% -Switch ( \Switch{code} )
57 %% -Function ( \Function{parameters}{return type}{code} )
58 %% -Procedure ( \Procedure{parametres}{code} )
59 %% -A type declaration instruction ( \Type{name or list of variables}{type name} )
60 %% -Some useful keywords: \True, \False, \And, \Or and \Not.
61 %% Most of these commands have a star-form (\WhileDo*{}, \IfThen*{}, ... ; all but \Rem, \Block \Switch
62 %% \Function and \Procedure). These star-forms are single-lined.
64 %% A list of algorithms is provided through \listofalgorithms.
65 %% To add an entry in this table, the matching algorithm must have a caption, thanks to "\caption{text}".
67 %% You can specifiy an option to the package : [french] ou [english] for the language of the keywords.
69 %%---------------------------------------------------------------------------------------------------------------
72 %%-----------------------------------------------------------------%%
73 %%---------------------- Identification ---------------------------%%
74 \NeedsTeXFormat{LaTeX2e}
75 \ProvidesClass{algorithme} %Nom de la classe / Class name
76 %%-----------------------------------------------------------------%%
79 %%-----------------------------------------------------------------%%
80 %%------------------------ Inclusions -----------------------------%%
81 \RequirePackage{float, ifthen, calc}
84 %%-----------------------------------------------------------------%%
85 %%------------------------ Langage/Language -----------------------%%
87 %% Changer le langage dans le contexte de babel /Change langage according to babel
88 \@ifpackageloaded{babel}
90 %\iflanguage{french}{\def\alg@language{french}}{}
91 \iflanguage{english}{\def\alg@language{english}}{}
92 \iflanguage{american}{\def\alg@language{english}}{}
95 % \def\alg@language{french} %Langage par defaut / Default language
98 %% Tenir compte de l'option specifiee explicitement / Handle explicit langage option
99 %\DeclareOption{french}{\def\alg@language{french}}
100 \DeclareOption{english}{\def\alg@language{english}}
101 \DeclareOption{american}{\def\alg@language{english}}
102 \ProcessOptions\relax
105 %% Declaration des commandes / Commands declaration
106 \ifthenelse{\equal{\alg@language}{french}}
108 \def\alg@floatname{Algorithme}
109 \def\alg@listname{Liste des Algorithmes}
111 \newcommand{\@TRUE}{\textbf{vrai}}%
112 \newcommand{\@FALSE}{\textbf{faux}}%
113 \newcommand{\@AND}{\textbf{ET }}%
114 \newcommand{\@OR}{\textbf{OU }}%
115 \newcommand{\@NOT}{\textbf{$\neg$}}%
117 \newcommand{\@WHILE}{\textbf{Tant que }}%
118 \newcommand{\@DO}{\textbf{faire }}%
119 \newcommand{\@ENDWHILE}{\textbf{Fait}}%
121 \newcommand{\@REPEAT}{\textbf{R\'ep\'eter }}%
122 \newcommand{\@UNTIL}{\textbf{jusqu'\`a ce que }}%
124 \newcommand{\@FOR}{\textbf{Pour }}%
125 \newcommand{\@FROM}{\textbf{de }}%
126 \newcommand{\@TO}{\textbf{\`a }}%
127 \newcommand{\@ENDFOR}{\textbf{Fin Pour}}%
129 \newcommand{\@IF}{\textbf{Si }}%
130 \newcommand{\@THEN}{\textbf{Alors }}%
131 \newcommand{\@ELSE}{\textbf{Sinon }}%
132 \newcommand{\@ENDIF}{\textbf{Fin Si}}%
134 \newcommand{\@SWITCH}{\textbf{Selon que }}%
135 \newcommand{\@ENDSWITCH}{\textbf{Fin Selon que}}%
137 \newcommand{\@FUNCTION}{\textbf{Fonction }}%
138 \newcommand{\@RETURN}{\textbf{Retourner }}%
139 \newcommand{\@ENDFUNCTION}{\textbf{Fin}}%
141 \newcommand{\@PROCEDURE}{\textbf{Proc\'edure }}%
142 \newcommand{\@ENDPROCEDURE}{\textbf{Fin}}%
144 \ifthenelse{\equal{\alg@language}{english}}
146 \def\alg@floatname{Algorithm}
147 \def\alg@listname{List of Algorithms}
149 \newcommand{\@TRUE}{\textbf{true}}%
150 \newcommand{\@FALSE}{\textbf{false}}%
151 \newcommand{\@AND}{\textbf{AND }}%
152 \newcommand{\@OR}{\textbf{OR }}%
153 \newcommand{\@NOT}{\textbf{$\neg$}}%
155 \newcommand{\@WHILE}{\textbf{While }}%
156 \newcommand{\@DO}{\textbf{do }}%
157 \newcommand{\@ENDWHILE}{\textbf{done}}%
159 \newcommand{\@REPEAT}{\textbf{Repeat }}%
160 \newcommand{\@UNTIL}{\textbf{until }}%
162 \newcommand{\@FOR}{\textbf{For }}%
163 \newcommand{\@FROM}{\textbf{from }}%
164 \newcommand{\@TO}{\textbf{to }}%
165 \newcommand{\@ENDFOR}{\textbf{end For}}%
167 \newcommand{\@IF}{\textbf{If }}%
168 \newcommand{\@THEN}{\textbf{then }}%
169 \newcommand{\@ELSE}{\textbf{else }}%
170 \newcommand{\@ENDIF}{\textbf{end If}}%
172 \newcommand{\@SWITCH}{\textbf{Switch }}%
173 \newcommand{\@ENDSWITCH}{\textbf{end Switch}}%
175 \newcommand{\@FUNCTION}{\textbf{Function }}%
176 \newcommand{\@RETURN}{\textbf{return }}%
177 \newcommand{\@ENDFUNCTION}{\textbf{End}}%
179 \newcommand{\@PROCEDURE}{\textbf{Procedure }}%
180 \newcommand{\@ENDPROCEDURE}{\textbf{End}}%
185 %%-----------------------------------------------------------------%%
186 %%----------------------- Commandes/Commands ----------------------%%
188 %% Adequation au package "float" / Match "float" package
189 \newcommand\floatc@alg[2]{\begin{center}{\bfseries\rmfamily #1:} #2\end{center}}
191 \let\@fs@capt\floatc@alg
192 \def\@fs@pre{}\def\@fs@post{}\def\@fs@mid{\vspace{3pt}}
193 \let\@fs@iftopcapt\iftrue}
194 \newfloat{algorithmfloat}{h}{loa}
195 \floatname{algorithmfloat}{\alg@floatname}
196 %\newcommand{\listofalgorithms}{\listof{algorithmfloat}{\alg@listname}}
197 \newlength{\alglength}
199 %% Les commandes disponibles / Provided commands
200 \newenvironment{algorithme}[1][H]
202 \setlength{\alglength}{.95\linewidth}
203 \begin{algorithmfloat}[#1]
205 %%Rem{texte} : ecrit une remarque
206 %%Rem{text} : puts a comment
207 \newcommand{\@Rem}[1]{\begin{minipage}[t]{\alglength}
213 %%Bloc{code} : Encapsule quelques lignes / encapsulate some lines
214 \newcommand{\@Block}[1]{\begin{minipage}[t]{\alglength}
220 %%WhileDo{condition}{code}
221 \newcommand{\@WhileDo}[2]{\begin{minipage}[t]{\alglength}
222 \@WHILE (##1) \@DO \\
224 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
225 \begin{tabular}{|p{\alglength}} ##2\\ \end{tabular}%
226 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
231 %%WhileDo{condition}{code} sur une seule ligne / on a single line
232 \newcommand{\@ShortWhileDo}[2]{\begin{minipage}[t]{\alglength}
233 \@WHILE (##1) \@DO ##2 \@ENDWHILE
238 %%RepeatUntil{code}{condition}
239 \newcommand{\@RepeatUntil}[2]{\begin{minipage}[t]{\alglength}
242 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
243 \begin{tabular}{|p{\alglength}} ##1\\ \end{tabular}%
244 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
249 %%RepeatUntil{code}{condition} sur une seule ligne / on a single line
250 \newcommand{\@ShortRepeatUntil}[2]{\begin{minipage}[t]{\alglength}
251 \@REPEAT ##1 \@UNTIL (##2)%
256 %%ForFromToDo{variable}{valeur initiale}{valeur finale}{code}
257 %%ForFromToDo{variable}{initial value}{final value}{code}
258 \newcommand{\@ForFromToDo}[4]{\begin{minipage}[t]{\alglength}
259 \@FOR ##1 \@FROM ##2 \@TO ##3 \@DO \\
261 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
262 \begin{tabular}{|p{\alglength}} ##4\\ \end{tabular}%
263 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
268 %%ForFromToDo{variable}{valeur initiale}{valeur finale}{code} sur une seule ligne
269 %%ForFromToDo{variable}{initial value}{final value}{code} on a single line
270 \newcommand{\@ShortForFromToDo}[4]{\begin{minipage}[t]{\alglength}
271 \@FOR ##1 \@FROM ##2 \@TO ##3 \@DO ##4 \@ENDFOR%
276 %%For{controle de boucle style C}{code}
277 %%For{C-like loop control}{code}
278 \newcommand{\@ForDo}[2]{\begin{minipage}[t]{\alglength}
279 \@FOR ##1 \@DO \vspace*{.5ex}\\
281 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
282 \begin{tabular}{|p{\alglength}} ##2\\ \end{tabular}%
283 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
288 %%For{controle de boucle style C}{code} sur une seule ligne
289 %%For{C-like loop control}{code} on a single line
290 \newcommand{\@ShortForDo}[2]{\begin{minipage}[t]{\alglength}
291 \@FOR ##1 \@DO ##2 \@ENDFOR%
296 %%IfThen{condition}{code}
297 \newcommand{\@IfThen}[2]{\begin{minipage}[t]{\alglength}
300 \addtolength{\alglength}{-1.5em-\tabcolsep-\arrayrulewidth}
301 \begin{tabular}{|p{\alglength}} ##2\\ \end{tabular}%
302 \addtolength{\alglength}{1.5em+\tabcolsep+\arrayrulewidth}
307 %%IfThen{condition}{code} sur une seule ligne / on a single line
308 \newcommand{\@ShortIfThen}[2]{\begin{minipage}[t]{\alglength}
309 \@IF (##1) \@THEN ##2 \@ENDIF%
314 %%IfThenElse{condition}{code du then}{code du else} NE PAS CONFONDRE avec le \ifthenelse de LaTeX
315 %%IfThenElse{condition}{then-code}{else-code} DO NOT CONFUSE with \ifthenelse from LaTeX
316 \newcommand{\@IfThenElse}[3]{\begin{minipage}[t]{\alglength}
319 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
320 \begin{tabular}{|p{\alglength}} ##2\\ \end{tabular}%
323 \begin{tabular}{|p{\alglength}} ##3\\ \end{tabular}%
324 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
329 %%IfThenElse{condition}{code du then}{code du else} sur une seule ligne
330 %%IfThenElse{condition}{then-code}{else-code} on a single line
331 \newcommand{\@ShortIfThenElse}[3]{\begin{minipage}[t]{\alglength}
332 \@IF (##1) \@THEN ##2 \@ELSE ##3 \@ENDIF%
337 %%Switch{code} (C'est le selon que)
338 \newcommand{\@Switch}[1]{\begin{minipage}[t]{\alglength}
341 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
342 \begin{tabular}{|p{\alglength}} ##1\\ \end{tabular}%
343 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
349 %%Function{parametres}{type de retour}{code}
350 %%Function{parameters}{return type}{code}
351 \newcommand{\@Function}[4]{\begin{minipage}[t]{\alglength}
352 \@FUNCTION ##1(##2) : \textbf{##3}\\
354 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
355 \begin{tabular}{|p{\alglength}} ##4\\ \end{tabular}%
356 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
362 %%Procedure{parametres}{code}
363 %%Procedure{parameters}{code}
364 \newcommand{\@Procedure}[3]{\begin{minipage}[t]{\alglength}
365 \@PROCEDURE ##1(##2)\\
367 \addtolength{\alglength}{-2em-\tabcolsep-\arrayrulewidth}
368 \begin{tabular}{|p{\alglength}} ##3\\ \end{tabular}%
369 \addtolength{\alglength}{2em+\tabcolsep+\arrayrulewidth}
375 %%Type{nom ou liste de variable}{nom de type}
376 %%Type{name or list of variables}{type name}
377 \newcommand{\@Type}[2]{##1 : \textbf{##2}}
379 %%Definition des macro-commandes pratiques pour l'utilisateur.
380 %%La forme etoilee de certaines commandes est un alias de leur version courte (sur une seule ligne)
381 %%Definition of macro-commands useful for the user.
382 %%The star-from of some commands is an alias towards ther short form (on a single line)
384 \def\False{ \@FALSE}%
390 \def\While{ \@ifstar{\@ShortWhileDo} {\@WhileDo}}
391 \def\WhileDo{ \@ifstar{\@ShortWhileDo} {\@WhileDo}}
392 \def\Repeat{ \@ifstar{\@ShortRepeatUntil} {\@RepeatUntil}}
393 \def\RepeatUntil{\@ifstar{\@ShortRepeatUntil} {\@RepeatUntil}}
394 \def\ForFromTo{ \@ifstar{\@ShortForFromToDo} {\@ForFromToDo}}
395 \def\ForFromToDo{\@ifstar{\@ShortForFromToDo} {\@ForFromToDo}}
396 \def\ForDo{ \@ifstar{\@ShortForDo} {\@ForDo}}
397 \def\For{ \@ifstar{\@ShortForDo} {\@ForDo}}
398 \def\If{ \@ifstar{\@ShortIfThen} {\@IfThen}}
399 \def\IfThen{ \@ifstar{\@ShortIfThen} {\@IfThen}}
400 \def\IfThenElse{ \@ifstar{\@ShortIfThenElse} {\@IfThenElse}}
401 \def\Switch{ \@ifstar{\@Switch} {\@Switch}}
402 \def\Function{ \@ifstar{\@Function} {\@Function}}
403 \def\Return{ \@RETURN}
404 \def\Procedure{ \@ifstar{\@Procedure} {\@Procedure}}
407 \begin{minipage}[t]{\alglength}
408 \begin{center}\begin{tabular}{|c|}\hline\\
410 \begin{minipage}[t]{\alglength}
412 %% Fin de l'environnement "algorithme" / end of "algorithme" environnment
414 \end{minipage}\hspace*{.5em}
415 \\\\\hline\end{tabular}\end{center}
420 %% ----------------------------- FIN / END ---------------------------------------