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