| 1 |
% Copyright 2022 by Qrrbrbirlbel |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
|
| 9 |
\unless\ifcsname tikzextset\endcsname |
| 10 |
\input tikzext-util.tex |
| 11 |
\fi |
| 12 |
|
| 13 |
\input pgfmath.tex |
| 14 |
|
| 15 |
%% Handlers |
| 16 |
%% .pgfmath evaluates values given to keys in PGFmath before handing them over. |
| 17 |
%% .pgfmath int truncates the result |
| 18 |
%% .pgfmath strcat concatenates the given values |
| 19 |
\pgfqkeys{/handlers}{ |
| 20 |
.ext_pgfmath/.code=% |
| 21 |
\begingroup |
| 22 |
\pgfmathparse{#1}% |
| 23 |
\expandafter\endgroup\expandafter |
| 24 |
\pgfkeys@exp@call\expandafter{\pgfmathresult}, |
| 25 |
.ext_pgfmath int/.code=% |
| 26 |
\begingroup |
| 27 |
\pgfmathint{#1}% |
| 28 |
\expandafter\endgroup\expandafter |
| 29 |
\pgfkeys@exp@call\expandafter{\pgfmathresult}, |
| 30 |
.ext_pgfmath wrap/.code 2 args={% |
| 31 |
\def\pgfkeys@temp##1{\def\pgfkeys@temp{#1}}% |
| 32 |
\begingroup |
| 33 |
\pgfmathparse{#2}% |
| 34 |
\expandafter\pgfkeys@temp\expandafter{\pgfmathresult}% |
| 35 |
\expandafter\endgroup\expandafter |
| 36 |
\pgfkeys@exp@call\expandafter{\pgfkeys@temp}% |
| 37 |
}, |
| 38 |
.ext_pgfmath if/.code n args={3}{% |
| 39 |
\begingroup |
| 40 |
\pgfmathifthenelse{#1}{"1"}{"0"}% |
| 41 |
\expandafter\endgroup\expandafter |
| 42 |
\ifcase\pgfmathresult\relax |
| 43 |
\expandafter\pgfutil@firstoftwo |
| 44 |
\else |
| 45 |
\expandafter\pgfutil@secondoftwo |
| 46 |
\fi |
| 47 |
{\pgfkeys@exp@call{#3}}% |
| 48 |
{\pgfkeys@exp@call{#2}}% |
| 49 |
}, |
| 50 |
.ext_if/.code n args={4}{% |
| 51 |
\if#1#2% |
| 52 |
\expandafter\pgfutil@firstoftwo |
| 53 |
\else |
| 54 |
\expandafter\pgfutil@secondoftwo |
| 55 |
\fi |
| 56 |
{\pgfkeys@exp@call{#3}}% |
| 57 |
{\pgfkeys@exp@call{#4}}% |
| 58 |
}, |
| 59 |
.ext_ifnum/.code n args={3}{% |
| 60 |
\ifnum#1\relax |
| 61 |
\expandafter\pgfutil@firstoftwo |
| 62 |
\else |
| 63 |
\expandafter\pgfutil@secondoftwo |
| 64 |
\fi |
| 65 |
{\pgfkeys@exp@call{#2}}% |
| 66 |
{\pgfkeys@exp@call{#3}}% |
| 67 |
}, |
| 68 |
.ext_ifdim/.code n args={3}{% |
| 69 |
\ifdim#1\relax |
| 70 |
\expandafter\pgfutil@firstoftwo |
| 71 |
\else |
| 72 |
\expandafter\pgfutil@secondoftwo |
| 73 |
\fi |
| 74 |
{\pgfkeys@exp@call{#2}}% |
| 75 |
{\pgfkeys@exp@call{#3}}% |
| 76 |
}, |
| 77 |
.ext_ifx/.code n args={4}{% |
| 78 |
\ifx#1#2% |
| 79 |
\expandafter\pgfutil@firstoftwo |
| 80 |
\else |
| 81 |
\expandafter\pgfutil@secondoftwo |
| 82 |
\fi |
| 83 |
{\pgfkeys@exp@call{#3}}% |
| 84 |
{\pgfkeys@exp@call{#4}}% |
| 85 |
}, |
| 86 |
.ext_ifxempty/.code n args={3}{% |
| 87 |
\edef\pgfkeys@temp{#1}% |
| 88 |
\pgfutil@ifxempty\pgfkeys@temp{\pgfkeys@exp@call{#2}}{\pgfkeys@exp@call{#3}}% |
| 89 |
}, |
| 90 |
.ext_ifempty/.code n args={3}{% |
| 91 |
\pgfutil@ifempty{#1}{\pgfkeys@exp@call{#2}}{\pgfkeys@exp@call{#3}}% |
| 92 |
}, |
| 93 |
%% http://tex.stackexchange.com/a/144187/16595 |
| 94 |
%% key/.List={(point-1),(point-2),(point-...),(point-6)} will call |
| 95 |
%% key=(point-1)(point-2)(point-3)(point-4)(point-5)(point-6) |
| 96 |
.ext_List/.code=% |
| 97 |
\let\pgfkeys@global@temp\pgfutil@empty |
| 98 |
\foreach\pgfkeys@temp in{#1}{% |
| 99 |
\expandafter\pgfutil@g@addto@macro\expandafter\pgfkeys@global@temp\expandafter{\pgfkeys@temp}% |
| 100 |
}% |
| 101 |
\expandafter\pgfkeys@exp@call\expandafter{\pgfkeys@global@temp}, |
| 102 |
.ext_--/.code=% decrements a value (only TeX integers!) |
| 103 |
\pgfkeyssetevalue{\pgfkeyscurrentpath} |
| 104 |
{\the\numexpr\pgfkeysvalueof{\pgfkeyscurrentpath}-1\relax}, |
| 105 |
.ext_++/.code=% increments a value (only TeX integers!) |
| 106 |
\pgfkeyssetevalue{\pgfkeyscurrentpath} |
| 107 |
{\the\numexpr\pgfkeysvalueof{\pgfkeyscurrentpath}+1\relax}, |
| 108 |
.ext_value/.code=% copies the value of one key to another w/o expanding it |
| 109 |
\pgfkeysgetvalue{#1}\pgfkeys@temp |
| 110 |
\expandafter\pgfkeys@exp@call\expandafter{\pgfkeys@temp}% |
| 111 |
} |
| 112 |
|
| 113 |
\pgfqkeys{/utils/ext}{ |
| 114 |
.code=\pgfqkeys{/utils/ext}{#1}, |
| 115 |
pgfmath if/.code n args={3}{% |
| 116 |
\begingroup |
| 117 |
\pgfmathifthenelse{#1}{"1"}{"0"}% |
| 118 |
\expandafter\endgroup\expandafter |
| 119 |
\ifcase\pgfmathresult\relax |
| 120 |
\expandafter\pgfutil@firstoftwo |
| 121 |
\else |
| 122 |
\expandafter\pgfutil@secondoftwo |
| 123 |
\fi |
| 124 |
{\pgfkeysalso{#3}} |
| 125 |
{\pgfkeysalso{#2}}% |
| 126 |
}, |
| 127 |
if/.code n args={4}{% |
| 128 |
\if#1#2\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi |
| 129 |
{\pgfkeysalso{#3}}{\pgfkeysalso{#4}}% |
| 130 |
}, |
| 131 |
ifnum/.code n args={3}{% |
| 132 |
\ifnum#1\relax\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi |
| 133 |
{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}% |
| 134 |
}, |
| 135 |
ifdim/.code n args={3}{% |
| 136 |
\ifdim#1\relax\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi |
| 137 |
{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}% |
| 138 |
}, |
| 139 |
ifx/.code n args={4}{% |
| 140 |
\ifx#1#2\relax\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi |
| 141 |
{\pgfkeysalso{#3}}{\pgfkeysalso{#4}}% |
| 142 |
}, |
| 143 |
ifxempty/.code n args={3}{% |
| 144 |
\edef\pgfkeys@temp{#1}% |
| 145 |
\pgfutil@ifxempty\pgfkeys@temp{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}% |
| 146 |
}, |
| 147 |
ifempty/.code n args={3}{% |
| 148 |
\pgfutil@ifempty{#1}{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}% |
| 149 |
}, |
| 150 |
loops/do until/.code 2 args={\pgfutil@loop\pgfkeysalso{#1}#2\relax\pgfutil@repeat}% |
| 151 |
} |
| 152 |
|
| 153 |
%%% Compatibility |
| 154 |
\tikzextset{ |
| 155 |
/tikz-ext/compat/add library={pgfkeys-plus}{pre 0.6}, |
| 156 |
compat/pgfkeys-plus/warn/.append code={% |
| 157 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/if}{/utils/ext/pgfmath if}% |
| 158 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/TeX/if}{/utils/ext/if}% |
| 159 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/TeX/ifx}{/utils/ext/ifx}% |
| 160 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/TeX/ifnum}{/utils/ext/ifnum}% |
| 161 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/TeX/ifdim}{/utils/ext/ifdim}% |
| 162 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/TeX/ifempty}{/utils/ext/ifempty}% |
| 163 |
\tikzextutil@compatwarning@key{pgfkeys-plus}{pre 0.6}{/utils/TeX/ifxempty}{/utils/ext/ifxempty}% |
| 164 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.pgfmath}{.ext_pgfmath}% |
| 165 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.pgfmath int}{.ext_pgfmath int}% |
| 166 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.pgfmath wrap}{.ext_pgfmath wrap}% |
| 167 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.pgfmath if}{.ext_pgfmath if}% |
| 168 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.if}{.ext_if}% |
| 169 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.ifx}{.ext_ifx}% |
| 170 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.ifdim}{.ext_ifdim}% |
| 171 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.ifxempty}{.ext_ifxempty}% |
| 172 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.ifempty}{.ext_ifempty}% |
| 173 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.List}{.ext_List}% |
| 174 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.--}{.ext_--}% |
| 175 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.++}{.ext_++}% |
| 176 |
\tikzextutil@compatwarning@handler{pgfkeys-plus}{pre 0.6}{.value}{.ext_value}% |
| 177 |
}, |
| 178 |
compat/pgfkeys-plus/pre 0.6/.append code={% |
| 179 |
\pgfkeysdef{/utils/if}{\pgfkeysvalueof{/utils/ext/pgfmath if/.@cmd}##1\pgfeov}% |
| 180 |
\pgfkeysdef{/utils/TeX/if}{\pgfkeysvalueof{/utils/ext/if/.@cmd}##1\pgfeov}% |
| 181 |
\pgfkeysdef{/utils/TeX/ifx}{\pgfkeysvalueof{/utils/ext/ifx/.@cmd}##1\pgfeov}% |
| 182 |
\pgfkeysdef{/utils/TeX/ifnum}{\pgfkeysvalueof{/utils/ext/ifnum/.@cmd}##1\pgfeov}% |
| 183 |
\pgfkeysdef{/utils/TeX/ifdim}{\pgfkeysvalueof{/utils/ext/ifdim/.@cmd}##1\pgfeov}% |
| 184 |
\pgfkeysdef{/utils/TeX/ifempty}{\pgfkeysvalueof{/utils/ext/ifempty/.@cmd}##1\pgfeov}% |
| 185 |
\pgfkeysdef{/utils/TeX/ifxempty}{\pgfkeysvalueof{/utils/ext/ifxempty/.@cmd}##1\pgfeov}% |
| 186 |
\pgfkeysdef{/handlers/.pgfmath}{\pgfkeysvalueof{/handlers/.ext_pgfmath/.@cmd}##1\pgfeov}% |
| 187 |
\pgfkeysdef{/handlers/.pgfmath int}{\pgfkeysvalueof{/handlers/.ext_pgfmath int/.@cmd}##1\pgfeov}% |
| 188 |
\pgfkeysdef{/handlers/.pgfmath wrap}{\pgfkeysvalueof{/handlers/.ext_pgfmath wrap/.@cmd}##1\pgfeov}% |
| 189 |
\pgfkeysdef{/handlers/.pgfmath if}{\pgfkeysvalueof{/handlers/.ext_pgfmath if/.@cmd}##1\pgfeov}% |
| 190 |
\pgfkeysdef{/handlers/.if}{\pgfkeysvalueof{/handlers/.ext_if/.@cmd}##1\pgfeov}% |
| 191 |
\pgfkeysdef{/handlers/.ifx}{\pgfkeysvalueof{/handlers/.ext_ifx/.@cmd}##1\pgfeov}% |
| 192 |
\pgfkeysdef{/handlers/.ifdim}{\pgfkeysvalueof{/handlers/.ext_ifdim/.@cmd}##1\pgfeov}% |
| 193 |
\pgfkeysdef{/handlers/.ifxempty}{\pgfkeysvalueof{/handlers/.ext_ifxempty/.@cmd}##1\pgfeov}% |
| 194 |
\pgfkeysdef{/handlers/.ifempty}{\pgfkeysvalueof{/handlers/.ext_ifempty/.@cmd}##1\pgfeov}% |
| 195 |
\pgfkeysdef{/handlers/.List}{\pgfkeysvalueof{/handlers/.ext_List/.@cmd}##1\pgfeov}% |
| 196 |
\pgfkeysdef{/handlers/.--}{\pgfkeysvalueof{/handlers/.ext_--/.@cmd}##1\pgfeov}% |
| 197 |
\pgfkeysdef{/handlers/.++}{\pgfkeysvalueof{/handlers/.ext_++/.@cmd}##1\pgfeov}% |
| 198 |
\pgfkeysdef{/handlers/.value}{\pgfkeysvalueof{/handlers/.ext_value/.@cmd}##1\pgfeov}% |
| 199 |
}, |
| 200 |
compat/pgfkeys-plus/\pgfkeysvalueof{/tikz/ext/compat/pgfkeys-plus}% |
| 201 |
} |
| 202 |
\endinput |