summaryrefslogtreecommitdiff
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
parent6b200dd5c2335baa8c78037d8f1c75d1295187f4 (diff)
binarytree (26jul16)
git-svn-id: svn://tug.org/texlive/trunk@41777 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/binarytree/README50
-rw-r--r--Master/texmf-dist/doc/latex/binarytree/binarytree.pdfbin372444 -> 382466 bytes
-rw-r--r--Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex1.pdfbin24663 -> 24663 bytes
-rw-r--r--Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex2.pdfbin14004 -> 14004 bytes
-rw-r--r--Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex3.pdfbin16320 -> 8830 bytes
-rw-r--r--Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex4.pdfbin9310 -> 9310 bytes
-rw-r--r--Master/texmf-dist/source/latex/binarytree/binarytree.dtx29
-rw-r--r--Master/texmf-dist/tex/latex/binarytree/binarytree.sty14
8 files changed, 70 insertions, 23 deletions
diff --git a/Master/texmf-dist/doc/latex/binarytree/README b/Master/texmf-dist/doc/latex/binarytree/README
index 3cc69561cba..45af80d50e3 100644
--- a/Master/texmf-dist/doc/latex/binarytree/README
+++ b/Master/texmf-dist/doc/latex/binarytree/README
@@ -13,18 +13,39 @@ and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
=========================== ABOUT ==========================
-The 'binarytree' package provides an easy but flexible way to draw binary trees using TikZ. It provides a macro \BinaryTree which takes two arguments: a path specification and a number indicating the maximum depth of the tree. The path specification and the setting of various options determine the style for each edge of the tree. The options can be set either by passing them as an optional argument to \BinaryTree, or by calling \btreeset.
+The 'binarytree' package provides an easy but flexible way
+to draw binary trees using TikZ. It provides a macro
+\BinaryTree which takes two arguments: a path specification
+and a number indicating the maximum depth of the tree. The
+path specification and the setting of various options
+determine the style for each edge of the tree. The options
+can be set either by passing them as an optional argument to
+\BinaryTree, or by calling \btreeset.
-There is support for the external library of TikZ which does not affect externalization of the rest of the TikZ figures in the document (externalization is enabled locally for each \BinaryTree). There is an option to use automatic file naming: this is useful if the trees are often moved around or new ones are added in between, in which case using the default naming will cause all of them to be rebuilt. Instead, giving a unique name to each tree will have TikZ use the already compiled image no matter where in the document it is or how many times it has been used. This feature is still in its very infancy and more control over how the file name is generated is planned for the future.
+There is support for the external library of TikZ which does
+not affect externalization of the rest of the TikZ figures
+in the document (externalization is enabled locally for each
+\BinaryTree). There is an option to use automatic file
+naming: this is useful if the trees are often moved around
+or new ones are added in between, in which case using the
+default naming will cause all of them to be rebuilt.
+Instead, giving a unique name to each tree will have TikZ
+use the already compiled image no matter where in the
+document it is or how many times it has been used. This
+feature is still in its very infancy and more control over
+how the file name is generated is planned for the future.
======================= INSTALLATION =======================
Extract all of the files and run latex on binarytree.ins:
latex binarytree.ins
-Move the generated binarytree.sty into a TeX searchable directory, for example on Linux:
+Move the generated binarytree.sty into a TeX searchable
+directory, for example on Linux:
mkdir -p <TeX folder>/tex/latex/binarytree
mv binarytree.sty <TeX folder>/tex/latex/binarytree
-for example the local user TeX directory is in 'C:\Documents and Settings\<user name>\texmf' on Windows, '~/texmf' on Linux or '~/Library/texmf' on OS X.
+The local user TeX directory is in
+'C:\Documents and Settings\<user name>\texmf' on Windows,
+'~/texmf' on Linux or '~/Library/texmf' on OS X.
If you wish to (re)create the documentation:
pdflatex binarytree.dtx
@@ -35,14 +56,25 @@ If you wish to (re)create the documentation:
pdflatex binarytree.dtx
========================== TESTING =========================
-Provided are four files to test the package (also included as examples in the documentation:
-* 'examples/binarytree-ex1.tex' draws two trees, names them as nodes and uses them in a simple graph. To recompile it, simply run:
+Provided are four files to test the package (also included
+as examples in the documentation:
+* 'examples/binarytree-ex1.tex' draws two trees, names them
+ as nodes and uses them in a simple graph. To recompile it,
+ simply run:
pdflatex examples/binarytree-ex1.tex
-* 'examples/binarytree-ex2.tex' draws 4 identically structured trees using different level and sibling distance scalings. To recompile it, simply run:
+* 'examples/binarytree-ex2.tex' draws 4 identically
+ structured trees using different level and sibling
+ distance scalings. To recompile it, simply run:
pdflatex examples/binarytree-ex2.tex
-* 'examples/binarytree-ex3.tex' draws a square with arrows on each side! To recompile it, simply run:
+* 'examples/binarytree-ex3.tex' draws a square with arrows
+ on each side! To recompile it, simply run:
pdflatex examples/binarytree-ex3.tex
-* 'examples/binarytree-ex4.tex' draws a similar square twice and exports them using the external library. It uses the 'list and make' mode, so it generates 'examples/binarytree-ex4.figlist' and 'examples/binarytree-ex4.makefile', requiring manual compilation of the exported figure:
+* 'examples/binarytree-ex4.tex' draws a similar square twice
+ and exports them using the external library. It uses the
+ 'list and make' mode, so it generates
+ 'examples/binarytree-ex4.figlist' and
+ 'examples/binarytree-ex4.makefile', requiring manual
+ compilation of the exported figure:
pdflatex examples/binarytree-ex4.tex
make -f examples/binarytree-ex4.makefile
pdflatex examples/binarytree-ex4.tex
diff --git a/Master/texmf-dist/doc/latex/binarytree/binarytree.pdf b/Master/texmf-dist/doc/latex/binarytree/binarytree.pdf
index 3c3498728bf..6b571ca64fd 100644
--- a/Master/texmf-dist/doc/latex/binarytree/binarytree.pdf
+++ b/Master/texmf-dist/doc/latex/binarytree/binarytree.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex1.pdf b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex1.pdf
index 886beb31500..3c1a5a66b14 100644
--- a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex1.pdf
+++ b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex1.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex2.pdf b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex2.pdf
index 2785a68ce2a..9fd73188e9f 100644
--- a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex2.pdf
+++ b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex2.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex3.pdf b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex3.pdf
index ea1ebb79bd4..be99a5d5249 100644
--- a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex3.pdf
+++ b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex3.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex4.pdf b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex4.pdf
index 0cfc20a4c74..b2ab7873ac9 100644
--- a/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex4.pdf
+++ b/Master/texmf-dist/doc/latex/binarytree/examples/binarytree-ex4.pdf
Binary files differ
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}
diff --git a/Master/texmf-dist/tex/latex/binarytree/binarytree.sty b/Master/texmf-dist/tex/latex/binarytree/binarytree.sty
index c41f83a811d..0fac4e064c6 100644
--- a/Master/texmf-dist/tex/latex/binarytree/binarytree.sty
+++ b/Master/texmf-dist/tex/latex/binarytree/binarytree.sty
@@ -23,7 +23,7 @@
%%
\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}
\newdimen\BT@bbox@r@width
\newdimen\BT@bbox@l@width
@@ -384,6 +384,8 @@
\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}}
@@ -392,7 +394,7 @@
\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#1\@nil\expandafter\@firstoftwo%
+ \ifx\@nil#1\expandafter\@firstoftwo%
\else\expandafter\expandafter\expandafter\@secondoftwo%
\expandafter\BT@gobble@till@nil\fi}
\def\BT@check@if@new@level#1{%
@@ -598,17 +600,17 @@
\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}
\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] {}%
+ \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)%
@@ -618,7 +620,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);%