summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/binarytree
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-07-30 23:12:58 +0000
committerKarl Berry <karl@freefriends.org>2016-07-30 23:12:58 +0000
commitad752eab7e8fbad49b6fbe4a023c71f97b8a9fa1 (patch)
treeff97d7f86c09fa924b189b1f51c67af324bbbac5 /Master/texmf-dist/source/latex/binarytree
parent6b200dd5c2335baa8c78037d8f1c75d1295187f4 (diff)
binarytree (26jul16)
git-svn-id: svn://tug.org/texlive/trunk@41777 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/binarytree')
-rw-r--r--Master/texmf-dist/source/latex/binarytree/binarytree.dtx29
1 files changed, 21 insertions, 8 deletions
diff --git a/Master/texmf-dist/source/latex/binarytree/binarytree.dtx b/Master/texmf-dist/source/latex/binarytree/binarytree.dtx
index abb161c5c35..dd2408b3453 100644
--- a/Master/texmf-dist/source/latex/binarytree/binarytree.dtx
+++ b/Master/texmf-dist/source/latex/binarytree/binarytree.dtx
@@ -20,7 +20,7 @@
%<*package>
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{binarytree}
- [2016/07/01 v1.0 Binary trees using TikZ]
+ [2016/07/25 v1.01 Binary trees using TikZ]
\RequirePackage{tikz}
%</package>
%<*driver>
@@ -234,6 +234,8 @@
% \section{Introduction}
% The \BT package provides a macro, |\BinaryTree|, which accepts a path specification and a number signifying the maximum tree depth. The path specification determines the style for each edge of the tree. The behaviour can be customized by calling |\btreeset| or |\btreesetexternal| with a list of \meta{key=value} pairs. These will have effect until the end of the current group. Additionally, one can pass these keys as an optional argument to |\BinaryTree| to have them affect only that single tree.
%
+% Each node is named, so you can refer to it later. The root is named |btree-root| while each of its children is named according to its ancestors, for example |btree-l-r| is the name of the right child of the root's left child.
+%
% The package supports the \TikZ |external| library. To use this feature however one needs to load this library and execute |\tikzexternalize| in the preamble. All of the externalization options passed to, for example, |\btreesetexternal| are only executed once inside the local group of each tree so there is no conflict between them and any global configuration of the library. One may therefore disable externalization globally by calling |\tikzexternaldisable|; externalization will still be enabled for all the trees of \BT for which the \BTkey{external} option is |true|.
%
% \section{Usage}
@@ -359,7 +361,7 @@
% \section{Examples}
%
% \begin{itemize}[leftmargin=0pt]
-% \item You can name each tree using \TikZ's |local bounding box key| and refer to it for example in a graph.\par
+% \item Each node has a unique name, but you can name the entire tree using \TikZ's |local bounding box key| and refer to it for example in a graph.\par
% \vskip 10pt\import{examples/}{binarytree-ex1.tex}
% \vskip 10pt\hrule
% \verbatiminput{examples/binarytree-ex1.tex}
@@ -407,7 +409,7 @@
% \clearpage
% \section{Implementation}
%
-% The tree is drawn in a simple recursive way, which creates exactly two child nodes for each previous node, up to a maximum depth of |\BT@max@depth|. The entire appearance is controlled by a global style \BTkey{/tikz/binary tree} (which is determined by the setting of various pgf keys) as well as individual styles for each edge, which are created on the fly as the path specification is processed. Each style lives under the \BTkey{/tikz/binary tree} directory and is named according to the unique place of the child in the tree, by appending |l@| or |r@| to the name of its parent. The root is called |@| and has a depth of 0, its immediate children are |@r@| and |@l@| on level 1, and so on.\par
+% The tree is drawn in a simple recursive way, which creates exactly two child nodes for each previous node, up to a maximum depth of |\BT@max@depth|. The entire appearance is controlled by a global style \BTkey{/tikz/binary tree} (which is determined by the setting of various pgf keys) as well as individual styles for each edge, which are created on the fly as the path specification is processed. Each style lives under the \BTkey{/tikz/binary tree} directory and is named according to the unique place of the child in the tree, by appending |l@| or |r@| to the name of its parent. The root is called |@| and has a depth of 0, its immediate children are |@r@| and |@l@| on level 1, and so on. Each node is also named similarly, for example |btree-l-l-r| or |btree-root|.\par
% We create template styles for each type of node: root, intermediate labelled, final labelled, unlabelled, or unvisited. When setting a style for a particular edge, the relevant template is used and a macro with the name |\|\meta{child name}| styled| is defined (let to |\relax|). This is so we don't override a previously set style unless one of \meta{label}, \meta{color} or \meta{anchor} is given explicitly. It is also used when drawing the tree to check if such a style exists, otherwise the style is set to \BTkey{/tikz/binary tree/default}.\par
% \TikZ would put unnecessary white space around the tree (especially if there are missing outer children), so we need to calculate the actual size of the tree and clip the bounding box accordingly: we need the left and right width, height and depth, since these will be coordinates for the clipping rectangle. It is mostly calculated on the fly, starting with 0pt for each 4 coordinates. If \BTkey{draw missing} is |true|, we set the bounding box size to the maximum for this depth (and don't change it further). Otherwise we proceed in the following way: the height is easy to deal with---we add a level distance to the height each time a new level is created (we keep track by defining a macro |\level |\meta{depth}| exists|). The width is trickier---consider for example the case where there are no children on the right, but there are right children to one of the left nodes; they may extend to the right side of the box. What is done is we keep track of a current x coordinate (which is relative to root, being negative on the left) and each time any left (right) edge is created, we compare the (magnitude of the) coordinate to the current left (right) width of the box, and if greater---set the box width to it.\par
% Additionally, we save the height (width) of the root's label since this will (may) add to the depth (width) of the box, but we do not add it to the size of the box just yet (since the root label may change several times). Furthermore, we keep track of the maximum height (width) of any of the final children's labels since these will increase the ``height''\footnote{Here ``height'' means height if the tree is growing up, depth if it's growing down, left/right width if it's growing left/right; and similarly for ``width''} of the box when the tree is growing vertically (sideways). We also save the width (height) of the left- and rightmost final children, as these will increase the ``width'' of the box when growing vertically (sideways). At the end all of these are used to increase the box (still assuming the tree is growing upwards). Finally, the four sides are cycled according to the actual growing direction.
@@ -1220,6 +1222,16 @@
% \subsection{Macros for setting the styles}
% \subsubsection{Helper macros}
%
+% \begin{macro}{\BT@at@to@dash}
+% \begin{macro}{\BT@at@to@dash@i}
+% Convert |@| to |-| (except trailing |@|, which is removed) for root children. For example |@r@l@| \(\to\) |-r-l|. Used in naming the child nodes. For root, |@|, it expands to empty.
+% \begin{macrocode}
+\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}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}{\BT@anchor@or@default}
% Use the given anchor, or if empty---the default one.\par
% \nsig{anchor,\ttup{root\vbar left\vbar right\vbar final}}
@@ -1252,7 +1264,7 @@
% \begin{macrocode}
\else\expandafter\BT@if@child@is@outer@ii\expandafter#2\fi}
\def\BT@if@child@is@outer@ii#1{%
- \ifx#1\@nil\expandafter\@firstoftwo%
+ \ifx\@nil#1\expandafter\@firstoftwo%
\else\expandafter\expandafter\expandafter\@secondoftwo%
\expandafter\BT@gobble@till@nil\fi}
% \end{macrocode}
@@ -1699,10 +1711,10 @@
\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 {}% right
+ 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 {}% left
+ binary tree/default\fi] {node (btree\BT@at@to@dash{#1l@}) {}% left
\BT@draw@tree@children{#1l@}{#2+1} }\fi}
% \end{macrocode}
% \end{macro}
@@ -1714,7 +1726,7 @@
\advance\BT@bbox@height\BT@level@distance\relax%
\BT@adjust@bbox@sides%
\edef\BT@tree{%
- \noexpand\node[\ifcsname @ styled\endcsname binary tree/@\fi] {}%
+ \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)%
@@ -1724,7 +1736,7 @@
\BT@tree;%
\else\BT@adjust@bbox@sides%
\edef\BT@tree{%
- \noexpand\node[\ifcsname @ styled\endcsname binary tree/@\fi] {}%
+ \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);%
@@ -1737,6 +1749,7 @@
%
% \hrule
% \begin{macro}{\BinaryTree}
+% \changes{1.01}{2016/07/25}{Each node is now uniquely named.}
% \begin{macro}{\@BinaryTree}
% \begin{macro}{\BT@max@depth}
% \begin{macro}{\BT@root@depth}