Debian Codegraph @

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

raw
1 %%
2 %% This is file `binarytree.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% binarytree.dtx (with options: `package')
8 %%
9 %% This is a generated file.
10 %%
11 %% Copyright (C) 2016 by Aleksandrina Nikolova
12 %% <[email protected]@gmail.com>
13 %%
14 %% This work may be distributed and/or modified under the
15 %% conditions of the LaTeX Project Public License, either
16 %% version 1.3 of this license or (at your option) any later
17 %% version. The latest version of this license is in:
18 %%
19 %% http://www.latex-project.org/lppl.txt
20 %%
21 %% and version 1.3 or later is part of all distributions of
22 %% LaTeX version 2005/12/01 or later.
23 %%
24 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
25 \ProvidesPackage{binarytree}
26 [2016/07/25 v1.01 Binary trees using TikZ]
27 \RequirePackage{tikz}
28 \newdimen\BT@bbox@r@width
29 \newdimen\BT@bbox@l@width
30 \newdimen\BT@bbox@height
31 \newdimen\BT@bbox@depth
32 \newdimen\BT@bbox@current@x
33 \newdimen\BT@root@width
34 \newdimen\BT@root@height
35 \newdimen\BT@max@final@width
36 \newdimen\BT@max@final@height
37 \newdimen\BT@l@final@width
38 \newdimen\BT@l@final@height
39 \newdimen\BT@r@final@width
40 \newdimen\BT@r@final@height
41 \newdimen\BT@bbox@padding@top
42 \newdimen\BT@bbox@padding@bottom
43 \newdimen\BT@bbox@padding@left
44 \newdimen\BT@bbox@padding@right
45 \newdimen\BT@sibling@distance
46 \newdimen\BT@level@distance
47 \newdimen\BT@label@distance
48 \newif\ifBT@root@edge
49 \newif\ifBT@draw@missing
50 \newif\ifBT@label@every@edge
51 \newif\ifBT@math@labels
52 \newif\ifBT@continue@at@end
53 \newif\ifBT@continue@after@turn
54 \newif\ifBT@default@color@after@turn
55 \newif\ifBT@sibling@distance@scales
56 \newif\ifBT@level@distance@scales
57 \newif\ifBT@framed
58 \newif\ifBT@separate
59 \newif\ifBT@external
60 \newif\ifBT@auto@file@name
61 \def\BT@key@is@tikz@or@error#1#2{%
62 \tikzset{binary tree/.append code={%
63 \pgfkeys{/tikz/#1/.try=#2,%
64 /pgf/#1/.lastretry=#2}}}}
65 \def\BT@key@is@tikz@external@or@error#1#2{%
66 \tikzset{binary tree/externalize/.append code={%
67 \pgfkeys{/tikz/external/#1=#2}}}}
68 \pgfkeys{/BT/.cd,%
69 .unknown/.code={%
70 \expandafter\BT@key@is@tikz@or@error\expandafter{%
71 \pgfkeyscurrentname}{#1}},%
72 external/.unknown/.code={%
73 \expandafter\BT@key@is@tikz@external@or@error\expandafter{%
74 \pgfkeyscurrentname}{#1}}}
75 \def\@btreeset#1#2{%
76 \pgfkeyssavekeyfilterstateto{\BT@restore@pgf@key@filter}%
77 \pgfkeys{/pgf/key filters/not/.install key filter={%
78 /pgf/key filters/and={/pgf/key filters/active families}{%
79 /pgf/key filters/defined}},%
80 /BT/local option outside of scope/.install key filter handler}%
81 \pgfqkeysactivatesinglefamilyandfilteroptions{/BT/local options}{#1}{#2}%
82 \BT@restore@pgf@key@filter}
83 \def\btreeset{\@btreeset{/BT}}
84 \def\btreesetexternal{\@btreeset{/BT/external}}
85 \pgfkeys{/BT/.cd,%
86 local options/.is family,%
87 local option outside of scope/.code={%
88 \PackageError{binarytree}{'\pgfkeyscurrentkey' only allowed %
89 locally\MessageBreak for each \string\BinaryTree}{}}}
90 \def\BT@set@max@l@or@r@bbox@size#1{%
91 \BT@bbox@current@x=\z@\relax%
92 \@tempcnta=\BT@root@depth\relax%
93 \loop%
94 \ifnum\@tempcnta < \numexpr\BT@max@depth\relax%
95 \advance\@tempcnta\@ne\relax%
96 \BT@check@if@new@level\@tempcnta%
97 \csname BT@#1@xshift\endcsname\@tempcnta%
98 \csname BT@update@bbox@#1@width\endcsname%
99 \repeat}%
100 \def\BT@bbox@scale@labels{%
101 \pgfmathparse{\BT@root@height / \BT@yscale}%
102 \BT@root@height\pgfmathresult pt\relax%
103 \pgfmathparse{\BT@root@width / \BT@xscale}%
104 \BT@root@width\pgfmathresult pt\relax%
105 \pgfmathparse{\BT@max@final@height / \BT@yscale}%
106 \BT@max@final@height\pgfmathresult pt\relax%
107 \pgfmathparse{\BT@max@final@width / \BT@xscale}%
108 \BT@max@final@width\pgfmathresult pt\relax%
109 \pgfmathparse{\BT@l@final@width / \BT@xscale}%
110 \BT@l@final@width\pgfmathresult pt\relax%
111 \pgfmathparse{\BT@r@final@width / \BT@xscale}%
112 \BT@r@final@width\pgfmathresult pt\relax}%
113 \def\BT@bbox@scale@padding{%
114 \pgfmathparse{\BT@bbox@padding@top / \BT@yscale}%
115 \BT@bbox@padding@top\pgfmathresult pt\relax%
116 \pgfmathparse{\BT@bbox@padding@bottom / \BT@yscale}%
117 \BT@bbox@padding@bottom\pgfmathresult pt\relax%
118 \pgfmathparse{\BT@bbox@padding@left / \BT@yscale}%
119 \BT@bbox@padding@left\pgfmathresult pt\relax%
120 \pgfmathparse{\BT@bbox@padding@right / \BT@yscale}%
121 \BT@bbox@padding@right\pgfmathresult pt\relax}
122 \def\BT@bbox@add@labels{%
123 \BT@bbox@scale@labels%
124 \pgfmathparse{\BT@label@distance / \BT@yscale}%
125 \ifdim\BT@root@height > \z@\relax%
126 \advance\BT@bbox@depth\dimexpr\BT@root@height%
127 + \pgfmathresult pt\relax\fi%
128 \ifdim\BT@max@final@height > \z@\relax%
129 \advance\BT@bbox@height\dimexpr\BT@max@final@height%
130 + \pgfmathresult pt\relax\fi%
131 \advance\BT@bbox@l@width\dimexpr\BT@l@final@width / 2\relax%
132 \advance\BT@bbox@r@width\dimexpr\BT@r@final@width / 2\relax%
133 \BT@set@dim@to@greater\BT@bbox@l@width{\BT@root@width / 2}%
134 \BT@set@dim@to@greater\BT@bbox@r@width{\BT@root@width / 2}}
135 \def\BT@bbox@add@padding{%
136 \BT@bbox@scale@padding%
137 \advance\BT@bbox@height\dimexpr\BT@bbox@padding@top\relax%
138 \advance\BT@bbox@depth\dimexpr\BT@bbox@padding@bottom\relax%
139 \advance\BT@bbox@l@width\dimexpr\BT@bbox@padding@left\relax%
140 \advance\BT@bbox@r@width\dimexpr\BT@bbox@padding@right\relax}
141 \pgfkeys{/BT/.cd,%
142 grow/.is choice,%
143 grow/up/.code={\def\BT@adjust@bbox@sides{%
144 \BT@bbox@add@labels%
145 \BT@bbox@add@padding}%
146 \def\BT@grow@direction{up}%
147 \pgfkeys{/BT/.cd,%
148 /tikz/binary tree/.append style={grow=up},
149 root label anchor=below,
150 left label anchor=north east,
151 right label anchor=north west,
152 final label anchor=above}},%
153 grow/down/.code={\def\BT@adjust@bbox@sides{%
154 \BT@bbox@add@labels
155 \BT@swap@dims\BT@bbox@depth\BT@bbox@height%
156 \BT@bbox@add@padding}%
157 \def\BT@grow@direction{down}%
158 \pgfkeys{/BT/.cd,%
159 /tikz/binary tree/.append style={grow'=down},
160 root label anchor=above,
161 left label anchor=south east,
162 right label anchor=south west,
163 final label anchor=below}},%
164 grow/left/.code={\def\BT@adjust@bbox@sides{%
165 \BT@swap@hooks\BT@xscale\BT@yscale%
166 \BT@swap@dims\BT@root@width\BT@root@height%
167 \BT@swap@dims\BT@max@final@width\BT@max@final@height%
168 \BT@swap@dims\BT@l@final@width\BT@l@final@height%
169 \BT@swap@dims\BT@r@final@width\BT@r@final@height%
170 \BT@bbox@add@labels%
171 \@tempdima\BT@bbox@depth\relax%
172 \BT@bbox@depth\BT@bbox@l@width\relax%
173 \BT@bbox@l@width\BT@bbox@height\relax%
174 \BT@bbox@height\BT@bbox@r@width\relax%
175 \BT@bbox@r@width\@tempdima\relax%
176 \BT@bbox@add@padding}%
177 \def\BT@grow@direction{left}%
178 \pgfkeys{/BT/.cd,%
179 /tikz/binary tree/.append style={grow=left},
180 root label anchor=right,
181 left label anchor=north west,
182 right label anchor=south west,
183 final label anchor=left}},%
184 grow/right/.code={\def\BT@adjust@bbox@sides{%
185 \BT@swap@hooks\BT@xscale\BT@yscale%
186 \BT@swap@dims\BT@root@width\BT@root@height%
187 \BT@swap@dims\BT@max@final@width\BT@max@final@height%
188 \BT@swap@dims\BT@l@final@width\BT@l@final@height%
189 \BT@swap@dims\BT@r@final@width\BT@r@final@height%
190 \BT@bbox@add@labels%
191 \BT@swap@dims\BT@bbox@depth\BT@bbox@l@width%
192 \BT@swap@dims\BT@bbox@height\BT@bbox@r@width%
193 \BT@bbox@add@padding}%
194 \def\BT@grow@direction{right}%
195 \pgfkeys{/BT/.cd,%
196 /tikz/binary tree/.append style={grow'=right},
197 root label anchor=left,
198 left label anchor=north east,
199 right label anchor=south east,
200 final label anchor=right}},%
201 root label anchor/.initial=,%
202 left label anchor/.initial=,%
203 right label anchor/.initial=,%
204 final label anchor/.initial=,%
205 root edge/.is if={BT@root@edge},%
206 root edge/.append code={%
207 \ifBT@root@edge%
208 \def\BT@effective@level##1{%
209 \ifnum\numexpr##1\relax < \numexpr 3\relax\expandafter\@firstoftwo%
210 \else\expandafter\@secondoftwo\fi{1}{(##1-1)}}%
211 \else\def\BT@effective@level##1{##1}\fi},%
212 draw missing/.is if={BT@draw@missing},%
213 draw missing/.append code={%
214 \ifBT@draw@missing%
215 \def\BT@set@min@bbox@size{\BT@set@max@l@or@r@bbox@size{l}%
216 \BT@set@max@l@or@r@bbox@size{r}%
217 \let\BT@l@xshift\@gobble%
218 \let\BT@r@xshift\@gobble%
219 \let\BT@update@bbox@l@width\relax%
220 \let\BT@update@bbox@r@width\relax}%
221 \tikzset{binary tree/default/.style={binary tree/empty={BT@default}}}%
222 \else\let\BT@set@min@bbox@size\relax%
223 \tikzset{binary tree/default/.style={missing}}\fi},%
224 label on every edge/.is if={BT@label@every@edge},%
225 math labels/.is if={BT@math@labels},%
226 math labels/.append code={%
227 \ifBT@math@labels\def\BT@wrap@label##1{\(##1\)}%
228 \else\def\BT@wrap@label##1{##1}\fi},%
229 continue at path end/.is if={BT@continue@at@end},%
230 continue after turn/.is if={BT@continue@after@turn},%
231 default color/.code={\colorlet{BT@default}{#1}},%
232 default color/.value required,%
233 default color after turn/.is if={BT@default@color@after@turn},%
234 xscale/.store in=\BT@xscale,%
235 xscale/.append style={/tikz/binary tree/.append style={xscale=#1}},%
236 xscale/.value required,%
237 yscale/.store in=\BT@yscale,%
238 yscale/.append style={/tikz/binary tree/.append style={yscale=#1}},%
239 yscale/.value required,%
240 scale/.forward to=/BT/xscale,%
241 scale/.forward to=/BT/yscale,%
242 label distance/.code={\BT@label@distance=\dimexpr#1\relax},%
243 label distance/.value required,%
244 sibling distance/.code={\BT@sibling@distance=\dimexpr#1\relax},%
245 sibling distance/.value required,%
246 level distance/.code={\BT@level@distance=\dimexpr#1\relax},%
247 level distance/.value required,%
248 sibling distance scales/.is if={BT@sibling@distance@scales},%
249 sibling distance scales/.append code={%
250 \ifBT@sibling@distance@scales%
251 \def\BT@current@sibling@distance##1{%
252 \BT@sibling@distance/(\BT@effective@level{##1})}%
253 \else\def\BT@current@sibling@distance##1{\BT@sibling@distance}\fi},%
254 level distance scales/.is if={BT@level@distance@scales},%
255 level distance scales/.append code={%
256 \ifBT@level@distance@scales%
257 \def\BT@current@level@distance##1{%
258 \BT@level@distance/(\BT@effective@level{##1})}%
259 \else\def\BT@current@level@distance##1{\BT@level@distance}\fi},%
260 top padding/.code={\BT@bbox@padding@top=#1\relax},%
261 top padding/.value required,%
262 bottom padding/.code={\BT@bbox@padding@bottom=#1\relax},%
263 bottom padding/.value required,%
264 left padding/.code={\BT@bbox@padding@left=#1\relax},%
265 left padding/.value required,%
266 right padding/.code={\BT@bbox@padding@right=#1\relax},%
267 right padding/.value required,%
268 framed/.is if={BT@framed},%
269 defaults/.style={/BT/.cd,%
270 default color=black,%
271 default color after turn=true,%
272 grow=up,%
273 root edge=false,%
274 draw missing=false,
275 label on every edge=false,%
276 math labels=false,%
277 continue at path end=true,%
278 continue after turn=true,%
279 scale=1,%
280 sibling distance=40mm,%
281 level distance=20mm,%
282 sibling distance scales=true,%
283 level distance scales=true,%
284 label distance=10pt,%
285 top padding=3pt,%
286 bottom padding=3pt,%
287 left padding=3pt,%
288 right padding=3pt,%
289 framed=false},%
290 defaults/.value forbidden,%
291 separate/.is if={BT@separate},%
292 separate/.append code={%
293 \ifBT@separate\else\pgfkeys{/BT/external=false}\fi},%
294 external/.is if={BT@external},%
295 external/.append code={%
296 \ifBT@external\pgfkeys{/BT/separate=true}\fi}}
297 \pgfkeys{/BT/external/.cd,%
298 use automatic file name/.is if={BT@auto@file@name},%
299 file name/.style={/tikz/binary tree/externalize/.append code={%
300 \tikzsetnextfilename{#1}}},%
301 file name/.belongs to family=/BT/local options,%
302 file name/.value required}
303 \tikzset{binary tree/.style={%
304 level/.style={level distance=\BT@current@level@distance{##1},%
305 sibling distance=\BT@current@sibling@distance{##1}},%
306 parent anchor=center,child anchor=center,%
307 label distance=\BT@label@distance,every node/.style={outer sep=0pt,%
308 inner sep=0pt}},%
309 binary tree/externalize/.code={%
310 \tikzexternalenable\tikzsetfigurename{binary-tree_}}}
311 \pgfqkeys{/BT}{%
312 defaults,%
313 separate=false,%
314 external=false,%
315 external/use automatic file name=false}
316 \def\BT@edge@label#1#2#3#4#5{%
317 [style=edge from parent, color=#3]%
318 (\tikzparentnode\tikzparentanchor) --%
319 node[anchor=#2,inner sep=\BT@label@distance/2] {#1}%
320 (\tikzchildnode\tikzchildanchor)}
321 \def\BT@edge@no@label#1#2#3{%
322 [style=edge from parent, color=#1]%
323 (\tikzparentnode\tikzparentanchor) --%
324 (\tikzchildnode\tikzchildanchor)}
325 \tikzset{binary tree/.cd,%
326 root/.style n args={3}{%
327 label={[text=#3]#2:#1},binary tree/empty={#3}},%
328 root/.value required,%
329 child/.style n args={3}{%
330 edge from parent macro=\BT@edge@label{#1}{#2}{#3},%
331 every child node/.style={}},%
332 child/.value required,%
333 final child/.style n args={3}{%
334 edge from parent macro=\BT@edge@no@label{#3},%
335 every child node/.style={label={[text=#3]#2:#1}}},%
336 final child/.value required,%
337 empty/.style={%
338 edge from parent macro=\BT@edge@no@label{#1},%
339 every child node/.style={}},%
340 empty/.value required}
341 \def\BT@message#1{\pgfinterruptpicture #1\par\endpgfinterruptpicture}
342 \def\BT@message#1{}
343 \def\BT@gobble@till@nil#1\@nil{}
344 \def\BT@endgroup@let#1#2{%
345 \expandafter\endgroup\expandafter\def\expandafter#1\expandafter{#2}}
346 \def\BT@app@to@hook#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
347 \def\BT@eapp@to@hook#1#2{\edef#1{\unexpanded\expandafter{#1}#2}}
348 \def\BT@if#1{\csname if#1\endcsname\expandafter\@firstoftwo%
349 \else\expandafter\@secondoftwo\fi}
350 \def\BT@if@blank#1{\BT@if@blank@i#1\@nil}
351 \def\BT@if@blank@i#1{\ifx\@nil#1\expandafter\@firstoftwo%
352 \else\expandafter\expandafter\expandafter\@secondoftwo\expandafter%
353 \BT@gobble@till@nil\fi}
354 \def\BT@strip@prefix#1#2{%
355 \begingroup%
356 \def\@@suffix#1##1\@nil{##1}%
357 \edef#2{\unexpanded\expandafter\expandafter\expandafter{%
358 \expandafter\@@suffix#2\@nil}}%
359 \BT@endgroup@let#2#2}
360 \def\BT@set@to@dim#1#2#3{%
361 \begingroup%
362 \setbox0\hbox{#3}%
363 \expandafter\endgroup\expandafter#2\the#10\relax}
364 \def\BT@set@to@width{\BT@set@to@dim\wd}
365 \def\BT@set@to@height{\BT@set@to@dim\ht}
366 \def\BT@set@to@depth{\BT@set@to@dim\dp}
367 \def\BT@set@to@total@height#1#2{%
368 \BT@set@to@height#1{#2}%
369 \begingroup%
370 \BT@set@to@depth#1{#2}%
371 \expandafter\endgroup\expandafter\advance\expandafter#1\the#1\relax}
372 \def\BT@swap@hooks#1#2{%
373 \expandafter\let\expandafter#1\expandafter#2%
374 \expandafter\def\expandafter#2\expandafter{#1}}
375 \def\BT@swap@dims#1#2{%
376 \expandafter#1\expandafter\the#2\expandafter\relax%
377 \expandafter#2\the#1\relax}
378 \def\BT@set@dim@to@greater#1#2{%
379 #1\dimexpr\ifdim\dimexpr#1\relax < \dimexpr#2\relax#2\else#1\fi\relax}
380 \def\BT@set@dim@to@smaller#1#2{%
381 #1\dimexpr\ifdim\dimexpr#1\relax < \dimexpr#2\relax#1\else#2\fi\relax}
382 \def\BT@extract@rgb@color@specs#1#2{%
383 \begingroup%
384 \extractcolorspecs{#1}{\tmp@mod}{\tmp@col}%
385 \convertcolorspec{\tmp@mod}{\tmp@col}{rgb}{\tmp@col}%
386 \BT@endgroup@let#2\tmp@col}
387 \def\BT@at@to@dash#1{\BT@at@to@dash@i#1\@nil}
388 \def\BT@at@to@dash@i @#1{\ifx\@nil#1\else-#1\expandafter\BT@at@to@dash@i\fi}
389 \def\BT@anchor@or@default#1#2{%
390 \BT@if@blank{#1}{\pgfkeysvalueof{/BT/#2 label anchor}}{#1}}
391 \def\BT@color@or@default#1{\BT@if@blank{#1}{BT@default}{#1}}
392 \def\BT@if@child@is@outer#1{\BT@if@child@is@outer@i#1\@nil}
393 \def\BT@if@child@is@outer@i @#1@#2{%
394 \ifx#1#2\expandafter\BT@if@child@is@outer@i\expandafter @\expandafter#2%
395 \else\expandafter\BT@if@child@is@outer@ii\expandafter#2\fi}
396 \def\BT@if@child@is@outer@ii#1{%
397 \ifx\@nil#1\expandafter\@firstoftwo%
398 \else\expandafter\expandafter\expandafter\@secondoftwo%
399 \expandafter\BT@gobble@till@nil\fi}
400 \def\BT@check@if@new@level#1{%
401 \ifcsname level \the\numexpr#1\relax exists\endcsname\else%
402 \BT@new@level{#1}%
403 \csname level \the\numexpr#1\relax exists\expandafter\endcsname\fi}
404 \def\BT@new@level#1{%
405 \BT@message{adding new level: \the\numexpr#1\relax}%
406 \pgfmathparse{\BT@current@level@distance{#1}}%
407 \advance\BT@bbox@height\pgfmathresult pt\relax%
408 \BT@message{added \pgfmathresult pt to bounding box height}}
409 \def\BT@l@xshift{\BT@xshift-}
410 \def\BT@r@xshift{\BT@xshift+}
411 \def\BT@xshift#1#2{%
412 \pgfmathparse{\BT@current@sibling@distance{#2} / 2}%
413 \advance\BT@bbox@current@x #1\pgfmathresult pt\relax%
414 \BT@message{current x coordinate is \the\BT@bbox@current@x}}
415 \def\BT@update@bbox@l@width{%
416 \@tempdima=-\BT@bbox@current@x\relax%
417 \BT@set@dim@to@greater\BT@bbox@l@width\@tempdima}
418 \def\BT@update@bbox@r@width{%
419 \BT@set@dim@to@greater\BT@bbox@r@width\BT@bbox@current@x}
420 \def\BT@save@final@child@size#1#2#3{%
421 \BT@set@to@width\@tempdima{%
422 \pgfinterruptpicture#3\endpgfinterruptpicture}%
423 \BT@set@to@total@height\@tempdimb{%
424 \pgfinterruptpicture#3\endpgfinterruptpicture}%
425 \BT@set@dim@to@greater\BT@max@final@width\@tempdima%
426 \BT@set@dim@to@greater\BT@max@final@height\@tempdimb%
427 \BT@if@child@is@outer{#2}{%
428 \csname BT@#1@final@width\endcsname\@tempdima\relax%
429 \csname BT@#1@final@height\endcsname\@tempdimb\relax}{}}
430 \def\BT@process@next@path#1,{%
431 \ifx\@nil#1\relax\expandafter\@firstoftwo%
432 \else\expandafter\@secondoftwo\fi{}{%
433 \BT@file@name@new@path%
434 \BT@bbox@current@x=\z@\relax%
435 \def\BT@current@child{@}%
436 \def\BT@current@side{}%
437 \def\BT@current@level{\BT@root@depth}%
438 \BT@if@blank{#1}{}{\BT@process@next@subpath#1!\@nil!}%
439 \BT@process@next@path}}
440 \def\BT@process@next@subpath#1!{%
441 \ifx\@nil#1\relax\expandafter\@firstoftwo%
442 \else\expandafter\@secondoftwo\fi{%
443 \BT@if{BT@continue@at@end}{%
444 \BT@message{continuing last path, starting at \BT@current@child}%
445 \BT@set@subpath@style c::::\@nil}{}}{%
446 \BT@if@blank{#1}{}{%
447 \BT@set@subpath@style#1::::\@nil}%
448 \BT@process@next@subpath}}
449 \def\BT@set@subpath@style#1:#2:#3:#4:#5\@nil{%
450 \BT@message{setting style (#2, #3, #4) for subpath #1,
451 starting at \BT@current@child}%
452 \BT@file@name@append@style{#1}{#2}{#3}{#4}%
453 \edef\tmp@hook{\noexpand\BT@set@next@style{\BT@current@child}{%
454 \BT@current@level}\unexpanded{{#2}}{#3}{#4}{\BT@current@side}%
455 \BT@if@blank{#1}{{}}{#1}s}%
456 \tmp@hook\@nil}%
457 \def\BT@set@next@style#1#2#3#4#5#6#7{%
458 \BT@message{previous: #1, went: #6, going #7, depth:
459 \the\numexpr#2\relax/\BT@max@depth}%
460 \ifnum\numexpr#2\relax = \numexpr\BT@max@depth\relax%
461 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
462 {\BT@terminate@path@style{#1}{#2}{#6}}%
463 {\ifcsname BT@go@#6@#7\endcsname%
464 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
465 {\csname BT@go@#6@#7\endcsname{#1}{#2}{#3}{#4}{#5}}%
466 {\PackageError{binarytree}{Invalid path: only l, r, c or s allowed}{}}}}
467 \def\BT@terminate@path@style#1#2#3{%
468 \edef\BT@current@child{#1}%
469 \edef\BT@current@level{\the\numexpr#2\relax}%
470 \def\BT@current@side{#3}%
471 \BT@gobble@till@nil}
472 \def\BT@go@@c{%
473 \BT@terminate@path@style{@}{\BT@root@depth}{}}
474 \def\BT@go@l@c{\BT@continue{l}}
475 \def\BT@go@r@c{\BT@continue{r}}
476 \let\BT@go@@s\BT@go@@c
477 \def\BT@go@l@s#1#2{\BT@terminate@path@style{#1}{#2}{l}}
478 \def\BT@go@r@s#1#2{\BT@terminate@path@style{#1}{#2}{r}}
479 \def\BT@go@@#1#2#3#4#5{%
480 \BT@set@root@style{#3}{#4}{#5}%
481 \BT@if{BT@label@every@edge}{%
482 \BT@set@next@style{@}{\BT@root@depth}{#3}{#4}{#5}{}}{%
483 \BT@set@next@style{@}{\BT@root@depth}{}{#4}{}{}}}
484 \def\BT@go@@l{\BT@go@l@or@r{l}}
485 \def\BT@go@@r{\BT@go@l@or@r{r}}
486 \let\BT@go@l@l\BT@go@@l
487 \let\BT@go@r@r\BT@go@@r
488 \def\BT@go@l@{\BT@stay@here{l}}
489 \def\BT@go@r@{\BT@stay@here{r}}
490 \def\BT@go@r@l{\BT@turn{r}{l}}
491 \def\BT@go@l@r{\BT@turn{l}{r}}
492 \def\BT@continue#1#2#3#4#5#6{%
493 \BT@if{BT@label@every@edge}{%
494 \BT@set@next@style{#2}{#3}{#4}{#5}{#6}#1#1c}{%
495 \BT@set@next@style{#2}{#3}{}{#5}{}#1#1c}}
496 \def\BT@turn#1#2#3#4#5#6#7{%
497 \BT@if{BT@continue@after@turn}{%
498 \@tempdimb=\BT@bbox@current@x\relax%
499 \BT@if{BT@default@color@after@turn}{%
500 \BT@set@next@style{#3}{#4}{}{}{#7}#1c\@nil}{%
501 \BT@set@next@style{#3}{#4}{}{#6}{#7}#1c\@nil}%
502 \BT@bbox@current@x=\@tempdimb\relax}{}%
503 \BT@go@l@or@r{#2}{#3}{#4}{#5}{#6}{#7}}
504 \def\BT@stay@here#1#2#3#4#5#6{%
505 \BT@set@child@style{#1}{#2}{#3}{#4}{#5}{#6}%
506 \BT@if{BT@label@every@edge}{%
507 \BT@set@next@style{#2}{#3}{#4}{#5}{#6}#1}{%
508 \BT@set@next@style{#2}{#3}{}{#5}{}#1}}
509 \def\BT@go@l@or@r#1#2#3#4#5#6{%
510 \BT@set@child@style{#1}{#2#1@}{#3+1}{#4}{#5}{#6}%
511 \BT@if{BT@label@every@edge}{%
512 \BT@set@next@style{#2#1@}{#3+1}{#4}{#5}{#6}#1}{%
513 \BT@set@next@style{#2#1@}{#3+1}{}{#5}{}#1}}
514 \def\BT@set@root@style#1#2#3{%
515 \BT@set@to@width\BT@root@width{\pgfinterruptpicture%
516 \BT@wrap@label{#1}\endpgfinterruptpicture}%
517 \BT@set@to@total@height\BT@root@height{\pgfinterruptpicture%
518 \BT@wrap@label{#1}\endpgfinterruptpicture}%
519 \BT@set@root@style@i{@}{\BT@wrap@label{#1}}{\BT@color@or@default{#2}}{#3}}
520 \def\BT@set@child@style#1#2#3#4#5#6{%
521 \BT@check@if@new@level{#3}%
522 \csname BT@#1@xshift\endcsname{#3}%
523 \csname BT@update@bbox@#1@width\endcsname%
524 \BT@if@blank{#4}{\BT@if@blank{#5}{%
525 \BT@set@default@if@missing{#2}}{%
526 \BT@set@empty@style{#2}{\BT@color@or@default{#5}}}}{%
527 \ifnum\numexpr#3\relax = \numexpr\BT@max@depth\relax%
528 \BT@set@final@style{#1}{#2}{#3}{#4}{#5}{#6}%
529 \else\BT@set@inter@style{#1}{#2}{#3}{#4}{#5}{#6}\fi}}
530 \def\BT@set@inter@style#1#2#3#4#5#6{%
531 \csname BT@set@inter@style@#1\endcsname{#2}{%
532 \BT@wrap@label{#4}}{\BT@color@or@default{#5}}{#6}}
533 \def\BT@set@final@style#1#2#3#4#5#6{%
534 \BT@save@final@child@size{#1}{#2}{\BT@wrap@label{#4}}%
535 \BT@set@final@style@i{#2}{%
536 \BT@wrap@label{#4}}{\BT@color@or@default{#5}}{#6}}
537 \def\BT@set@root@style@i#1#2#3#4{%
538 \BT@message{setting style (#2, #3,
539 \BT@anchor@or@default{#4}{root}) for root}%
540 \ifcsname#1 styled\endcsname\else\csname#1 styled\expandafter\endcsname\fi%
541 \tikzset{binary tree/#1/.style={binary tree/root={#2}{%
542 \BT@anchor@or@default{#4}{root}}{#3}}}}
543 \def\BT@set@inter@style@l#1#2#3#4{%
544 \BT@message{setting style (#2, #3,
545 \BT@anchor@or@default{#4}{left}) for left child #1}%
546 \ifcsname#1 styled\endcsname\else\csname#1 styled\expandafter\endcsname\fi%
547 \tikzset{binary tree/#1/.style={binary tree/child={#2}{%
548 \BT@anchor@or@default{#4}{left}}{#3}}}}
549 \def\BT@set@inter@style@r#1#2#3#4{%
550 \BT@message{setting style (#2, #3,
551 \BT@anchor@or@default{#4}{right}) for right child #1}%
552 \ifcsname#1 styled\endcsname\else\csname#1 styled\expandafter\endcsname\fi%
553 \tikzset{binary tree/#1/.style={binary tree/child={#2}{%
554 \BT@anchor@or@default{#4}{right}}{#3}}}}
555 \def\BT@set@final@style@i#1#2#3#4{%
556 \BT@message{setting style (#2, #3,
557 \BT@anchor@or@default{#4}{final}) for final child #1}%
558 \ifcsname#1 styled\endcsname\else\csname#1 styled\expandafter\endcsname\fi%
559 \tikzset{binary tree/#1/.style={binary tree/final child={#2}{%
560 \BT@anchor@or@default{#4}{final}}{#3}}}}
561 \def\BT@set@empty@style#1#2{%
562 \BT@message{setting empty style (#2) for child #1}%
563 \ifcsname#1 styled\endcsname\else\csname#1 styled\expandafter\endcsname\fi%
564 \tikzset{binary tree/#1/.style={binary tree/empty={#2}}}}
565 \def\BT@set@default@if@missing#1{%
566 \BT@message{setting default style for child #1}%
567 \ifcsname#1 styled\endcsname\else%
568 \tikzset{binary tree/#1/.style={binary tree/empty={BT@default}}}%
569 \csname#1 styled\expandafter\endcsname\fi}
570 \def\BT@file@name@init{%
571 \BT@extract@rgb@color@specs{BT@default}{\@@tmp}%
572 \edef\BT@file@name{%
573 btree-\the\numexpr\BT@max@depth\relax% prefix and depth
574 _\BT@grow@direction% grow direction
575 \ifBT@root@edge _edge\fi% root edge?
576 _\@@tmp% default color
577 _\number\BT@level@distance% level distance in sp
578 \ifBT@level@distance@scales%
579 -scaled\fi% level distance scales
580 _\number\BT@sibling@distance% sibling distance in sp
581 \ifBT@sibling@distance@scales%
582 -scaled\fi% sibling distance scales
583 _\number\BT@label@distance% label distance in sp
584 _\BT@xscale% x-scale
585 _\BT@yscale}}% y-scale
586 \def\BT@file@name@new@path{\BT@eapp@to@hook\BT@file@name{_}}
587 \def\BT@file@name@append@style#1#2#3#4{%
588 \BT@if@blank{#3}{\def\@@tmp{}}{%
589 \BT@extract@rgb@color@specs{#3}{\@@tmp}}%
590 \BT@eapp@to@hook\BT@file@name{%
591 -#1% subpath
592 -\BT@if@blank{#2}{}{% label
593 \ifBT@math@labels MATH\else#2\fi}%
594 -#4% anchor
595 -\@@tmp}}% color
596 \def\BT@file@name@set{%
597 \ifBT@auto@file@name%
598 \if\relax\detokenize\expandafter{\tikzexternal@nextfile}\relax%
599 \expandafter\tikzsetnextfilename\expandafter{\BT@file@name}\fi\fi}
600 \def\BT@draw@tree@children#1#2{%
601 \ifnum\numexpr#2\relax = \numexpr\BT@max@depth\relax\else%
602 child[\ifcsname#1r@ styled\endcsname binary tree/#1r@\else%
603 binary tree/default\fi] {node (btree\BT@at@to@dash{#1r@}) {}% right
604 \BT@draw@tree@children{#1r@}{#2+1} }%
605 child[\ifcsname#1l@ styled\endcsname binary tree/#1l@\else%
606 binary tree/default\fi] {node (btree\BT@at@to@dash{#1l@}) {}% left
607 \BT@draw@tree@children{#1l@}{#2+1} }\fi}
608 \def\BT@draw@tree{%
609 \ifBT@root@edge%
610 \advance\BT@bbox@height\BT@level@distance\relax%
611 \BT@adjust@bbox@sides%
612 \edef\BT@tree{%
613 \noexpand\node[\ifcsname @ styled\endcsname binary tree/@\fi] (btree-root) {}%
614 child[\ifcsname @ styled\endcsname binary tree/@\fi] {%
615 node {} \BT@draw@tree@children{@}{\BT@root@depth}}}%
616 \clip (-\BT@bbox@l@width,-\BT@bbox@depth)%
617 rectangle (\BT@bbox@r@width,\BT@bbox@height);%
618 \ifBT@framed\draw (current bounding box.south west)%
619 rectangle (current bounding box.north east);\fi%
620 \BT@tree;%
621 \else\BT@adjust@bbox@sides%
622 \edef\BT@tree{%
623 \noexpand\node[\ifcsname @ styled\endcsname binary tree/@\fi] (btree-root) {}%
624 \BT@draw@tree@children{@}{\BT@root@depth}}%
625 \clip (-\BT@bbox@l@width,-\BT@bbox@depth)%
626 rectangle (\BT@bbox@r@width,\BT@bbox@height);%
627 \ifBT@framed\draw (current bounding box.south west)%
628 rectangle (current bounding box.north east);\fi%
629 \BT@tree;%
630 \fi}
631 \def\BinaryTree{\@ifnextchar[\@BinaryTree{\@BinaryTree[]}}
632 \def\@BinaryTree[#1]#2#3{%
633 \begingroup%
634 \BT@bbox@r@width=\z@\relax%
635 \BT@bbox@l@width=\z@\relax%
636 \BT@bbox@height=\z@\relax%
637 \BT@bbox@depth=\z@\relax%
638 \BT@root@width=\z@\relax%
639 \BT@root@height=\z@\relax%
640 \BT@max@final@width=\z@\relax%
641 \BT@max@final@height=\z@\relax%
642 \BT@l@final@width=\z@\relax%
643 \BT@l@final@height=\z@\relax%
644 \BT@r@final@width=\z@\relax%
645 \BT@r@final@height=\z@\relax%
646 \pgfqkeys{/BT}{#1}%
647 \ifBT@root@edge\def\BT@max@depth{#3+1}\def\BT@root@depth{1}%
648 \else\def\BT@max@depth{#3}\def\BT@root@depth{0}\fi%
649 \BT@set@min@bbox@size%
650 \BT@file@name@init%
651 \BT@process@next@path#2,\@nil,%
652 \ifBT@separate\ifBT@external%
653 \tikzset{binary tree/externalize}\BT@file@name@set\fi%
654 \begin{tikzpicture}[binary tree]%
655 \BT@draw@tree%
656 \end{tikzpicture}%
657 \else\begin{scope}[binary tree]%
658 \BT@draw@tree%
659 \end{scope}\fi%
660 \endgroup}
661 \endinput
662 %%
663 %% End of file `binarytree.sty'.