Debian Codegraph @

texmf-dist/tex/latex/fenetrecas/FenetreCas.sty

raw
1 % Author : C. Pierquet
2 % licence : Released under the LaTeX Project Public License v1.3c
3 % or later, see http://www.latex-project.org/lppl.txtf
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{FenetreCas}[2023/11/05 0.1.4 Simuler une fenetre CAS type Geogebra ou Xcas]
7 % 0.1.4 Passage \tikzstyle vers \tikzset
8 % 0.1.3 Clé [PosRes] pour positionner la réponse (gauche/centre/droite) + Correction de bugs mineurs.
9 % 0.1.2 Clés [Select] pour les numéros avec des ronds.
10 % 0.1.1 Clés [FondCouleur] pour le fond des cases.
11 % 0.1.0 Version initiale.
12
13 %------Option(s)
14
15 %------Packages utiles
16 \RequirePackage{tikz}
17 \RequirePackage{xstring}
18 \RequirePackage{xintexpr}
19 \RequirePackage{simplekv}
20 \RequirePackage{settobox}
21 %librairies tikz
22 \usetikzlibrary{calc,positioning}
23
24 %%------FENÊTRE CALCUL FORMEL GEOGEBRA
25 %compteurs pour les n° de lignes
26 \newcounter{geogebracfnum}
27
28 %--création de l'environnement, en TikZ
29 \newsavebox{\maboiteggbtitre}
30 \newlength{\hauteurboiteggbtitre}
31
32 %def des clés
33 \defKV[paramfengeogebracf]{%
34 Largeur=\def\GEOCFlarg{#1},%
35 CouleurEntete=\def\GEOCFcoulentete{#1},%
36 LargeurNumero=\def\GEOCFlargnum{#1},%
37 CouleurNumero=\def\GEOCFcoulnum{#1},%
38 PoliceEntete=\def\GEOCFfontenete{#1},%
39 PoliceNumero=\def\GEOCFpolnum{#1},%
40 Titre=\def\GEOCFtitre{#1}
41 }
42 \setKVdefault[paramfengeogebracf]{%
43 Largeur=10,%
44 CouleurEntete=lightgray!25,%
45 LargeurNumero=1,%
46 CouleurNumero=cyan!5,%
47 PoliceEntete=\bfseries\large\sffamily,%
48 PoliceNumero=\large\sffamily,%
49 Titre={$\triangleright$ Calcul formel},%
50 Entete=true
51 }
52
53 \NewDocumentEnvironment{CalculFormelGeogebra}{ O{} D<>{} }
54 {%
55 \useKVdefault[paramfengeogebracf]%
56 \setKV[paramfengeogebracf]{#1}% on paramètres les nouvelles clés et on les simplifie
57 \setcounter{geogebracfnum}{0}%on repart avec le compteur à 0
58 \sbox{\maboiteggbtitre}{\GEOCFfontenete\GEOCFtitre}\settoboxtotalheight{\hauteurboiteggbtitre}{\maboiteggbtitre}
59 \begin{tikzpicture}[#2]
60 %ENTETE
61 \ifboolKV[paramfengeogebracf]{Entete}
62 {
63 \def\HCroix{\the\hauteurboiteggbtitre}%
64 \draw[semithick,fill=\GEOCFcoulentete] (0,0) rectangle (\GEOCFlarg,{2.25*\the\hauteurboiteggbtitre}) ;%
65 \draw (0,{2.25*0.5*\the\hauteurboiteggbtitre}) node[right=4pt,font=\GEOCFfontenete] {\GEOCFtitre} ;%
66 %crois fermeture
67 \coordinate (CROIXGEO) at ($({\GEOCFlarg},{2.25*0.5*\the\hauteurboiteggbtitre})+({-\the\hauteurboiteggbtitre},0)$) ;
68 \draw[semithick] ($(CROIXGEO)+({-0.35*\the\hauteurboiteggbtitre},{0.35*\the\hauteurboiteggbtitre})$)--++({0.7*\HCroix},{-0.7*\HCroix}) ;
69 \draw[semithick] ($(CROIXGEO)+({-0.35*\the\hauteurboiteggbtitre},{-0.35*\the\hauteurboiteggbtitre})$)--++({0.7*\HCroix},{0.7*\HCroix}) ;
70 \draw[semithick] ($(CROIXGEO)+({-0.5*\the\hauteurboiteggbtitre},{0.5*\the\hauteurboiteggbtitre})$)rectangle++({\HCroix},{-\HCroix}) ;
71 }
72 {}
73 }%
74 {%
75 \end{tikzpicture}%
76 }
77
78 %--création des lignes, une par une
79 %commande externe pour les hauteurs
80 \newsavebox{\maboiteggbcmd}
81 \newsavebox{\maboiteggbres}
82 \newlength{\hauteurboiteggbcmd}
83 \newlength{\hauteurboiteggbres}
84 \newlength{\offsetcfgeogebra}
85
86 %def des clés
87 \defKV[paramlgeogebra]{%
88 HauteurLigne=\def\GEOCFhauteur{#1},%
89 TailleCommande=\def\GEOCFtaillecmd{#1},%
90 TailleResultat=\def\GEOCFtailleres{#1},%
91 ElargirAuto=\def\GEOCFelargirauto{#1},%
92 MargeV=\def\GEOCFoffset{#1},%
93 MargeH=\def\GEOCFoffseth{#1},%
94 CouleurFond=\def\GEOCFcolfond{#1},%
95 CouleurSelect=\def\GEOCFcolselect{#1},%
96 PosRes=\def\GEOCFposrep{#1}
97 }
98 \setKVdefault[paramlgeogebra]{%
99 HauteurLigne=2,%
100 TailleCommande=\normalsize,%
101 TailleResultat=\large,%
102 ElargirAuto=1,%
103 HauteurAuto=true,%
104 MargeV=6pt,%
105 MargeH=0.2,%
106 Fond=false,%
107 CouleurFond=white,%
108 Select=true,%
109 CouleurSelect=white,%
110 PosRes=gauche
111 }
112
113 \NewDocumentCommand\LigneCalculsGeogebra{ O{} m m }{%
114 %clés
115 \useKVdefault[paramlgeogebra]%
116 \setKV[paramlgeogebra]{#1}% on paramètres les nouvelles clés et on les simplifie
117 %récupération des tailles des lignes cmd et res poour ajustement
118 \setlength{\offsetcfgeogebra}{\GEOCFoffset}
119 \ifboolKV[paramlgeogebra]{HauteurAuto}
120 {%
121 \sbox{\maboiteggbcmd}{\pgfinterruptpicture \GEOCFtaillecmd#2\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboiteggbcmd}{\maboiteggbcmd}
122 \sbox{\maboiteggbres}{\pgfinterruptpicture \GEOCFtailleres#3\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboiteggbres}{\maboiteggbres}
123 \def\GEOCFhauteur{\GEOCFelargirauto*(\the\hauteurboiteggbcmd+\the\hauteurboiteggbres+4*\the\offsetcfgeogebra)}
124 }
125 {}
126 %compteur et raccourcis
127 \addtocounter{geogebracfnum}{1}%
128 \def\GGBL{\thegeogebracfnum}%
129 \def\GGBLA{\inteval{\GGBL-1}}%
130 %déclaration des nœuds (les "4" coins des blocs numéros)
131 \xintifboolexpr{\GGBL == 1}%si c'est la première ligne
132 {\coordinate (A0\GGBL) at (0,0);}
133 {\coordinate (A0\GGBL) at (A1\GGBLA) ;}
134 \coordinate (A1\GGBL) at ($(A0\GGBL) + (0,{-\GEOCFhauteur})$);
135 \coordinate (A2\GGBL) at ($(A0\GGBL) + ({\GEOCFlargnum},0)$);
136 \coordinate (A3\GGBL) at ($(A1\GGBL) + ({\GEOCFlargnum},0)$);
137 \coordinate (AH\GGBL) at ($(A0\GGBL) + ({0.5*\GEOCFlargnum},{-0.33*\GEOCFhauteur})$);
138 \coordinate (AM\GGBL) at ($(A0\GGBL) + ({0.5*\GEOCFlargnum},{-0.5*\GEOCFhauteur})$);
139 \coordinate (AB\GGBL) at ($(A0\GGBL) + ({0.5*\GEOCFlargnum},{-0.66*\GEOCFhauteur})$);
140 %les tracés
141 \ifboolKV[paramlgeogebra]{Select}%si on choisit les petits ronds par défaut ^^
142 {%
143 \draw[semithick,fill=\GEOCFcoulnum] (A0\GGBL) rectangle (A3\GGBL) ; %
144 \draw[semithick,draw=black,fill=\GEOCFcolselect] ($(AM\GGBL) + (0,-0.375)$) circle[radius=4pt] ;%
145 \draw[black] ($(AM\GGBL) + (0,0.375)$) node[font=\GEOCFpolnum] {\GGBL} ;%
146
147 }%
148 {%
149 \draw[semithick,fill=\GEOCFcoulnum] (A0\GGBL) rectangle (A3\GGBL) node[midway,font=\GEOCFpolnum] {\GGBL} ;%
150 }%
151 \ifboolKV[paramlgeogebra]{Fond}
152 {\draw[semithick,fill=\GEOCFcolfond] (A2\GGBL) rectangle++({\GEOCFlarg-\GEOCFlargnum},{-\GEOCFhauteur}) ;}
153 {\draw[semithick] (A2\GGBL) rectangle++({\GEOCFlarg-\GEOCFlargnum},{-\GEOCFhauteur}) ;}
154 %les commande/résultat
155 \ifboolKV[paramlgeogebra]{HauteurAuto}
156 {%
157 %commande
158 \draw ($(A2\GGBL) + ({\GEOCFoffseth},{-\the\offsetcfgeogebra-0.5*\GEOCFelargirauto*\the\hauteurboiteggbcmd})$) node[font=\GEOCFtaillecmd,right] {#2} ;
159 %résultat
160 \IfStrEq{\GEOCFposrep}{gauche}
161 {%
162 \draw ($(A3\GGBL) + ({\GEOCFoffseth},{\the\offsetcfgeogebra+0.5*\GEOCFelargirauto*\the\hauteurboiteggbres})$) node[font=\GEOCFtailleres,right] {#3} ;
163 }{}%
164 \IfStrEq{\GEOCFposrep}{droite}
165 {%
166 \draw ($(A3\GGBL) + ({\GEOCFlarg-\GEOCFlargnum},0) + ({-\GEOCFoffseth},{\the\offsetcfgeogebra+0.5*\GEOCFelargirauto*\the\hauteurboiteggbres})$) node[font=\GEOCFtailleres,left] {#3} ;
167 %\draw ($(A3\GGBL) + ({\GEOCFlarg-\GEOCFlargnum},0) + ({-\GEOCFoffseth},{\the\offsetcfgeogebra+0.5*\GEOCFelargirauto*\the\hauteurboiteggbres})$) node[font=\GEOCFtailleres,left] {#3} ;
168 }{}%
169 \IfStrEq{\GEOCFposrep}{centre}
170 {%
171 \draw ($(A3\GGBL) + ({0.5*(\GEOCFlarg-\GEOCFlargnum)},{\the\offsetcfgeogebra+0.5*\GEOCFelargirauto*\the\hauteurboiteggbres})$) node[font=\GEOCFtailleres] {#3} ;
172 }{}%
173 }%
174 {%
175 %commande
176 \draw ($(A2\GGBL) + ({\GEOCFoffseth},{-0.25*\GEOCFhauteur})$) node[font=\GEOCFtaillecmd,right] {#2} ;
177 %résultat
178 \IfStrEq{\GEOCFposrep}{gauche}
179 {%
180 \draw ($(A2\GGBL) + ({\GEOCFoffseth},{-0.66*\GEOCFhauteur})$) node[font=\GEOCFtailleres,right] {#3} ;
181 }{}%
182 \IfStrEq{\GEOCFposrep}{droite}
183 {%
184 \draw ($(A2\GGBL) + ({\GEOCFlarg-\GEOCFlargnum},0) + ({-\GEOCFoffseth},{-0.66*\GEOCFhauteur})$) node[font=\GEOCFtailleres,left] {#3} ;
185 }{}%
186 \IfStrEq{\GEOCFposrep}{centre}
187 {%
188 \draw ($(A2\GGBL) + ({0.5*(\GEOCFlarg-\GEOCFlargnum)},0) + (0,{-0.66*\GEOCFhauteur})$) node[font=\GEOCFtailleres] {#3} ;
189 }%
190 {}%
191 }
192 }
193
194 %%------FENÊTRE CALCUL FORMEL XCAS
195 \newcounter{xcascfnum}
196 %def des clés
197 \defKV[paramfenxcascf]{%
198 Largeur=\def\XCCFlarg{#1},%
199 EspaceLg=\def\XCCFesplg{#1},%
200 Couleur=\def\XCCFcouleur{#1},%
201 PoliceEntete=\def\XCCFfontenete{#1},%
202 TexteOptions=\def\XCCFtxtopts{#1}
203 }
204 \setKVdefault[paramfenxcascf]{%
205 Largeur=14,%
206 EspaceLg=2pt,%
207 Couleur=darkgray,%
208 Menu=true,%
209 Entete=true,%
210 NoirBlanc=false,%
211 PoliceEntete=\scriptsize,%
212 Sep=true,%
213 TexteOptions={Config : exact real RAD 12 xcas}
214 }
215
216 \NewDocumentEnvironment{CalculFormelXcas}{ O{} D<>{} }
217 {%
218 \useKVdefault[paramfenxcascf]%
219 \setKV[paramfenxcascf]{#1}% on paramètres les nouvelles clés et on les simplifie
220 \setcounter{xcascfnum}{0}%on repart avec le compteur à 0
221 %couleurs
222 \ifboolKV[paramfenxcascf]{NoirBlanc}%si NB=true
223 {
224 \def\CoulXCASPt{lightgray!20}\def\CoulXCASSave{lightgray!20}\def\CoulXCASMid{lightgray!20}\def\CoulXCASStop{black}
225 }
226 {
227 \def\CoulXCASPt{cyan!20}\def\CoulXCASSave{green!20}\def\CoulXCASMid{violet!20}\def\CoulXCASStop{red}
228 }
229 \begin{tikzpicture}[#2]
230 \tikzset{xcastitre/.style={font=\XCCFfontenete\ttfamily,inner sep=1pt,outer sep=0pt}}%
231 %\tikzstyle{xcastitre}=[font=\XCCFfontenete\ttfamily,inner sep=1pt,outer sep=0pt]
232 %LE BLOC "TITRE"
233 \ifboolKV[paramfenxcascf]{Entete}%si titre=true
234 {%
235 \node[semithick,draw=\XCCFcouleur,fill=\CoulXCASPt,above right,xcastitre] (PTIN) at ($(0,0)+(0,2pt)$) {\strut {\,?\,}} ;
236 \node[semithick,draw=\XCCFcouleur,fill=\CoulXCASSave,xcastitre,right=2pt] (SAUV) at (PTIN.east) {\strut \,Sauver\,} ;
237 \node[semithick,draw=\XCCFcouleur,fill=lightgray!20,xcastitre,above left] (CLOSE) at ($({\XCCFlarg},0)+(0,2pt)$) {\strut \,$\mathtt{\times}$\,} ;
238 \node[semithick,draw=\XCCFcouleur,fill=lightgray!20,xcastitre,left=6pt] (KBD) at (CLOSE.west) {\strut \:\:Kbd\:\:} ;
239 \node[semithick,draw=\XCCFcouleur,fill=lightgray!20,xcastitre,left=2pt] (STOP) at (KBD.west) {\strut \,\textcolor{\CoulXCASStop}{STOP}\,} ;
240 \draw[semithick,\XCCFcouleur,fill=\CoulXCASMid] ($(SAUV.north east)+({2pt},0)$) rectangle ($(STOP.south west)+({-2pt},0)$) node[midway,xcastitre,black] {\strut \XCCFtxtopts} ;
241 }
242 {}
243 }%
244 {%
245 \end{tikzpicture}%
246 }
247
248 \newsavebox{\maboitecmdxcas}
249 \newsavebox{\maboiteresxcas}
250 \newlength{\hauteurboitecmdxcas}
251 \newlength{\hauteurboiteresxcas}
252 \newlength{\offsetcfxcas}
253
254 \defKV[paramlgxcas]{%
255 TailleCommande=\def\XCCFtaillecmd{#1},%
256 TailleResultat=\def\XCCFtailleres{#1},%
257 ElargirAuto=\def\XCCFelargirauto{#1},%
258 MargeV=\def\XCCFoffset{#1},%
259 MargeH=\def\XCCFoffseth{#1},%
260 CouleurCmd=\def\XCCFcoulcmd{#1},%
261 CouleurRes=\def\XCCFcoulres{#1},%
262 PosRes=\def\XCCFposres{#1},%
263 CouleurFond=\def\XCCFcolfond{#1}
264 }
265
266 \setKVdefault[paramlgxcas]{%
267 TailleCommande=\normalsize,%
268 TailleResultat=\large,%
269 ElargirAuto=1,%
270 MargeV=6pt,%
271 MargeH=0.15,%
272 CouleurCmd=red,%
273 CouleurRes=blue,%
274 PosRes=centre,%
275 Fond=false,%
276 CouleurFond=white
277 }
278
279 \NewDocumentCommand\LigneCalculsXcas{ O{} m m }{%
280 %clés
281 \useKVdefault[paramlgxcas]%
282 \setKV[paramlgxcas]{#1}% on paramètres les nouvelles clés et on les simplifie
283 %récupération des tailles des lignes cmd et res poour ajustement
284 \setlength{\offsetcfxcas}{\XCCFoffset}
285 \sbox{\maboitecmdxcas}{\pgfinterruptpicture \XCCFtaillecmd #2\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboitecmdxcas}{\maboitecmdxcas}
286 \sbox{\maboiteresxcas}{\pgfinterruptpicture \XCCFtailleres #3\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboiteresxcas}{\maboiteresxcas}
287 \def\XCCFhauteur{\XCCFelargirauto*(\the\hauteurboitecmdxcas+\the\hauteurboiteresxcas+4*\the\offsetcfxcas)}
288 %couleurs forcées
289 \ifboolKV[paramfenxcascf]{NoirBlanc}%si NB=true
290 {\def\XCCFcoulcmd{black}\def\XCCFcoulres{black}}{}
291 %compteur et raccourcis
292 \addtocounter{xcascfnum}{1}%
293 \def\XCL{\thexcascfnum}%
294 \def\XCLA{\inteval{\XCL-1}}%
295 %déclaration des nœuds (les "4" coins des blocs numéros)
296 \xintifboolexpr{\XCL == 1}%si c'est la première ligne
297 {\coordinate (A0\XCL) at (0,0);}
298 {\coordinate (A0\XCL) at ($(A1\XCLA)+(0,{-\XCCFesplg})$) ;}
299 \coordinate (A1\XCL) at ($(A0\XCL) + (0,{-\XCCFhauteur})$);
300 \coordinate (A2\XCL) at ($(A0\XCL) + ({\XCCFlarg},0)$);
301 \coordinate (A3\XCL) at ($(A1\XCL) + ({\XCCFlarg},0)$);
302 %les tracés
303 \ifboolKV[paramlgxcas]{Fond}%si on met une couleur de fond
304 {%
305 \IfSubStr{\XCCFcolfond}{/}%
306 {\StrCut{\XCCFcolfond}{/}{\XCCFcolfondC}{\XCCFcolfondR}}%
307 {\def\XCCFcolfondC{\XCCFcolfond}\def\XCCFcolfondR{\XCCFcolfond}}%
308 \draw[semithick,\XCCFcouleur,fill=\XCCFcolfondC] (A0\XCL) rectangle++ ($(0,{-2*\the\offsetcfxcas-\XCCFelargirauto*\the\hauteurboitecmdxcas})+({\XCCFlarg},0)$) ;%
309 \draw[semithick,\XCCFcouleur,fill=\XCCFcolfondR] ($(A0\XCL)+(0,{-2*\the\offsetcfxcas-\XCCFelargirauto*\the\hauteurboitecmdxcas})$) rectangle (A3\XCL) ;%
310 }
311 {\draw[semithick,\XCCFcouleur] (A0\XCL) rectangle (A3\XCL) ;}
312 %LA COMMANDE À GAUCHE
313 \draw ($(A0\XCL) + ({\XCCFoffseth},{-\the\offsetcfxcas-0.5*\XCCFelargirauto*\the\hauteurboitecmdxcas})$) node[\XCCFcoulcmd,font=\XCCFtaillecmd,right] {#2} ;
314 %LE RÉSULTAT
315 \IfStrEq{\XCCFposres}{centre}%si posrep=center
316 {%
317 \draw ($(A1\XCL) + ({0.5*\XCCFlarg},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres] {#3} ;
318 }{}
319 \IfStrEq{\XCCFposres}{gauche}%si posrep=left
320 {%
321 \draw ($(A1\XCL) + ({{\XCCFoffseth}},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres,right] {#3} ;
322 }{}
323 \IfStrEq{\XCCFposres}{droite}%si posrep=right
324 {%
325 \ifboolKV[paramfenxcascf]{Menu}%si menu=true
326 {%
327 \draw ($(A1\XCL) + ({\XCCFlarg-1},0) + ({-\XCCFoffseth},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres,left] {#3} ;
328 }%
329 {%
330 \draw ($(A1\XCL) + ({\XCCFlarg},0) + ({-\XCCFoffseth},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres,left] {#3} ;
331 }%
332 }{}
333 %LA LIGNE DE SÉPARATION
334 \ifboolKV[paramfenxcascf]{Sep}%si sep=true
335 {\draw[semithick,\XCCFcouleur] ($(A0\XCL)+(0,{-2*\the\offsetcfxcas-\XCCFelargirauto*\the\hauteurboitecmdxcas})$)--++({\XCCFlarg},0);}
336 {}
337 %LE BOUTON MENU
338 \ifboolKV[paramfenxcascf]{Menu}%si menu=true
339 {
340 \draw[semithick] (A3\XCL) node[draw=\XCCFcouleur,black,fill=lightgray!25,outer sep=0pt,inner sep=2pt,draw,above left,font=\tiny\sffamily\bfseries] {MENU} ;
341 }{}
342 %LE PETIT NUMÉRO
343 \draw[semithick] (A0\XCL) node[draw=\XCCFcouleur,fill=\CoulXCASMid,outer sep=0pt,inner sep=2pt,draw,below left,font=\footnotesize\sffamily] {\XCL} ;
344 }
345
346 \endinput