Debian Codegraph @

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

raw
1 % !TeX root = ./examples/tikzlings.tex
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % This is the main part of the TikZlings package
5 % A package to bring cute little animals and other beings into tikz
6 % Maintained by samcarter
7 %
8 % Project repository and bug tracker:
9 % https://github.com/samcarter/tikzlings
10 %
11 % Released under the LaTeX Project Public License v1.3c or later
12 % See https://www.latex-project.org/lppl.txt
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 \ProvidesPackage{tikzlings}[2025/12/11 version v2.5 Collection of packages to draw animals and other beings in TikZ]
16
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 %
19 % List of all TikZlings
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 \RequirePackage{tikzlings-list}
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %
26 % load sub-packages
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 \RequirePackage{tikz}
30
31 \ExplSyntaxOn
32 \cs_new_eq:NN \tikzlings@clistMapInlineNn \clist_map_inline:Nn
33 \ExplSyntaxOff
34
35 \tikzlings@clistMapInlineNn{\tikzlings@packages@clist}{%
36 \RequirePackage{tikzlings-#1}}
37
38 \RequirePackage{tikzlings-addons}
39
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %
42 % Hooks
43 %
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45
46 \NewHook{tikzlings/background}
47 \NewHook{tikzlings/body}
48 \NewHook{tikzlings/clothing}
49 \NewHook{tikzlings/hair}
50 \NewHook{tikzlings/hat}
51 \NewHook{tikzlings/foreground}
52
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %
55 % Drawing a random tikzling
56 %
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 \ExplSyntaxOn
59 \ifdefined\sys_rand_seed:
60 \pgfmathsetseed{\sys_rand_seed:}
61 \else
62 \ifdefined\pdfrandomseed % pdflatex
63 \else
64 \ifdefined\randomseed
65 \let\pdfrandomseed\randomseed % post TL19 xelatex and lualatex
66 \else
67 \let\pdfrandomseed\time % pre TL19 xelatex
68 \fi
69 \fi
70 \pgfmathsetseed{\number\pdfrandomseed}
71 \fi
72
73 % #1: tikzling name.
74 % The second argument of \__tikzlings_show_tikzling:nn will be provided
75 % by \tikzling.
76 \cs_new:Npn \__tikzlings_brace_item:n #1
77 { { \__tikzlings_show_tikzling:nn {#1} } }
78
79 % #1: tikzling name
80 % #2: options passed to its command
81 \cs_new_protected:Npn \__tikzlings_show_tikzling:nn #1#2
82 {
83 \group_begin:
84 \pgfkeys
85 {
86 /#1/.search~also/.expanded =
87 { /tikz, /pgf, /thing, \tikzlings@search@paths@clist }
88 }
89 \use:c {#1} [{#2}]
90 \group_end:
91 }
92
93 \cs_new_protected:Npn \__tikzlings_declare_pgfmath_random_list:n #1
94 {
95 \pgfmathdeclarerandomlist { tikzlings } {#1}
96 }
97
98 % Variant that uses \edef on the argument, then passes the result to
99 % \__tikzlings_declare_pgfmath_random_list:n
100 \cs_generate_variant:Nn \__tikzlings_declare_pgfmath_random_list:n { x }
101
102 % Works because \clist_map_function:NN is expandable
103 \__tikzlings_declare_pgfmath_random_list:x
104 {
105 \clist_map_function:NN \g__tikzlings_names_clist \__tikzlings_brace_item:n
106 }
107 \ExplSyntaxOff
108
109 \newcommand{\tikzling}[1][]{%
110 \pgfmathrandomitem{\tikzlings@random}{tikzlings}%
111 % #1 is passed as second argument to \__tikzlings_show_tikzling:nn
112 \tikzlings@random{#1}%
113 }