summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-base/latex/tkz/tkzbase/tkz-tools-utilities.tex
blob: 412ad2d8d308d917a7d636e9464c72df639a0683 (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
% Copyright 2011 by Alain Matthes
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.


\def\fileversion{1.16 d}
\def\filedate{2018/09/19}

%<--------------------------------------------------------------------------–>
\def\tkzutil@empty{}
\def\tkzutil@firstofone#1{#1}
\def\tkzutil@firstoftwo#1#2{#1}
\def\tkzutil@secondoftwo#1#2{#2}
%<--------------------------------------------------------------------------–>
\long\def\tkzutil@ifundefined#1{%
  \expandafter\ifx\csname#1\endcsname\relax
    \expandafter\tkzutil@firstoftwo
  \else
    \expandafter\tkzutil@secondoftwo
  \fi} 
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\global\def\tkzActivOff{%
\edef\tkzTwoPtCode{\the\catcode`\:} 
\edef\tkzPtExCode{\the\catcode`\!} 
\edef\tkzPtVirCode{\the\catcode`\;} 
\catcode`\:=12 \catcode`\!=12 \catcode`\;=12}%
\global\def\tkzActivOn{%
\catcode`\:=\tkzTwoPtCode\relax
\catcode`\!=\tkzPtExCode\relax
\catcode`\;=\tkzPtVirCode\relax
}% 
 
%<----------------------------– autres tools -------------------------------->   
%<--------------------------  Initialisation -------------------------------->   
\pgfkeys{
/tkzsupcol/.cd,
  background/.code    = {\global\edef\tkz@suc@bkc{#1}},%
  text/.code          = {\global\edef\tkz@suc@txt{#1}}, 
} 
\def\tkzSetUpColors{\pgfutil@ifnextchar[{\tkz@SetUpColors}{\tkz@SetUpColors[]}} 
\def\tkz@SetUpColors[#1]{%
\begingroup
\pgfkeys{%
tkzsupcol/.cd,
  background  = \tkz@backgroundcolor,
  text        = \tkz@textcolor
  }
\pgfqkeys{/tkzsupcol}{#1} 
\global\edef\tkz@fillcolor{\tkz@suc@bkc}   
\global\edef\tkz@mainlinecolor{\tkz@suc@txt}
\global\edef\tkz@textcolor{\tkz@suc@txt}
\global\def\tkz@otherlinecolor{\tkz@suc@txt!50}
\global\edef\tkz@sua@color{\tkz@mainlinecolor}       
\pagecolor{\tkz@suc@bkc}
\color{\tkz@suc@txt}  
 \InputIfFileExists{tkz-base.cfg}{\typeout{Local configuration file tkz-param.cfg found and used}}{\typeout{tkz-base.cfg not found}  
%<---------   axes cartesian system  ---------------------------------------–>  
\global\edef\tkz@init@color{\tkz@textcolor} 
\global\def\tkz@init@lw{0.4 pt}
\global\def\tkz@init@xlabel{$x$}
\global\def\tkz@init@ylabel{$y$}  
\global\def\tkz@init@tickwd{0.8 pt}
\global\def\tkz@init@ticka{2 pt}  
\global\def\tkz@init@tickb{2 pt}
\global\def\tkz@init@rightspace{.5} 
\global\def\tkz@init@leftspace{0}
\global\def\tkz@init@upspace{.5} 
\global\def\tkz@init@downspace{0}
\global\let\tkzmathstyle\displaystyle   
\tikzset{xlabel style/.style={below=3 pt,
                              inner sep = 1pt,
                              outer sep = 0pt}}
\tikzset{xaxe style/.style ={>=latex,->}}
\tikzset{ylabel style/.style={left = 3 pt,
                              inner sep = 1pt,
                              outer sep = 0pt}}
\tikzset{yaxe style/.style ={>=latex,->}} 
%<--------------------------   rep  ---------------------------------------–>
\global\edef\tkz@sur@color{\tkz@mainlinecolor}
\global\edef\tkz@sur@colorlabel{\tkz@mainlinecolor}
\global\def\tkz@sur@lw{0.8 pt}
\global\def\tkz@sur@posxlabel{below=2pt}
\global\def\tkz@sur@posylabel{left=2pt} 
%<--------------------------   grid  ---------------------------------------–>
\global\edef\tkz@grid@color{gray}
\global\def\tkz@grid@lw{0.4 pt}
\global\def\tkzCoeffSubColor{50} 
\global\def\tkzCoeffSubLw{0.8}
\global\def\tkz@grid@xstep{0.2}
\global\def\tkz@grid@ystep{0.2}  
%<--------------------------   line  ---------------------------------------–>
\global\edef\tkz@euc@linecolor{\tkz@mainlinecolor}
\global\def\tkz@euc@linewidth{0.6pt}
\global\def\tkz@euc@linestyle{solid}
\global\def\tkz@euc@lineleft{.2}
\global\def\tkz@euc@lineright{.2}
\global\def\tkz@legend@line@len{1cm}  
\global\edef\tkz@euc@segmentcolor{\tkz@mainlinecolor}
\global\edef\tkz@euc@circlecolor{\tkz@mainlinecolor}
\tikzset{line style/.style={%
         line width = \tkz@euc@linewidth,
         color      = \tkz@euc@linecolor,
         style      = \tkz@euc@linestyle,
         add        = {\tkz@euc@lineleft} and {\tkz@euc@lineright}}}  
%<--------------------------    points   -----------------------------------–>
\global\edef\tkz@euc@pointshape{circle}
\global\edef\tkz@euc@pointcolor{\tkz@mainlinecolor}
\global\edef\tkz@euc@labelcolor{\tkz@mainlinecolor} 
\global\def\tkz@euc@pointsize{6}
\global\def\tkz@euc@pointpos{below right}
\tikzset{point style/.style={draw         = \tkz@euc@pointcolor,
                             inner sep    = 0pt,
                             shape        = \tkz@euc@pointshape,
                             minimum size = \tkz@euc@pointsize*\pgflinewidth,
                             fill         = \tkz@euc@pointcolor!50}}  
%<----------------------------    mark   -----------------------------------–> 
\global\edef\tkz@mk@color{\tkz@mainlinecolor}   
\global\edef\tkz@mk@mark{*}
\global\edef\tkz@mk@size{3pt}
\global\edef\tkz@mk@fill{\tkz@otherlinecolor} 
\tikzset{mark style/.style={mark=\tkz@mk@mark,mark size=\tkz@mk@size,mark options={color=\tkz@mk@color,fill=\tkz@mk@fill}}}
\tikzset{arrow coord style/.style={dashed,
                             \tkz@euc@linecolor,
                             >=latex',
                             ->}}
\tikzset{xcoord style/.style={\tkz@euc@labelcolor,
                           font=\normalsize,text height=1ex,
                           inner sep = 0pt,
                           outer sep = 0pt,
                           fill=\tkz@fillcolor,
                           below=3pt}} 
\tikzset{ycoord style/.style={\tkz@euc@labelcolor,
                           font=\normalsize,text height=1ex, 
                           inner sep = 0pt,
                           outer sep = 0pt, 
                           fill=\tkz@fillcolor,
                           left=3pt}}  
%<---------------------------  vector --------------------------------------–>
\tikzset{vector style/.style={>=latex,->}}   
%<-------------------------    compass   -----------------------------------–> 
\global\edef\tkz@euc@compasscolor{\tkz@otherlinecolor}
\global\def\tkz@euc@compasswidth{0.4pt}
\global\def\tkz@euc@compassstyle{solid}  
\tikzset{compass style/.style={color      = \tkz@euc@compasscolor,
                               line width = \tkz@euc@compasswidth,
                               style      = \tkz@euc@compassstyle}}    
}
\endgroup}

%<--------------------------------------------------------------------------–>
%              Pour savoir le nombre de décimales d'un nombre
% le nombre dans #1 et le résultat dans \c@pgfmath@countb
%<--------------------------------------------------------------------------–>

\newcommand*\tkz@getdecimal[1]{%
  \expandafter\@getdecimal#1.\@nil
}

\def\@getdecimal#1.#2\@nil{%
  \ifx\empty#2\empty
    % Si #2 est vide, c'est qu'il n'y avait pas de point
    % dans la chaîne initiale
    \c@pgfmath@countb0 %
   \global\def\tkz@decpart{}%
  \else
    % sinon c'est la chaîne qui suit le point décimal...
    \CountToken{#2}%
    % ... y compris le point en trop ajouté par \tkz@getdecimal  :-)
    \advance\c@pgfmath@countb by-1 %
    \@@getdecimal#2\@nil
  \fi
}
\def\@@getdecimal#1.\@nil{\global\def\tkz@decpart{#1}}
%<--------------------------------------------------------------------------–>
% code from JCC modifi
\newcommand\CountToken[1]{%
 \c@pgfmath@countb0 %
  \expandafter\C@untToken#1\@nil
%modifi ajout du expandafter
}
\newcommand\C@untToken{%
  \afterassignment\C@untT@ken\let\CurrT@ken=
}
\newcommand\C@untT@ken{%
 \ifx\CurrT@ken\@nil \else
   \advance\c@pgfmath@countb by1 %
   \expandafter\C@untToken
 \fi
}
% end code from JCC    

%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%            Tools
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%<–––––––– code from TeX in Practice ––––––––>
\newif\if@TestSubString
\def\SubStringConditional #1#2{%
    TT\fi
    \edef\@MainString{#1}%
    \edef\@SubStringConditionalTemp{{#1}{#2}}%
    \expandafter\@SubStringConditional\@SubStringConditionalTemp
}
\def\@SubStringConditional #1#2{% 
    \def\@TestSubS ##1#2##2\\{% 
        \def\@TestTemp{##1}% 
    }% 
    \@TestSubS #1#2\\
    \ifx\@MainString\@TestTemp
        \@TestSubStringfalse
    \else
        \@TestSubStringtrue
    \fi
    \if@TestSubString
}

\def\RecursionMacroEnd #1#2#3{% 
    #1\relax
        \def\@RecursionMacroEndNext{#2}% 
    \else
        \def\@RecursionMacroEndNext{#3}% 
    \fi
    \@RecursionMacroEndNext
}

\def\ReplaceSubStrings #1#2#3#4{%
    \def\@ReplaceResult{#1}%
    \edef\@ReplaceMain{#2}%
    \edef\@ReplaceSub{#3}%
    \edef\@ReplaceSubRep{#4}%
    \@ReplaceSubStrings
}
\def\@ReplaceSubStrings{% 
    \RecursionMacroEnd
        {\if\SubStringConditional{\@ReplaceMain}{\@ReplaceSub}}%
      {\@ReplaceSubStringsDo}{\expandafter\edef\@ReplaceResult{\@ReplaceMain}}%
}
\def\@ReplaceSubStringsDoX{%
    \def\@ReplaceSubStringsDoA ##1%
}%
\def\@ReplaceSubStringsDo{% 
    \expandafter\@ReplaceSubStringsDoX \@ReplaceSub
                                    ##2\@EndReplaceSubStrings{%
        \edef\@ReplaceMain{##1\@ReplaceSubRep ##2}%
    }%
    \expandafter\@ReplaceSubStringsDoA\@ReplaceMain
        \@EndReplaceSubStrings
    \@ReplaceSubStrings
}
\def\tkzPrintFrac#1#2{% 
\begingroup
\tkzReducFrac{#1}{#2}
\global\edef\tkzprintfrac{$     \frac{\tkzMathFirstResult}{\tkzMathSecondResult}$}%
 \ifnum\tkzMathFirstResult=0%
    \global\edef\tkzprintfrac{$0$}%
 \else
 \ifnum\tkzMathSecondResult=1 %
    \ifnum\tkzMathFirstResult=1 %
         \global\edef\tkzprintfrac{$1$}%
      \else
       \ifnum\tkzMathFirstResult=-1%
          \global\edef\tkzprintfrac{$-1$}%
        \else
          \global\edef\tkzprintfrac{$\tkzMathFirstResult$}%
       \fi\fi
 \else 
   \ifnum\tkzMathFirstResult=1 %
          \global\edef\tkzprintfrac{$\tkzmathstyle\frac{1}{\tkzMathSecondResult}$}%
     \else
       \ifnum\tkzMathFirstResult=-1 %
      \global\edef\tkzprintfrac{$\tkzmathstyle\frac{-1}{\tkzMathSecondResult}$}%
        \else
     \global\edef\tkzprintfrac{$\tkzmathstyle\frac{\tkzMathFirstResult}{%
                             \tkzMathSecondResult}$}%
 \fi\fi\fi\fi   
\endgroup}
%<--------------------------------------------------------------------------->
\def\tkzPrintFracWithPi#1#2{% 
\begingroup
\tkzReducFrac{#1}{#2}
\global\edef\tkzprintfrac{$\tkzmathstyle\frac{\tkzMathFirstResult\pi}{\tkzMathSecondResult}$}%
 \ifnum\tkzMathFirstResult=0%
    \global\edef\tkzprintfrac{$0$}%
 \else
 \ifnum\tkzMathSecondResult=1 %
    \ifnum\tkzMathFirstResult=1 %
         \global\edef\tkzprintfrac{$\pi$}%
      \else
       \ifnum\tkzMathFirstResult=-1%
          \global\edef\tkzprintfrac{$-\pi$}%
        \else
          \global\edef\tkzprintfrac{$\tkzMathFirstResult\pi$}%
       \fi\fi
 \else 
   \ifnum\tkzMathFirstResult=1 %
          \global\edef\tkzprintfrac{$\tkzmathstyle\frac{\pi}{\tkzMathSecondResult}$}%
     \else
       \ifnum\tkzMathFirstResult=-1 %
      \global\edef\tkzprintfrac{$\tkzmathstyle\frac{-\pi}{\tkzMathSecondResult}$}%
        \else
     \global\edef\tkzprintfrac{$\tkzmathstyle\frac{\tkzMathFirstResult\pi}{%
                             \tkzMathSecondResult}$}%
 \fi\fi\fi\fi   
\endgroup}%

%<--------------------------------------------------------------------------->
% chargement des modules
\def\tkz@obj@all{polygons,vectors,arcs,sectors,angles,protractor}
\def\tkz@obj@txt{all}
\def\usetkzobj{\pgfutil@ifnextchar[{\use@usetkzobj}{\use@@usetkzobj}}%}
\def\use@usetkzobj[#1]{\use@@usetkzobj{#1}}
\def\use@@usetkzobj#1{% 
  \def\tkz@list{#1}
  \ifx\tkz@obj@txt\tkz@list \edef\tkz@list{\tkz@obj@all}% 
      \else  
      \edef\tkz@list{#1}%
    \fi
  %\edef\tkz@list{#1}%
  \pgfutil@for\tkz@temp:=\tkz@list\do{%
    \expandafter\ifx\csname tkz@library@\tkz@temp @loaded\endcsname\relax%
      \expandafter\global\expandafter\let\csname tkz@library@\tkz@temp @loaded\endcsname=\pgfutil@empty%
      \expandafter\edef\csname tkz@obj@#1@atcode\endcsname{\the\catcode`\@}
      \expandafter\edef\csname tkz@obj@#1@barcode\endcsname{\the\catcode`\|}
      \catcode`\@=11
      \catcode`\|=12   
      \input tkz-obj-\tkz@temp.tex 
            \catcode`\@=\csname tkz@obj@#1@atcode\endcsname
      \catcode`\|=\csname tkz@obj@#1@barcode\endcsname  
    \fi%
  }%
}%
\def\DisabledNumprint{\let\tkz@numprint\numprint
\let\numprint\relax}
\def\EnabledNumprint{\let\numprint\tkz@numprint} 
\endinput