summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tikz-qtree/pgftree.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/tikz-qtree/pgftree.tex')
-rw-r--r--Master/texmf-dist/tex/latex/tikz-qtree/pgftree.tex119
1 files changed, 119 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/tikz-qtree/pgftree.tex b/Master/texmf-dist/tex/latex/tikz-qtree/pgftree.tex
new file mode 100644
index 00000000000..4cdaad16433
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/tikz-qtree/pgftree.tex
@@ -0,0 +1,119 @@
+% pgftree.tex
+% Version 1, 22 Dec 2009
+
+% Copyright 2009 by David Chiang
+
+% This program is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+
+% You should have received a copy of the GNU General Public License along
+% with this program; if not, write to the Free Software Foundation, Inc.,
+% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+% to do:
+% if \nodename does not exist as desired, wrap inside a rectangle node
+% don't use pgfsubpic internals, use anchors instead
+
+\newdimen\levelsep \levelsep=30pt
+\newdimen\subtreesep \subtreesep=2pt
+\newif\ifrighttoleft
+\newif\ifupsidedown
+\def\drawnode#1{\pgfnode{rectangle}{base}{#1}{\nodename}{\pgfusepath{discard}}}
+\def\drawedge{%
+\pgfpathmoveto{\pgfpointanchor{\parentnodename}{\ifupsidedown north\else south\fi}}%
+\pgfpathlineto{\pgfpointanchor{\nodename}{\ifupsidedown south\else north\fi}}%
+\pgfusepath{stroke}}
+
+% local variables that we need to assign to inside a \pgfforeach
+\newdimen\pgftree@childx
+\newdimen\pgftree@savechildx
+\newcount\pgftree@childi
+\newcount\pgftree@savechildi
+
+\def\nodename{r}
+
+%%% \pgftree{root}{subtrees}
+
+% The first argument draws the root node using PGF/TikZ commands.
+% The node must be named \nodename.
+
+% The second argument is an even-length sequence of tokens.
+% Token 2n-1 in the sequence draws the nth edge. It should draw an edge from \parentnodename to \nodename.
+% Token 2n in the sequence draws the nth subtree. Its root must be named \nodename.
+
+\def\pgftree#1#2{%
+\pgfscope
+% create root node
+#1
+\let\parentnodename\nodename
+\ifupsidedown
+\pgftransformshift{\pgfpoint{0}{\levelsep}}%
+\else
+\pgftransformshift{\pgfpoint{0}{-\levelsep}}%
+\fi
+\pgftree@savechildx=\pgftree@childx
+\pgftree@savechildi=\pgftree@childi
+\pgfsubpicture
+\pgftree@childx=0pt%
+\pgftree@childi=0%
+{\process@children #2}%
+\endpgfsubpicture
+\ifnum\pgftree@childi>0%
+% Center children so that parent is midway between origins of first and last children
+\pgftransformshift{\pgfpointscale{-0.5}{\pgfpoint{\the\pgftree@childx}{0}}}%
+\pgfplacesubpicture
+% Draw the edges
+\pgftree@childi=0%
+{\process@edges #2}%
+\fi
+\global\pgftree@childi=\pgftree@savechildi
+\global\pgftree@childx=\pgftree@savechildx
+\endpgfscope
+}
+
+\def\process@children{%
+\pgfutil@ifnextchar\egroup
+{% Step back to origin of last child
+\advance\pgftree@childx by \ifrighttoleft-\pgf@subpicminx\else-\pgf@subpicmaxx\fi
+\global\pgftree@childx=\pgftree@childx
+\global\pgftree@childi=\pgftree@childi
+}%
+{\@process@children}%
+}
+\def\@process@children#1#2{%
+\edef\nodename{\parentnodename-\the\pgftree@childi}%
+\def\child{#2}%
+\pgfsubpicture
+#2%
+\endpgfsubpicture
+\ifnum\pgftree@childi>0%
+\advance\pgftree@childx by \ifrighttoleft-\pgf@subpicmaxx\else-\pgf@subpicminx\fi
+\advance\pgftree@childx by \ifrighttoleft-\subtreesep\else\subtreesep\fi
+\fi
+\pgfscope
+\pgftransformshift{\pgfpoint{\the\pgftree@childx}{0}}%
+\pgfplacesubpicture
+\endpgfscope
+\advance\pgftree@childx by \ifrighttoleft\pgf@subpicminx\else\pgf@subpicmaxx\fi
+\advance\pgftree@childi by 1%
+\process@children
+}
+
+\def\process@edges{%
+\pgfutil@ifnextchar\egroup
+{}%
+{\@process@edges}%
+}
+\def\@process@edges#1#2{%
+\edef\nodename{\parentnodename-\the\pgftree@childi}%
+#1%
+\advance\pgftree@childi by 1%
+\process@edges
+}