Debian Codegraph @

texmf-dist/tex/latex/tikzfxgraph/tikzfxgraph.sty

raw
1 %%%==============================================================================
2 %% Copyright 2025-present by Alceu Frigeri
3 %%
4 %% This work may be distributed and/or modified under the conditions of
5 %%
6 %% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
7 %% version 1.3c (or later), and/or
8 %% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
9 %% version 3 (or later)
10 %%
11 %% This work has the LPPL maintenance status *maintained*.
12 %%
13 %% The Current Maintainer of this work is Alceu Frigeri
14 %%
15 %% This is version {1.1} {2025/11/15}
16 %%
17 %% The list of files that compose this work can be found in the README.md file at
18 %% https://ctan.org/pkg/tikzfxgraph
19 %%
20 %%%==============================================================================
21 \NeedsTeXFormat{LaTeX2e}[2022/06/01]
22
23 \ProvidesExplPackage
24 {tikzfxgraph}
25 {2025/11/15}
26 {1.1}
27 {tikzfxgraph Plotting functions in a simplified way.}
28
29 %%%%%%%
30 %%%
31 %%% Just an attempt of having my package's info in a regular way
32 %%% \Pkginfograb_set:nn {<pkg-name>} { props} for each and all.
33 %%%
34 %%%%%%%
35 \RequirePackage{pkginfograb}
36 \pkginfograb_set:nn { tikzfxgraph }
37 {
38 name = {tikzfxgraph} ,
39 prefix = {tikzfxgraph} ,
40 date = {2025/11/15},
41 version = {1.1} ,
42 description = {tikzfxgraph~ Plotting~ functions~ in~ a~ simplified~ way.}
43 }
44 %%%%%%%
45 %%% End of cut-n-paste
46 %%%%%%%
47
48 \bool_new:N \l__tikzfxgraph_use_file_bool
49
50
51 \keys_define:nn { tikzfxgraph}
52 {
53 samples~ default .usage:n = general ,
54 samples~ default .tl_set:N = \l__tikzfxgraph_samples_default_key_tl ,
55 samples~ default .value_required:n = true ,
56 samples~ default .initial:n = {2000} ,
57
58 use~ file .usage:n = general,
59 use~ file .bool_set:N = \l__tikzfxgraph_use_file_key_bool,
60 use~ file .value_forbidden:n = true ,
61
62 no~ domain~ warning .usage:n = general,
63 no~ domain~ warning .code:n =
64 {
65 \msg_redirect_name:nnn {tikzfxgraph} { x domain} { none }
66 }
67 }
68 \ProcessKeyOptions [tikzfxgraph]
69
70
71 \msg_new:nnnn {tikzfxgraph} { no explicit domain}
72 {
73 (ID:#1)~You~ didn't~ explicitily~ define~ a~ range/domain~ for~ the~ x~ axis.
74 }
75 {
76 You~ didn't~ explicitily~ define~ a~ range/domain~ for~ the~ x~ axis.
77 ~Error~ Code~ ID:<#1>.
78 }
79
80 \msg_new:nnnn {tikzfxgraph} { ticks min max}
81 {
82 (ID:#1)~Missing~ min~ and~ max~ values.~Got~#2
83 }
84 {
85 You~ need~ to~ supply~ both~ min~ and~ max~ values.
86 ~Error~ Code~ ID:<#1>.
87 }
88
89 \msg_new:nnnn {tikzfxgraph} { ticks N delta}
90 {
91 (ID:#1)~Missing~ N~ or~ delta.~ ticks~ not~ generated.
92 }
93 {
94 You~ need~ to~ supply~ at~ least~ N~ or~ delta.~ ticks~ not~ generated.
95 ~Error~ Code~ ID:<#1>.
96 }
97
98
99 \msg_new:nnnn {tikzfxgraph} { log min max}
100 {
101 (ID:#1)~For~ a~ log~ axis~ both~ min~ max~ values~ must~ be~ positive.~Got~#2
102 }
103 {
104 For~ a~ log~ axis~ both~ min~ max~ values~ must~ be~ positive.
105 ~Error~ Code~ ID:<#1>.
106 }
107
108 \msg_new:nnnn {tikzfxgraph} { x domain}
109 {
110 (ID:#1)~X~ min/max~ isn't~ explicitly~ defined.~ This~ might~ be~ an~ error.
111 }
112 {
113 X~ min/max~ isn't~ explicitly~ defined.~ This~ might~ be~ an~ error.
114 ~Error~ Code~ ID:<#1>.
115 }
116
117 \msg_new:nnnn {tikzfxgraph} {fxset already defined}
118 {
119 (ID:#1)~fxset~ #2~ already~ defined.
120 }
121 {
122 The~ fxset~ #2~ is~ already~ defined.
123 ~Error~ Code~ ID:<#1>.
124 }
125
126 \msg_new:nnnn {tikzfxgraph} {fxset undefined}
127 {
128 (ID:#1)~invalid/undefined~ fxset~ #2.
129 }
130 {
131 The~ fxset~ #1~ doesn't~ exist,~ isn't~ defined.
132 ~Error~ Code~ ID:<#1>.
133 }
134
135
136
137 \pgfplotscreateplotcyclelist{fxgraph~ color~ list}
138 {
139 red!80!black,
140 green!80!black,
141 blue!80!black,
142 black,
143 brown!70!black,
144 teal!80!black,
145 orange!80!black,
146 violet!80!black,
147 cyan!80!black,
148 magenta!80!black,
149 yellow!75!black,
150 black!60!white
151 }
152 \pgfplotscreateplotcyclelist{fxgraph~ line~ list}
153 {
154 solid,
155 solid,
156 solid,
157 dashed,
158 dashed,
159 dashed,
160 dashdotdotted,
161 dashdotdotted,
162 dashdotdotted
163 }
164
165 \pgfkeys{
166 pgfplots,
167 linear~ axis/.style =
168 {
169 grid=both,
170 tick~ align=outside,
171 width=0.8\textwidth,
172 height=0.35\textwidth,
173 axis~ line~ style={color=black!85!white,very~ thick},
174 axis~ x~ line=bottom,
175 axis~ y~ line=left,
176 cycle~ multiindex*~ list =
177 {
178 fxgraph~ color~ list\nextlist fxgraph~ line~ list
179 } ,
180 legend~ style =
181 {
182 font=\footnotesize,
183 legend~ pos = outer~ north~ east,
184 draw = none ,
185 inner~ xsep=0pt,
186 inner~ ysep=0pt,
187 anchor = west ,
188 } ,
189 } ,
190 semilog~ x~ axis/.style =
191 {
192 linear~ axis,
193 log~ identify~ minor~ tick~ positions=true,
194 % log~ basis~ x = 10,
195 } ,
196 semilog~ y~ axis/.style =
197 {
198 linear~ axis,
199 log~ identify~ minor~ tick~ positions=true,
200 % log~ basis~ y = 10,
201 } ,
202 loglog~ axis/.style =
203 {
204 linear~ axis,
205 log~ identify~ minor~ tick~ positions=true,
206 % log~ basis~ x = 10,
207 % log~ basis~ y = 10,
208 }
209 }
210
211
212
213 \int_new:N \l__tikzfxgraph_tmpi_int
214 \seq_new:N \l__tikzfxgraph_tick_tmpi_seq
215 \fp_new:N \l__tikzfxgraph_tmpi_fp
216 \fp_new:N \l__tikzfxgraph_delta_tmpi_fp
217 \tl_new:N \l__tikzfxgraph_nill_tl
218 \tl_new:N \l__tikzfxgraph_tmpi_tl
219
220 \cs_generate_variant:Nn \fp_set:Nn {Ne}
221 \cs_generate_variant:Nn \fp_add:Nn {Ne}
222 \cs_generate_variant:Nn \seq_put_right:Nn {Ne}
223
224
225 \tl_new:N \l__tikzfxgraph_axis_kind_key_tl
226 \tl_new:N \l__tikzfxgraph_axis_style_key_tl
227 \tl_new:N \l__tikzfxgraph_Xaxis_type_key_tl
228 \tl_new:N \l__tikzfxgraph_Yaxis_type_key_tl
229
230 \tl_new:N \l__tikzfxgraph_Xticks_key_tl
231 \tl_new:N \l__tikzfxgraph_Xmin_key_tl
232 \tl_new:N \l__tikzfxgraph_Xmax_key_tl
233 \tl_new:N \l__tikzfxgraph_Xunits_key_tl
234
235 \tl_new:N \l__tikzfxgraph_Yticks_key_tl
236 \tl_new:N \l__tikzfxgraph_Ymin_key_tl
237 \tl_new:N \l__tikzfxgraph_Ymax_key_tl
238 \tl_new:N \l__tikzfxgraph_Yunits_key_tl
239
240 \tl_new:N \l__tikzfxgraph_functions_tl
241
242 \tl_new:N \l__tikzfxgraph_fxstyles_key_tl
243
244 \clist_new:N \l__tikzfxgraph_fxset_key_clist
245
246
247 \tl_new:N \l__tikzfxgraph_tmpa_tl
248 \tl_new:N \l__tikzfxgraph_tmpb_tl
249 \tl_new:N \l__tikzfxgraph_tmpc_tl
250
251
252 \keys_define:nn {tikzfxgraph / axis kind}
253 {
254 linear .usage:n = general ,
255 linear .code:n =
256 {
257 \tl_set:Nn \l__tikzfxgraph_axis_kind_key_tl {axis}
258 \tl_set:Nn \l__tikzfxgraph_axis_basestyle_key_tl {linear~ axis}
259 \tl_set:Nn \l__tikzfxgraph_Xaxis_type_key_tl {linear}
260 \tl_set:Nn \l__tikzfxgraph_Yaxis_type_key_tl {linear}
261 } ,
262 linear .value_forbidden:n = true ,
263
264 loglog .usage:n = general ,
265 loglog .code:n =
266 {
267 \tl_set:Nn \l__tikzfxgraph_axis_kind_key_tl {loglogaxis}
268 \tl_set:Nn \l__tikzfxgraph_axis_basestyle_key_tl {loglog~ axis}
269 \tl_set:Nn \l__tikzfxgraph_Xaxis_type_key_tl {log}
270 \tl_set:Nn \l__tikzfxgraph_Yaxis_type_key_tl {log}
271 } ,
272 loglog .value_forbidden:n = true ,
273
274 semilog~ x .usage:n = general ,
275 semilog~ x .code:n =
276 {
277 \tl_set:Nn \l__tikzfxgraph_axis_kind_key_tl {semilogxaxis}
278 \tl_set:Nn \l__tikzfxgraph_axis_basestyle_key_tl {semilog~ x~ axis}
279 \tl_set:Nn \l__tikzfxgraph_Xaxis_type_key_tl {log}
280 \tl_set:Nn \l__tikzfxgraph_Yaxis_type_key_tl {linear}
281 } ,
282 semilog~ x .value_forbidden:n = true ,
283
284 semilog~ y .usage:n = general ,
285 semilog~ y .code:n =
286 {
287 \tl_set:Nn \l__tikzfxgraph_axis_kind_key_tl {semilogyaxis}
288 \tl_set:Nn \l__tikzfxgraph_axis_basestyle_key_tl {semilog~ y~ axis}
289 \tl_set:Nn \l__tikzfxgraph_Xaxis_type_key_tl {linear}
290 \tl_set:Nn \l__tikzfxgraph_Yaxis_type_key_tl {log}
291 } ,
292 semilog~ y .value_forbidden:n = true ,
293 }
294
295 \cs_new_protected:Npn \__tikzfxgraph_axiskind_init:n #1
296 {
297 \keys_set:nn {tikzfxgraph / axis kind} {#1}
298 }
299
300
301 \keys_define:nn {tikzfxgraph / axis ticks}
302 {
303 x~ ticks .usage:n = general ,
304 x~ ticks .code:n =
305 {
306 \__tikzfxgraph_ticks_set:NVn \l__tikzfxgraph_Xticks_key_tl \l__tikzfxgraph_Xaxis_type_key_tl {#1}
307
308 \tl_set:NV \l__tikzfxgraph_Xmin_key_tl \l__tikzfxgraph_min_key_tl
309 \tl_set:NV \l__tikzfxgraph_Xmax_key_tl \l__tikzfxgraph_max_key_tl
310 \tl_set:NV \l__tikzfxgraph_Xunits_key_tl \l__tikzfxgraph_units_key_tl
311 } ,
312 x~ ticks .value_required:n = true ,
313
314 y~ ticks .usage:n = general ,
315 y~ ticks .code:n =
316 {
317 \__tikzfxgraph_ticks_set:NVn \l__tikzfxgraph_Yticks_key_tl \l__tikzfxgraph_Yaxis_type_key_tl {#1}
318
319 \tl_set:NV \l__tikzfxgraph_Ymin_key_tl \l__tikzfxgraph_min_key_tl
320 \tl_set:NV \l__tikzfxgraph_Ymax_key_tl \l__tikzfxgraph_max_key_tl
321 \tl_set:NV \l__tikzfxgraph_Yunits_key_tl \l__tikzfxgraph_units_key_tl
322 } ,
323 y~ ticks .value_required:n = true ,
324 }
325
326 \cs_new_protected:Npn \__tikzfxgraph_axisticks_init:
327 {
328 \tl_clear:N \l__tikzfxgraph_Xticks_key_tl
329 \tl_clear:N \l__tikzfxgraph_Xmin_key_tl
330 \tl_clear:N \l__tikzfxgraph_Xmax_key_tl
331 \tl_clear:N \l__tikzfxgraph_Xunits_key_tl
332 \tl_clear:N \l__tikzfxgraph_Yticks_key_tl
333 \tl_clear:N \l__tikzfxgraph_Ymin_key_tl
334 \tl_clear:N \l__tikzfxgraph_Ymax_key_tl
335 \tl_clear:N \l__tikzfxgraph_Yunits_key_tl
336 }
337
338
339
340 \keys_define:nn {}
341 {
342 tikzfxgraph / graph desc .inherit:n =
343 {
344 tikzfxgraph / axis kind ,
345 tikzfxgraph / axis ticks ,
346 }
347 }
348
349 \keys_define:nn {tikzfxgraph / graph desc}
350 {
351 sans~ tikz picture .usage:n = general ,
352 sans~ tikz picture .bool_set:N = \l__tikzfxgraph_sanstikz_key_bool ,
353
354 without~ tikz picture .usage:n = general ,
355 without~ tikz picture .bool_set:N = \l__tikzfxgraph_sanstikz_key_bool ,
356
357 use~ file .usage:n = general,
358 use~ file .bool_set:N = \l__tikzfxgraph_use_file_key_bool,
359
360 function .usage:n = general ,
361 function .code:n =
362 {
363 \__tikzfxgraph_fxset_append:nn {default _ set}{#1}
364 } ,
365 function .value_required:n = true ,
366
367 fx~ set .usage:n = general ,
368 fx~ set .clist_set:N = \l__tikzfxgraph_fxset_key_clist ,
369 fx~ set .value_required:n = true ,
370
371 unknown .code:n =
372 {
373 \__tikzfxgraph_fxstyles_setkey:NVn
374 \l__tikzfxgraph_axis_style_key_tl
375 \l_keys_key_str
376 {#1}
377 } ,
378 }
379
380 \cs_new_protected:Npn \__tikzfxgraph_graphdesc_init:
381 {
382 \__tikzfxgraph_fxset_clear:n {default _ set}
383 \clist_clear:N \l__tikzfxgraph_fxset_key_clist
384 \bool_set_false:N \l__tikzfxgraph_sanstikz_key_bool
385 \tl_clear:N \l__tikzfxgraph_axis_style_key_tl
386
387 \__tikzfxgraph_axisticks_init:
388 \__tikzfxgraph_axiskind_init:n {linear}
389 }
390
391
392 \keys_define:nn {}
393 {
394 tikzfxgraph / keys desc .inherit:n =
395 {
396 tikzfxgraph / axis kind ,
397 tikzfxgraph / axis ticks ,
398 }
399 }
400
401 \keys_define:nn {tikzfxgraph / keys desc}
402 {
403 unknown .code:n =
404 {
405 \__tikzfxgraph_fxstyles_setkey:NVn
406 \l__tikzfxgraph_axis_style_key_tl
407 \l_keys_key_str
408 {#1}
409 } ,
410 }
411
412
413 \cs_new_protected:Npn \__tikzfxgraph_keysdesc_init:
414 {
415 \tl_clear:N \l__tikzfxgraph_axis_style_key_tl
416
417 \__tikzfxgraph_axisticks_init:
418 \__tikzfxgraph_axiskind_init:n {linear}
419 }
420
421
422 \keys_define:nn {tikzfxgraph / ticks}
423 {
424 min .usage:n = general ,
425 min .tl_set:N = \l__tikzfxgraph_min_key_tl ,
426 min .value_required:n = true ,
427
428 max .usage:n = general ,
429 max .tl_set:N = \l__tikzfxgraph_max_key_tl ,
430 max .value_required:n = true ,
431
432 delta .usage:n = general ,
433 delta .tl_set:N = \l__tikzfxgraph_delta_key_tl ,
434 delta .value_required:n = true ,
435
436 N .usage:n = general ,
437 N .tl_set:N = \l__tikzfxgraph_N_key_tl ,
438 N .value_required:n = true ,
439
440 units .usage:n = general ,
441 units .tl_set:N = \l__tikzfxgraph_units_key_tl ,
442 units .value_required:n = true ,
443
444 phi .usage:n = general ,
445 phi .code:n =
446 {
447 \tl_set:Nn \l__tikzfxgraph_min_key_tl {-3.14159265}
448 \tl_set:Nn \l__tikzfxgraph_max_key_tl { 3.14159265}
449 \tl_set:Nn \l__tikzfxgraph_N_key_tl { 8 }
450 \tl_set:Nn \l__tikzfxgraph_units_key_tl { rad }
451 } ,
452 phi .value_forbidden:n = true ,
453
454 db .usage:n = general ,
455 db .code:n =
456 {
457 \tl_set:Nn \l__tikzfxgraph_min_key_tl {-20}
458 \tl_set:Nn \l__tikzfxgraph_max_key_tl { 80}
459 \tl_set:Nn \l__tikzfxgraph_N_key_tl { 5 }
460 \tl_set:Nn \l__tikzfxgraph_units_key_tl { db }
461 } ,
462 db .value_forbidden:n = true ,
463 }
464
465 \cs_new_protected:Npn \__tikzfxgraph_ticks_init:
466 {
467 \tl_clear:N \l__tikzfxgraph_min_key_tl
468 \tl_clear:N \l__tikzfxgraph_max_key_tl
469 \tl_clear:N \l__tikzfxgraph_delta_key_tl
470 \tl_clear:N \l__tikzfxgraph_N_key_tl
471 \tl_clear:N \l__tikzfxgraph_units_key_tl
472 }
473
474
475 \keys_define:nn {tikzfxgraph / fx set}
476 {
477 fx .usage:n = general ,
478 fx .tl_set:N = \l__tikzfxgraph_fx_key_tl ,
479 fx .value_required:n = true ,
480
481 id .usage:n = general ,
482 id .tl_set:N = \l__tikzfxgraph_fxid_key_tl ,
483 id .value_required:n = true ,
484
485 legend .usage:n = general ,
486 legend .tl_set:N = \l__tikzfxgraph_fxlegend_key_tl ,
487 legend .value_required:n = true ,
488
489 use~ file .usage:n = general ,
490 use~ file .bool_set:N = \l__tikzfxgraph_fx_use_file_key_bool ,
491 use~ file .value_forbidden:n = true ,
492
493 samples .usage:n = general ,
494 samples .tl_set:N = \l__tikzfxgraph_samples_key_tl ,
495 samples .value_required:n = true ,
496
497 unknown .code:n =
498 {
499 \__tikzfxgraph_fxstyles_setkey:NVn
500 \l__tikzfxgraph_fxstyles_key_tl
501 \l_keys_key_str
502 {#1}
503 } ,
504 }
505
506
507 \cs_new_protected:Npn \__tikzfxgraph_fxset_init:
508 {
509 \tl_clear:N \l__tikzfxgraph_fxstyles_key_tl
510 \tl_clear:N \l__tikzfxgraph_fx_key_tl
511 \tl_clear:N \l__tikzfxgraph_fxid_key_tl
512 \tl_clear:N \l__tikzfxgraph_fxlegend_key_tl
513 \tl_set_eq:NN \l__tikzfxgraph_samples_key_tl \l__tikzfxgraph_samples_default_key_tl
514 \bool_set_false:N \l__tikzfxgraph_fx_use_file_key_bool
515 }
516
517
518 \prg_generate_conditional_variant:Nnn \fp_compare:nNn {eNn} {p , T , F , TF}
519
520
521 \cs_new_protected:Npn \__tikzfxgraph_fxstyles_setkey:Nnn #1#2#3
522 {
523 \tl_if_blank:VF #1
524 { \tl_put_right:Nn #1 , }
525 \tl_if_blank:nTF {#3}
526 { \tl_put_right:Nn #1 {#2} }
527 { \tl_put_right:Nn #1 {#2={#3}} }
528 }
529
530 \cs_generate_variant:Nn \__tikzfxgraph_fxstyles_setkey:Nnn {NVn}
531
532
533 \cs_new_protected:Npn \__tikzfxgraph_ticks_set:Nnn #1#2#3
534 {
535 \__tikzfxgraph_ticks_init:
536
537 \keys_set:nn {tikzfxgraph / ticks}
538 {#3}
539 \bool_lazy_or:nnTF
540 {\tl_if_blank_p:V \l__tikzfxgraph_min_key_tl} {\tl_if_blank_p:V \l__tikzfxgraph_max_key_tl}
541 {
542 \msg_error:nnne {tikzfxgraph} {ticks min max}{ticks-01}
543 {min:<\l__tikzfxgraph_min_key_tl> ~-~ max:<\l__tikzfxgraph_max_key_tl>}
544 }
545 {
546 \tl_if_blank:VTF \l__tikzfxgraph_N_key_tl
547 {
548 \tl_if_blank:VTF \l__tikzfxgraph_delta_key_tl
549 {
550 \msg_warning:nnn {tikzfxgraph} {ticks N delta}{ticks-02}
551 \tl_clear:N #1
552 }
553 {
554 \int_zero:N \l__tikzfxgraph_tmpi_int
555 \seq_clear:N \l__tikzfxgraph_tick_tmpi_seq
556 \str_if_eq:nnTF {#2}{linear}
557 {
558 \fp_set:Ne \l__tikzfxgraph_tmpi_fp {\l__tikzfxgraph_min_key_tl}
559 \fp_set:Ne \l__tikzfxgraph_delta_tmpi_fp { \l__tikzfxgraph_delta_key_tl }
560 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_use:N \l__tikzfxgraph_tmpi_fp}
561 \fp_while_do:nNnn
562 {\l__tikzfxgraph_tmpi_fp} < {\l__tikzfxgraph_max_key_tl}
563 {
564 \fp_add:Nn \l__tikzfxgraph_tmpi_fp {\l__tikzfxgraph_delta_tmpi_fp}
565 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_use:N \l__tikzfxgraph_tmpi_fp}
566 }
567 \tl_set:Ne #1 {\seq_use:Nn \l__tikzfxgraph_tick_tmpi_seq {~,~}}
568 }
569 { %log
570 \bool_lazy_and:nnTF
571 { \fp_compare_p:eNn {\l__tikzfxgraph_max_key_tl} > {0} } { \fp_compare_p:eNn {\l__tikzfxgraph_min_key_tl} > {0} }
572 {
573 \fp_set:Ne \l__tikzfxgraph_tmpi_fp {ln(\l__tikzfxgraph_min_key_tl)}
574 \fp_set:Ne \l__tikzfxgraph_tmpii_fp {ln(\l__tikzfxgraph_max_key_tl)}
575 \fp_set:Ne \l__tikzfxgraph_delta_tmpi_fp { ln(\l__tikzfxgraph_delta_key_tl) }
576 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_eval:n {exp(\l__tikzfxgraph_tmpi_fp)}}
577 \fp_while_do:nNnn
578 {\l__tikzfxgraph_tmpi_fp} < {\l__tikzfxgraph_tmpii_fp}
579 {
580 \fp_add:Nn \l__tikzfxgraph_tmpi_fp {\l__tikzfxgraph_delta_tmpi_fp}
581 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_eval:n {exp(\l__tikzfxgraph_tmpi_fp)}}
582 }
583 \tl_set:Ne #1 {\seq_use:Nn \l__tikzfxgraph_tick_tmpi_seq {~,~}}
584 }
585 {
586 \msg_error:nnne {tikzfxgraph}{log min max}{ticks-03}
587 {min:<\l__tikzfxgraph_min_key_tl> ~-~ max:<\l__tikzfxgraph_max_key_tl>} % both must be positive
588 }
589 }
590 }
591 }
592 {
593 \int_zero:N \l__tikzfxgraph_tmpi_int
594 \seq_clear:N \l__tikzfxgraph_tick_tmpi_seq
595 \str_if_eq:nnTF {#2}{linear}
596 {
597 \fp_set:Ne \l__tikzfxgraph_tmpi_fp {\l__tikzfxgraph_min_key_tl}
598 \fp_set:Ne \l__tikzfxgraph_delta_tmpi_fp { (\l__tikzfxgraph_max_key_tl - \l__tikzfxgraph_min_key_tl) / \l__tikzfxgraph_N_key_tl}
599 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_use:N \l__tikzfxgraph_tmpi_fp}
600 \int_while_do:nNnn
601 {\l__tikzfxgraph_tmpi_int} < {\l__tikzfxgraph_N_key_tl}
602 {
603 \fp_add:Nn \l__tikzfxgraph_tmpi_fp {\l__tikzfxgraph_delta_tmpi_fp}
604 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_use:N \l__tikzfxgraph_tmpi_fp}
605 \int_incr:N \l__tikzfxgraph_tmpi_int
606 }
607 \tl_set:Ne #1 {\seq_use:Nn \l__tikzfxgraph_tick_tmpi_seq {~,~}}
608 }
609 { %log
610 \bool_lazy_and:nnTF
611 { \fp_compare_p:eNn {\l__tikzfxgraph_max_key_tl} > {0} } { \fp_compare_p:eNn {\l__tikzfxgraph_min_key_tl} > {0} }
612 {
613 \fp_set:Ne \l__tikzfxgraph_tmpi_fp {ln(\l__tikzfxgraph_min_key_tl)}
614 \fp_set:Ne \l__tikzfxgraph_delta_tmpi_fp { (ln(\l__tikzfxgraph_max_key_tl) - ln(\l__tikzfxgraph_min_key_tl)) / \l__tikzfxgraph_N_key_tl}
615 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_eval:n {exp(\l__tikzfxgraph_tmpi_fp)}}
616 \int_while_do:nNnn
617 {\l__tikzfxgraph_tmpi_int} < {\l__tikzfxgraph_N_key_tl}
618 {
619 \fp_add:Nn \l__tikzfxgraph_tmpi_fp {\l__tikzfxgraph_delta_tmpi_fp}
620 \seq_put_right:Ne \l__tikzfxgraph_tick_tmpi_seq {\fp_eval:n {exp(\l__tikzfxgraph_tmpi_fp)}}
621 \int_incr:N \l__tikzfxgraph_tmpi_int
622 }
623 \tl_set:Ne #1 {\seq_use:Nn \l__tikzfxgraph_tick_tmpi_seq {~,~}}
624 }
625 {
626 \msg_error:nnne {tikzfxgraph}{log min max}{ticks-04}
627 {min:<\l__tikzfxgraph_min_key_tl> ~-~ max:<\l__tikzfxgraph_max_key_tl>} % both must be positive
628 }
629 }
630 }
631 }
632 }
633 \cs_generate_variant:Nn \__tikzfxgraph_ticks_set:Nnn { NVn }
634
635
636 \cs_new_protected:Npn \__tikzfxgraph_seq_put:Nnn #1#2#3
637 {
638 \seq_put_right:Nn #1
639 { {#2}{#3} }
640 }
641 \cs_generate_variant:Nn \__tikzfxgraph_seq_put:Nnn {cVV}
642
643 \cs_new_protected:Npn \__tikzfxgraph_fxset_addplot:nn #1#2
644 {
645 \__tikzfxgraph_fxset_init:
646
647 \keys_set:nn {tikzfxgraph / fx set}
648 {#2}
649
650 \tl_set:Ne \l__tikzfxgraph_tmpa_tl {samples=\l__tikzfxgraph_samples_key_tl}
651 \tl_if_blank:VTF \l__tikzfxgraph_fxid_key_tl
652 {
653 \tl_clear:N \l__tikzfxgraph_tmpc_tl
654 }
655 {
656 \tl_put_right:Ne \l__tikzfxgraph_tmpa_tl {,id=\l__tikzfxgraph_fxid_key_tl}
657 \exp_args:Ne \IfFileExists {\jobname . \l__tikzfxgraph_fxid_key_tl .table}
658 {
659 \tl_set:Ne \l__tikzfxgraph_tmpc_tl
660 {\exp_not:N\addplot table [x ~ index=0,y ~ index=1,header=false] {\jobname . \l__tikzfxgraph_fxid_key_tl .table};}
661 }
662 {
663 \tl_clear:N \l__tikzfxgraph_tmpc_tl
664 }
665 }
666
667 \tl_set:Ne \l__tikzfxgraph_tmpb_tl
668 {
669 \exp_not:N\addplot+ gnuplot
670 [ \l__tikzfxgraph_tmpa_tl , \l__tikzfxgraph_fxstyles_key_tl ]
671 {\l__tikzfxgraph_fx_key_tl};
672 }
673 \tl_if_blank:VF \l__tikzfxgraph_fxlegend_key_tl
674 {
675 \tl_put_right:Ne \l__tikzfxgraph_tmpb_tl
676 {
677 \exp_not:N\addlegendentry {\l__tikzfxgraph_fxlegend_key_tl}
678 }
679 \tl_if_blank:VF \l__tikzfxgraph_tmpc_tl
680 {
681 \tl_put_right:Ne \l__tikzfxgraph_tmpc_tl
682 {
683 \exp_not:N\addlegendentry {\l__tikzfxgraph_fxlegend_key_tl}
684 }
685 }
686 }
687
688 \tl_if_blank:VTF \l__tikzfxgraph_tmpc_tl
689 {
690 \__tikzfxgraph_seq_put:cVV
691 {l__tikzfxgraph_fxset_ #1 _seq}
692 \l__tikzfxgraph_tmpb_tl
693 \l__tikzfxgraph_tmpb_tl
694 }
695 {
696 \bool_if:NTF \l__tikzfxgraph_fx_use_file_key_bool
697 {
698 \__tikzfxgraph_seq_put:cVV
699 {l__tikzfxgraph_fxset_ #1 _seq}
700 \l__tikzfxgraph_tmpc_tl
701 \l__tikzfxgraph_tmpc_tl
702 }
703 {
704 \__tikzfxgraph_seq_put:cVV
705 {l__tikzfxgraph_fxset_ #1 _seq}
706 \l__tikzfxgraph_tmpb_tl
707 \l__tikzfxgraph_tmpc_tl
708 }
709 }
710 }
711
712 \cs_new_protected:Npn \__tikzfxgraph_fxset_new:n #1
713 {
714 \seq_if_exist:cTF {l__tikzfxgraph_fxset_ #1 _seq}
715 {
716 \msg_error:nnnn {tikzfxgraph}{fxset already defined}{fxset-01}{#1}
717 }
718 {
719 \seq_new:c {l__tikzfxgraph_fxset_ #1 _seq}
720 }
721 }
722
723
724 \__tikzfxgraph_fxset_new:n {default _ set}
725
726 \cs_new_protected:Npn \__tikzfxgraph_fxset_clear:n #1
727 {
728 \seq_if_exist:cTF {l__tikzfxgraph_fxset_ #1 _seq}
729 {
730 \seq_clear:c {l__tikzfxgraph_fxset_ #1 _seq}
731 }
732 {
733 \msg_error:nnnn {tikzfxgraph}{fxset undefined}{fxset-02}{#1}
734 }
735 }
736
737
738
739 \cs_new_protected:Npn \__tikzfxgraph_fxset_append:nn #1#2
740 {
741 \seq_if_exist:cTF {l__tikzfxgraph_fxset_ #1 _seq}
742 {
743 \__tikzfxgraph_fxset_addplot:nn {#1}{#2}
744 }
745 {
746 \msg_error:nnnn {tikzfxgraph}{fxset undefined}{fxset-03}{#1}
747 }
748 }
749
750 \NewDocumentCommand{\fxsetnew}{m}
751 { \__tikzfxgraph_fxset_new:n {#1} }
752
753
754 \NewDocumentCommand{\fxsetappend}{mm}
755 { \__tikzfxgraph_fxset_append:nn {#1}{#2} }
756
757
758 \NewDocumentCommand{\fxsetnewstyle}{mm}
759 {
760 \__tikzfxgraph_keysdesc_init:
761
762 \keys_set:nn {tikzfxgraph / keys desc}
763 {#2}
764 \__tikzfxgraph_set_keys:N \l__tikzfxgraph_stylekeys_set_tl
765 \use:e
766 {
767 \exp_not:N\pgfkeys{pgfplots,
768 #1/.style =
769 { \l__tikzfxgraph_stylekeys_set_tl }
770 }
771 }
772 }
773
774
775 \cs_new_protected:Npn \__tikzfxgraph_axisdraw:nnnn #1#2#3#4
776 {
777 \bool_if:NTF \l__tikzfxgraph_sanstikz_key_bool
778 {
779 \tl_set:Nn \l__tikzfxgraph_tmpa_tl
780 {
781 \begin{#1}[#2]
782 #3
783 #4
784 \end{#1}
785 }
786 }
787 {
788 \tl_set:Nn \l__tikzfxgraph_tmpa_tl
789 {
790 \begin{tikzpicture}
791 \begin{#1}[#2]
792 #3
793 #4
794 \end{#1}
795 \end{tikzpicture}
796 }
797 }
798 \l__tikzfxgraph_tmpa_tl
799 }
800
801 \cs_generate_variant:Nn \__tikzfxgraph_axisdraw:nnnn {VVVn}
802
803 \cs_new_protected:Npn \__tikzfxgraph_set_keys:Nnnn #1#2#3#4
804 {
805 \tl_if_blank:nTF {#2}
806 { \tl_clear:N #1 }
807 { \tl_set:Nn #1 {#2} }
808 \tl_if_blank:nF {#3}
809 { \tl_put_right:Nn #1 {xtick={#3},} }
810 \tl_if_blank:nF {#4}
811 { \tl_put_right:Nn #1 {ytick={#4}} }
812 }
813
814 \cs_generate_variant:Nn \__tikzfxgraph_set_keys:Nnnn {NVVV}
815
816 \tl_new:N \l__tikzfxgraph_stylekeys_set_tl
817
818 \cs_new_protected:Npn \__tikzfxgraph_set_keys:N #1
819 {
820 \tl_clear:N \l__tikzfxgraph_tmpa_tl
821 \tl_if_blank:VF \l__tikzfxgraph_axis_style_key_tl
822 {
823 \tl_set:NV \l__tikzfxgraph_tmpa_tl \l__tikzfxgraph_axis_style_key_tl
824 \tl_put_right:Nn \l__tikzfxgraph_tmpa_tl {,}
825 }
826
827 \bool_lazy_or:nnTF {\tl_if_blank_p:V \l__tikzfxgraph_Xmin_key_tl } {\tl_if_blank_p:V \l__tikzfxgraph_Xmax_key_tl}
828 {
829 \msg_warning:nnn {tikzfxgraph}{x domain}{keys-01}
830 }
831 {
832 \tl_put_right:Ne \l__tikzfxgraph_tmpa_tl
833 {
834 xmin=\l__tikzfxgraph_Xmin_key_tl,
835 xmax=\l__tikzfxgraph_Xmax_key_tl,
836 domain=\l__tikzfxgraph_Xmin_key_tl : \l__tikzfxgraph_Xmax_key_tl,
837 }
838 }
839 \tl_if_blank:VF \l__tikzfxgraph_Xunits_key_tl
840 {
841 \tl_put_right:Ne \l__tikzfxgraph_tmpa_tl
842 { x~ unit=\l__tikzfxgraph_Xunits_key_tl, }
843 }
844 \bool_lazy_or:nnF {\tl_if_blank_p:V \l__tikzfxgraph_Ymin_key_tl} {\tl_if_blank_p:V \l__tikzfxgraph_Ymax_key_tl}
845 {
846 \tl_put_right:Ne \l__tikzfxgraph_tmpa_tl
847 {
848 ymin=\l__tikzfxgraph_Ymin_key_tl,
849 ymax=\l__tikzfxgraph_Ymax_key_tl,
850 }
851 }
852 \tl_if_blank:VF \l__tikzfxgraph_Yunits_key_tl
853 {
854 \tl_put_right:Ne \l__tikzfxgraph_tmpa_tl
855 { y~ unit=\l__tikzfxgraph_Yunits_key_tl, }
856 }
857
858 \__tikzfxgraph_set_keys:NVVV
859 #1
860 \l__tikzfxgraph_tmpa_tl
861 \l__tikzfxgraph_Xticks_key_tl
862 \l__tikzfxgraph_Yticks_key_tl
863
864 }
865
866
867 \NewDocumentCommand{\fxgraphdraw}{m}
868 {
869 \begin{fxgraph}{#1}
870 \end{fxgraph}
871 }
872
873
874
875 \cs_new:Npn \__tikzfxgraph_i_ii:Nnn #1#2#3
876 {
877 \tl_put_right:Nn #1 {#2}
878 }
879 \cs_new:Npn \__tikzfxgraph_i_iii:Nnn #1#2#3
880 {
881 \tl_put_right:Nn #1 {#3}
882 }
883
884 \NewDocumentEnvironment{fxgraph}{m +b}
885 {
886 \__tikzfxgraph_graphdesc_init:
887
888 \keys_set:nn {tikzfxgraph / graph desc}
889 {#1}
890
891 \__tikzfxgraph_set_keys:N \l__tikzfxgraph_stylekeys_set_tl
892
893 \tl_clear:N \l__tikzfxgraph_tmpb_tl
894 \clist_put_left:Nn \l__tikzfxgraph_fxset_key_clist {default_set}
895
896 \bool_if:NTF \l__tikzfxgraph_use_file_key_bool
897 { \cs_set_eq:NN \__tikzfxgraph_map:Nnn \__tikzfxgraph_i_iii:Nnn }
898 { \cs_set_eq:NN \__tikzfxgraph_map:Nnn \__tikzfxgraph_i_ii:Nnn }
899
900 \clist_map_inline:Nn \l__tikzfxgraph_fxset_key_clist
901 {
902 \seq_if_exist:cTF {l__tikzfxgraph_fxset_ ##1 _seq}
903 {
904 \seq_map_inline:cn {l__tikzfxgraph_fxset_ ##1 _seq}
905 {\__tikzfxgraph_map:Nnn \l__tikzfxgraph_tmpb_tl ####1} %% remember: each item is composed of two n's: {}{}
906 }
907 {
908 \msg_error:nnnn {tikzfxgraph} {fxset undefined}{set-02}{##1}
909 }
910 }
911
912 \tl_set:NV \l__tikzfxgraph_tmpa_tl \l__tikzfxgraph_axis_basestyle_key_tl
913 \tl_put_right:Nn \l__tikzfxgraph_tmpa_tl {,}
914 \tl_put_right:NV \l__tikzfxgraph_tmpa_tl \l__tikzfxgraph_stylekeys_set_tl
915
916 \__tikzfxgraph_axisdraw:VVVn
917 \l__tikzfxgraph_axis_kind_key_tl
918 \l__tikzfxgraph_tmpa_tl
919 \l__tikzfxgraph_tmpb_tl
920 {#2}
921 }
922 {}