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
|
% proflycee-tools-pythontex.tex
% Copyright 2023 Cédric Pierquet
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%2.5.8 Style alternatif + Modification marges + Modification arguments
%%------CONSOLEPYTHON
\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}}},%
TaillePolice=\def\CSPYfonte{#1},%
EspacementVertical=\def\CSPYstretch{#1}
}
\setKVdefault[envpythonconsole]{%
Largeur=\linewidth,%
Centre=false,%
Label=true,%
TaillePolice=\footnotesize,%
EspacementVertical=1
}
\newenvironment{ConsolePythontex}[2][]
{%
\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 label
{\begin{pyconsole}[][%
framesep=3mm,frame=single,fontsize=\CSPYfonte,framerule=1pt,rulecolor=\color{ForestGreen},label={[\scriptsize Début de la console python]\scriptsize Fin de la console python},baselinestretch=\CSPYstretch]}%
{\begin{pyconsole}[][%
framesep=3mm,frame=single,fontsize=\CSPYfonte,framerule=1pt,rulecolor=\color{ForestGreen},baselinestretch=\CSPYstretch]}
}%
{%
\end{pyconsole}
\end{minipage}
\hookcenterpost
}
%=========CODEPYTHONTEX=========== OK!!
\defKV[envpythonverb]{%
Largeur=\def\CODPYlargeur{#1},%
TaillePolice=\def\CODPYfonte{#1},%
EspacementVertical=\def\CODPYstretch{#1}
% Centre=\testboolKV{#1}
% {\def\verbcenterpre{\begin{center}}\def\verbcenterpost{\end{center}}}
% {\def\verbcenterpre{}\def\verbcenterpost{}}
}
\setKVdefault[envpythonverb]{%
Largeur=\linewidth,%
% Centre=false,%
Lignes=true,%
TaillePolice=\footnotesize,%
EspacementVertical=1
}
%v1
\tcbset{stylepythontex/.style={%
enhanced,boxrule=1.25pt,%
sharp corners=downhill,arc=12pt,
before skip=0.5\baselineskip,after skip=0.5\baselineskip,%
top=\baselineskip,bottom=1mm,right=5mm,left=0.6em,
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{p},
watermark text={\faPython},watermark opacity=0.175,watermark zoom=0.50,
colframe=Green,colback=ForestGreen!5,%
before upper=\renewcommand\theFancyVerbLine{\scriptsize\ttfamily\color{darkgray}\arabic{FancyVerbLine}}
}
}
\tcbset{stylepythonnolineos/.style={%
stylepythontex,leftupper=1em
}
}
\tcbset{stylepythonlineos/.style={%
stylepythontex,leftupper=2em
}
}
\newtcolorbox{tcpythontexcode}[2][\linewidth]{%
width=#1,stylepythonlineos,#2
}
\newtcolorbox{tcpythontexcodeno}[2][\linewidth]{%
width=#1,stylepythonnolineos,#2
}
\NewDocumentEnvironment{CodePythontex}{ O{} m }
{%
\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]{#2}}
{\begin{tcpythontexcodeno}[\CODPYlargeur]{#2}}
\ifboolKV[envpythonverb]{Lignes}%si lignes=true
{\begin{pyverbatim}[][fontsize=\CODPYfonte,numbers=left,numbersep=0.75em,commandchars=\\\{\},mathescape,baselinestretch=\CODPYstretch]}
{\begin{pyverbatim}[][numbers=none,numbersep=0pt,fontsize=\CODPYfonte,commandchars=\\\{\},mathescape,baselinestretch=\CODPYstretch]}
}%
{%
\end{pyverbatim}
\ifboolKV[envpythonverb]{Lignes}%si lignes=true
{\end{tcpythontexcode}}
{\end{tcpythontexcodeno}}
% \verbcenterpost
}
%v2
\tcbset{stylepythontexalt/.style={%
enhanced,boxrule=0.75pt,colframe=DarkGray!50!Black,%
sharp corners,top=0mm,bottom=0mm,left=0.2em,right=5mm,%
before skip=0.5\baselineskip,after skip=0.5\baselineskip,%
colback=white,
fontupper=\footnotesize,fontlower=\footnotesize,%
title={{\scriptsize\faCode} Code Python},
lefttitle=0.4em,
watermark text={\faPython},watermark opacity=0.25,watermark zoom=0.50,
fonttitle=\bfseries\footnotesize\sffamily,colbacktitle=DarkGray!50!Black,
before upper=\renewcommand\theFancyVerbLine{\scriptsize\ttfamily\color{darkgray}\arabic{FancyVerbLine}}
}
}
\tcbset{stylepythonnolineosalt/.style={%
stylepythontexalt,leftupper=0.2em,
}
}
\tcbset{stylepythonlineosalt/.style={%
stylepythontexalt,leftupper=1.35em,
underlay={%
\begin{tcbclipinterior}
\filldraw[lightgray!25] (interior.south west) rectangle ([xshift=1.3em]interior.north west) ;
\end{tcbclipinterior}%
}
}
}
\newtcolorbox{tcpythontexcodealt}[2][\linewidth]{%
width=#1,stylepythonlineosalt,#2
}
\newtcolorbox{tcpythontexcodenoalt}[2][\linewidth]{%
width=#1,stylepythonnolineosalt,#2
}
\NewDocumentEnvironment{CodePythontexAlt}{ O{} m }
{%
\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{tcpythontexcodealt}[\CODPYlargeur]{#2}}
{\begin{tcpythontexcodenoalt}[\CODPYlargeur]{#2}}
\ifboolKV[envpythonverb]{Lignes}%si lignes=true
{\begin{pyverbatim}[][fontsize=\CODPYfonte,numbers=left,numbersep=0.75em,commandchars=\\\{\},mathescape,baselinestretch=\CODPYstretch]}
{\begin{pyverbatim}[][numbers=none,numbersep=0pt,fontsize=\CODPYfonte,commandchars=\\\{\},mathescape,baselinestretch=\CODPYstretch]}
}%
{%
\end{pyverbatim}
\ifboolKV[envpythonverb]{Lignes}%si lignes=true
{\end{tcpythontexcodealt}}
{\end{tcpythontexcodenoalt}}
% \verbcenterpost
}
\endinput
|