summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/fenetrecas/tex/FenetreCas.sty
blob: 56b12746f53aa2d9e1764bdd4e64e20b369f66ca (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
% 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{FenetreCas}[2023/03/17 0.1.0 Simuer une fenetre CAS type Geogebra ou Xcas]
% 0.1.0	Version initiale

%------Option(s)

%------Packages utiles
\RequirePackage{tikz}
\RequirePackage{xstring}
\RequirePackage{xintexpr}
\RequirePackage{simplekv}
\RequirePackage{settobox}
%librairies tikz
\usetikzlibrary{calc,positioning}

%%------FENÊTRE CALCUL FORMEL GEOGEBRA
%compteurs pour les n° de lignes
\newcounter{geogebracfnum}

%--création de l'environnement, en TikZ
\newsavebox{\maboiteggbtitre}
\newlength{\hauteurboiteggbtitre}

%def des clés
\defKV[paramfengeogebracf]{%
	Largeur=\def\GEOCFlarg{#1},%
	CouleurEntete=\def\GEOCFcoulentete{#1},%
	LargeurNumero=\def\GEOCFlargnum{#1},%
	CouleurNumero=\def\GEOCFcoulnum{#1},%
	PoliceEntete=\def\GEOCFfontenete{#1},%
	PoliceNumero=\def\GEOCFpolnum{#1},%
	Titre=\def\GEOCFtitre{#1}
}
\setKVdefault[paramfengeogebracf]{%
	Largeur=10,%
	CouleurEntete=lightgray!25,%
	LargeurNumero=1,%
	CouleurNumero=cyan!5,%
	PoliceEntete=\bfseries\large\sffamily,%
	PoliceNumero=\Large\sffamily,%
	Titre={$\triangleright$ Calcul formel},%
	Entete=true
}

\NewDocumentEnvironment{CalculFormelGeogebra}{ O{} D<>{} }
{%
	\useKVdefault[paramfengeogebracf]%
	\setKV[paramfengeogebracf]{#1}% on paramètres les nouvelles clés et on les simplifie
	\setcounter{geogebracfnum}{0}%on repart avec le compteur à 0
	\sbox{\maboiteggbtitre}{\GEOCFfontenete\GEOCFtitre}\settoboxtotalheight{\hauteurboiteggbtitre}{\maboiteggbtitre}
	\begin{tikzpicture}[#2]
		%ENTETE
		\ifboolKV[paramfengeogebracf]{Entete}
			{
				\def\HCroix{\the\hauteurboiteggbtitre}%
				\draw[semithick,fill=\GEOCFcoulentete] (0,0) rectangle (\GEOCFlarg,{2.25*\the\hauteurboiteggbtitre}) ;%
				\draw (0,{2.25*0.5*\the\hauteurboiteggbtitre}) node[right=4pt,font=\GEOCFfontenete] {\GEOCFtitre} ;%
				%crois fermeture
				\coordinate (CROIXGEO) at ($({\GEOCFlarg},{2.25*0.5*\the\hauteurboiteggbtitre})+({-\the\hauteurboiteggbtitre},0)$) ;
				\draw[semithick] ($(CROIXGEO)+({-0.35*\the\hauteurboiteggbtitre},{0.35*\the\hauteurboiteggbtitre})$)--++({0.7*\HCroix},{-0.7*\HCroix}) ;
				\draw[semithick] ($(CROIXGEO)+({-0.35*\the\hauteurboiteggbtitre},{-0.35*\the\hauteurboiteggbtitre})$)--++({0.7*\HCroix},{0.7*\HCroix}) ;
				\draw[semithick] ($(CROIXGEO)+({-0.5*\the\hauteurboiteggbtitre},{0.5*\the\hauteurboiteggbtitre})$)rectangle++({\HCroix},{-\HCroix}) ;
			}
			{}
}%
{%
	\end{tikzpicture}%
}

%--création des lignes, une par une
%commande externe pour les hauteurs
\newsavebox{\maboiteggbcmd}
\newsavebox{\maboiteggbres}
\newlength{\hauteurboiteggbcmd}
\newlength{\hauteurboiteggbres}
\newlength{\offsetcfgeogebra}

%def des clés
\defKV[paramlgeogebra]{%
	HauteurLigne=\def\GEOCFhauteur{#1},%
	TailleCommande=\def\GEOCFtaillecmd{#1},%
	TailleResultat=\def\GEOCFtailleres{#1},%
	ElargirAuto=\def\GEOCFelargirauto{#1},%
	MargeV=\def\GEOCFoffset{#1},%
	MargeH=\def\GEOCFoffseth{#1}
}
\setKVdefault[paramlgeogebra]{%
	HauteurLigne=2,%
	TailleCommande=\normalsize,%
	TailleResultat=\large,%
	ElargirAuto=1,%
	HauteurAuto=true,%
	MargeV=6pt,%
	MargeH=0.2
}

\NewDocumentCommand\LigneCalculsGeogebra{ O{} m m }{%
	%clés
	\useKVdefault[paramlgeogebra]%
	\setKV[paramlgeogebra]{#1}% on paramètres les nouvelles clés et on les simplifie
	%récupération des tailles des lignes cmd et res poour ajustement
	\setlength{\offsetcfgeogebra}{\GEOCFoffset}
	\ifboolKV[paramlgeogebra]{HauteurAuto}
		{%
			\sbox{\maboiteggbcmd}{\pgfinterruptpicture \GEOCFtaillecmd#2\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboiteggbcmd}{\maboiteggbcmd}
			\sbox{\maboiteggbres}{\pgfinterruptpicture \GEOCFtailleres#3\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboiteggbres}{\maboiteggbres}
			\def\GEOCFhauteur{\GEOCFelargirauto*(\the\hauteurboiteggbcmd+\the\hauteurboiteggbres+4*\the\offsetcfgeogebra)}
		}
		{}
	%compteur et raccourcis
	\addtocounter{geogebracfnum}{1}%
	\def\GGBL{\thegeogebracfnum}%
	\def\GGBLA{\inteval{\GGBL-1}}%
	%déclaration des nœuds (les "4" coins des blocs numéros)
	\xintifboolexpr{\GGBL == 1}%si c'est la première ligne
		{\coordinate (A0\GGBL) at (0,0);}
		{\coordinate (A0\GGBL) at (A1\GGBLA) ;}
	\coordinate (A1\GGBL) at ($(A0\GGBL) + (0,{-\GEOCFhauteur})$);
	\coordinate (A2\GGBL) at ($(A0\GGBL) + ({\GEOCFlargnum},0)$);
	\coordinate (A3\GGBL) at ($(A1\GGBL) + ({\GEOCFlargnum},0)$);
	%les tracés
	\draw[semithick,fill=\GEOCFcoulnum] (A0\GGBL) rectangle (A3\GGBL) node[midway,font=\GEOCFpolnum] {\GGBL} ;
	\draw[semithick] (A2\GGBL) rectangle++({\GEOCFlarg-\GEOCFlargnum},{-\GEOCFhauteur}) ;
	%les commande/résultat
	\ifboolKV[paramlgeogebra]{HauteurAuto}
		{%
			\draw ($(A2\GGBL) + ({\GEOCFoffseth},{-\the\offsetcfgeogebra-0.5*\GEOCFelargirauto*\the\hauteurboiteggbcmd})$) node[font=\GEOCFtaillecmd,right] {#2} ;
			\draw ($(A3\GGBL) + ({\GEOCFoffseth},{\the\offsetcfgeogebra+0.5*\GEOCFelargirauto*\the\hauteurboiteggbres})$) node[font=\GEOCFtailleres,right] {#3} ;
		}
		{%
			\draw ($(A2\GGBL) + ({\GEOCFoffseth},{-0.25*\GEOCFhauteur})$) node[font=\GEOCFtaillecmd,right] {#2} ;
			\draw ($(A2\GGBL) + ({\GEOCFoffseth},{-0.66*\GEOCFhauteur})$) node[font=\GEOCFtailleres,right] {#3} ;
		}
}

%%------FENÊTRE CALCUL FORMEL XCAS
\newcounter{xcascfnum}
%def des clés
\defKV[paramfenxcascf]{%
	Largeur=\def\XCCFlarg{#1},%
	EspaceLg=\def\XCCFesplg{#1},%
	Couleur=\def\XCCFcouleur{#1},%
	PoliceEntete=\def\XCCFfontenete{#1},%
	TexteOptions=\def\XCCFtxtopts{#1}
}
\setKVdefault[paramfenxcascf]{%
	Largeur=14,%
	EspaceLg=2pt,%
	Couleur=darkgray,%
	Menu=true,%
	Entete=true,%
	NoirBlanc=false,%
	PoliceEntete=\scriptsize,%
	Sep=true,%
	TexteOptions={Config : exact real RAD 12 xcas}
}

\NewDocumentEnvironment{CalculFormelXcas}{ O{} D<>{} }
{%
	\useKVdefault[paramfenxcascf]%
	\setKV[paramfenxcascf]{#1}% on paramètres les nouvelles clés et on les simplifie
	\setcounter{xcascfnum}{0}%on repart avec le compteur à 0
	%couleurs
	\ifboolKV[paramfenxcascf]{NoirBlanc}%si NB=true
		{
			\def\CoulXCASPt{lightgray!20}\def\CoulXCASSave{lightgray!20}\def\CoulXCASMid{lightgray!20}\def\CoulXCASStop{black}
		}
		{
			\def\CoulXCASPt{cyan!20}\def\CoulXCASSave{green!20}\def\CoulXCASMid{violet!20}\def\CoulXCASStop{red}
		}
	\begin{tikzpicture}[#2]
		\tikzstyle{xcastitre}=[font=\XCCFfontenete\ttfamily,inner sep=1pt,outer sep=0pt]
		%LE BLOC "TITRE"
		\ifboolKV[paramfenxcascf]{Entete}%si titre=true
			{%
				\node[semithick,draw=\XCCFcouleur,fill=\CoulXCASPt,above right,xcastitre] (PTIN) at ($(0,0)+(0,2pt)$) {\strut {\,?\,}} ;
				\node[semithick,draw=\XCCFcouleur,fill=\CoulXCASSave,xcastitre,right=2pt] (SAUV) at (PTIN.east) {\strut \,Sauver\,} ;
				\node[semithick,draw=\XCCFcouleur,fill=lightgray!20,xcastitre,above left] (CLOSE) at ($({\XCCFlarg},0)+(0,2pt)$) {\strut \,$\mathtt{\times}$\,} ;
				\node[semithick,draw=\XCCFcouleur,fill=lightgray!20,xcastitre,left=6pt] (KBD) at (CLOSE.west) {\strut \:\:Kbd\:\:} ;
				\node[semithick,draw=\XCCFcouleur,fill=lightgray!20,xcastitre,left=2pt] (STOP) at (KBD.west) {\strut \,\textcolor{\CoulXCASStop}{STOP}\,} ;
				\draw[semithick,\XCCFcouleur,fill=\CoulXCASMid] ($(SAUV.north east)+({2pt},0)$) rectangle ($(STOP.south west)+({-2pt},0)$) node[midway,xcastitre,black] {\strut \XCCFtxtopts} ;
			}
			{}
}%
{%
	\end{tikzpicture}%
}

\newsavebox{\maboitecmdxcas}
\newsavebox{\maboiteresxcas}
\newlength{\hauteurboitecmdxcas}
\newlength{\hauteurboiteresxcas}
\newlength{\offsetcfxcas}

\defKV[paramlgxcas]{%
	TailleCommande=\def\XCCFtaillecmd{#1},%
	TailleResultat=\def\XCCFtailleres{#1},%
	ElargirAuto=\def\XCCFelargirauto{#1},%
	MargeV=\def\XCCFoffset{#1},%
	MargeH=\def\XCCFoffseth{#1},%
	CouleurCmd=\def\XCCFcoulcmd{#1},%
	CouleurRes=\def\XCCFcoulres{#1},%
	PosRes=\def\XCCFposres{#1}
}

\setKVdefault[paramlgxcas]{%
	TailleCommande=\normalsize,%
	TailleResultat=\large,%
	ElargirAuto=1,%
	MargeV=6pt,%
	MargeH=0.15,%
	CouleurCmd=red,%
	CouleurRes=blue,%
	PosRes=centre
}

\NewDocumentCommand\LigneCalculsXcas{ O{} m m }{%
	%clés
	\useKVdefault[paramlgxcas]%
	\setKV[paramlgxcas]{#1}% on paramètres les nouvelles clés et on les simplifie
	%récupération des tailles des lignes cmd et res poour ajustement
	\setlength{\offsetcfxcas}{\XCCFoffset}
	\sbox{\maboitecmdxcas}{\pgfinterruptpicture \XCCFtaillecmd #2\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboitecmdxcas}{\maboitecmdxcas}
	\sbox{\maboiteresxcas}{\pgfinterruptpicture \XCCFtailleres #3\endpgfinterruptpicture}\settoboxtotalheight{\hauteurboiteresxcas}{\maboiteresxcas}
	\def\XCCFhauteur{\XCCFelargirauto*(\the\hauteurboitecmdxcas+\the\hauteurboiteresxcas+4*\the\offsetcfxcas)}
	%couleurs forcées
	\ifboolKV[paramfenxcascf]{NoirBlanc}%si NB=true
		{\def\XCCFcoulcmd{black}\def\XCCFcoulres{black}}{}
	%compteur et raccourcis
	\addtocounter{xcascfnum}{1}%
	\def\XCL{\thexcascfnum}%
	\def\XCLA{\inteval{\XCL-1}}%
	%déclaration des nœuds (les "4" coins des blocs numéros)
	\xintifboolexpr{\XCL == 1}%si c'est la première ligne
		{\coordinate (A0\XCL) at (0,0);}
		{\coordinate (A0\XCL) at ($(A1\XCLA)+(0,{-\XCCFesplg})$) ;}
	\coordinate (A1\XCL) at ($(A0\XCL) + (0,{-\XCCFhauteur})$);
	\coordinate (A2\XCL) at ($(A0\XCL) + ({\XCCFlarg},0)$);
	\coordinate (A3\XCL) at ($(A1\XCL) + ({\XCCFlarg},0)$);
	%les tracés
	\draw[semithick,\XCCFcouleur] (A0\XCL) rectangle (A3\XCL) ;
	%LA COMMANDE À GAUCHE
	\draw ($(A0\XCL) + ({\XCCFoffseth},{-\the\offsetcfxcas-0.5*\XCCFelargirauto*\the\hauteurboitecmdxcas})$) node[\XCCFcoulcmd,font=\XCCFtaillecmd,right] {#2} ;
	%LE RÉSULTAT
	\IfStrEq{\XCCFposres}{centre}%si posrep=center
		{%
			\draw ($(A1\XCL) + ({0.5*\XCCFlarg},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres] {#3} ;
		}{}
	\IfStrEq{\XCCFposres}{gauche}%si posrep=left
		{%
			\draw ($(A1\XCL) + ({{\XCCFoffseth}},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres,right] {#3} ;
		}{}
	\IfStrEq{\XCCFposres}{droite}%si posrep=right
		{%
			\draw ($(A1\XCL) + ({\XCCFlarg-{\XCCFoffseth}},{\the\offsetcfxcas+0.5*\XCCFelargirauto*\the\hauteurboiteresxcas})$) node[\XCCFcoulres,font=\XCCFtailleres,left] {#3} ;
		}{}
	%LA LIGNE DE SÉPARATION
	\ifboolKV[paramfenxcascf]{Sep}%si sep=true
		{\draw[semithick,\XCCFcouleur] ($(A0\XCL)+(0,{-2*\the\offsetcfxcas-\XCCFelargirauto*\the\hauteurboitecmdxcas})$)--++({\XCCFlarg},0);}
		{}
	%LE BOUTON MENU
	\ifboolKV[paramfenxcascf]{Menu}%si menu=true
		{
			\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} ;
		}{}
	%LE PETIT NUMÉRO
	\draw[semithick] (A0\XCL) node[draw=\XCCFcouleur,fill=\CoulXCASMid,outer sep=0pt,inner sep=2pt,draw,below left,font=\footnotesize\sffamily] {\XCL} ;
}

\endinput