diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/tikz-qtree/tikz-qtree.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/tikz-qtree/tikz-qtree.tex | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/tikz-qtree/tikz-qtree.tex b/Master/texmf-dist/tex/latex/tikz-qtree/tikz-qtree.tex new file mode 100644 index 00000000000..6114da8468b --- /dev/null +++ b/Master/texmf-dist/tex/latex/tikz-qtree/tikz-qtree.tex @@ -0,0 +1,170 @@ +% tikztree.tex +% Version 1, 22 Dec 2009 + +% Copyright (C) 2002, 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. + +%% These macros facilitate building up an object recursively before +%% putting it into the input stream. + +\newtoks\@result +\def\@call#1#2{\let\@cont=#2\bgroup\@result={}#1} +\def\@return{\global\@result=\@result\egroup\@cont} + +\def\@ifequal#1#2{\edef\testa{#1}\edef\testb{#2}\ifx\testa\testb} + +%% scan a tree: this just scans a subtree and then puts it onto the +%% input stream + +\def\Tree{\@call\@subtree\@Tree} +\def\@Tree{% +%\showthe\@result %debug +\ifpgfpicture\the\@result\else\tikzpicture\the\@result\endtikzpicture\fi % is there a test for tikzpicture? +} + +%% scan a subtree +\newtoks\child@list +\newtoks\root@node + +\def\@subtree[{% +\root@node={}% +\pgfutil@ifnextchar.{\@call\@interior\@@subtree}{\@@@subtree}} +\def\@@subtree{% +\root@node=\@result +\@@@subtree +} +\def\@@@subtree{% +\@call\@children\@@@@subtree +} +\def\@@@@subtree]{% +\child@list=\@result +\pgfutil@ifnextchar.{\@call\@interior\@@@@@subtree}{\@@@@@@subtree}} +\def\@@@@@subtree{% +%%% Check for mismatch. +\@ifequal{\the\root@node}{\pgfutil@empty}% + \root@node=\@result +\fi +\@ifequal{\the\root@node}{\the\@result}\else + \message{Warning: mismatched labels, \the\root@node{} and \the\@result.}% +\fi +\@@@@@@subtree +} +\def\@@@@@@subtree{% +\@ifequal{\the\root@node}{\pgfutil@empty} +\edef\act{\noexpand\@result={\noexpand\pgftree{\noexpand\path coordinate (\noexpand\nodename);}{\the\child@list}}}% +\else +\edef\act{\noexpand\@result={\noexpand\pgftree{\the\root@node}{\the\child@list}}}% +\fi +\act +\@return} + +%% scan a sequence of subtrees or leaves + +\newif\ifscanned@edge + +\def\@children{% +\scanned@edgefalse +\child@list{}% +\@@children} +\def\@@children{% +\pgfutil@ifnextchar]{\@result\child@list\@return}{% end of children +\pgfutil@ifnextchar\edge{% explicit edge +\ifscanned@edge +\message{Warning: more than one edge given for a single child}\let\next\@@children % ignore +\else +\scanned@edgetrue\let\next\@@@children +\fi +\@call\@edge\next}{% +% else, a real node is next +\ifscanned@edge\else % no explicit edge, supply default +\expandafter\child@list\expandafter{\the\child@list{\edge@adapter{}}}% +\fi +\scanned@edgefalse +\pgfutil@ifnextchar[{\@call\@subtree\@@@children}% subtree +{\@call\@leaf\@@@children} % leaf +}}} +\def\@@@children{% +% wrap child inside curly braces +\expandafter\@result\expandafter{\expandafter{\the\@result}} +\edef\act{\noexpand\child@list{\the\child@list \the\@result}}\act +\@@children +} + +\def\@interior.{\@result{\node[alias=\nodename][every tree node,every internal node]}\@label} + +\def\@leaf{\@result{\node[alias=\nodename][every tree node,every leaf node]}\@label} + +\def\@edge\edge #1;{% +\@result{\edge@adapter{#1}}% +\@return} +\def\edge@adapter#1{% +\let\tikzparentnode\parentnodename +\let\tikzchildnode\nodename +\path edge from parent #1;% +} + +% a label is either text or PGF/TikZ code starting with \node +\def\@label{\pgfutil@ifnextchar\node{\@litlabel}{\@@label}} +\def\@@label#1 {% +\expandafter\@result\expandafter{\the\@result{#1};}% +\@return} + +% try to copy \node command into \@result without stripping braces +\def\@litlabel\node{\@@litlabel} +\def\@@litlabel{\pgfutil@ifnextchar\bgroup{\@@@litlabel}{\@@@@litlabel}} +\def\@@@litlabel#1{\expandafter\@result\expandafter{\the\@result {#1}}\@@litlabel} +\def\@@@@litlabel#1;{\expandafter\@result\expandafter{\the\@result #1;}\@return} + +% predefined edges + +\def\tree@edge#1#2{% +\ifupsidedown +(#1.north) -- (#2.south) +\else +(#1.south) -- (#2.north) +\fi +} + +\def\roof@edge#1#2{ +\ifupsidedown +(#1.north) -- (#2.south west) -- (#2.south east) -- cycle +\else +(#1.south) -- (#2.north west) -- (#2.north east) -- cycle +\fi +} + +%%% Options + +\tikzoption{level distance}{\pgfmathsetlength\levelsep{#1}} +\tikzoption{sibling distance}{\pgfmathsetlength\subtreesep{#1}} % different semantics + +% I don't really like this scheme +\tikzoption{grow}{\csname grow@#1\endcsname} +\tikzoption{grow'}{\csname growprime@#1\endcsname} +\def\grow@up{\upsidedowntrue\righttolefttrue} +\def\grow@down{\upsidedownfalse\righttoleftfalse} +\def\growprime@up{\upsidedowntrue\righttoleftfalse} +\def\growprime@down{\upsidedownfalse\righttolefttrue} + +% defaults appropriate for linguistic trees +\tikzset{every tree node/.style={anchor=base}} +\tikzset{every leaf node/.style={}} +\tikzset{every internal node/.style={}} +\def\tikz@edge@to@parent@path{\tree@edge{\tikzparentnode}{\tikzchildnode}} + +% predefined roof style +\tikzset{roof/.style={edge from parent path=\roof@edge{\tikzparentnode}{\tikzchildnode}}} + |