summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/proflycee/tex/proflycee-tools-piton.tex
blob: e9fd389d6dedcb20cac4f99479d895711109d999 (plain)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
% proflycee-tools-piton.tex
% Copyright 2023  Cédric Pierquet
% Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt

%3.01e	Correction du comportement de la console repl piton/pyluatex
%2.7.6	Correction du comportement de la console, avec une meilleure gestion de la largeur ^^ (merci à ablasz ;-))
%2.7.5	Ajout d'un argument optionnel pour commencer les codes python à un numéro de ligne différent de 1
%2.7.3	Correction de la couleur des bordures
%2.6.9	Amalioration de la gestion des style := intégration directe dans la tcbox !
%2.5.9	Ajout d'une clé pour la couleur des nombres
%2.5.8	Modification des marges
%2.5.7	Style alternatif

\RequirePackage{iftex}

%%=============PYTHONPITON

%==Clés globales
\defKV[envpiton]{%
	Largeur=\def\CODPITlargeur{#1},%
	Alignement=\def\CODPITalign{#1},%
	TaillePolice=\def\CODPITfonte{#1},%
	Style=\def\CODPITstyle{#1},%
	Titre=\def\CODPITtitre{#1},%
	EspacementV=\def\CODPITespV{#1},%
	CouleurNombres=\def\CODPITcolnb{#1}
}

\setKVdefault[envpiton]{%
	Largeur=\linewidth,%
	Alignement=center,%
	Lignes=true,%
	Gobble=true,%
	TaillePolice=\footnotesize,%
	Filigrane=false,%
	Style=Moderne,%
	Cadre=true,%
	BarreTitre=true,%
	Titre={{\scriptsize\faCode} Code Python},%
	EspacementV=0.5\baselineskip,%
	CouleurNombres=orange
}

%==Style Moderne
\tcbset{stylepiton/.style={%
	enhanced,boxrule=1.25pt,%
	sharp corners=downhill,arc=12pt,
	before skip=\CODPITespV,after skip=\CODPITespV,%
	top=\baselineskip,bottom=0mm,left=0.6em,right=5mm,%
	attach boxed title to top right={yshift=-\tcboxedtitleheight},
	boxed title style={
		size=small,colback=CouleurVertForet!25,boxrule=1.25pt,
		colframe=CouleurVertForet,boxsep=1.25pt,
		sharp corners=downhill,
		arc=12pt,
		top=2pt,bottom=1pt,left=6pt,right=6pt
		},
	fonttitle=\color{CouleurVertForet}\itshape\ttfamily\footnotesize,
	title={{\scriptsize\faPython}\:Code Python}
	}
}

%==Style Classique
\tcbset{thonnystyle/.style={%
	enhanced,boxrule=0.75pt,colframe=darkgray!50!black,%
	sharp corners,top=0mm,bottom=0mm,left=0.4em,right=5mm,%
	before skip=\CODPITespV,after skip=\CODPITespV,%
	colback=white
	}
}

\tcbset{thonnystylelineos/.style={%
	thonnystyle,%
	underlay={%
		\begin{tcbclipinterior}
			\draw[draw=none,fill=lightgray!25] (interior.south west) rectangle ([xshift=1.3em]interior.north west) ;
		\end{tcbclipinterior}%
		}
	}
}

%==Création de la boîte (essai v2 ?)
\ifluatex
\RequirePackage{piton}
\NewPitonEnvironment{CodePiton}{ 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{ Number = \color{\CODPITcolnb} }%
	\ifboolKV[envpiton]{Lignes}%si lignes=true
		{\PitonOptions{left-margin=0.75em,all-line-numbers,line-numbers={#3}}}%left-margin=auto,
		{}%
	\ifboolKV[envpiton]{Gobble}%si gobble=true
		{\PitonOptions{tabs-auto-gobble}}%
		{}%
	\PitonOptions{break-lines,indent-broken-lines}%,numbers-sep=0.65em}
	%------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}}}%
			%\tcbset{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,#2]
}%
{%
	\endtcolorbox%
}
\fi


%======CONSOLE PYLUATEX (package à charger manuellement !!)
\tcbset{consolepylua/.style={%base de la boîte
	enhanced,colback=white,colframe=CouleurVertForet,sharp corners,boxrule=1pt,%
	top=1.5mm,bottom=1.5mm,left=2mm,right=2mm,fontupper=\footnotesize,%
	before skip=0.5\baselineskip,after skip=0.5\baselineskip,%
	}
}

\tcbset{consolepyluatexlogo/.style={%avec logo python
	consolepylua,%
	overlay={%
		\draw ([yshift=0.5pt]frame.south) node[CouleurVertForet!50!black,fill=white,font=\scriptsize\ttfamily] {\scalebox{0.8}[0.8]{\faPython} Fin de la Console Python \scalebox{0.8}[0.8]{\faPython}} ;
		\draw ([yshift=-0.5pt]frame.north) node[CouleurVertForet!50!black,fill=white,font=\scriptsize\ttfamily] {\scalebox{0.8}[0.8]{\faPython} Début de la Console Python \scalebox{0.8}[0.8]{\faPython}} ;
		}
	}
}

\tcbset{consolepyluatex/.style={%sans logo python
	consolepylua,%
	overlay={%
		\draw ([yshift=0.5pt]frame.south) node[CouleurVertForet!50!black,fill=white,font=\scriptsize\ttfamily] {Fin de la Console Python} ;
		\draw ([yshift=-0.5pt]frame.north) node[CouleurVertForet!50!black,fill=white,font=\scriptsize\ttfamily] {Début de la Console Python} ;
		}
	}
}

\defKV[consolepyluatex]{%
	Largeur=\def\ConsPyluaLarg{#1},
	Alignement=\def\ConsPyluaAlign{#1}
}
\setKVdefault[consolepyluatex]{%
	Logo=true,%
	Largeur=\linewidth,%
	Alignement=flush left
}

\NewDocumentEnvironment{ConsolePiton}{ O{} D<>{} m }%
%1=options piton
%2=clés
%3=options tcbox
{
	\restoreKV[consolepyluatex]% revenir au valeurs par défaut
	\setKV[consolepyluatex]{#2}% lit les arguments optionnels
	\PitonOptions{width={\ConsPyluaLarg-4mm},break-lines,end-of-broken-line={},continuation-symbol={},#1}
	\PyLTVerbatimEnv
	\ifboolKV[consolepyluatex]{Logo}
		{%
			\begin{tcolorbox}[consolepyluatexlogo,width=\ConsPyluaLarg,\ConsPyluaAlign,#3]
		}%
		{%
			\begin{tcolorbox}[consolepyluatex,width=\ConsPyluaLarg,\ConsPyluaAlign,#3]
		}%
%		{\tcbset{consolepyluatexlogo,width=\ConsPyluaLarg,\ConsPyluaAlign,#3}}
%		{\tcbset{consolepyluatex,width=\ConsPyluaLarg,\ConsPyluaAlign,#3}}
		\begin{pythonrepl}%
}
{
	\end{pythonrepl}%
	\directlua{
	tex.print("\\begin{Piton}")
	tex.print(pyluatex.get_last_output())
	tex.print("\\end{Piton}")
	}%
	\end{tcolorbox}
}

\endinput