diff options
Diffstat (limited to 'macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex')
-rw-r--r-- | macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex | 165 |
1 files changed, 159 insertions, 6 deletions
diff --git a/macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex b/macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex index 418c5aa8cc..52ef738955 100644 --- a/macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex +++ b/macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex @@ -2,6 +2,8 @@ % Copyright 2023-2024 Cédric Pierquet % Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt +%3.04f Ajout de clés pour la coloration des nombres et Piton +%3.04d PitonInputFile et styles, pour compatibilité pfm %3.03c Thonny via piton + modification clé gobble ? %3.01f PseudoCode via piton (?) %3.01e Correction du comportement de la console repl piton/pyluatex @@ -41,7 +43,7 @@ BarreTitre=true,% Titre={{\scriptsize\faCode}~~Code Python},% EspacementV=0.5\baselineskip,% - CouleurNombres=orange + CouleurNombres={orange!75!black} } %==Style Moderne @@ -159,7 +161,7 @@ \useKVdefault[envpiton]% \setKV[envpiton]{#1}% on paramètres les nouvelles clés et on les simplifie %------les styles piton - \SetPitonStyle{ Number = \color{\CODPITcolnb} } + \SetPitonStyle[Python]{ Number = \color{\CODPITcolnb} } \ifboolKV[envpiton]{Lignes}%si lignes=true {\PitonOptions{left-margin=0.75em,line-numbers={skip-empty-lines=false,label-empty-lines=true,#3}}}%left-margin=auto, {}% @@ -220,6 +222,57 @@ \endtcolorbox% } +%inputfile +\NewDocumentCommand\CodePitonFichier{ O{} m D<>{} }{% + {\tcbset{reset} + \useKVdefault[envpiton]% + \setKV[envpiton]{#1}% on paramètres les nouvelles clés et on les simplifie + %------les styles piton + \SetPitonStyle[Python]{ Number = \color{\CODPITcolnb} } + \ifboolKV[envpiton]{Lignes}%si lignes=true + {\PitonOptions{left-margin=0.75em,line-numbers,line-numbers={skip-empty-lines=false,label-empty-lines=true,#3}}}%left-margin=auto, + {}% + \PitonOptions{break-lines,indent-broken-lines,continuation-symbol={\;}}%,numbers-sep=0.65em}%language=Python} + %------les styles tcbox + \IfEq{\CODPITstyle}{Moderne}%style Moderne (défaut) + {% + \tcbset{cadre/.style={}} + \tcbset{titre/.style={}} + \tcbset{stylebase/.style={stylepiton,colframe=CouleurVertForet,colback=CouleurVertForet!5,width=\CODPITlargeur,fontupper=\CODPITfonte,fontlower=\CODPITfonte,\CODPITalign,leftupper=0.75em}} + \ifboolKV[envpiton]{Filigrane}%si filigrane + {\tcbset{filigrane/.style={watermark text={\faPython},watermark opacity=0.175,watermark zoom=0.50}}}% + {\tcbset{filigrane/.style={}}}% + } + {}% + \IfEq{\CODPITstyle}{Classique}%style Classique + {% + \ifboolKV[envpiton]{Lignes}%si lignes=true + {\tcbset{stylebase/.style={thonnystylelineos,leftupper=0.75em,width=\CODPITlargeur,colframe=darkgray!50!black,fontupper=\CODPITfonte,fontlower=\CODPITfonte,\CODPITalign}}}% + {\tcbset{stylebase/.style={thonnystyle,leftupper=0.4em,width=\CODPITlargeur,colframe=darkgray!50!black,fontupper=\CODPITfonte,fontlower=\CODPITfonte,\CODPITalign}}}% + \ifboolKV[envpiton]{Filigrane}%si filigrane + {\tcbset{filigrane/.style={watermark text={\faPython},watermark opacity=0.25,watermark zoom=0.50}}}% + {\tcbset{filigrane/.style={}}}% + \ifboolKV[envpiton]{BarreTitre}% + {% + \ifboolKV[envpiton]{Cadre} + {\tcbset{cadre/.style={}}}% + {\tcbset{cadre/.style={boxrule=0pt,frame hidden}}}% + \tcbset{titre/.style={lefttitle=0.4em,title={\CODPITtitre},fonttitle=\bfseries\footnotesize\sffamily,colbacktitle=darkgray!50!black}} + }% + {% + \tcbset{titre/.style={notitle}} + \ifboolKV[envpiton]{Cadre} + {\tcbset{cadre/.style={}}} + {\tcbset{cadre/.style={boxrule=0pt,frame hidden}}} + } + } + {}% + %on crée la boîte + \tcolorbox[stylebase,filigrane,cadre,titre] + \PitonInputFile{#2} + \endtcolorbox}% +} + %piton >= 2.4 \NewPitonEnvironment{PseudoCodePiton}{ O{} m D<>{} }% {% @@ -317,6 +370,86 @@ \endtcolorbox% } +%--inputfile +\NewDocumentCommand\PseudoCodePitonFichier{ O{} m D<>{} }{% + {\tcbset{reset} + \useKVdefault[envpcpiton]% + \setKV[envpcpiton]{#1}% on paramètres les nouvelles clés et on les simplifie + %------les styles piton + \ifboolKV[envpcpiton]{Lignes}%si lignes=true + {\PitonOptions{left-margin=0.75em,all-line-numbers}}%left-margin=auto, + {}% + \PitonOptions{break-lines,indent-broken-lines,language=minimal,continuation-symbol={\;}}%,numbers-sep=0.65em}% + \SetPitonStyle{ Number = } + \ifboolKV[envpcpiton]{Couleurs}% + {% + \SetPitonIdentifier[minimal]{Algorithme,Fonction,Début,Paramètre,Paramètres,Faire,Fin,Si,Pour,Tant,Que,que,alors,Alors,Sinon,SinonSi,FinSi,FinPour,FinTantQue,TantQue,Variable,Variables,Procédure}{\color{MotsClesPseudoCodeA}} + \SetPitonIdentifier[minimal]{Afficher,Renvoyer,Saisir}{\color{MotsClesPseudoCodeB}} + % \PitonOptions{ + % identifiers = + % { + % names = {Algorithme,Fonction,Début,Paramètre,Paramètres,allant,Faire,Fin,Si,Pour,Tant,Que,que,alors,Alors,Sinon,SinonSi,FinSi,FinPour,FinTantQue,TantQue,Variable,Variables,Procédure}, + % style = \color{MotsClesPseudoCodeA} + % } , + % identifiers = + % { + % names = {Afficher,Retourner,Saisir}, + % style = \color{MotsClesPseudoCodeB} + % } + % }% + \SetPitonStyle + { + String = \color{MotsClesPseudoCodeChaine}, + Comment = \itshape\color{gray}, + } + }% + {% + \SetPitonStyle + { + String = , + Comment = \itshape + } + }% + %------les styles tcbox + \IfEq{\CODPITPCstyle}{Moderne}%style Moderne (défaut) + {% + \tcbset{cadre/.style={}} + \tcbset{titre/.style={}} + \tcbset{stylebase/.style={stylepcpiton,colframe=CouleurVertForet,colback=CouleurVertForet!5,width=\CODPITPClargeur,fontupper=\CODPITPCfonte,fontlower=\CODPITPCfonte,\CODPITPCalign,leftupper=0.75em}} + \ifboolKV[envpcpiton]{Filigrane}%si filigrane + {\tcbset{filigrane/.style={watermark text={\faCode},watermark opacity=0.175,watermark zoom=0.50}}}% + {\tcbset{filigrane/.style={}}}% + } + {}% + \IfEq{\CODPITPCstyle}{Classique}%style Classique + {% + \ifboolKV[envpcpiton]{Lignes}%si lignes=true + {\tcbset{stylebase/.style={thonnypcstylelineos,leftupper=0.75em,width=\CODPITPClargeur,colframe=darkgray!50!black,fontupper=\CODPITPCfonte,fontlower=\CODPITPCfonte,\CODPITPCalign}}}% + {\tcbset{stylebase/.style={thonnypcstyle,leftupper=0.4em,width=\CODPITPClargeur,colframe=darkgray!50!black,fontupper=\CODPITPCfonte,fontlower=\CODPITPCfonte,\CODPITPCalign}}}% + \ifboolKV[envpcpiton]{Filigrane}%si filigrane + {\tcbset{filigrane/.style={watermark text={\faCode},watermark opacity=0.25,watermark zoom=0.50}}}% + {\tcbset{filigrane/.style={}}}% + \ifboolKV[envpcpiton]{BarreTitre}% + {% + \ifboolKV[envpcpiton]{Cadre} + {\tcbset{cadre/.style={}}}% + {\tcbset{cadre/.style={boxrule=0pt,frame hidden}}}% + \tcbset{titre/.style={lefttitle=0.4em,title={\CODPITPCtitre},fonttitle=\bfseries\footnotesize\sffamily,colbacktitle=darkgray!50!black}} + }% + {% + \tcbset{titre/.style={notitle}} + \ifboolKV[envpcpiton]{Cadre} + {\tcbset{cadre/.style={}}} + {\tcbset{cadre/.style={boxrule=0pt,frame hidden}}} + } + } + {}% + %on crée la boîte + \tcolorbox[stylebase,filigrane,cadre,titre] + \PitonInputFile{#2}% + \endtcolorbox}% +} + %======CONSOLE PYLUATEX (package à charger manuellement !!) \tcbset{consolepylua/.style={%base de la boîte enhanced,colback=white,colframe=CouleurVertForet,sharp corners,boxrule=1pt,% @@ -345,12 +478,14 @@ \defKV[consolepyluatex]{% Largeur=\def\ConsPyluaLarg{#1}, - Alignement=\def\ConsPyluaAlign{#1} + Alignement=\def\ConsPyluaAlign{#1},% + CouleurNombres=\def\CODPITcolnb{#1} } \setKVdefault[consolepyluatex]{% Logo=true,% Largeur=\linewidth,% - Alignement=flush left + Alignement=flush left,% + CouleurNombres={orange!75!black} } \NewDocumentEnvironment{ConsolePiton}{ O{} D<>{} m }% @@ -360,6 +495,7 @@ { \restoreKV[consolepyluatex]% revenir au valeurs par défaut \setKV[consolepyluatex]{#2}% lit les arguments optionnels + \SetPitonStyle[Python]{ Number = \color{\CODPITcolnb} } \PitonOptions{width={\ConsPyluaLarg-5mm},break-lines,end-of-broken-line={\,},continuation-symbol={\;},#1} %\PitonOptions{width={\ConsPyluaLarg-5mm},#1} \PyLTVerbatimEnv @@ -392,14 +528,16 @@ NomFichier=\def\thonnypitonfilename{#1},% NomConsole=\def\thonnypitonshellname{#1},% IntroConsole=\def\thonnypitonintroconsole{#1},% - Gobble=\def\thonnypitongobble{#1} + Gobble=\def\thonnypitongobble{#1},% + CouleurNombres=\def\CODPITcolnb{#1} } \setKVdefault[pitonthonny]{% NomFichier=script.py,% NomConsole=console,% IntroConsole={Python 3.11.6 /usr/bin/python},% - Gobble={} + Gobble={},% + CouleurNombres={orange!75!black} } \NewPitonEnvironment{PitonThonnyEditor}{ D<>{} O{} m }% @@ -407,6 +545,7 @@ \restoreKV[pitonthonny]% \setKV[pitonthonny]{#1}% \settowidth{\LargeurNumbersThonny}{\footnotesize\texttt{00}}% + \SetPitonStyle[Python]{Number=\color{\CODPITcolnb}} \PitonOptions{left-margin=\LargeurNumbersThonny+1mm,line-numbers={skip-empty-lines=false,label-empty-lines=true},break-lines,indent-broken-lines,continuation-symbol={}}% %--gestion du gobble \IfStrEqCase{\thonnypitongobble}{% @@ -428,6 +567,19 @@ \endtcolorbox% }% +\NewDocumentCommand\PitonThonnyEditorFichier{ D<>{} O{\linewidth} m }{% + {\restoreKV[pitonthonny]% + \setKV[pitonthonny]{#1}% + \settowidth{\LargeurNumbersThonny}{\footnotesize\texttt{00}}% + \SetPitonStyle[Python]{Number=\color{\CODPITcolnb}} + \PitonOptions{left-margin=\LargeurNumbersThonny+1mm,line-numbers,line-numbers={skip-empty-lines=false,label-empty-lines=true},break-lines,indent-broken-lines,continuation-symbol={}}% + \tcbset{tcbthonnypiton/.style={title=\vphantom{pf}\thonnypitonfilename\:\textcolor{gray}{×}},before skip=0.33\baselineskip,after skip=0.33\baselineskip}% + \tcolorbox[sharp corners=all,enhanced,size=small,width=#2,colframe=gray,colback=lightgray!5,tcbthonnypiton,fonttitle=\scriptsize\sffamily,coltitle=black, + attach boxed title to top left={yshift*=-0.4pt},fontupper=\footnotesize,bottom=-0.25mm,boxed title style={size=tight,colback=lightgray!15,sharp corners=all,boxrule=0.4pt,boxsep=2pt},boxrule=0.4pt,overlay={\begin{tcbclipinterior}\fill[draw=none,gray!25] ([shift={(0.4pt,0.4pt)}]frame.south west) rectangle ([shift={(\LargeurNumbersThonny+1mm+0.8pt,-0.4pt)}]frame.north west) ;\end{tcbclipinterior}}]% + \PitonInputFile{#3} + \endtcolorbox}% +}% + \NewDocumentEnvironment{PitonThonnyConsole}{ D<>{} O{} m }% { \restoreKV[pitonthonny]% @@ -435,6 +587,7 @@ \PyLTVerbatimEnv% \tcbset{tcbthonnypitonconsole/.style={title=\vphantom{pf}\thonnypitonshellname\:\textcolor{gray}{×}},before skip=0.33\baselineskip,after skip=0.33\baselineskip}% \noindent% + \SetPitonStyle[Python]{Number=\color{\CODPITcolnb}} %--gestion du gobble \IfStrEqCase{\thonnypitongobble}{% {auto}{\PitonOptions{auto-gobble}}% |