| 1 |
% \iffalse meta-comment |
| 2 |
% vim: tw=80 |
| 3 |
% |
| 4 |
%% File: algobox.dtx (C) Copyright 2016-2019 RIVAUD Julien |
| 5 |
%% |
| 6 |
%% It may be distributed and/or modified under the conditions of the |
| 7 |
%% General Public License (GPL), either version 3 of this |
| 8 |
%% license or (at your option) any later version. |
| 9 |
% |
| 10 |
%<*driver|package> |
| 11 |
% The version of expl3 required is tested as early as possible, as |
| 12 |
% some really old versions do not define \ProvidesExplPackage. |
| 13 |
\NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 14 |
\RequirePackage{expl3}[2018/06/19] |
| 15 |
\def\ExplFileName{algobox} |
| 16 |
\def\ExplFileDescription{Typeset Algobox programs} |
| 17 |
\def\ExplFileDate{2019/09/29} |
| 18 |
\def\ExplFileVersion{1.3} |
| 19 |
%</driver|package> |
| 20 |
%<*driver> |
| 21 |
\documentclass[full,a4paper]{l3doc} |
| 22 |
\usepackage{fontspec} |
| 23 |
\usepackage{algobox} |
| 24 |
\usepackage{url} |
| 25 |
\begin{document} |
| 26 |
\def\Algobox{\textsc{AlgoBox}} |
| 27 |
\DocInput{\jobname.dtx} |
| 28 |
\end{document} |
| 29 |
%</driver> |
| 30 |
% \fi |
| 31 |
% |
| 32 |
% \title{^^A |
| 33 |
% The \textsf{\ExplFileName} package\\ \ExplFileDescription^^A |
| 34 |
% \thanks{This file describes v\ExplFileVersion, |
| 35 |
% last revised \ExplFileDate.}^^A |
| 36 |
% } |
| 37 |
% |
| 38 |
% \author{^^A |
| 39 |
% Julien ``\_FrnchFrgg\_'' \textsc{Rivaud}\thanks |
| 40 |
% {^^A |
| 41 |
% E-mail: |
| 42 |
% \href{mailto:[email protected]} |
| 43 |
% {[email protected]}^^A |
| 44 |
% }^^A |
| 45 |
% } |
| 46 |
% |
| 47 |
% \date{Released \ExplFileDate} |
| 48 |
% |
| 49 |
% \maketitle |
| 50 |
% |
| 51 |
% \begin{documentation} |
| 52 |
% |
| 53 |
% \section{Documentation} |
| 54 |
% |
| 55 |
% \subsection{Getting support} |
| 56 |
% |
| 57 |
% If you find bugs or keywords not recognized by the package, you can report it |
| 58 |
% at the address \url{https://gitlab.com/frnchfrgg-latex/algobox/issues}. |
| 59 |
% |
| 60 |
% \subsection{Rationale} |
| 61 |
% |
| 62 |
% French mathematics and/or computer science teachers can use \Algobox\ |
| 63 |
% (\url{http://www.xm1math.net/algobox/}) to teach algorithmics to beginners. |
| 64 |
% It uses tree-like indentation, fixed-form structures entered by buttons and |
| 65 |
% dialogs rather than free text. This prevents most typos or small beginner |
| 66 |
% mistakes that are often hard to detect. |
| 67 |
% |
| 68 |
% \Algobox\ can save a project in its own format, and export in a variety of |
| 69 |
% formats, including \LaTeX. Several problems arise: |
| 70 |
% \begin{itemize} |
| 71 |
% \item The output is not similar to what \Algobox\ displays itself. |
| 72 |
% \item The generated code is standalone and uses dependencies that might not |
| 73 |
% be wanted, like \textsf{algorithm} and \textsf{algpseudocode} that can |
| 74 |
% clash with other algorithm-like packages. |
| 75 |
% \item The algorithm part of the generated code does not look like \Algobox\ |
| 76 |
% code and can thus be annoying to modify by hand if needed. |
| 77 |
% \end{itemize} |
| 78 |
% |
| 79 |
% This small package intends to solve the problem by using a syntax very close |
| 80 |
% to the real \Algobox\ syntax and having a typeset output of the best quality |
| 81 |
% possible, resembling the most to what \Algobox\ displays in its editing |
| 82 |
% window. |
| 83 |
% |
| 84 |
% \subsection{Simple usage} |
| 85 |
% |
| 86 |
% To convert an \Algobox\ program to input suitable for this package you just |
| 87 |
% have to: |
| 88 |
% |
| 89 |
% \begin{enumerate} |
| 90 |
% \item Copy the program from the \string"Tester l'algorithme\string" |
| 91 |
% window and remove the line numbers. |
| 92 |
% \item Add \cs{;} at the end of each line (or at the beginning of each line |
| 93 |
% if like me you prefer to have those out of the way). The reason is that |
| 94 |
% some constructs in \Algobox\ programs depend on the line cuts whereas |
| 95 |
% \TeX\ treats those as normal spaces by default. Of course, one can setup |
| 96 |
% \TeX\ so that it temporarily obeys lines, but it \emph{cannot work} if |
| 97 |
% the algorithm is between braces (if you put in in a macro like |
| 98 |
% \cs{fbox}). |
| 99 |
% \item Add a backslash at the beginning of all \Algobox\ keywords, like |
| 100 |
% "VARIABLES", "SI", "DEBUT_SINON" and so on. |
| 101 |
% \item Remove all underscores in \Algobox\ keywords. You probably want to |
| 102 |
% remove them in all cases because \Algobox\ programs are not typeset in |
| 103 |
% math mode and \TeX\ will complain that you tried to use a subscript. If |
| 104 |
% you really want an underscore, replace it by \cs{_} \emph{but not in |
| 105 |
% keywords} or they will not be recognized anymore. |
| 106 |
% \item Put everything between "\begin{algobox}" and |
| 107 |
% "\end{algobox}". |
| 108 |
% \end{enumerate} |
| 109 |
% |
| 110 |
% Here is an example of the result: |
| 111 |
% |
| 112 |
% \begin{verbatim} |
| 113 |
% \begin{algobox} |
| 114 |
% \; \VARIABLES |
| 115 |
% \; a1 \ESTDUTYPE NOMBRE |
| 116 |
% \; b1 \ESTDUTYPE NOMBRE |
| 117 |
% \; a2 \ESTDUTYPE NOMBRE |
| 118 |
% \; b2 \ESTDUTYPE NOMBRE |
| 119 |
% \; \DEBUTALGORITHME |
| 120 |
% \; \LIRE a1 |
| 121 |
% \; \LIRE b1 |
| 122 |
% \; \LIRE a2 |
| 123 |
% \; \LIRE b2 |
| 124 |
% \; \SI (a1 == a2) \ALORS |
| 125 |
% \; \DEBUTSI |
| 126 |
% \; \SI (b1 == b2) \ALORS |
| 127 |
% \; \DEBUTSI |
| 128 |
% \; \AFFICHER "Les droites sont parallèles" |
| 129 |
% \; \FINSI |
| 130 |
% \; \SINON |
| 131 |
% \; \DEBUTSINON |
| 132 |
% \; \AFFICHER "Les droites sont sécantes" |
| 133 |
% \; \FINSINON |
| 134 |
% \; \FINSI |
| 135 |
% \; \SINON |
| 136 |
% \; \DEBUTSINON |
| 137 |
% \; \AFFICHER "Les droites sont confondues" |
| 138 |
% \; \FINSINON |
| 139 |
% \; \FINALGORITHME |
| 140 |
% \end{algobox} |
| 141 |
% \end{verbatim} |
| 142 |
% |
| 143 |
% The spacing is only for your convenience as \TeX\ treats any number of |
| 144 |
% consecutive spaces as a single one. |
| 145 |
% |
| 146 |
% Typesetting the previous example gives: |
| 147 |
% |
| 148 |
% \begin{algobox} |
| 149 |
% \def"{\string"} |
| 150 |
% \; \VARIABLES |
| 151 |
% \; a1 \ESTDUTYPE NOMBRE |
| 152 |
% \; b1 \ESTDUTYPE NOMBRE |
| 153 |
% \; a2 \ESTDUTYPE NOMBRE |
| 154 |
% \; b2 \ESTDUTYPE NOMBRE |
| 155 |
% \; \DEBUTALGORITHME |
| 156 |
% \; \LIRE a1 |
| 157 |
% \; \LIRE b1 |
| 158 |
% \; \LIRE a2 |
| 159 |
% \; \LIRE b2 |
| 160 |
% \; \SI (a1 == a2) \ALORS |
| 161 |
% \; \DEBUTSI |
| 162 |
% \; \SI (b1 == b2) \ALORS |
| 163 |
% \; \DEBUTSI |
| 164 |
% \; \AFFICHER "Les droites sont parallèles" |
| 165 |
% \; \FINSI |
| 166 |
% \; \SINON |
| 167 |
% \; \DEBUTSINON |
| 168 |
% \; \AFFICHER "Les droites sont sécantes" |
| 169 |
% \; \FINSINON |
| 170 |
% \; \FINSI |
| 171 |
% \; \SINON |
| 172 |
% \; \DEBUTSINON |
| 173 |
% \; \AFFICHER "Les droites sont confondues" |
| 174 |
% \; \FINSINON |
| 175 |
% \; \FINALGORITHME |
| 176 |
% \end{algobox} |
| 177 |
% |
| 178 |
% The algorithm is typeset as a TikZ picture, so is not breakable between pages. |
| 179 |
% |
| 180 |
% You can of course put the environment in anything you deem fit, like a "\fbox" |
| 181 |
% for instance. Here is an example: |
| 182 |
% |
| 183 |
% \fbox{ |
| 184 |
% \begin{algobox} |
| 185 |
% \def"{\string"} |
| 186 |
% \; \VARIABLES |
| 187 |
% \; note \ESTDUTYPE NOMBRE |
| 188 |
% \; \DEBUTALGORITHME |
| 189 |
% \; \LIRE note |
| 190 |
% \; \SI (note<10) \ALORS |
| 191 |
% \; \DEBUTSI |
| 192 |
% \; \AFFICHER "Il y a encore du travail" |
| 193 |
% \; \FINSI |
| 194 |
% \; \AFFICHER "On ne se relâche pas" |
| 195 |
% \; \POUR j \ALLANTDE 1 \A 25 |
| 196 |
% \; \DEBUTPOUR |
| 197 |
% \; \AFFICHERCALCUL i+3 |
| 198 |
% \; \FINPOUR |
| 199 |
% \; \FINALGORITHME |
| 200 |
% \end{algobox} |
| 201 |
% } |
| 202 |
% |
| 203 |
% \subsection{Customizing the appearance} |
| 204 |
% |
| 205 |
% TODO |
| 206 |
% |
| 207 |
% \end{documentation} |
| 208 |
% |
| 209 |
% \begin{implementation} |
| 210 |
% |
| 211 |
% \section{\pkg{\ExplFileName} implementation} |
| 212 |
% |
| 213 |
% \begin{macrocode} |
| 214 |
%<*package> |
| 215 |
%<@@=algobox> |
| 216 |
% \end{macrocode} |
| 217 |
% |
| 218 |
% \begin{macrocode} |
| 219 |
\ProvidesExplPackage |
| 220 |
{\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} |
| 221 |
% \end{macrocode} |
| 222 |
% \begin{macrocode} |
| 223 |
\RequirePackage{xparse} |
| 224 |
\RequirePackage{environ} |
| 225 |
\RequirePackage{tikz} |
| 226 |
|
| 227 |
\ExplSyntaxOff |
| 228 |
\usetikzlibrary{calc} |
| 229 |
\ExplSyntaxOn |
| 230 |
|
| 231 |
\RequirePackage{xcolor} |
| 232 |
|
| 233 |
\int_new:N \l_@@_level_int |
| 234 |
|
| 235 |
% \end{macrocode} |
| 236 |
% The colors are defined in "algohighlighter.cpp" in the \Algobox\ source, |
| 237 |
% except for the tree lines color. The names here are the same, with "algobox" |
| 238 |
% prepended. |
| 239 |
% \begin{macrocode} |
| 240 |
|
| 241 |
\definecolor{algoboxarbre}{RGB}{146,146,146} |
| 242 |
\definecolor{algoboxColorStandard}{HTML}{000000} |
| 243 |
\definecolor{algoboxColorComment}{HTML}{606060} |
| 244 |
\definecolor{algoboxColorBloc}{HTML}{800000} |
| 245 |
\definecolor{algoboxColorCommande}{HTML}{0000CC} |
| 246 |
\definecolor{algoboxColorSi}{HTML}{800080} |
| 247 |
\definecolor{algoboxColorTantQue}{HTML}{DD6F06} |
| 248 |
\definecolor{algoboxColorPour}{HTML}{BB8800} |
| 249 |
\definecolor{algoboxColorFonction}{HTML}{9A4D00} |
| 250 |
|
| 251 |
\tikzset{ |
| 252 |
every~algobox/.style=, |
| 253 |
every~smalgobox/.style={baseline=(block.base)}, |
| 254 |
algobox~ligne/.style={ |
| 255 |
xshift=1em, text~depth=0pt, |
| 256 |
inner~xsep=0.1ex, inner~ysep=0.5ex |
| 257 |
}, |
| 258 |
algobox~arbre/.style={ultra~thick, color=algoboxarbre}, |
| 259 |
algobox~indentsymb/.style={x=1ex, y=0.6ex, color=algoboxarbre}, |
| 260 |
algobox~indent/.style={xshift=2em}, |
| 261 |
algobox~normal/.style={ |
| 262 |
font=\sffamily, |
| 263 |
color=algoboxColorStandard, |
| 264 |
}, |
| 265 |
algobox~commentaire/.style={ |
| 266 |
algobox~normal/.try, |
| 267 |
color=algoboxColorComment, |
| 268 |
}, |
| 269 |
algobox~commande/.style={ |
| 270 |
algobox~normal/.try, |
| 271 |
color=algoboxColorCommande, |
| 272 |
}, |
| 273 |
algobox~structure/.style={ |
| 274 |
font=\sffamily\bfseries, |
| 275 |
color=algoboxColorBloc |
| 276 |
}, |
| 277 |
algobox~sialors/.style={ |
| 278 |
algobox~structure/.try, |
| 279 |
color=algoboxColorSi, |
| 280 |
}, |
| 281 |
algobox~pour/.style={ |
| 282 |
algobox~structure/.try, |
| 283 |
color=algoboxColorPour, |
| 284 |
}, |
| 285 |
algobox~tantque/.style={ |
| 286 |
algobox~structure/.try, |
| 287 |
color=algoboxColorTantQue, |
| 288 |
}, |
| 289 |
algobox~fonctions/.style={ |
| 290 |
algobox~structure/.try, |
| 291 |
color=algoboxColorFonction, |
| 292 |
}, |
| 293 |
} |
| 294 |
|
| 295 |
% \end{macrocode} |
| 296 |
% \subsection{Formatting commands} |
| 297 |
% \begin{macrocode} |
| 298 |
|
| 299 |
|
| 300 |
\tl_new:N \l_@@_lastnode_tl |
| 301 |
\cs_new_protected:Nn \@@_block:nn { |
| 302 |
\node[algobox~ligne/.try, |
| 303 |
\tl_if_empty:nF{#1}{algobox~#1/.try}, |
| 304 |
anchor=north~west |
| 305 |
] |
| 306 |
(block) at (A\int_use:N \l_@@_level_int |- H) |
| 307 |
{\vphantom{A}#2}; |
| 308 |
\draw[algobox~arbre/.try] |
| 309 |
(A\int_use:N \l_@@_level_int) |
| 310 |
-- (A\int_use:N \l_@@_level_int |- block.west) |
| 311 |
coordinate (A\int_use:N \l_@@_level_int) |
| 312 |
-- (block.west); |
| 313 |
\coordinate (H) at (block.south); |
| 314 |
\tl_set:Nn \l_@@_lastnode_tl {block} |
| 315 |
} |
| 316 |
|
| 317 |
\cs_new_protected:Nn \@@_indent:nn { |
| 318 |
\node[algobox~ligne/.try, |
| 319 |
\tl_if_empty:nF{#1}{algobox~#1/.try}, |
| 320 |
anchor=north~west |
| 321 |
] |
| 322 |
(block) at (A\int_use:N \l_@@_level_int |- H) |
| 323 |
{\vphantom{A}#2}; |
| 324 |
\draw[algobox~arbre/.try] |
| 325 |
(A\int_use:N \l_@@_level_int) |
| 326 |
-- (A\int_use:N \l_@@_level_int |- H); |
| 327 |
\fill[algobox~indentsymb/.try] |
| 328 |
(A\int_use:N \l_@@_level_int |- block.west) |
| 329 |
+(0,-1) -- +(1,1) -- +(-1,1) -- cycle; |
| 330 |
\coordinate (H) at (block.south); |
| 331 |
\coordinate (T) at (A\int_use:N \l_@@_level_int |- H); |
| 332 |
\coordinate (A\int_use:N \l_@@_level_int) at (T); |
| 333 |
\int_incr:N \l_@@_level_int |
| 334 |
\coordinate[algobox~indent/.try] (A\int_use:N \l_@@_level_int) at (T); |
| 335 |
\tl_set:Nn \l_@@_lastnode_tl {block} |
| 336 |
} |
| 337 |
\cs_new_protected:Nn \@@_unindent: { |
| 338 |
\int_decr:N \l_@@_level_int |
| 339 |
} |
| 340 |
|
| 341 |
\cs_new_protected:Nn \@@_node:nn { |
| 342 |
\node[algobox~#1/.try, anchor=base~west, inner~xsep=0pt] |
| 343 |
(node) at (\l_@@_lastnode_tl.base~east) {#2}; |
| 344 |
\tl_set:Nn \l_@@_lastnode_tl {node} |
| 345 |
} |
| 346 |
|
| 347 |
% \end{macrocode} |
| 348 |
% \subsection{Parsing helpers} |
| 349 |
% \begin{macrocode} |
| 350 |
|
| 351 |
|
| 352 |
\cs_new_protected:Nn \@@_parseall:n { |
| 353 |
\tl_set:Nn \l_tmpa_tl {#1} |
| 354 |
\seq_set_split:NnV \l_tmpa_seq {\;} \l_tmpa_tl |
| 355 |
% Now build up the algorithm body, working around the few infix notations. |
| 356 |
\tl_clear:N \l_@@_body_tl |
| 357 |
\seq_map_variable:NNn \l_tmpa_seq \l_tmpa_tl { |
| 358 |
\tl_if_in:NnT \l_tmpa_tl {\ESTDUTYPE} { |
| 359 |
\tl_put_left:Nn \l_tmpa_tl {\@@_ESTDUTYPE:w} |
| 360 |
} |
| 361 |
\tl_if_in:NnT \l_tmpa_tl {\PRENDLAVALEUR} { |
| 362 |
\tl_put_left:Nn \l_tmpa_tl {\@@_PRENDLAVALEUR:w} |
| 363 |
} |
| 364 |
\tl_put_right:Nn \l_tmpa_tl { \; } |
| 365 |
\tl_put_right:NV \l_@@_body_tl \l_tmpa_tl |
| 366 |
} |
| 367 |
\tl_use:N \l_@@_body_tl |
| 368 |
} |
| 369 |
|
| 370 |
\bool_new:N \l_@@_balanced_first_bool |
| 371 |
\cs_new_protected:Npn \@@_new_balanced_command:nNNnn #1#2#3 { |
| 372 |
\cs_new_protected:cpn {#1} ##1 #2 { |
| 373 |
\tl_set:Nn \l_@@_prefix_tl { ##1 } |
| 374 |
\tl_clear:N \l_@@_balanced_tl |
| 375 |
\bool_set_true:N \l_@@_balanced_first_bool |
| 376 |
\use:c {#1_stage2} #2 |
| 377 |
} |
| 378 |
\cs_new_protected:cpn {#1_stage2} ##1 #2 ##2 #3 { |
| 379 |
\tl_put_right:Nn \l_@@_balanced_tl { ##1 } |
| 380 |
\bool_if:NF \l_@@_balanced_first_bool { |
| 381 |
\tl_put_right:Nn \l_@@_balanced_tl { #2 } |
| 382 |
} |
| 383 |
\tl_if_in:nnTF {##2} {#2} { |
| 384 |
\bool_set_false:N \l_@@_balanced_first_bool |
| 385 |
\use:c {#1_stage2} ##2 \q_mark |
| 386 |
}{ |
| 387 |
\tl_put_right:Nn \l_@@_balanced_tl { ##2 } |
| 388 |
\tl_replace_all:Nnn \l_@@_balanced_tl {\q_mark} {#3} |
| 389 |
\tl_set:Nx \l_tmpa_tl { |
| 390 |
\exp_not:c {#1_stage3} |
| 391 |
\exp_not:V \l_@@_prefix_tl |
| 392 |
\exp_not:n {#2} |
| 393 |
{ |
| 394 |
\exp_not:V \l_@@_balanced_tl |
| 395 |
} |
| 396 |
} |
| 397 |
\tl_use:N \l_tmpa_tl |
| 398 |
} |
| 399 |
} |
| 400 |
\exp_args:Nc \NewDocumentCommand {#1_stage3} |
| 401 |
} |
| 402 |
|
| 403 |
\cs_new_protected:Npn \@@_if_next:NTF #1#2#3 { |
| 404 |
\peek_meaning_remove_ignore_spaces:NTF \; { |
| 405 |
\@@_if_next:NTF #1 {#2} {#3} |
| 406 |
}{ |
| 407 |
\peek_meaning_remove_ignore_spaces:NTF \par { |
| 408 |
\@@_if_next:NTF #1 {#2} {#3} |
| 409 |
}{ |
| 410 |
\peek_meaning_ignore_spaces:NTF #1 {#2} {#3} |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
% \end{macrocode} |
| 415 |
% \subsection{Parsing/typesetting commands} |
| 416 |
% \begin{macrocode} |
| 417 |
|
| 418 |
\NewDocumentCommand \@@_ESTDUTYPE:w { +u{\ESTDUTYPE} +u{\;} } { |
| 419 |
\@@_block:nn {normal} { |
| 420 |
\ignorespaces #1 \unskip\c_space_token\null |
| 421 |
} |
| 422 |
\@@_node:nn {commande}{EST_DU_TYPE} |
| 423 |
\@@_node:nn {normal}{\null\c_space_token#2} |
| 424 |
} |
| 425 |
|
| 426 |
\NewDocumentCommand \@@_FINALGORITHME:w {} { |
| 427 |
\int_while_do:nNnn \l_@@_level_int > \c_zero_int { |
| 428 |
\@@_unindent: |
| 429 |
} |
| 430 |
\@@_block:nn {structure} {FIN_ALGORITHME} |
| 431 |
} |
| 432 |
|
| 433 |
\NewDocumentCommand \@@_PRENDLAVALEUR:w { u{\PRENDLAVALEUR} m } { |
| 434 |
\@@_block:nn {normal} { |
| 435 |
\ignorespaces#1\unskip\c_space_token\null |
| 436 |
} |
| 437 |
\@@_node:nn {commande}{PREND_LA_VALEUR} |
| 438 |
\@@_node:nn {normal}{\null\c_space_token#2} |
| 439 |
} |
| 440 |
|
| 441 |
\@@_new_balanced_command:nNNnn |
| 442 |
{@@_SI:w} \DEBUTSI \FINSI { r() u{\DEBUTSI} +m } |
| 443 |
{ |
| 444 |
\@@_indent:nn {sialors} {SI} |
| 445 |
\@@_node:nn {normal}{\null\c_space_token(#1)\c_space_token\null} |
| 446 |
\@@_node:nn {sialors}{ALORS} |
| 447 |
\@@_block:nn {sialors} {DEBUT_SI} |
| 448 |
#3 |
| 449 |
\@@_block:nn {sialors} {FIN_SI} |
| 450 |
\@@_if_next:NTF \SINON { |
| 451 |
\@@_SINON:w |
| 452 |
}{ |
| 453 |
\@@_unindent: |
| 454 |
} |
| 455 |
} |
| 456 |
\@@_new_balanced_command:nNNnn |
| 457 |
{@@_SINON:w} \DEBUTSINON \FINSINON { u{\DEBUTSINON} +m } { |
| 458 |
\@@_indent:nn {sialors} {SINON} |
| 459 |
\@@_block:nn {sialors} {DEBUT_SINON} |
| 460 |
#2 |
| 461 |
\@@_block:nn {sialors} {FIN_SINON} |
| 462 |
\@@_unindent: |
| 463 |
\@@_unindent: |
| 464 |
} |
| 465 |
|
| 466 |
\@@_new_balanced_command:nNNnn |
| 467 |
{@@_POUR:w} \DEBUTPOUR \FINPOUR |
| 468 |
{ u{\ALLANTDE} u{\A} u{\DEBUTPOUR} +m } { |
| 469 |
\@@_indent:nn {pour} {POUR} |
| 470 |
\@@_node:nn {normal}{\null\c_space_token #1\unskip\c_space_token\null} |
| 471 |
\@@_node:nn {pour}{ALLANT_DE} |
| 472 |
\@@_node:nn {normal}{\null\c_space_token #2\unskip |
| 473 |
\c_space_token A~#3\unskip\c_space_token\null} |
| 474 |
\@@_block:nn {pour} {DEBUT_POUR} |
| 475 |
#4 |
| 476 |
\@@_block:nn {pour} {FIN_POUR} |
| 477 |
\@@_unindent: |
| 478 |
} |
| 479 |
|
| 480 |
\@@_new_balanced_command:nNNnn {@@_TANTQUE:w} \DEBUTTANTQUE \FINTANTQUE |
| 481 |
{ r() u{\DEBUTTANTQUE} +m } |
| 482 |
{ |
| 483 |
\@@_indent:nn {tantque} {TANT_QUE} |
| 484 |
\@@_node:nn {normal}{\null\c_space_token(#1)\c_space_token\null} |
| 485 |
\@@_node:nn {tantque}{FAIRE} |
| 486 |
\@@_block:nn {tantque} {DEBUT_TANT_QUE} |
| 487 |
#3 |
| 488 |
\@@_block:nn {tantque} {FIN_TANT_QUE} |
| 489 |
\@@_unindent: |
| 490 |
} |
| 491 |
|
| 492 |
\NewDocumentCommand \@@_FONCTION:w { +u{\;} } { |
| 493 |
\int_while_do:nNnn \l_@@_level_int > \c_one_int { |
| 494 |
\@@_unindent: |
| 495 |
} |
| 496 |
\@@_indent:nn {fonctions} {FONCTION} |
| 497 |
\@@_node:nn {normal}{\null\c_space_token#1} |
| 498 |
} |
| 499 |
|
| 500 |
\NewDocumentCommand \@@_LINE:w { s O{normal} m } { |
| 501 |
\IfBooleanTF {#1} { |
| 502 |
\@@_indent:nn {#2} {#3} |
| 503 |
\@@_unindent: |
| 504 |
}{ |
| 505 |
\@@_block:nn {#2} {#3} |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
\NewDocumentCommand \@@_NODE:w { O{normal} m } { |
| 510 |
\@@_node:nn {#1} {#2} |
| 511 |
} |
| 512 |
|
| 513 |
% \end{macrocode} |
| 514 |
% \subsection{User commands and environment} |
| 515 |
% \begin{macrocode} |
| 516 |
|
| 517 |
\cs_new_protected_nopar:Nn \@@_make_keyword:n { |
| 518 |
\tl_set:Nn \l_tmpa_tl {#1} |
| 519 |
\tl_replace_all:Nnn \l_tmpa_tl {_} {} |
| 520 |
\cs_set:cpn {\l_tmpa_tl} {\@@_keyword:nw {#1}} |
| 521 |
} |
| 522 |
|
| 523 |
\NewDocumentCommand \@@_keyword:nw {m +u{\;}} { |
| 524 |
\@@_block:nn {commande} {#1} |
| 525 |
\@@_node:nn {normal}{\null\c_space_token#2} |
| 526 |
} |
| 527 |
|
| 528 |
\cs_new_protected_nopar:Nn \@@_make_structure:nn { |
| 529 |
\tl_set:Nn \l_tmpa_tl {#2} |
| 530 |
\tl_replace_all:Nnn \l_tmpa_tl {_} {} |
| 531 |
\cs_set:cpn {\l_tmpa_tl} {\@@_topstructure:nn {#1}{#2}} |
| 532 |
} |
| 533 |
|
| 534 |
\cs_new_protected_nopar:Nn \@@_topstructure:nn { |
| 535 |
\int_while_do:nNnn \l_@@_level_int > \c_zero_int { |
| 536 |
\@@_unindent: |
| 537 |
} |
| 538 |
\@@_indent:nn {#1} {#2} |
| 539 |
} |
| 540 |
|
| 541 |
\cs_new_protected_nopar:Nn \@@_make_func_structure:nn { |
| 542 |
\tl_set:Nn \l_tmpa_tl {#1} |
| 543 |
\tl_replace_all:Nnn \l_tmpa_tl {_} {} |
| 544 |
\cs_set:cpn {\l_tmpa_tl} {\@@_funcstructure:nn {#1}{#2}} |
| 545 |
} |
| 546 |
|
| 547 |
\cs_new_protected_nopar:Nn \@@_funcstructure:nn { |
| 548 |
\int_while_do:nNnn \l_@@_level_int > { 2 } { |
| 549 |
\@@_unindent: |
| 550 |
} |
| 551 |
\bool_if:nTF {#2}{\@@_indent:nn}{\@@_block:nn} {fonctions} {#1} |
| 552 |
} |
| 553 |
|
| 554 |
\clist_const:Nn \c_@@_keywords_clist { |
| 555 |
PAUSE, LIRE, AFFICHERCALCUL, AFFICHER, |
| 556 |
TRACER_POINT, TRACER_POINT_Rouge, TRACER_POINT_Vert, |
| 557 |
TRACER_POINT_Bleu, TRACER_POINT_Blanc, |
| 558 |
TRACER_SEGMENT, TRACER_SEGMENT_Rouge, TRACER_SEGMENT_Vert, |
| 559 |
TRACER_SEGMENT_Bleu, TRACER_SEGMENT_Blanc, |
| 560 |
RENVOYER, APPELER_FONCTION |
| 561 |
} |
| 562 |
|
| 563 |
\cs_new_protected_nopar:Nn \@@_begincode:n { |
| 564 |
\int_zero:N \l_@@_level_int |
| 565 |
\begin{tikzpicture}[#1] |
| 566 |
\coordinate (H) at (0,0); |
| 567 |
\coordinate (A\int_use:N \l_@@_level_int) at (0,0); |
| 568 |
\cs_set_eq:NN \par \prg_do_nothing: |
| 569 |
\cs_set_eq:NN \; \prg_do_nothing: |
| 570 |
\cs_set_eq:NN \LINE \@@_LINE:w |
| 571 |
\cs_set_eq:NN \NODE \@@_NODE:w |
| 572 |
\cs_set_eq:NN \FINALGORITHME \@@_FINALGORITHME:w |
| 573 |
\cs_set_eq:NN \SI \@@_SI:w |
| 574 |
\cs_set_eq:NN \POUR \@@_POUR:w |
| 575 |
\cs_set_eq:NN \TANTQUE \@@_TANTQUE:w |
| 576 |
\cs_set_eq:NN \FONCTION \@@_FONCTION:w |
| 577 |
\cs_set:Npn \//##1\; {\@@_block:nn{commentaire}{//##1}} |
| 578 |
\clist_map_function:NN \c_@@_keywords_clist \@@_make_keyword:n |
| 579 |
\@@_make_structure:nn {structure} {VARIABLES} |
| 580 |
\@@_make_structure:nn {structure} {DEBUT_ALGORITHME} |
| 581 |
\@@_make_structure:nn {fonctions} {FONCTIONS_UTILISEES} |
| 582 |
\@@_make_func_structure:nn {VARIABLES_FONCTION} \c_true_bool |
| 583 |
\@@_make_func_structure:nn {DEBUT_FONCTION} \c_false_bool |
| 584 |
\@@_make_func_structure:nn {FIN_FONCTION} \c_false_bool |
| 585 |
} |
| 586 |
\cs_new_protected_nopar:Nn \@@_closecode: { |
| 587 |
\end{tikzpicture} |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
\NewDocumentCommand \smalgobox { O{} m } { |
| 593 |
\group_begin: |
| 594 |
\@@_begincode:n {every~smalgobox/.try,#1} |
| 595 |
\@@_parseall:n {#2} |
| 596 |
\@@_closecode: |
| 597 |
\group_end: |
| 598 |
} |
| 599 |
|
| 600 |
\NewDocumentEnvironment {algobox} {O{}} { |
| 601 |
\cs_set_protected:Nn \@@_algobox:n { |
| 602 |
\@@_begincode:n {every~algobox/.try,#1} |
| 603 |
\@@_parseall:n {##1} |
| 604 |
\@@_closecode: |
| 605 |
} |
| 606 |
\Collect@Body\@@_algobox:n |
| 607 |
}{ |
| 608 |
} |
| 609 |
%</package> |
| 610 |
% \end{macrocode} |
| 611 |
% |
| 612 |
% \end{implementation} |