forked from cathleruste/Logique2-Syllabus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgoesi.sty
172 lines (158 loc) · 7.41 KB
/
algoesi.sty
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
% Adaptation du package algorithmicx pour écrire les algorithmes
% du cours de logique à l'ESI
\usepackage{algpseudocode} % Perme d'écrire des algorithmes
\usepackage{algorithm} % Pour des algorithmes flottants
% ==============================================================================
% Le code suivant permet d'avoir des lignes verticales pour délimiter les blocs.
% cf: http://tex.stackexchange.com/questions/52473/is-it-possible-to-have-connecting-loop-lines-like-algorithm2e-in-algorithmic
% J'ai changé la ligne (plus grosse et grise)
% ==============================================================================
\makeatletter
% This is the vertical rule that is inserted
\definecolor{rulecolor}{gray}{0.7}
\def\therule{\makebox[\algorithmicindent][l]{\hspace*{.4em}{\color{rulecolor}\vrule height .75\baselineskip width 0.05em depth .25\baselineskip}}}%
\newtoks\therules% Contains rules
\therules={}% Start with empty token list
\def\appendto#1#2{\expandafter#1\expandafter{\the#1#2}}% Append to token list
\def\gobblefirst#1{% Remove (first) from token list
#1\expandafter\expandafter\expandafter{\expandafter\@gobble\the#1}}%
\def\LState{\State\unskip\the\therules}% New line-state
\def\pushindent{\appendto\therules\therule}%
\def\popindent{\gobblefirst\therules}%
\def\printindent{\unskip\the\therules}%
\def\printandpush{\printindent\pushindent}%
\def\popandprint{\popindent\printindent}%
% *** DECLARED LOOPS ***
% (from algpseudocode.sty)
\algdef{SE}[WHILE]{While}{EndWhile}[1]
{\printandpush\algorithmicwhile\ #1\ \algorithmicdo}
{\popandprint\algorithmicend\ \algorithmicwhile}%
\algdef{SE}[FOR]{For}{EndFor}[1]
{\printandpush\algorithmicfor\ #1\ \algorithmicdo}
{\popandprint\algorithmicend\ \algorithmicfor}%
%\algdef{S}[FOR]{ForAll}[1]
% {\printindent\algorithmicforall\ #1\ \algorithmicdo}%
\algdef{SE}[LOOP]{Loop}{EndLoop}
{\printandpush\algorithmicloop}
{\popandprint\algorithmicend\ \algorithmicloop}%
\algdef{SE}[REPEAT]{Repeat}{Until}
{\printandpush\algorithmicrepeat}[1]
{\popandprint\algorithmicuntil\ #1}%
\algdef{SE}[IF]{If}{EndIf}[1]
{\printandpush\algorithmicif\ #1\ \algorithmicthen}
{\popandprint\algorithmicend\ \algorithmicif}%
\algdef{SE}[BLOCK]{Begin}{End}[1]
{\printandpush \algorithmicbegin\ #1}
{\popandprint \algorithmicend}%
\algdef{SE}[BLOC]{Block}{EndBlock}[1]
{\printandpush \algorithmicblock\ #1}
{\popandprint \algorithmicend\ \algorithmicblock}%
\algdef{C}[IF]{IF}{ElsIf}[1]
{\popandprint\pushindent\algorithmicelse\ \algorithmicif\ #1\ \algorithmicthen}%
\algdef{Ce}[ELSE]{IF}{Else}{EndIf}
{\popandprint\pushindent\algorithmicelse}%
\algdef{SE}[PROCEDURE]{Procedure}{EndProcedure}[2]
{\printandpush\algorithmicprocedure\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
{\popandprint\algorithmicend\ \algorithmicprocedure}%
\algdef{SE}[FUNCTION]{Function}{EndFunction}[2]
{\printandpush\algorithmicfunction\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
{\popandprint\algorithmicend\ \algorithmicfunction}%
\algdef{SE}[SWITCH]{Switch}{EndSwitch}[1]
{\printandpush\algorithmicswitch\ #1}
{\popandprint\algorithmicend\ \algorithmicswitch}%
\algdef{C}[SWITCH]{SWITCH}{Case}[1]
{\popandprint\pushindent\ #1:}%
\algdef{SE}[STRUCT]{Struct}{EndStruct}[1]
{\printandpush\algorithmicstruct\ #1}
{\popandprint\algorithmicend\ \algorithmicstruct}%
\algdef{SE}[INTERFACE]{Interface}{EndInterface}[1]
{\printandpush\algorithmicinterface\ #1}
{\popandprint\algorithmicend\ \algorithmicinterface}%
\algdef{SE}[CLASS]{Class}{EndClass}[1]
{\printandpush\algorithmicclass\ #1}
{\popandprint\algorithmicend\ \algorithmicclass}%
% ==============================================================================
% Fin du code pour les lignes verticales
% ==============================================================================
% Ajouts propres pour la francisation des termes prédéfinis
\algnewcommand\algorithmicclass{\textbf{classe}}
\algnewcommand\algorithmicmethod{\textbf{méthode}}
\algnewcommand\algorithmicconstr{\textbf{constructeur}}
\algnewcommand\algorithmicstruct{\textbf{structure}}
\algnewcommand\algorithmicinterface{\textbf{interface}}
\algnewcommand\algorithmicblock{\textbf{bloc}}
\algnewcommand\algorithmicbegin{\textbf{début}}
\algrenewcommand\algorithmicend{\textbf{fin}}
\algrenewcommand\algorithmicprocedure{\textbf{module}}
\algrenewcommand\algorithmicfunction{\textbf{module}}
\algrenewcommand\algorithmicwhile{\textbf{tant que}}
\algrenewcommand\algorithmicfor{\textbf{pour}}
\algrenewcommand\algorithmicrepeat{\textbf{répéter}}
\algrenewcommand\algorithmicuntil{\textbf{jusqu'à ce que}}
\algrenewcommand\algorithmicdo{\textbf{faire}}
\algrenewcommand\algorithmicreturn{\textbf{retourner}}
\algrenewcommand\algorithmicif{\textbf{si}}
\algrenewcommand\algorithmicthen{\textbf{alors}}
\algrenewcommand\algorithmicelse{\textbf{sinon}}
\algnewcommand\algorithmicswitch{\textbf{selon que}}
\floatname{algorithm}{Algorithme}
% Modifications de style
\algrenewcommand\textproc{\textit} % Nom de module en italique plutôt qu'en small caps
\restylefloat{ labelsep=b }
% ajout d'e petits éléments de syntaxe non existants
\newcommand{\In}{\ensuremath{\downarrow}}
\newcommand{\Out}{\ensuremath{\uparrow}}
\newcommand{\InOut}{\In{}\Out{}}
\newcommand{\Gets}{\ensuremath{\gets}\ }
\newcommand{\Gives}{\ensuremath{\rightarrow}{}}
\newcommand{\T}[1]{\textsf{#1}} % Type
\newcommand{\K}[1]{\textbf{#1}} % Keyword
%\definecolor{declarecolor}{gray}{0.2}
\newcommand{\Declare}[2]{\LState{#1 : #2}}
\newcommand{\Decl}{\LState}
\renewcommand{\Return}{\LState\algorithmicreturn\ }
%\newcommand{\Gets}[2]{\LState #1 \ensuremath{\gets}{} #2}
\newcommand{\Read}{\LState\textbf{lire}\ }
\newcommand{\Write}{\LState\textbf{afficher}\ }
\newcommand{\Writef}{\LState\textbf{écrire}\ }
\newcommand{\Alloc}{\textbf{allouer}\ }
\newcommand{\Free}{\LState\textbf{libérer}\ }
\newcommand{\Empty}{\LState}
\newcommand{\Stmt}{\LState}
\newcommand{\Let}{\LState}
\newcommand{\Error}{\LState\textbf{erreur}\ }
% \Module{nom}{param}{return_type} ... \EndModule
\algblockdefx[MODULE]{Module}{EndModule}[3]%
{\printandpush\algorithmicprocedure\ \textproc{#1}(#2)\ifthenelse{\equal{#3}{}}{}{\Gives\ #3}}
{\popandprint\algorithmicend\ \algorithmicprocedure}
\algblockdefx[METHOD]{Method}{EndMethod}[3]%
{\printandpush\algorithmicmethod\ \textproc{#1}(#2)\ifthenelse{\equal{#3}{}}{}{\Gives\ #3}}
{\popandprint\algorithmicend\ \algorithmicmethod}
\algblockdefx[CONSTR]{Constr}{EndConstr}[2]%
{\printandpush\algorithmicconstr\ \textproc{#1}(#2)}
{\popandprint\algorithmicend\ \algorithmicconstr}
\algdef{C}[CLASS]{CLASS}{Private}{\popandprint\pushindent\ privé:}%
\algdef{C}[CLASS]{CLASS}{Public}{\popandprint\pushindent\ public:}%
\newcommand{\ModuleSign}[3]{\Stmt \algorithmicprocedure\ \textproc{#1}(#2)\ifthenelse{\equal{#3}{}}{}{\Gives\ #3}}
\newcommand{\MethodSign}[3]{\Stmt \algorithmicmethod\ \textproc{#1}(#2)\ifthenelse{\equal{#3}{}}{}{\Gives\ #3}}
\newcommand{\ConstrSign}[2]{\Stmt \algorithmicconstr\ \textproc{#1}(#2)}
\algrenewcommand{\algorithmiccomment}[1]{{\small\hskip1em// #1}}
\newcommand{\LComment}{\Empty\hskip-1em\Comment}
\newcommand{\RComment}{\hfill\Comment}
\newcommand{\Indent}{\expandafter\hskip\algorithmicindent\relax}
% =====
\newenvironment{pseudo}{%
\begin{minipage}{0.95\linewidth}
\begin{sffamily}
\begin{algorithmic}[0]
\small
}{%
\end{algorithmic}
\end{sffamily}
\end{minipage}
}
\newcommand{\cadre}[1]{%
\fcolorbox{gray}{gray!10}{%
\begin{minipage}{0.98\textwidth}#1\end{minipage}%
}%
}