diff options
author | Karl Berry <karl@freefriends.org> | 2017-09-03 23:01:37 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-09-03 23:01:37 +0000 |
commit | 06e60056232709831f2923080884ad32888fa866 (patch) | |
tree | 50b56e13d82f18f54ddfe9ce98fce65cba27742f /Master/texmf-dist/tex/latex | |
parent | f5cd2c11a5f8e60d8ba81823546e7aac93472baa (diff) |
algobox (3sep17)
git-svn-id: svn://tug.org/texlive/trunk@45207 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/algobox/algobox.sty | 344 |
1 files changed, 344 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/algobox/algobox.sty b/Master/texmf-dist/tex/latex/algobox/algobox.sty new file mode 100644 index 00000000000..86be6ae0a29 --- /dev/null +++ b/Master/texmf-dist/tex/latex/algobox/algobox.sty @@ -0,0 +1,344 @@ +%% +%% This is file `algobox.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% algobox.dtx (with options: `package') +%% +%% File: algobox.dtx (C) Copyright 2016 RIVAUD Julien +%% +%% It may be distributed and/or modified under the conditions of the +%% General Public License (GPL), either version 3 of this +%% license or (at your option) any later version. +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\RequirePackage{expl3}[2016/01/19] +\def\ExplFileName{algobox} +\def\ExplFileDescription{Typeset Algobox programs} +\def\ExplFileDate{2017/09/03} +\def\ExplFileVersion{1.1} +\ProvidesExplPackage + {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} +\RequirePackage{xparse} +\RequirePackage{environ} +\RequirePackage{tikz} + +\ExplSyntaxOff +\usetikzlibrary{calc} +\ExplSyntaxOn + +\RequirePackage{xcolor} + +\int_new:N \l__algobox_level_int + +\definecolor{algoboxarbre}{RGB}{146,146,146} +\colorlet {algoboxcommentaire}{algoboxarbre!70!black} +\definecolor{algoboxstructure}{RGB}{134,0,0} +\definecolor{algoboxmotclef}{RGB}{25,3,180} +\definecolor{algoboxsialors}{RGB}{147,0,128} +\definecolor{algoboxpour}{RGB}{187,136,0} +\definecolor{algoboxtantque}{RGB}{222,111,6} +\definecolor{algoboxnormal}{RGB}{0,0,0} + +\tikzset{ + every~algobox/.style=, + every~smalgobox/.style={baseline=(block.base)}, + algobox~ligne/.style={ + xshift=1em, text~depth=0pt, + inner~xsep=0.1ex, inner~ysep=0.5ex + }, + algobox~arbre/.style={ultra~thick, color=algoboxarbre}, + algobox~indentsymb/.style={x=1ex, y=0.6ex, color=algoboxarbre}, + algobox~indent/.style={xshift=2em}, + algobox~normal/.style={ + font=\sffamily, + color=algoboxnormal, + }, + algobox~commentaire/.style={ + algobox~normal/.try, + color=algoboxcommentaire, + }, + algobox~motclef/.style={ + algobox~normal/.try, + color=algoboxmotclef, + }, + algobox~structure/.style={ + font=\sffamily\bfseries, + color=algoboxstructure + }, + algobox~sialors/.style={ + algobox~structure/.try, + color=algoboxsialors, + }, + algobox~pour/.style={ + algobox~structure/.try, + color=algoboxpour, + }, + algobox~tantque/.style={ + algobox~structure/.try, + color=algoboxtantque, + }, +} + + +\tl_new:N \l__algobox_lastnode_tl +\cs_new_protected:Nn \__algobox_block:nn { + \node[algobox~ligne/.try, + \tl_if_empty:nF{#1}{algobox~#1/.try}, + anchor=north~west + ] + (block) at (A\int_use:N \l__algobox_level_int |- H) + {\vphantom{A}#2}; + \draw[algobox~arbre/.try] + (A\int_use:N \l__algobox_level_int) + -- (A\int_use:N \l__algobox_level_int |- block.west) + coordinate (A\int_use:N \l__algobox_level_int) + -- (block.west); + \coordinate (H) at (block.south); + \tl_set:Nn \l__algobox_lastnode_tl {block} +} + +\cs_new_protected:Nn \__algobox_indent:nn { + \node[algobox~ligne/.try, + \tl_if_empty:nF{#1}{algobox~#1/.try}, + anchor=north~west + ] + (block) at (A\int_use:N \l__algobox_level_int |- H) + {\vphantom{A}#2}; + \draw[algobox~arbre/.try] + (A\int_use:N \l__algobox_level_int) + -- (A\int_use:N \l__algobox_level_int |- H); + \fill[algobox~indentsymb/.try] + (A\int_use:N \l__algobox_level_int |- block.west) + +(0,-1) -- +(1,1) -- +(-1,1) -- cycle; + \coordinate (H) at (block.south); + \coordinate (T) at (A\int_use:N \l__algobox_level_int |- H); + \coordinate (A\int_use:N \l__algobox_level_int) at (T); + \int_incr:N \l__algobox_level_int + \coordinate[algobox~indent/.try] (A\int_use:N \l__algobox_level_int) at (T); + \tl_set:Nn \l__algobox_lastnode_tl {block} +} +\cs_new_protected:Nn \__algobox_unindent: { + \int_decr:N \l__algobox_level_int +} + +\cs_new_protected:Nn \__algobox_node:nn { + \node[algobox~#1/.try, anchor=base~west, inner~xsep=0pt] + (node) at (\l__algobox_lastnode_tl.base~east) {#2}; + \tl_set:Nn \l__algobox_lastnode_tl {node} +} + + +\cs_new_protected:Nn \__algobox_parseall:n { + \tl_set:Nn \l_tmpa_tl {#1} + \seq_set_split:NnV \l_tmpa_seq {\;} \l_tmpa_tl + % Now build up the algorithm body, working around the few infix notations. + \tl_clear:N \l__algobox_body_tl + \seq_map_variable:NNn \l_tmpa_seq \l_tmpa_tl { + \tl_if_in:NnT \l_tmpa_tl {\ESTDUTYPE} { + \tl_put_left:Nn \l_tmpa_tl {\__algobox_ESTDUTYPE:w} + } + \tl_if_in:NnT \l_tmpa_tl {\PRENDLAVALEUR} { + \tl_put_left:Nn \l_tmpa_tl {\__algobox_PRENDLAVALEUR:w} + } + \tl_put_right:Nn \l_tmpa_tl { \; } + \tl_put_right:NV \l__algobox_body_tl \l_tmpa_tl + } + \tl_use:N \l__algobox_body_tl +} + +\bool_new:N \l__algobox_balanced_first_bool +\cs_new_protected:Npn \__algobox_new_balanced_command:nNNnn #1#2#3 { + \cs_new_protected:cpn {#1} ##1 #2 { + \tl_set:Nn \l__algobox_prefix_tl { ##1 } + \tl_clear:N \l__algobox_balanced_tl + \bool_set_true:N \l__algobox_balanced_first_bool + \use:c {#1_stage2} #2 + } + \cs_new_protected:cpn {#1_stage2} ##1 #2 ##2 #3 { + \tl_put_right:Nn \l__algobox_balanced_tl { ##1 } + \bool_if:NF \l__algobox_balanced_first_bool { + \tl_put_right:Nn \l__algobox_balanced_tl { #2 } + } + \tl_if_in:nnTF {##2} {#2} { + \bool_set_false:N \l__algobox_balanced_first_bool + \use:c {#1_stage2} ##2 \q_mark + }{ + \tl_put_right:Nn \l__algobox_balanced_tl { ##2 } + \tl_replace_all:Nnn \l__algobox_balanced_tl {\q_mark} {#3} + \tl_set:Nx \l_tmpa_tl { + \exp_not:c {#1_stage3} + \exp_not:V \l__algobox_prefix_tl + \exp_not:n {#2} + { + \exp_not:V \l__algobox_balanced_tl + } + } + \tl_use:N \l_tmpa_tl + } + } + \exp_args:Nc \NewDocumentCommand {#1_stage3} +} + +\cs_new_protected:Npn \__algobox_if_next:NTF #1#2#3 { + \peek_meaning_remove_ignore_spaces:NTF \; { + \__algobox_if_next:NTF #1 {#2} {#3} + }{ + \peek_meaning_remove_ignore_spaces:NTF \par { + \__algobox_if_next:NTF #1 {#2} {#3} + }{ + \peek_meaning_ignore_spaces:NTF #1 {#2} {#3} + } + } +} + +\NewDocumentCommand \__algobox_VARIABLES:w {} { + \__algobox_indent:nn {structure} {VARIABLES} +} + +\NewDocumentCommand \__algobox_ESTDUTYPE:w { +u{\ESTDUTYPE} +u{\;} } { + \__algobox_block:nn {normal} { + \ignorespaces #1 \unskip\c_space_token\null + } + \__algobox_node:nn {motclef}{EST_DU_TYPE} + \__algobox_node:nn {normal}{\null\c_space_token#2} +} + +\NewDocumentCommand \__algobox_DEBUTALGORITHME:w {} { + \int_compare:nNnT \l__algobox_level_int = \c_one { + % if there was a VARIABLES before + \__algobox_unindent: + } + \__algobox_indent:nn {structure} {DEBUT_ALGORITHME} +} + +\NewDocumentCommand \__algobox_FINALGORITHME:w {} { + \int_compare:nNnT \l__algobox_level_int = \c_one { + \__algobox_unindent: + \__algobox_block:nn {structure} {FIN_ALGORITHME} + } +} + +\NewDocumentCommand \__algobox_PRENDLAVALEUR:w { u{\PRENDLAVALEUR} m } { + \__algobox_block:nn {normal} { + \ignorespaces#1\unskip\c_space_token\null + } + \__algobox_node:nn {motclef}{PREND_LA_VALEUR} + \__algobox_node:nn {normal}{\null\c_space_token#2} +} + +\__algobox_new_balanced_command:nNNnn + {__algobox_SI:w} \DEBUTSI \FINSI { r() u{\DEBUTSI} +m } +{ + \__algobox_indent:nn {sialors} {SI} + \__algobox_node:nn {normal}{\null\c_space_token(#1)\c_space_token\null} + \__algobox_node:nn {sialors}{ALORS} + \__algobox_block:nn {sialors} {DEBUT_SI} + #3 + \__algobox_block:nn {sialors} {FIN_SI} + \__algobox_if_next:NTF \SINON { + \__algobox_SINON:w + }{ + \__algobox_unindent: + } +} +\__algobox_new_balanced_command:nNNnn + {__algobox_SINON:w} \DEBUTSINON \FINSINON { u{\DEBUTSINON} +m } { + \__algobox_indent:nn {sialors} {SINON} + \__algobox_block:nn {sialors} {DEBUT_SINON} + #2 + \__algobox_block:nn {sialors} {FIN_SINON} + \__algobox_unindent: + \__algobox_unindent: +} + +\__algobox_new_balanced_command:nNNnn + {__algobox_POUR:w} \DEBUTPOUR \FINPOUR + { u{\ALLANTDE} u{\A} u{\DEBUTPOUR} +m } { + \__algobox_indent:nn {pour} {POUR} + \__algobox_node:nn {normal}{\null\c_space_token #1\unskip\c_space_token\null} + \__algobox_node:nn {pour}{ALLANT_DE} + \__algobox_node:nn {normal}{\null\c_space_token #2\unskip + \c_space_token A~#3\unskip\c_space_token\null} + \__algobox_block:nn {pour} {DEBUT_POUR} + #4 + \__algobox_block:nn {pour} {FIN_POUR} + \__algobox_unindent: +} + +\__algobox_new_balanced_command:nNNnn {__algobox_TANTQUE:w} \DEBUTTANTQUE \FINTANTQUE + { r() u{\DEBUTTANTQUE} +m } +{ + \__algobox_indent:nn {tantque} {TANT_QUE} + \__algobox_node:nn {normal}{\null\c_space_token(#1)\c_space_token\null} + \__algobox_node:nn {tantque}{FAIRE} + \__algobox_block:nn {tantque} {DEBUT_TANT_QUE} + #3 + \__algobox_block:nn {tantque} {FIN_TANT_QUE} + \__algobox_unindent: +} + +\NewDocumentCommand \__algobox_LINE:w { s O{normal} m } { + \IfBooleanTF {#1} { + \__algobox_indent:nn {#2} {#3} + \__algobox_unindent: + }{ + \__algobox_block:nn {#2} {#3} + } +} + +\NewDocumentCommand \__algobox_NODE:w { O{normal} m } { + \__algobox_node:nn {#1} {#2} +} + + +\cs_new_protected_nopar:Nn \__algobox_begincode:n { + \int_zero:N \l__algobox_level_int + \begin{tikzpicture}[#1] + \coordinate (H) at (0,0); + \coordinate (A\int_use:N \l__algobox_level_int) at (0,0); + \cs_set_eq:NN \par \prg_do_nothing: + \cs_set_eq:NN \; \prg_do_nothing: + \cs_set_eq:NN \LINE \__algobox_LINE:w + \cs_set_eq:NN \NODE \__algobox_NODE:w + \cs_set_eq:NN \VARIABLES \__algobox_VARIABLES:w + \cs_set_eq:NN \DEBUTALGORITHME \__algobox_DEBUTALGORITHME:w + \cs_set_eq:NN \FINALGORITHME \__algobox_FINALGORITHME:w + \cs_set_eq:NN \SI \__algobox_SI:w + \cs_set_eq:NN \POUR \__algobox_POUR:w + \cs_set_eq:NN \TANTQUE \__algobox_TANTQUE:w + \cs_set:Npn \AFFICHER {\__algobox_keyword:nw {AFFICHER}} + \cs_set:Npn \AFFICHERCALCUL {\__algobox_keyword:nw {AFFICHERCALCUL}} + \cs_set:Npn \LIRE {\__algobox_keyword:nw {LIRE}} + \cs_set:Npn \PAUSE {\__algobox_block:nn{motclef}{PAUSE}} + \cs_set:Npn \//##1\; {\__algobox_block:nn{commentaire}{//##1}} +} +\cs_new_protected_nopar:Nn \__algobox_closecode: { + \end{tikzpicture} +} + +\NewDocumentCommand \__algobox_keyword:nw {m +u{\;}} { + \__algobox_block:nn {motclef} {#1} + \__algobox_node:nn {normal}{\null\c_space_token#2} +} + +\NewDocumentCommand \smalgobox { O{} m } { + \group_begin: + \__algobox_begincode:n {every~smalgobox/.try,#1} + \__algobox_parseall:n {#2} + \__algobox_closecode: + \group_end: +} + +\NewDocumentEnvironment {algobox} {O{}} { + \cs_set_protected:Nn \__algobox_algobox:n { + \__algobox_begincode:n {every~algobox/.try,#1} + \__algobox_parseall:n {##1} + \__algobox_closecode: + } + \Collect@Body\__algobox_algobox:n +}{ +} +%% +%% +%% End of file `algobox.sty'. |