summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/proflycee/tex/ProfLycee.sty
blob: ceaf2ef19116a18516ac0602f4eca76e140f64ac (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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
% Author     : C. Pierquet
% licence    : Released under the LaTeX Project Public License v1.3c
% or later, see http://www.latex-project.org/lppl.txtf

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ProfLycee}[2022/02/13 - v1.0.2 - Aide pour l'utilisation de LaTeX en lycée]
% 1.0.2	Environnement pour présenter du code python (avec pythontex)
% 1.0.1	Modif mineure du chargement de xcolor (compatibilité avec d'autres packages notamment...)
% 1.0	Version initiale

%------Packages utiles
\RequirePackage[table,svgnames]{xcolor}%Gestion des couleurs
\RequirePackage{tikz}
\RequirePackage{pgf,pgffor}
\RequirePackage{ifthen}
\RequirePackage{xkeyval}
\RequirePackage{xfp}
\RequirePackage{xstring}
\RequirePackage{simplekv}
\RequirePackage{listofitems}
\RequirePackage{xintexpr}
\RequirePackage{fontawesome5}
%librairies tikz
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
%tcolorbox
\RequirePackage[most]{tcolorbox}
%divers
\RequirePackage{ifluatex}
%python
\RequirePackage{fancyvrb}
\RequirePackage[gobble=auto]{pythontex}
\setpythontexlistingenv{pythont}

%---------------SPLINES----------------------
%------commande utile pour extraire des infos d'une liste
\newcommand\extractcoeff[2]{% #1=liste & #2=numero
	\setsepchar{§}%
	\readlist\lcoeffs{#1}
	\ifnum \lcoeffslen=1
		\def\COEFFA{#1}
		\def\COEFFB{#1}
	\else
		\itemtomacro\lcoeffs[#2]\COEFF
		\IfSubStr{\COEFF}{/}%
			{\StrCut{\COEFF}{/}{\COEFFA}{\COEFFB}}%
			{\def\COEFFA{\COEFF}\def\COEFFB{\COEFF}}
	\fi
}

%------splines en tikz avec ..controls
\defKV[spline]{%
	liste=\def\SPLliste{#1},%
	width=\def\SPLepaisseur{#1},%
	couleur=\def\SPLcouleur{#1},%
	coeffs=\def\SPLcoeffs{#1},%
	couleurpoints=\def\SPLcouleurpoints{#1},%
	taillepoints=\def\SPLtaillepoints{#1},%
	style=\def\SPLstyle{#1}
}

\setKVdefault[spline]{%
	liste=,%
	width=1.25pt,%
	couleur=red,%
	coeffs=3,%
	couleurpoints=black,%
	taillepoints=2pt,%
	affpoints=false,%
	style=
}

\newcommand\splinetikz[1][]{%
	\useKVdefault[spline]
	\setKV[spline]{#1}% on paramètres les nouvelles clés et on les simplifie
	%on lit la liste des points/nbderivés et on stocke dans \listepoints
	\setsepchar[.]{§./}%
	\readlist\SPLlistepoints\SPLliste
	\def\SPLnbsplines{\inteval{\SPLlistepointslen-1}}
	%si uniquement deux points, pas de boucle...
	\ifnum \SPLlistepointslen=2
		%extraction des coeffs de compensation
		\extractcoeff{\SPLcoeffs}{1}%
		%extraction des coordonnées
		\itemtomacro\SPLlistepoints[1,1]\xa
		\itemtomacro\SPLlistepoints[1,2]\ya
		\itemtomacro\SPLlistepoints[1,3]\fprimea
		\itemtomacro\SPLlistepoints[2,1]\xb
		\itemtomacro\SPLlistepoints[2,2]\yb
		\itemtomacro\SPLlistepoints[2,3]\fprimeb
		\draw[line width=\SPLepaisseur,\SPLcouleur,\SPLstyle] (\xa,\ya) ..controls +({atan \fprimea}:{(\xb-\xa)/\COEFFA}) and +({-180 + atan \fprimeb}:{(\xb-\xa)/\COEFFA}).. (\xb,\yb) ;%
	%sinon on construit bout par bout !
	\else
		\foreach \i in {1,2,...,\SPLnbsplines}{
			%extraction des coeffs de compensation
			\extractcoeff{\SPLcoeffs}{\i}
			\def\j{\inteval{\i+1}}
			\itemtomacro\SPLlistepoints[\i,1]\xa
			\itemtomacro\SPLlistepoints[\i,2]\ya
			\itemtomacro\SPLlistepoints[\i,3]\fprimea
			\itemtomacro\SPLlistepoints[\j,1]\xb
			\itemtomacro\SPLlistepoints[\j,2]\yb
			\itemtomacro\SPLlistepoints[\j,3]\fprimeb
			\draw[line width=\SPLepaisseur,\SPLcouleur,\SPLstyle] (\xa,\ya) ..controls +({atan \fprimea}:{(\xb-\xa)/\COEFFA}) and +({-180 + atan \fprimeb}:{(\xb-\xa)/\COEFFB}).. (\xb,\yb) ;%
		}
	\fi
	\ifboolKV[spline]{affpoints}%on affiche les points de contrôle
	{%
		\foreach \i in {1,2,...,\SPLlistepointslen}{%
			\itemtomacro\SPLlistepoints[\i,1]\xa
			\itemtomacro\SPLlistepoints[\i,2]\ya
			\filldraw[\SPLcouleurpoints] (\xa,\ya) circle[radius=\SPLtaillepoints] ;%
		}
	}
	{}
}

%------tangente(s) en TikZ, avec point/dérivée ou liste points/dérivées
\defKV[tgte]{%
	liste=\def\TGTliste{#1},%
	width=\def\TGTepaisseur{#1},%
	couleur=\def\TGTcouleur{#1},%
	xl=\def\TGTXL{#1},%
	xr=\def\TGTXR{#1},%
	style=\def\TGTstyle{#1},%
	point=\def\TGTnumpt{#1}
}

\setKVdefault[tgte]{
	liste=,%
	width=1.25pt,%
	couleur=red,%
	xl=0.5,xr=0.5,%
	style=,%
	point=1
}

\newcommand\tangentetikz[1][]{%
	\useKVdefault[tgte]%
	\setKV[tgte]{#1}% on paramètres les nouvelles clés et on les simplifie
	\setsepchar[.]{§./}%
	\readlist\TGTlistepoints\TGTliste
	\itemtomacro\TGTlistepoints[\TGTnumpt,1]\xa
	\itemtomacro\TGTlistepoints[\TGTnumpt,2]\ya
	\itemtomacro\TGTlistepoints[\TGTnumpt,3]\fprimea
	\def\TGTDEB{\fpeval{\xa-\TGTXL}}\def\TGTFIN{\fpeval{\xa+\TGTXR}}%
	\draw[line width=\TGTepaisseur,\TGTcouleur,domain=\TGTDEB:\TGTFIN,\TGTstyle] plot (\x,{\fprimea*(\x-\xa)+\ya}) ;%
}

%----------------FENÊTRE CALCUL FORMEL
\newcommand\CFchap{\textasciicircum}
\newcounter{CFnum}
% ========= DEF DES CLES PARAM FENETRES XCAS
\defKV[paramfenxcas]{%
	larg=\def\CFlarg{#1},%
	esplg=\def\CFesplg{#1},%
	premcol=\def\CFpremcol{#1},%
	hpremcol=\def\CFhpremcol{#1},%
	taille=\def\CFtaille{#1},%
	couleur=\def\CFcouleur{#1},%
	tailletitre=\def\CFtailletitre{#1},%
	couleurcmd=\def\CFcoulcmd{#1},%
	couleurres=\def\CFcoulres{#1},%
	poscmd=\def\CFposcmd{#1},%
	posres=\def\CFposres{#1},%
	labeltitre=\def\CFlabeltitre{#1}%
}
\setKVdefault[paramfenxcas]{%
	larg=16,esplg=2pt,premcol=0.3,hpremcol=0.4,%
	couleur=darkgray,menu=true,titre=false,tailletitre=\normalsize,taille=\normalsize,%
	sep=true,posres=centre,poscmd=gauche,%
	couleurcmd=red,couleurres=blue,%
	labeltitre={Résultats obtenus avec un logiciel de Calcul Formel}}
\newcommand\paramCF[1][]{%
	\setcounter{CFnum}{0}
	\useKVdefault[paramfenxcas]%
	\setKV[paramfenxcas]{#1}% on paramètres les nouvelles clés et on les simplifie
}
% ========= DEF DES CLES PARAM LIGNES XCAS =========
\defKV[paramlgxcas]{%
	hc=\def\CFhle{#1},%
	hr=\def\CFhlr{#1}
}
\setKVdefault[paramlgxcas]{hc=0.75,hr=0.75}
\newcommand\ligneCF[3][]{%
	\addtocounter{CFnum}{1}
	\def\CFL{\theCFnum}
	\def\CFLA{\inteval{\CFL-1}}%
	\useKVdefault[paramlgxcas]%
	\setKV[paramlgxcas]{#1}% on paramètres les nouvelles clés et on les simplifie
	\def\CFLA{\inteval{\CFL-1}}%
	%DÉCLARATION DES NŒUDS (les "6" coins des lignes commande et résultat)
	\xintifboolexpr{\CFL == 1}%si c'est la première ligne
		{\coordinate (A0\CFL) at (0,0);}
		{\coordinate (A0\CFL) at ($(A2\CFLA) + (0,{-\CFesplg})$);}
	\coordinate (A1\CFL) at ($(A0\CFL) +  (0,{-\CFhle})$);
	\coordinate (A2\CFL) at ($(A1\CFL) +  (0,{-\CFhlr})$);
	\coordinate (A3\CFL) at ($(A0\CFL) +  ({\CFlarg},0)$);
	\coordinate (A4\CFL) at ($(A1\CFL) +  ({\CFlarg},0)$);
	\coordinate (A5\CFL) at ($(A2\CFL) +  ({\CFlarg},0)$);
	%DÉCLARATION DES NŒUDS INTERMÉDIAIRES (pour les commandes et les résultats)
	\coordinate (C1\CFL) at ($(A0\CFL) + (0,{-0.5*\CFhle})$);
	\coordinate (C2\CFL) at ($(A0\CFL) + ({0.5*\CFlarg},{-0.5*\CFhle})$);
	\coordinate (C3\CFL) at ($(A0\CFL) + ({\CFlarg},{-0.5*\CFhle})$);
	\coordinate (R1\CFL) at ($(A1\CFL) + (0,{-0.5*\CFhlr})$);
	\coordinate (R2\CFL) at ($(A1\CFL) + ({0.5*\CFlarg},{-0.5*\CFhlr})$);
	\coordinate (R3\CFL) at ($(A1\CFL) + ({\CFlarg},{-0.5*\CFhlr})$);
	%RECTANGLE DE BASE
	\draw[\CFcouleur] (A0\CFL) rectangle (A5\CFL) ;
	%LA COMMANDE EN ROUGE
	\IfStrEq{\CFposcmd}{centre}%si poscmd=center
		{\draw (C2\CFL) node[\CFcoulcmd] {#2} ;}
		{}
	\IfStrEq{\CFposcmd}{gauche}%si poscmd=left
		{\draw (C1\CFL) node[right,\CFcoulcmd] {#2} ;}
		{}
	\IfStrEq{\CFposcmd}{right}%si poscmd=right
		{\draw (C3\CFL) node[left,\CFcoulcmd] {#2} ;}
		{}
	%LA LIGNE DE SÉPARATION
	\ifboolKV[paramfenxcas]{sep}%si sep=true
		{\draw[\CFcouleur] (A1\CFL) -- (A4\CFL);}
		{}
	%LE RÉSULTAT
	\IfStrEq{\CFposres}{centre}%si posrep=center
		{\draw (R2\CFL) node[\CFcoulres] {#3} ;}
		{}
	\IfStrEq{\CFposres}{gauche}%si posrep=left
		{\draw (R1\CFL) node[right,\CFcoulres] {#3} ;}
		{}
	\IfStrEq{\CFposres}{right}%si posrep=right
		{\draw (R3\CFL) node[left,\CFcoulres] {#3} ;}
		{}
	\ifboolKV[paramfenxcas]{sep}%si sep=true
		{\draw[\CFcouleur] (A1\CFL) -- (A4\CFL);}%
		{}
	%LE PETIT NUMÉRO
	\draw[\CFcouleur] (A0\CFL) rectangle ++ ({-\CFpremcol},{-\CFhpremcol}) node[\CFcouleur,midway,font=\small\sffamily\bfseries] {\CFL} ;
	%LE RECTANGLE "MENU"
	\ifboolKV[paramfenxcas]{menu}%si menu=true
		{\draw[\CFcouleur,fill=\CFcouleur!25] (A5\CFL) rectangle ++ (-0.65,0.25) node[black,midway,font=\tiny\sffamily\bfseries] {MENU} ;}%
		{}
	%LE BLOC "TITRE"
	\ifboolKV[paramfenxcas]{titre}%si titre=true
		{\draw[\CFcouleur,fill=lightgray!25,rounded corners] ($(A01) + (0,2pt)$) rectangle ++ ($({\CFlarg},2em)$) node[ForestGreen!50!\CFcouleur,midway,font=\CFtailletitre\ttfamily\bfseries] {\CFlabeltitre};}
		{}
}


%=========CONSOLEPYTHON=========== OK !!
\defKV[envpythonconsole]{%
	largeur=\def\CSPYlargeur{#1},%
	centre=\testboolKV{#1}
		{\def\hookcenterpre{\begin{center}}\def\hookcenterpost{\end{center}}}
		{\def\hookcenterpre{\begin{flushleft}}\def\hookcenterpost{\end{flushleft}}}
}

\setKVdefault[envpythonconsole]{%
	largeur=\linewidth,%
	centre=true,%
	label=true
}

\newenvironment{envconsolepythontex}[1][]{%
	\useKVdefault[envpythonconsole]%
	\setKV[envpythonconsole]{#1}% on paramètres les nouvelles clés et on les simplifie
	\VerbatimEnvironment
	\hookcenterpre
	\begin{minipage}{\CSPYlargeur}
		\ifboolKV[envpythonconsole]{label}%si sep=true
		{\begin{pyconsole}[][%
				framesep=3mm,frame=single,fontsize=\footnotesize,framerule=1pt,rulecolor=\color{ForestGreen},label={[\scriptsize Début de la console python]\scriptsize Fin de la console python}]}%
		{\begin{pyconsole}[][%
				framesep=3mm,frame=single,fontsize=\footnotesize,framerule=1pt,rulecolor=\color{ForestGreen}]}
			}
			{
		\end{pyconsole}
	\end{minipage}
	\hookcenterpost
}

%=========CODEPYTHONTEX=========== OK!!
\defKV[envpythonverb]{%
	largeur=\def\CODPYlargeur{#1},%
	centre=\testboolKV{#1}
		{\def\verbcenterpre{\begin{center}}\def\verbcenterpost{\end{center}}}
		{\def\verbcenterpre{}\def\verbcenterpost{}}
}

\setKVdefault[envpythonverb]{%
	largeur=\linewidth,%
	centre=true,%
	lignes=true
}

\tcbset{stylepythontex/.style={%
		enhanced,boxrule=1.25pt,%
		sharp corners=downhill,arc=12pt,
		before skip=12pt,after skip=12pt,%
		top=10pt,bottom=1mm,rightupper=4pt,%leftupper=25pt,
		attach boxed title to top right={yshift=-\tcboxedtitleheight},
		boxed title style={
			size=small,colback=ForestGreen!25,boxrule=1.25pt,
			colframe=Green,boxsep=1.25pt,
			sharp corners=downhill,
			arc=12pt,
			top=2pt,bottom=1pt,left=6pt,right=6pt
		},
		fonttitle=\color{ForestGreen}\itshape\ttfamily\footnotesize,
		title={\scriptsize\faPython}\:Code Python\vphantom{/},
		watermark text={\faPython},watermark opacity=0.175,watermark zoom=0.50,
	}
}

\tcbset{stylepythonnolineos/.style={%
		stylepythontex,leftupper=10pt,
		colframe=Green,colback=ForestGreen!5,%
		fontlower=\small,%
		before upper = \renewcommand\theFancyVerbLine{\scriptsize\ttfamily\color{Green}\arabic{FancyVerbLine}}
	}
}

\tcbset{stylepythonlineos/.style={%
		stylepythontex,leftupper=25pt,
		colframe=Green,colback=ForestGreen!5,%
		fontlower=\small,%
		before upper = \renewcommand\theFancyVerbLine{\scriptsize\ttfamily\color{Green}\arabic{FancyVerbLine}}
	}
}

\newtcolorbox{tcpythontexcode}[1][\linewidth]{%
	width=#1,stylepythonlineos
}

\newtcolorbox{tcpythontexcodeno}[1][\linewidth]{%
	width=#1,stylepythonnolineos
}

\newenvironment{envcodepythontex}[1][]{%
	\useKVdefault[envpythonverb]%
	\setKV[envpythonverb]{#1}% on paramètres les nouvelles clés et on les simplifie
	\VerbatimEnvironment
	\verbcenterpre
	\ifboolKV[envpythonverb]{lignes}%si lignes=true
		{\begin{tcpythontexcode}[\CODPYlargeur]}
		{\begin{tcpythontexcodeno}[\CODPYlargeur]}
	\ifboolKV[envpythonverb]{lignes}%si lignes=true
		{\begin{pyverbatim}[][fontsize=\footnotesize,numbers=left,numbersep=10pt,commandchars=\\\{\},mathescape]}
		{\begin{pyverbatim}[][numbers=none,numbersep=0pt,fontsize=\footnotesize,commandchars=\\\{\},mathescape]}
		}
		{
	\end{pyverbatim}
	\ifboolKV[envpythonverb]{lignes}%si lignes=true
		{\end{tcpythontexcode}}
		{\end{tcpythontexcodeno}}
	\verbcenterpost
}

\endinput