summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-ext/tex/generic/pgfkeyslibraryext.pgfkeys-plus.code.tex
blob: 49aedb64c6c23974d5af050b2fc5e0c2d4a466cd (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
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%

\input pgfmath.tex

%% Handlers
%% .pgfmath evaluates values given to keys in PGFmath before handing them over.
%% .pgfmath int truncates the result
%% .pgfmath strcat concatenates the given values
\pgfqkeys{/handlers}{
  .pgfmath/.code=%
    \begingroup
      \pgfmathparse{#1}%
    \expandafter\endgroup\expandafter
    \pgfkeys@exp@call\expandafter{\pgfmathresult},
  .pgfmath int/.code=%
    \begingroup
      \pgfmathint{#1}%
    \expandafter\endgroup\expandafter
    \pgfkeys@exp@call\expandafter{\pgfmathresult},
  .pgfmath wrap/.code 2 args={%
    \def\pgfkeys@temp##1{\def\pgfkeys@temp{#1}}%
    \begingroup
      \pgfmathparse{#2}%
      \expandafter\pgfkeys@temp\expandafter{\pgfmathresult}%
    \expandafter\endgroup\expandafter
    \pgfkeys@exp@call\expandafter{\pgfkeys@temp}%
  },
  .pgfmath if/.code n args={3}{%
    \begingroup
      \pgfmathifthenelse{#1}{"1"}{"0"}%
    \expandafter\endgroup\expandafter
    \ifcase\pgfmathresult\relax
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
    {\pgfkeys@exp@call{#3}}%
    {\pgfkeys@exp@call{#2}}%
  },
  .if/.code n args={4}{%
    \if#1#2%
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
    {\pgfkeys@exp@call{#3}}%
    {\pgfkeys@exp@call{#4}}%
  },
  .ifnum/.code n args={3}{%
    \ifnum#1\relax
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
    {\pgfkeys@exp@call{#2}}%
    {\pgfkeys@exp@call{#3}}%
  },
  .ifdim/.code n args={3}{%
    \ifdim#1\relax
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
    {\pgfkeys@exp@call{#2}}%
    {\pgfkeys@exp@call{#3}}%
  },
  .ifx/.code n args={4}{%
    \ifx#1#2%
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
    {\pgfkeys@exp@call{#3}}%
    {\pgfkeys@exp@call{#4}}%
  },
  .ifxempty/.code n args={3}{%
    \edef\pgfkeys@temp{#1}%
    \pgfutil@ifxempty\pgfkeys@temp{\pgfkeys@exp@call{#2}}{\pgfkeys@exp@call{#3}}%
  },
  .ifempty/.code n args={3}{%
    \pgfutil@ifempty{#1}{\pgfkeys@exp@call{#2}}{\pgfkeys@exp@call{#3}}%
  },
  %% http://tex.stackexchange.com/a/144187/16595
  %% key/.List={(point-1),(point-2),(point-...),(point-6)} will call
  %% key=(point-1)(point-2)(point-3)(point-4)(point-5),(point-6)
  .List/.code=%
    \let\pgfkeys@global@temp\pgfutil@empty
    \foreach\pgfkeys@temp in{#1}{%
        \expandafter\pgfutil@g@addto@macro\expandafter\pgfkeys@global@temp\expandafter{\pgfkeys@temp}%
    }%
    \expandafter\pgfkeys@exp@call\expandafter{\pgfkeys@global@temp}%
}

\pgfqkeys{/utils}{
  if/.code n args={3}{%
    \begingroup
      \pgfmathifthenelse{#1}{"1"}{"0"}%
    \expandafter\endgroup\expandafter
    \ifcase\pgfmathresult\relax
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
    {\pgfkeysalso{#3}}
    {\pgfkeysalso{#2}}%
  },
  TeX/if/.code n args={4}{%
    \if#1#2\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi
    {\pgfkeysalso{#3}}{\pgfkeysalso{#4}}%
  },
  TeX/ifnum/.code n args={3}{%
    \ifnum#1\relax\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi
    {\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
  },
  TeX/ifdim/.code n args={3}{%
    \ifdim#1\relax\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi
    {\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
  },
  TeX/ifx/.code n args={4}{%
    \ifx#1#2\relax\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi
    {\pgfkeysalso{#3}}{\pgfkeysalso{#4}}%
  },
  TeX/ifxempty/.code n args={3}{%
    \edef\pgfkeys@temp{#1}%
    \pgfutil@ifxempty\pgfkeys@temp{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
  },
  TeX/ifempty/.code n args={3}{%
    \pgfutil@ifempty{#1}{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
  },
  tex/.search also=/utils/TeX,
}

\endinput