Stuff.
authorEugen Sawin <sawine@me73.com>
Sun, 03 Jun 2012 20:15:28 +0200
changeset 115112f3e2f3d2
parent 10 c30d95faea4a
child 12 7a9fd24ae3f4
Stuff.
exercises/blatt03.pdf
exercises/blatt04.pdf
exercises/solutions/pgfsubpic.sty
exercises/solutions/pgfsubpic.tex
exercises/solutions/pgftree.sty
exercises/solutions/pgftree.tex
exercises/solutions/sol04.tex
exercises/solutions/tikz-qtree-compat.sty
exercises/solutions/tikz-qtree-manual.tex
exercises/solutions/tikz-qtree.sty
exercises/solutions/tikz-qtree.tex
     1.1 Binary file exercises/blatt03.pdf has changed
     2.1 Binary file exercises/blatt04.pdf has changed
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/exercises/solutions/pgfsubpic.sty	Sun Jun 03 20:15:28 2012 +0200
     3.3 @@ -0,0 +1,4 @@
     3.4 +\RequirePackage{pgf}
     3.5 +
     3.6 +\input{pgfsubpic.tex}
     3.7 +\endinput
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/exercises/solutions/pgfsubpic.tex	Sun Jun 03 20:15:28 2012 +0200
     4.3 @@ -0,0 +1,209 @@
     4.4 +%    pgfsubpic.tex
     4.5 +%    Version 1.1, 25 Dec 2009
     4.6 +
     4.7 +%    Copyright 2009 by David Chiang
     4.8 +
     4.9 +%    This program is free software; you can redistribute it and/or modify
    4.10 +%    it under the terms of the GNU General Public License as published by
    4.11 +%    the Free Software Foundation; either version 2 of the License, or
    4.12 +%    (at your option) any later version.
    4.13 +
    4.14 +%    This program is distributed in the hope that it will be useful,
    4.15 +%    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.16 +%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.17 +%    GNU General Public License for more details.
    4.18 +
    4.19 +%    You should have received a copy of the GNU General Public License along
    4.20 +%    with this program; if not, write to the Free Software Foundation, Inc.,
    4.21 +%    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    4.22 +
    4.23 +% New in version 1.1:
    4.24 +% - the ability to save a subpicture in local variables
    4.25 +% - nodes in subpictures are tracked if the subpicture is placed with arbitrary transforms
    4.26 +% - new \pgffitsubpicture macro to transform a subpicture (preserving aspect) to fit in a desired box
    4.27 +
    4.28 +\newdimen\pgf@subpicminx
    4.29 +\newdimen\pgf@subpicminy
    4.30 +\newdimen\pgf@subpicmaxx
    4.31 +\newdimen\pgf@subpicmaxy
    4.32 +
    4.33 +% Special virtual node for current subpicture's bounding box
    4.34 +\expandafter\def\csname pgf@sh@ns@current subpicture\endcsname{rectangle}
    4.35 +\expandafter\def\csname pgf@sh@np@current subpicture\endcsname{%
    4.36 +  \def\southwest{\pgfqpoint{\pgf@subpicminx}{\pgf@subpicminy}}%
    4.37 +  \def\northeast{\pgfqpoint{\pgf@subpicmaxx}{\pgf@subpicmaxy}}%
    4.38 +}
    4.39 +\expandafter\def\csname pgf@sh@nt@current subpicture\endcsname{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}} % the transformation at invocation time
    4.40 +\expandafter\def\csname pgf@sh@pi@current subpicture\endcsname{\pgfpictureid}
    4.41 +
    4.42 +% Create a pgfpicture inside an hbox for delayed placement
    4.43 +\def\pgfsubpicture{%
    4.44 +\expandafter\global\expandafter\setbox\pgf@hbox=\hbox\bgroup
    4.45 +\pgfinterruptpicture
    4.46 +\pgfpicture
    4.47 +\relax % not sure why. otherwise a curly brace immediately after causes an error
    4.48 +}
    4.49 +
    4.50 +\def\endpgfsubpicture{
    4.51 +\global\pgf@subpicminx=\pgf@picminx
    4.52 +\global\pgf@subpicminy=\pgf@picminy
    4.53 +\global\pgf@subpicmaxx=\pgf@picmaxx
    4.54 +\global\pgf@subpicmaxy=\pgf@picmaxy
    4.55 +\global\edef\subpictureid{\pgfpictureid}%
    4.56 +\pgfsetbaseline{\pgf@picminy}%
    4.57 +\endpgfpicture%
    4.58 +\endpgfinterruptpicture%
    4.59 +\egroup
    4.60 +}
    4.61 +
    4.62 +% Allocate registers for saving a subpicture. #1 is text, not a control sequence.
    4.63 +\def\pgfnewsubpicture#1{%
    4.64 +\expandafter\newbox\csname pgf@subpic@hbox@#1\endcsname
    4.65 +\expandafter\newdimen\csname pgf@subpic@minx@#1\endcsname
    4.66 +\expandafter\newdimen\csname pgf@subpic@miny@#1\endcsname
    4.67 +\expandafter\newdimen\csname pgf@subpic@maxx@#1\endcsname
    4.68 +\expandafter\newdimen\csname pgf@subpic@maxy@#1\endcsname
    4.69 +}
    4.70 +
    4.71 +% saved subpictures are local to the current group
    4.72 +\def\pgfsavesubpicture#1{%
    4.73 +\expandafter\setbox\csname pgf@subpic@hbox@#1\endcsname\box\pgf@hbox
    4.74 +\csname pgf@subpic@minx@#1\endcsname\pgf@subpicminx
    4.75 +\csname pgf@subpic@miny@#1\endcsname\pgf@subpicminy
    4.76 +\csname pgf@subpic@maxx@#1\endcsname\pgf@subpicmaxx
    4.77 +\csname pgf@subpic@maxy@#1\endcsname\pgf@subpicmaxy
    4.78 +\expandafter\edef\csname pgf@subpic@id@#1\endcsname{\subpictureid}%
    4.79 +}
    4.80 +
    4.81 +% place current subpicture into named subpicture
    4.82 +\def\pgfmergesubpicture#1{%
    4.83 +\begin{pgfsubpicture}
    4.84 +% place current subpicture
    4.85 +\pgfplacesubpicture
    4.86 +% override containing picture
    4.87 +\expandafter\xdef\csname pgf@sh@pi@\subpictureid\endcsname{\csname pgf@subpic@id@#1\endcsname}%
    4.88 +% copy contents of #1
    4.89 +\pgfrestoresubpicture{#1}
    4.90 +\pgflowlevelobj{\pgftransformshift{\pgfqpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}}{\pgfqbox\pgf@hbox}
    4.91 +\pgfpathrectanglecorners{\pgfqpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}{\pgfqpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
    4.92 +\pgfusepath{use as bounding box}%
    4.93 +%
    4.94 +\end{pgfsubpicture}
    4.95 +\expandafter\setbox\csname pgf@subpic@hbox@#1\endcsname\box\pgf@hbox
    4.96 +\csname pgf@subpic@minx@#1\endcsname\pgf@subpicminx
    4.97 +\csname pgf@subpic@miny@#1\endcsname\pgf@subpicminy
    4.98 +\csname pgf@subpic@maxx@#1\endcsname\pgf@subpicmaxx
    4.99 +\csname pgf@subpic@maxy@#1\endcsname\pgf@subpicmaxy
   4.100 +% but don't save the new picture id, keep the existing one
   4.101 +}
   4.102 +
   4.103 +\def\pgfrestoresubpicture#1{%
   4.104 +\edef\act{\global\noexpand\setbox\pgf@hbox\noexpand\box\csname pgf@subpic@hbox@#1\endcsname}\act
   4.105 +\expandafter\global\expandafter\pgf@subpicminx\csname pgf@subpic@minx@#1\endcsname
   4.106 +\expandafter\global\expandafter\pgf@subpicminy\csname pgf@subpic@miny@#1\endcsname
   4.107 +\expandafter\global\expandafter\pgf@subpicmaxx\csname pgf@subpic@maxx@#1\endcsname
   4.108 +\expandafter\global\expandafter\pgf@subpicmaxy\csname pgf@subpic@maxy@#1\endcsname
   4.109 +\xdef\subpictureid{\csname pgf@subpic@id@#1\endcsname}%
   4.110 +}
   4.111 +
   4.112 +% Place a previously-created subpicture, lining up its origin with the current origin
   4.113 +\def\pgfplacesubpicture{
   4.114 +\pgfscope
   4.115 +% expand current bounding box to accommodate subpicture
   4.116 +\pgfpathrectanglecorners{\pgfqpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}{\pgfqpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
   4.117 +\pgfusepath{use as bounding box}%
   4.118 +%
   4.119 +% make the subpicture a node in the containing picture
   4.120 +\expandafter\gdef\csname pgf@sh@ns@\subpictureid\endcsname{rectangle}%
   4.121 +\expandafter\xdef\csname pgf@sh@np@\subpictureid\endcsname{%
   4.122 +  \noexpand\def\noexpand\southwest{\noexpand\pgfqpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}%
   4.123 +  \noexpand\def\noexpand\northeast{\noexpand\pgfqpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
   4.124 +}%
   4.125 +\pgfgettransform\pgf@temp
   4.126 +\expandafter\xdef\csname pgf@sh@nt@\subpictureid\endcsname{\pgf@temp}%
   4.127 +\expandafter\xdef\csname pgf@sh@pi@\subpictureid\endcsname{\pgfpictureid}%
   4.128 +%
   4.129 +% align origin of subpicture with origin
   4.130 +\pgftransformshift{\pgfqpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}%
   4.131 +\pgfqboxsynced{\pgf@hbox}%
   4.132 +\endpgfscope
   4.133 +}
   4.134 +
   4.135 +% Hook onto existing macro \pgf@shape@interpictureshift.
   4.136 +% This is called whenever we look up an anchor of a node.
   4.137 +% This hook recursively checks to see if the node's picture
   4.138 +% is a subpicture of another, and if so, adjusts its position accordingly.
   4.139 +
   4.140 +% This is slow. It makes drawing trees O(n^2) in the depth of the tree.
   4.141 +% The alternative is to store, for each picture, a list of the nodes
   4.142 +% inside it. But this way doesn't require us to hijack \pgfnode, and
   4.143 +% is robust to re-placement of a subpicture. A compromise would be
   4.144 +% to store, for each picture, a list of the *subpictures* inside it.
   4.145 +
   4.146 +\let\orig@pgf@shape@interpictureshift\pgf@shape@interpictureshift
   4.147 +\def\unwind@subpic#1{%
   4.148 +% is #1 the current picture?
   4.149 +\edef\subpicid{#1}%
   4.150 +\ifx\subpicid\pgfpictureid
   4.151 +% yes, we're done
   4.152 +\else
   4.153 +% does #1 have a parent picture?
   4.154 +\expandafter\ifx\csname pgf@sh@pi@#1\endcsname\relax
   4.155 +% no, the original node was not inside the current picture
   4.156 +\fallback
   4.157 +\else
   4.158 +% yes, apply transform and move up to parent picture
   4.159 +{%
   4.160 +  \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
   4.161 +  \pgf@pos@transform{\pgf@x}{\pgf@y}%
   4.162 +  \global\pgf@x=\pgf@x
   4.163 +  \global\pgf@y=\pgf@y
   4.164 +}%
   4.165 +\unwind@subpic{\csname pgf@sh@pi@#1\endcsname}%
   4.166 +\fi
   4.167 +\fi
   4.168 +}
   4.169 +\def\pgf@shape@interpictureshift#1{%
   4.170 +\edef\fallback{\pgf@x=\the\pgf@x\pgf@y=\the\pgf@y\noexpand\orig@pgf@shape@interpictureshift{#1}}%
   4.171 +\unwind@subpic{\csname pgf@sh@pi@#1\endcsname}%
   4.172 +}
   4.173 +
   4.174 +% \pgffitsubpicture{sw}{ne}
   4.175 +% Make the subpicture fit in the rectangle from sw to ne, preserving its aspect ratio.
   4.176 +\def\pgffitsubpicture#1#2{%
   4.177 +% current size
   4.178 +\pgfpointdiff{\pgfpointanchor{current subpicture}{south west}}{\pgfpointanchor{current subpicture}{north east}}%
   4.179 +\pgf@xa=\pgf@x \pgf@ya=\pgf@y
   4.180 +% desired size
   4.181 +\pgf@process{\pgfpointdiff{#1}{#2}}%
   4.182 +\pgf@xb=\pgf@x \pgf@yb=\pgf@y
   4.183 +\pgfmathparse{min(\pgf@xb/\pgf@xa,\pgf@yb/\pgf@ya)}%
   4.184 +\pgfmathparse{min(1,\pgfmathresult)}%
   4.185 +\pgftransformscale{\pgfmathresult}%
   4.186 +%
   4.187 +% current position
   4.188 +\pgfpointanchor{current subpicture}{center}%
   4.189 +\pgf@xa=\pgf@x \pgf@ya=\pgf@y
   4.190 +% desired position
   4.191 +% we scaled transform, so apply reverse scaling to argument
   4.192 +\pgfmathparse{1/\pgfmathresult}%
   4.193 +\pgf@process{\pgfpointscale{\pgfmathresult}{\pgfpointlineattime{0.5}{#1}{#2}}}%
   4.194 +\pgf@xb=\pgf@x \pgf@yb=\pgf@y
   4.195 +\pgfpointdiff{\pgfpoint{\pgf@xa}{\pgf@ya}}{\pgfpoint{\pgf@xb}{\pgf@yb}}%
   4.196 +\pgftransformshift{\pgfpoint{\pgf@x}{\pgf@y}}%
   4.197 +}
   4.198 +
   4.199 +% utility functions -- not currently used
   4.200 +
   4.201 +\def\pgfnodedelete#1{%
   4.202 +\expandafter\global\expandafter\let\csname pgf@sh@ns@#1\endcsname\relax
   4.203 +\expandafter\global\expandafter\let\csname pgf@sh@np@#1\endcsname\relax
   4.204 +\expandafter\global\expandafter\let\csname pgf@sh@nt@#1\endcsname\relax
   4.205 +\expandafter\global\expandafter\let\csname pgf@sh@pi@#1\endcsname\relax
   4.206 +\expandafter\global\expandafter\let\csname pgf@sh@ma@#1\endcsname\relax
   4.207 +}
   4.208 +
   4.209 +\def\pgfnodeifexists#1#2#3{%
   4.210 +\expandafter\ifx\csname pgf@sh@ns@#1\endcsname\relax#3\else#2\fi
   4.211 +}
   4.212 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/exercises/solutions/pgftree.sty	Sun Jun 03 20:15:28 2012 +0200
     5.3 @@ -0,0 +1,6 @@
     5.4 +\RequirePackage{pgf}
     5.5 +\RequirePackage{pgffor}
     5.6 +\RequirePackage{pgfsubpic}
     5.7 +
     5.8 +\input{pgftree.tex}
     5.9 +\endinput
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/exercises/solutions/pgftree.tex	Sun Jun 03 20:15:28 2012 +0200
     6.3 @@ -0,0 +1,188 @@
     6.4 +%    pgftree.tex
     6.5 +%    Version 1.1, 25 Dec 2009
     6.6 +
     6.7 +%    Copyright 2009 by David Chiang
     6.8 +
     6.9 +%    This program is free software; you can redistribute it and/or modify
    6.10 +%    it under the terms of the GNU General Public License as published by
    6.11 +%    the Free Software Foundation; either version 2 of the License, or
    6.12 +%    (at your option) any later version.
    6.13 +
    6.14 +%    This program is distributed in the hope that it will be useful,
    6.15 +%    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.16 +%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.17 +%    GNU General Public License for more details.
    6.18 +
    6.19 +%    You should have received a copy of the GNU General Public License along
    6.20 +%    with this program; if not, write to the Free Software Foundation, Inc.,
    6.21 +%    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    6.22 +
    6.23 +% New in version 1.1:
    6.24 +% - major restructuring to not do arbitrary nesting of subpicture environments
    6.25 +% - sideways trees
    6.26 +
    6.27 +% To do:
    6.28 +% - trees with all leaves at same level
    6.29 +% - if \nodename does not exist as desired, wrap inside a rectangle node
    6.30 +% - don't use pgfsubpic internals
    6.31 +
    6.32 +\newdimen\levelsep \levelsep=30pt
    6.33 +\newdimen\subtreesep \subtreesep=2pt
    6.34 +
    6.35 +\def\leveldirection{down}
    6.36 +\def\siblingdirection{right}
    6.37 +
    6.38 +% definitions of growing directions
    6.39 +\def\pgftree@levelshift{\csname pgftree@levelshift@\leveldirection\endcsname}
    6.40 +\def\pgftree@parentanchor{\csname pgftree@parentanchor@\leveldirection\endcsname}
    6.41 +\def\pgftree@childanchor{\csname pgftree@childanchor@\leveldirection\endcsname}
    6.42 +% these assume that the current subpicture is the child
    6.43 +\def\pgftree@presiblingshift{\csname pgftree@presiblingshift@\siblingdirection\endcsname}
    6.44 +\def\pgftree@postsiblingshift{\csname pgftree@postsiblingshift@\siblingdirection\endcsname}
    6.45 +
    6.46 +\def\pgftree@levelshift@down{\pgfpoint{0}{-\levelsep}}
    6.47 +\def\pgftree@parentanchor@down{south}
    6.48 +\def\pgftree@childanchor@down{north}
    6.49 +
    6.50 +\def\pgftree@levelshift@up{\pgfpoint{0}{\levelsep}}
    6.51 +\def\pgftree@parentanchor@up{north}
    6.52 +\def\pgftree@childanchor@up{south}
    6.53 +
    6.54 +\def\pgftree@levelshift@right{\pgfpoint{\levelsep}{0}}
    6.55 +\def\pgftree@parentanchor@right{east}
    6.56 +\def\pgftree@childanchor@right{west}
    6.57 +
    6.58 +\def\pgftree@levelshift@left{\pgfpoint{-\levelsep}{0}}
    6.59 +\def\pgftree@parentanchor@left{west}
    6.60 +\def\pgftree@childanchor@left{east}
    6.61 +
    6.62 +\def\pgftree@presiblingshift@right{\pgf@process{\pgf@x-\pgf@subpicminx \advance\pgf@x\subtreesep \pgf@y 0pt}}
    6.63 +\def\pgftree@postsiblingshift@right{\pgf@process{\pgf@x\pgf@subpicmaxx \pgf@y 0pt}}
    6.64 +
    6.65 +\def\pgftree@presiblingshift@left{\pgf@process{\pgf@x-\pgf@subpicmaxx \advance\pgf@x-\subtreesep \pgf@y 0pt}}
    6.66 +\def\pgftree@postsiblingshift@left{\pgf@process{\pgf@x\pgf@subpicminx \pgf@y 0pt}}
    6.67 +
    6.68 +\def\pgftree@presiblingshift@up{\pgf@process{\pgf@x 0pt \pgf@y-\pgf@subpicminy \advance\pgf@y\subtreesep}}
    6.69 +\def\pgftree@postsiblingshift@up{\pgf@process{\pgf@x 0pt \pgf@y\pgf@subpicmaxy}}
    6.70 +
    6.71 +\def\pgftree@presiblingshift@down{\pgf@process{\pgf@x 0pt \pgf@y-\pgf@subpicmaxy \advance\pgf@y-\subtreesep}}
    6.72 +\def\pgftree@postsiblingshift@down{\pgf@process{\pgf@x 0pt \pgf@y\pgf@subpicminy}}
    6.73 +
    6.74 +% for convenience if you are using \pgftree directly
    6.75 +\def\drawnode#1{\pgfnode{rectangle}{base}{#1}{\nodename}{\pgfusepath{discard}}}
    6.76 +\def\drawedge{%
    6.77 +\pgfpathmoveto{\pgfpointanchor{\parentnodename}{\pgftree@parentanchor}}%
    6.78 +\pgfpathlineto{\pgfpointanchor{\nodename}{\pgftree@childanchor}}%
    6.79 +\pgfusepath{stroke}}
    6.80 +
    6.81 +% local variables that we need to assign to inside a \pgfforeach
    6.82 +\newdimen\pgftree@childx
    6.83 +\newdimen\pgftree@savechildx
    6.84 +\newdimen\pgftree@childy
    6.85 +\newdimen\pgftree@savechildy
    6.86 +\newcount\pgftree@childi
    6.87 +\newcount\pgftree@savechildi
    6.88 +
    6.89 +%%% \pgftree{subtree}
    6.90 +
    6.91 +\def\pgftree#1{%
    6.92 +\def\nodename{r}%
    6.93 +#1%
    6.94 +\pgfplacesubpicture
    6.95 +}
    6.96 +
    6.97 +%%% \pgfsubtree{root}{subtrees}
    6.98 +% The first argument draws the root node using PGF/TikZ commands.
    6.99 +% The node must be named \nodename.
   6.100 +
   6.101 +% The second argument is an even-length sequence of tokens.
   6.102 +% Token 2n-1 in the sequence draws the nth edge. It should draw an edge from \parentnodename to \nodename.
   6.103 +% Token 2n in the sequence draws the nth subtree. Its root must be named \nodename.
   6.104 +
   6.105 +\pgfnewsubpicture{children}
   6.106 +\newdimen\pgftree@lastchildx
   6.107 +\newdimen\pgftree@lastchildy
   6.108 +
   6.109 +\def\pgfsubtree#1#2{%
   6.110 +\let\parentnodename\nodename
   6.111 +\pgftree@savechildx=\pgftree@childx
   6.112 +\pgftree@savechildy=\pgftree@childy
   6.113 +\pgftree@savechildi=\pgftree@childi
   6.114 +% Build subpicture with all the children and their subtrees
   6.115 +{\pgftree@childx=0pt%
   6.116 +\pgftree@childy=0pt%
   6.117 +\pgftree@childi=0%
   6.118 +\process@children #2}%
   6.119 +\begin{pgfsubpicture}%
   6.120 +% Create node
   6.121 +#1%
   6.122 +\ifnum\pgftree@childi>0%
   6.123 +% Place children
   6.124 +% move down \levelsep
   6.125 +{\pgftransformshift{\pgftree@levelshift}%
   6.126 +% center so that parent is midway between origins of first and last children
   6.127 +\pgftransformshift{\pgfpointscale{-0.5}{\pgfqpoint{\the\pgftree@childx}{\the\pgftree@childy}}}%
   6.128 +\pgfplacesubpicture}%
   6.129 +% Draw the edges
   6.130 +{\pgftree@childi=0%
   6.131 +\process@edges #2}%
   6.132 +\fi
   6.133 +\end{pgfsubpicture}%
   6.134 +\global\pgftree@childi=\pgftree@savechildi
   6.135 +\global\pgftree@childx=\pgftree@savechildx
   6.136 +\global\pgftree@childy=\pgftree@savechildy
   6.137 +}
   6.138 +
   6.139 +\def\process@children{%
   6.140 +\pgfutil@ifnextchar\egroup
   6.141 +{% No more children, step back to origin of last child
   6.142 +\global\pgftree@childx\pgftree@lastchildx
   6.143 +\global\pgftree@childy\pgftree@lastchildy
   6.144 +\global\pgftree@childi\pgftree@childi
   6.145 +\ifnum\pgftree@childi>0%
   6.146 +\pgfrestoresubpicture{children}% pass children back to caller
   6.147 +\fi
   6.148 +}%
   6.149 +{\@process@children}%
   6.150 +}
   6.151 +\def\@process@children#1#2{% #1 is the edge, #2 is the child
   6.152 +% Build the current child
   6.153 +{\edef\nodename{\parentnodename-\the\pgftree@childi}%
   6.154 +#2}%
   6.155 +\begin{pgfsubpicture}%
   6.156 +% Place current child
   6.157 +\ifnum\pgftree@childi>0% the first child is always at 0
   6.158 +\pgftree@presiblingshift \global\advance\pgftree@childx\pgf@x \global\advance\pgftree@childy\pgf@y
   6.159 +\fi
   6.160 +{\pgftransformshift{\pgfqpoint{\the\pgftree@childx}{\the\pgftree@childy}}%
   6.161 +\pgfplacesubpicture}%
   6.162 +\global\pgftree@lastchildx\pgftree@childx
   6.163 +\global\pgftree@lastchildy\pgftree@childy
   6.164 +\pgftree@postsiblingshift \global\advance\pgftree@childx\pgf@x \global\advance\pgftree@childy\pgf@y
   6.165 +% Save the augmented row of children back into "children"
   6.166 +\end{pgfsubpicture}
   6.167 +\ifnum\pgftree@childi>0%
   6.168 +\pgfmergesubpicture{children}
   6.169 +\else
   6.170 +\pgfsavesubpicture{children}%
   6.171 +\fi
   6.172 +\advance\pgftree@childi by 1%
   6.173 +\process@children
   6.174 +}
   6.175 +
   6.176 +\def\process@edges{%
   6.177 +\pgfutil@ifnextchar\egroup
   6.178 +{}%
   6.179 +{\@process@edges}%
   6.180 +}
   6.181 +\def\@process@edges#1#2{%
   6.182 +\edef\nodename{\parentnodename-\the\pgftree@childi}%
   6.183 +#1%
   6.184 +\advance\pgftree@childi by 1%
   6.185 +\process@edges
   6.186 +}
   6.187 +
   6.188 +\def\subtreeof#1{%
   6.189 +% the subpicture which contains a node also contains exactly its subtree
   6.190 +\csname pgf@sh@pi@#1\endcsname
   6.191 +}
     7.1 --- a/exercises/solutions/sol04.tex	Fri Jun 01 04:10:58 2012 +0200
     7.2 +++ b/exercises/solutions/sol04.tex	Sun Jun 03 20:15:28 2012 +0200
     7.3 @@ -9,6 +9,12 @@
     7.4  \usepackage{mathtools}
     7.5  \usepackage{multirow}
     7.6  \usepackage[all]{xy}
     7.7 +\usepackage{tikz}
     7.8 +\usepackage{tikz-qtree}
     7.9 +\usetikzlibrary{decorations.pathmorphing} % noisy shapes
    7.10 +\usetikzlibrary{fit}					% fitting shapes to coordinates
    7.11 +\usetikzlibrary{backgrounds}	% drawin
    7.12 +\usetikzlibrary{shapes,snakes}
    7.13  \addtolength{\voffset}{-20pt}
    7.14  \title{Spieltheorie \"Ubung 4}
    7.15  \author{Eugen Sawin}
    7.16 @@ -65,5 +71,130 @@
    7.17    0&=\alpha(a)\cdot(u-U_1(a,\beta))&\forall a\in A\\
    7.18    0&=\beta(b)\cdot(v-U_2(\alpha,b))&\forall b\in B
    7.19  \end{align}
    7.20 -Gleichungen (15) und (16) sind zu expandieren, wie in den Gleichungen (1)-(10) gezeigt. Au\ss erdem muss f\"ur die Normalform hierbei zus\"atzliche Variablen eingef\"uhrt werden. Wir unterlassen beides um die \"Ubersichtlichkeit zu erhalten.
    7.21 +Gleichungen (15) und (16) sind zu expandieren, wie in den Gleichungen (1)-(10) gezeigt. Au\ss erdem m\"ussen f\"ur die Normalform daf\"ur zus\"atzliche Variablen eingef\"uhrt werden. Wir unterlassen beides um die \"Ubersichtlichkeit zu erhalten. Auch (11) und (12) definieren insgesamt 10 Ungleichungen, f\"ur jede Aktion eine.\\\\
    7.22 +%
    7.23 +(b) 
    7.24 +
    7.25 +\section*{Aufgabe 4.2}
    7.26 +(a) Das extensive Spiel ist $\Gamma=\langle N,H,P,(u_i)_{i\in N}\rangle$ mit 
    7.27 +\begin{align*}
    7.28 +  N&=\{R,E,K\}\\
    7.29 +  H&=\{\langle\rangle,\langle r\rangle,\langle e\rangle,\langle r,b\rangle,\langle r,h\rangle,\langle e,b\rangle,\langle e,h\rangle,\langle r,b,b\rangle,\langle r,b,h\rangle,\langle r,h,b\rangle,\langle r,h,h\rangle,\langle e,b,b\rangle,\langle e,b,h\rangle,\langle e,h,b\rangle,\langle e,h,h\rangle\}\\
    7.30 +  P(h)&=\left\{\begin{array}{l l}
    7.31 +   K, & \text{falls } h=\langle\rangle\\
    7.32 +   R, & \text{falls } h\in\{\langle r\rangle,\langle e,b\rangle,\langle e,h\rangle\}\\
    7.33 +   E, & \text{falls } h\in\{\langle e\rangle,\langle r,b\rangle,\langle r,h\rangle\}\\
    7.34 +               \end{array} \right.\\
    7.35 + u_R(h)&=\left\{\begin{array}{l l}
    7.36 +  2, &\text{falls } h\in\{\langle r,b,b\rangle,\langle e,b,b\rangle\}\\
    7.37 +  1, &\text{falls } h\in\{\langle r,h,h\rangle,\langle e,h,h\rangle\}\\
    7.38 +  0, &\text{sonst}\\
    7.39 +             \end{array} \right.\\
    7.40 + u_E(h)&=u_K(h)=\left\{\begin{array}{l l}
    7.41 +  2, &\text{falls } h\in\{\langle r,h,h\rangle,\langle e,h,h\rangle\}\\
    7.42 +  1, &\text{falls } h\in\{\langle r,b,b\rangle,\langle e,b,b\rangle\}\\
    7.43 +  0, &\text{sonst}\\
    7.44 +             \end{array} \right.\\
    7.45 +\end{align*}
    7.46 +Der Spielbaum ist in Abbildung 1 zu sehen.
    7.47 +\begin{figure}[h]
    7.48 +\centering
    7.49 +\tikzstyle{var}=[circle,
    7.50 +  draw=black!100,
    7.51 +  fill=black!0]
    7.52 +\begin{tikzpicture}[>=latex,text height=1.5ex,text depth=0.25ex]
    7.53 +  \matrix[row sep=1.1cm,column sep=0.7cm] {    
    7.54 +    \node(eng)[var]{$eng$}; &\node(spa)[var]{$spa$}; &\node(ukr)[var]{$ukr$}; &\node(nor)[var]{$nor$}; &\node(jap)[var]{$jap$};\\
    7.55 +  \node(red)[var]{$red$}; &\node(gre)[var]{$gre$}; &\node(ivo)[var]{$ivo$}; &\node(yel)[var]{$yel$}; &\node(blu)[var]{$blu$};\\
    7.56 +  \node(dog)[var]{$dog$}; &\node(sna)[var]{$sna$}; &\node(fox)[var]{$fox$}; &\node(hor)[var]{$hor$}; &\node(zeb)[var]{$zeb$};\\
    7.57 +  \node(cof)[var]{$cof$}; &\node(tea)[var]{$tea$}; &\node(mil)[var]{$mil$}; &\node(jui)[var]{$jui$}; &\node(wat)[var]{$wat$};\\
    7.58 +  \node(old)[var]{$old$}; &\node(koo)[var]{$koo$}; &\node(che)[var]{$che$}; &\node(luc)[var]{$luc$}; &\node(par)[var]{$par$};\\
    7.59 +  };
    7.60 +  \path[-]
    7.61 +  (eng) edge (red)
    7.62 +  (spa) edge[bend right=60] (dog)
    7.63 +  (cof) edge (gre)
    7.64 +  (ukr) edge (tea)
    7.65 +  (old) edge (sna)
    7.66 +  (koo) edge (yel)
    7.67 +  (luc) edge (jui)
    7.68 +  (jap) edge[bend left] (par)
    7.69 +  (che) edge[bend left] (fox)
    7.70 +  (yel) edge (hor)
    7.71 +  (nor) edge (blu)
    7.72 +  (gre) edge (ivo)
    7.73 +
    7.74 +  (eng) edge (spa)
    7.75 +  (eng) edge[bend left] (ukr)
    7.76 +  (eng) edge[bend left] (nor)
    7.77 +  (eng) edge[bend left] (jap)
    7.78 +  (spa) edge (ukr)
    7.79 +  (spa) edge[bend right] (nor)
    7.80 +  (spa) edge[bend right] (jap)
    7.81 +  (ukr) edge (nor)
    7.82 +  (ukr) edge[bend left] (jap)
    7.83 +  (nor) edge (jap)
    7.84 +
    7.85 +  (red) edge (gre)
    7.86 +  (red) edge[bend left] (ivo)
    7.87 +  (red) edge[bend left] (yel)
    7.88 +  (red) edge[bend left] (blu)
    7.89 +  (gre) edge (ivo)
    7.90 +  (gre) edge[bend right] (yel)
    7.91 +  (gre) edge[bend right] (blu)
    7.92 +  (ivo) edge (yel)
    7.93 +  (ivo) edge[bend left] (blu)
    7.94 +  (yel) edge (blu)
    7.95 +  
    7.96 +  (dog) edge (sna)
    7.97 +  (dog) edge[bend left] (fox)
    7.98 +  (dog) edge[bend left] (hor)
    7.99 +  (dog) edge[bend left] (zeb)
   7.100 +  (sna) edge (fox)
   7.101 +  (sna) edge[bend right] (hor)
   7.102 +  (sna) edge[bend right] (zeb)
   7.103 +  (fox) edge (hor)
   7.104 +  (fox) edge[bend left] (zeb)
   7.105 +  (hor) edge (zeb)
   7.106 +
   7.107 +  (cof) edge (tea)
   7.108 +  (cof) edge[bend left] (mil)
   7.109 +  (cof) edge[bend left] (jui)
   7.110 +  (cof) edge[bend left] (wat)
   7.111 +  (tea) edge (mil)
   7.112 +  (tea) edge[bend right] (jui)
   7.113 +  (tea) edge[bend right] (wat)
   7.114 +  (mil) edge (jui)
   7.115 +  (mil) edge[bend left] (wat)
   7.116 +  (jui) edge (wat)
   7.117 +
   7.118 +  (old) edge (koo)
   7.119 +  (old) edge[bend left] (che)
   7.120 +  (old) edge[bend left] (luc)
   7.121 +  (old) edge[bend left] (par)
   7.122 +  (koo) edge (che)
   7.123 +  (koo) edge[bend right] (luc)
   7.124 +  (koo) edge[bend right] (par)
   7.125 +  (che) edge (luc)
   7.126 +  (che) edge[bend left] (par)
   7.127 +  (luc) edge (par)
   7.128 +  ;      
   7.129 +\end{tikzpicture}
   7.130 +\caption{(3.1b) primal constraint graph of $N$}
   7.131 +\end{figure}\\
   7.132 +
   7.133 +(b) Die Strategien f\"ur Spieler $R$ sind $bbb$, $bbh$, $bhb$, $bhh$, $hbb$, $hbh$, $hhb$ und $hhh$.\\\\
   7.134 +(c) Wir geben die Profile als Tupel in der Form $(s_R,s_E,s_K)$, wobei die $s_i$ jeweils die Folge von Aktionen f\"ur Spieler $i$ sind. Analog fassen wir die Auszahlungen in dem Tupel $u(h)=(u_R(h),u_E(h),u_K(h))$ zusammen. Um zu zeigen, dass Aktionsprofil $s^*=(bbb,hbh,r)$ ein TPG ist, reicht es dessen Auszahlung mit derer zu vergleichen, die f\"ur einen Spieler in einer Aktion abweichen.
   7.135 +
   7.136 +Wir untersuchen nun alle solche Aktionsprofile, ber\"ucksichtigen dabei jedoch nur solche, die zu einer anderen Auszahlung f\"uhren, d.h. die abweichende Aktion liegt tats\"achlich in dem Ergebnis.
   7.137 +
   7.138 +Das Ergebnis $O(s^*)=\langle r,b,b\rangle$ hat die Auszahlungen $u_R(\langle r,b,b\rangle)=2$ und $u_E(\langle r,b,b\rangle)=u_K(\langle r,b,b\rangle)=1$, also $u(O(s^*))=(2,1,1)=u^*$. Wir betrachten nun alle relevanten, abweichenden Aktionsprofile und deren Auszahlungen.
   7.139 +
   7.140 +Spieler $R$ kann in $h=\langle r \rangle$ von Aktion $b$ auf $h$ abweichen, was zu dem Aktionsprofil $(hbb,hbh,r)$, dem Ergebnis $O((hbb,hbh,r))=\langle r,h,h\rangle$ und der Auszahlung $u_R(\langle r,h,h\rangle)=1$ f\"uhrt. Wir sehen, dass diese Auszahlung geringer ist, als in $u^*$.
   7.141 +
   7.142 +Spieler $E$ kann in $h=\langle r,b\rangle$ von Aktion $b$ auf $h$ abweichen, was zu dem Aktionsprofil $(bbb,hhh,r)$, dem Ergebnis $O((bbb,hhh,r))=\langle r,b,h\rangle$ und der Auszahlung $u_E(\langle r,b,h\rangle)=0$ f\"uhrt. Wir sehen, dass diese Auszahlung geringer ist, als in $u^*$.
   7.143 +
   7.144 +Spieler $K$ kann in $h=\langle \rangle$ von Aktion $r$ auf $e$ abweichen, was zu dem Aktionsprofil $(bbb,hbh,e)$, dem Ergebnis $O((bbb,hbh,e))=\langle e,h,b\rangle$ und der Auszahlung $u_K(\langle e,h,b\rangle)=0$ f\"uhrt. Wir sehen, dass diese Auszahlung geringer ist, als in $u^*$.
   7.145 +
   7.146 +Daraus folgt, dass $s^*=(bbb,hbh,r)$ ein TPG ist.
   7.147  \end{document}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/exercises/solutions/tikz-qtree-compat.sty	Sun Jun 03 20:15:28 2012 +0200
     8.3 @@ -0,0 +1,72 @@
     8.4 +%    tikz-qtree-compat.tex
     8.5 +%    Version 1.1, 25 Dec 2009
     8.6 +
     8.7 +\RequirePackage{tikz-qtree}
     8.8 +
     8.9 +\let\orig@Tree\Tree
    8.10 +\def\Tree{\automath \qtreeprimes@internal \orig@Tree}
    8.11 +
    8.12 +\def\qsetw#1{\message{\noexpand\qsetw is not supported, sorry!}}
    8.13 +\def\faketreewidth#1{\message{\noexpand\faketreewidth is not supported, sorry!}}
    8.14 +\def\qbalance{\message{\noexpand\qbalance is not supported, sorry!}}
    8.15 +\def\qframesubtree{\message{\noexpand\qframesubtree is not supported, sorry!}}
    8.16 +
    8.17 +% Implement \qroof as a fancy leaf node
    8.18 +\newtoks\@qrooflabel
    8.19 +
    8.20 +\def\qroof#1.{%
    8.21 +\begin{tikzpicture}[baseline]
    8.22 +{\pgftransformshift{\pgftree@levelshift}%
    8.23 +\node(qroofbot){#1};}
    8.24 +\@qroof
    8.25 +}
    8.26 +\def\@qroof{\@ifnextchar\egroup{%
    8.27 +% since we are putting the qroof inside a node, we already have an inner sep
    8.28 +% so for the purposes of defining our bounding box, we must eliminate inner sep
    8.29 +\begin{pgfsubpicture}
    8.30 +\node [inner sep=0pt] {\the\@qrooflabel};% 
    8.31 +\end{pgfsubpicture}
    8.32 +\pgfpathrectanglecorners{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}{\pgfpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
    8.33 +\pgfusepath{use as bounding box}%
    8.34 +\node (qrooftop) {\the\@qrooflabel};
    8.35 +\draw \roof@edge{qrooftop}{qroofbot};%
    8.36 +\end{tikzpicture}}
    8.37 +{\@@qroof}}
    8.38 +\def\@@qroof#1{\expandafter\@qrooflabel\expandafter{\the\@qrooflabel #1}\@qroof}
    8.39 +
    8.40 +%%% This is lifted straight from qtree.sty
    8.41 +
    8.42 +% and another odd convenience:
    8.43 +%
    8.44 +% Make _, ^ go into math mode automatically in the scope of \automath
    8.45 +%
    8.46 +{ % Temporarily change catcodes 
    8.47 +\catcode`\_=\active
    8.48 +\catcode`\^=\active
    8.49 +
    8.50 +  \global\def\automath{%
    8.51 +    \catcode`\_=\active
    8.52 +    \catcode`\^=\active
    8.53 +    \def_##1{\@ifnextchar^{\automath@two_{##1}}{\ensuremath{\sb{##1}}}}%
    8.54 +    \def^##1{\@ifnextchar_{\automath@two^{##1}}{\ensuremath{\sp{##1}}}}}
    8.55 +}
    8.56 +\def\automath@two#1#2#3#4{\ensuremath{#1{#2}\relax #3{#4}}}
    8.57 +% Restore default catcodes for ^, _
    8.58 +\def\noautomath{\catcode`\_=8 \catcode`\^=7 }
    8.59 +
    8.60 +
    8.61 +% Let \0, \1, \2 produce ^0, $'$, $''$
    8.62 +% The \rlap results in better centering of the label (ignoring the
    8.63 +%  superscript)
    8.64 +\def\qtreeprimes@internal{%
    8.65 +  \def\0{\ifmmode ^0\else \rlap{$^0$}\fi}%
    8.66 +  \def\1{\ifmmode '\else \rlap{$'$}\fi}%
    8.67 +  \def\2{\ifmmode ''\else \rlap{$''$}\fi}%
    8.68 +}
    8.69 +
    8.70 +% Same commands, but without the \rlap feature
    8.71 +\def\qtreeprimes{%
    8.72 +  \def\0{\ensuremath{^0}}%
    8.73 +  \def\1{\ensuremath{'}}%
    8.74 +  \def\2{\ensuremath{''}}}
    8.75 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/exercises/solutions/tikz-qtree-manual.tex	Sun Jun 03 20:15:28 2012 +0200
     9.3 @@ -0,0 +1,392 @@
     9.4 +\documentclass{article}
     9.5 +
     9.6 +\usepackage{xltxtra,fontspec}
     9.7 +
     9.8 +\iffalse
     9.9 +\setmainfont[Mapping=tex-text]{DejaVu Serif}
    9.10 +\setmonofont[Scale=0.95]{DejaVu Sans Mono}
    9.11 +\newfontfamily\verbfont[Scale=0.8]{DejaVu Sans Mono}
    9.12 +\newfontfamily\ar[Script=Arabic]{DejaVu Sans}
    9.13 +\newfontfamily\ja{VL Gothic}
    9.14 +\newfontfamily\javerbfont[Scale=0.85,LetterSpace=5.0]{VL Gothic}
    9.15 +\fi
    9.16 +
    9.17 +\iftrue
    9.18 +\setmainfont[Mapping=tex-text]{DejaVu Serif}
    9.19 +\setmonofont[Scale=0.95]{DejaVu Sans Mono}
    9.20 +\newfontfamily\verbfont[Scale=0.8]{DejaVu Sans Mono}
    9.21 +\newfontfamily\ar[Script=Arabic]{DejaVu Sans}
    9.22 +\newfontfamily\ja{Hiragino Maru Gothic Pro}
    9.23 +\newfontfamily\javerbfont[Scale=0.85,LetterSpace=5.0]{Hiragino Maru Gothic Pro}
    9.24 +\fi
    9.25 +
    9.26 +\usepackage{tikz}
    9.27 +\usepackage{tikz-qtree}
    9.28 +
    9.29 +\usepackage{fullpage}
    9.30 +
    9.31 +\usepackage{fancyvrb,fvrb-ex}
    9.32 +\fvset{gobble=0,xleftmargin=0.5in,xrightmargin=2.75in,formatcom=\verbfont}
    9.33 +\VerbatimFootnotes
    9.34 +
    9.35 +\newcommand\tikztree{\texttt{tikz-qtree}}
    9.36 +
    9.37 +\tikzset{>=latex}
    9.38 +
    9.39 +\title{\tikztree: better trees with TikZ}
    9.40 +\author{David Chiang}
    9.41 +\date{Version 1.11 (Christmas 2010)}
    9.42 +
    9.43 +\begin{document}
    9.44 +
    9.45 +\maketitle
    9.46 +
    9.47 +The \tikztree{} package provides a macro for drawing trees with
    9.48 +TikZ\footnote{\texttt{http://sourceforge.net/projects/pgf/}} using the
    9.49 +easy syntax of Alexis Dimitriadis'
    9.50 +Qtree\footnote{\texttt{http://www.ling.upenn.edu/advice/latex/qtree/}}. It
    9.51 +improves on TikZ's standard tree-drawing facility by laying out tree
    9.52 +nodes without collisions; it improves on Qtree by adding lots of
    9.53 +features from TikZ; and it improves on \verb|pst-qtree| in being
    9.54 +usable with pdf\TeX{} and
    9.55 +\XeTeX{}.\footnote{Although \XeTeX{} works with \verb|pst-qtree| using the \verb|xetex-pstricks| package. For typesetting very large trees or a large number of trees, this may be the better option.}
    9.56 +
    9.57 +\section{Basics}
    9.58 +
    9.59 +To load the package in \LaTeX{}:
    9.60 +\begin{Verbatim}
    9.61 +\usepackage{tikz}
    9.62 +\usepackage{tikz-qtree}
    9.63 +\end{Verbatim}
    9.64 +%
    9.65 +The simplest usage is identical to Qtree:
    9.66 +\begin{center}
    9.67 +\begin{SideBySideExample}
    9.68 +\Tree [.S [.NP [.Det the ] [.N cat ] ] 
    9.69 +          [.VP [.V sat ] 
    9.70 +               [.PP [.P on ] 
    9.71 +                    [.NP [.Det the ] [.N mat ] ] ] ] ]
    9.72 +\end{SideBySideExample}
    9.73 +\end{center}
    9.74 +Subtrees are delimited by square brackets. A subtree's root label is
    9.75 +joined by a dot (\verb|.|) to its opening bracket.\footnote{You can
    9.76 +also write the label after the closing bracket instead of the opening
    9.77 +bracket, or both, or neither. Please see the Qtree documentation for
    9.78 +details.} As in Qtree, spaces are required after every (internal or
    9.79 +leaf) node label. 
    9.80 +
    9.81 +\verb|\Tree| works inside or outside a
    9.82 +\verb|tikzpicture| environment, but many of the features described 
    9.83 +below require the explicit \verb|tikzpicture| environment.
    9.84 +
    9.85 +\goodbreak
    9.86 +
    9.87 +\paragraph{Options} Some options for standard TikZ trees work for \verb|\Tree| as
    9.88 +well:
    9.89 +\begin{itemize}
    9.90 +\item \verb|level distance|: vertical distance between the anchors of a parent and its children
    9.91 +\item \verb|sibling distance|: horizontal distance between the boundaries of sister subtrees (not the anchors of their roots, as in standard TikZ trees). Note that TikZ nodes already have some horizontal space around them (\verb|inner xsep|, by default \verb|0.3333em|), so even \verb|sibling distance=0pt| leaves some room.
    9.92 +\end{itemize}
    9.93 +These are set either by writing
    9.94 +\verb|\tikzset{|\textit{option}\verb|=|\textit{value}\verb|}| or by
    9.95 +writing \verb|[|\textit{option}\verb|=|\textit{value}\verb|]| after a
    9.96 +\verb|\begin{tikzpicture}| or \verb|\begin{scope}|.\footnote{Allowing
    9.97 +options after \verb|\Tree| would have made sense, but there would be
    9.98 +no way to disambiguate the two uses of square brackets.} For example:
    9.99 +
   9.100 +\begin{center}
   9.101 +\begin{SideBySideExample}
   9.102 +\begin{tikzpicture}
   9.103 +\tikzset{level distance=72pt}
   9.104 +\Tree [.NP [.Adj tall ] [.N tree ] ]
   9.105 +\end{tikzpicture}
   9.106 +%
   9.107 +\begin{tikzpicture}[sibling distance=72pt]
   9.108 +\Tree [.NP [.Adj fat ] [.N tree ] ]
   9.109 +\end{tikzpicture}
   9.110 +\end{SideBySideExample}
   9.111 +\end{center}
   9.112 +
   9.113 +The \verb|grow=|\textit{direction}\/ and \verb|grow'=|\textit{direction}\/ options control the orientation of trees just as for standard TikZ trees. However, \textit{direction}\/ must be one of \verb|up|, \verb|down|, \verb|left|, or \verb|right|. The difference between \verb|grow| and \verb|grow'| is that \verb|grow| places children counterclockwise with respect to their parent and \verb|grow'| places them clockwise:
   9.114 +\begin{center}
   9.115 +\begin{SideBySideExample}
   9.116 +\begin{tikzpicture}[grow'=down]
   9.117 +\Tree [.NP [.Adj reverse ] [.N tree ] ]
   9.118 +\end{tikzpicture}
   9.119 +%
   9.120 +\begin{tikzpicture}[grow'=up]
   9.121 +\Tree [.NP [.Adj upside-down ] [.N tree ] ]
   9.122 +\end{tikzpicture}
   9.123 +\end{SideBySideExample}
   9.124 +\vspace{3ex}
   9.125 +\begin{SideBySideExample}
   9.126 +\begin{tikzpicture}[grow=left]
   9.127 +\tikzset{level distance=60pt,sibling distance=18pt}
   9.128 +\tikzset{execute at begin node=\strut}
   9.129 +\Tree [.NP [.Adj sideways ] [.N tree ] ]
   9.130 +\end{tikzpicture}
   9.131 +\end{SideBySideExample}
   9.132 +\end{center}
   9.133 +Note that in sideways trees, \verb|level distance| is horizontal and \verb|sibling distance| is vertical. Sideways trees do take a little extra adjusting to look right, since the defaults are geared towards vertically growing trees. The meaning of the option \verb|execute at begin node=\strut| is, before typesetting the label of every node, insert the command \verb|\strut|, which is an invisible box that maximizes the height and depth of the node.
   9.134 +
   9.135 +\paragraph{Styles} TikZ lets you define \emph{styles}\/ which encapsulate multiple options:
   9.136 +\begin{Verbatim}
   9.137 +\tikzset{small/.style={level distance=20pt,sibling distance=0pt}}
   9.138 +\end{Verbatim}
   9.139 +Then the option \verb|small| causes the options in its definition to be used:
   9.140 +\begin{center}
   9.141 +\tikzset{small/.style={level distance=20pt,sibling distance=0pt}}
   9.142 +\begin{SideBySideExample}
   9.143 +\begin{tikzpicture}[small]
   9.144 +\Tree [.NP [.Adj small ] [.N tree ] ]
   9.145 +\end{tikzpicture}
   9.146 +%
   9.147 +\begin{tikzpicture}
   9.148 +\Tree [.NP [.Adj normal ] [.N tree ] ]
   9.149 +\end{tikzpicture}
   9.150 +\end{SideBySideExample}
   9.151 +\end{center}
   9.152 +The following TikZ styles are automatically applied inside trees,
   9.153 +providing a hook for you to change the appearance of particular kinds
   9.154 +of tree parts:
   9.155 +\begin{itemize}
   9.156 +\item \verb|every tree node| to every (internal and leaf) node (default: \verb|anchor=base|)
   9.157 +\item \verb|every internal node| to every internal node
   9.158 +\item \verb|every leaf node| to every leaf node
   9.159 +\item \verb|edge from parent| to every edge (default: \verb|draw|)
   9.160 +\end{itemize}
   9.161 +
   9.162 +The options for nodes and edges are all handled by TikZ and are
   9.163 +described in detail in the TikZ documentation. For example, if you
   9.164 +have a font named \verb|\ar| and want to set all the leaf labels in
   9.165 +this font:
   9.166 +\begin{center}
   9.167 +\begin{SideBySideExample}
   9.168 +\begin{tikzpicture}
   9.169 +\tikzset{grow'=down}
   9.170 +\tikzset{every leaf node/.style={font=\ar}}
   9.171 +\Tree [.S [.NP القط ] 
   9.172 +          [.VP [.V وجلس ] 
   9.173 +               [.PP [.P على ] [.NP حصيرة ] ] ] ]
   9.174 +\end{tikzpicture}
   9.175 +\end{SideBySideExample}
   9.176 +\end{center}
   9.177 +
   9.178 +You can make the nodes in a sideways tree line up on their left edge using \verb|anchor=base west|:
   9.179 +\begin{center}
   9.180 +\begin{SideBySideExample}
   9.181 +\begin{tikzpicture}
   9.182 +\tikzset{grow'=right,level distance=32pt}
   9.183 +\tikzset{execute at begin node=\strut}
   9.184 +\tikzset{every tree node/.style={anchor=base west}}
   9.185 +\Tree [.S [.NP [.Det the ] [.N cat ] ] 
   9.186 +          [.VP [.V sat ] 
   9.187 +               [.PP [.P on ] 
   9.188 +                    [.NP [.Det the ] [.N mat ] ] ] ] ]
   9.189 +\end{tikzpicture}                    
   9.190 +\end{SideBySideExample}
   9.191 +\end{center}
   9.192 +
   9.193 +In Qtree, it was allowed to use a line break (\verb|\\|) inside a node. TikZ nodes by default don't allow this, but the \verb|align| option (in PGF/TikZ version 2.1 or later) enables it as a side effect:\footnote{Thanks to Alan Munn for figuring this out. Prior to PGF/TikZ version 2.1, the fix was to use the options \verb|text width=2em,text centered|.}
   9.194 +\begin{center}
   9.195 +\begin{SideBySideExample}
   9.196 +\begin{tikzpicture}
   9.197 +\tikzset{every tree node/.style={align=center,anchor=north}}
   9.198 +\Tree [.S [.NP Det\\the N\\cat ]
   9.199 +          [.VP V\\sat
   9.200 +               [.PP P\\on
   9.201 +                    [.NP Det\\the N\\mat ] ] ] ]
   9.202 +\end{tikzpicture}
   9.203 +\end{SideBySideExample}
   9.204 +\end{center}
   9.205 +
   9.206 +You can also define a style for all the edges in a tree. For example, if you want the edges to be a little darker:
   9.207 +\begin{center}
   9.208 +\begin{SideBySideExample}
   9.209 +\begin{tikzpicture}
   9.210 +\tikzset{edge from parent/.style={draw,thick}}
   9.211 +\Tree [.S [.NP [.Det the ] [.N cat ] ] 
   9.212 +          [.VP [.V sat ] 
   9.213 +               [.PP [.P on ] 
   9.214 +                    [.NP [.Det the ] [.N mat ] ] ] ] ]
   9.215 +\end{tikzpicture}
   9.216 +\end{SideBySideExample}
   9.217 +\end{center}
   9.218 +The \verb|draw| option is necessary, as by default they will not be
   9.219 +drawn. As a more complex example, edges have an
   9.220 +\verb|edge from parent path| option which lets you change the shape of
   9.221 +the edge. Its value is a TikZ path expressed in terms of
   9.222 +\verb|\tikzparentnode|, the parent node, and \verb|\tikzchildnode|,
   9.223 +the child node.
   9.224 +\begin{center}
   9.225 +\begin{SideBySideExample}
   9.226 +\begin{tikzpicture}
   9.227 +\tikzset{edge from parent/.style=
   9.228 +  {draw,
   9.229 +   edge from parent path={(\tikzparentnode.south) 
   9.230 +                          -- +(0,-8pt) 
   9.231 +                          -| (\tikzchildnode)}}} 
   9.232 +\Tree [.S [.NP [.Det the ] [.N cat ] ] 
   9.233 +          [.VP [.V sat ] 
   9.234 +               [.PP [.P on ] 
   9.235 +                    [.NP [.Det the ] [.N mat ] ] ] ] ]
   9.236 +\end{tikzpicture}                    
   9.237 +\end{SideBySideExample}
   9.238 +\end{center}
   9.239 +
   9.240 +\clearpage
   9.241 +
   9.242 +\section{Embedding TikZ nodes}
   9.243 +
   9.244 +Inside a \verb|\Tree|, in place of a node label, you can use a TikZ
   9.245 +\verb|\node| command.\footnote{\verb|\Tree| specifically watches out
   9.246 +for the token \verb|\node|; do not use \verb|\path node| or other
   9.247 +equivalents.}
   9.248 +\begin{quote}
   9.249 +\verb|\node [|\textit{options}\verb|] (|\textit{name}\verb|) {|\textit{label}\verb|};|
   9.250 +\end{quote}
   9.251 +Don't forget the terminating semicolon. The
   9.252 +\verb|[|\textit{options}\verb|]|, which are optional, let you change
   9.253 +the appearance of the node; for example, the \verb|draw| option draws
   9.254 +a border around the node. The \verb|(|\textit{name}\verb|)|, which is
   9.255 +also optional, can be used for drawing lines/arrows to/from the node.
   9.256 +\begin{center}
   9.257 +\begin{Example}
   9.258 +\begin{tikzpicture}
   9.259 +\Tree [.CP [.NP \node(wh){what}; ] 
   9.260 +           [.C$'$ [.I did ] 
   9.261 +                  [.\node[draw]{IP}; 
   9.262 +                    [.NP [.Det the ] [.N cat ] ]
   9.263 +                    [.VP [.V sit ] 
   9.264 +                         [.PP [.P on ] 
   9.265 +                              [.\node[draw]{NP}; 
   9.266 +                                [.NP [.Det a ] [.N book ] ] 
   9.267 +                                [.PP [.P about ] [.NP \node(t){$t$}; ] ] ] ] ] ] ] ]
   9.268 +\draw[semithick,->] (t)..controls +(south west:5) and +(south:5) .. (wh);
   9.269 +\end{tikzpicture}
   9.270 +\end{Example}
   9.271 +\end{center}
   9.272 +
   9.273 +You can also refer to the whole subtree rooted at the node named \textit{name}\/ using \verb|\subtreeof{|\textit{name}\verb|}|:
   9.274 +\begin{center}
   9.275 +\begin{SideBySideExample}
   9.276 +\begin{tikzpicture}
   9.277 +\Tree [.S [.NP [.Det the ] [.N cat ] ] 
   9.278 +          [.\node(site){VP}; [.V sat ] ] ]
   9.279 +\begin{scope}[shift={(1in,0.5in)}]
   9.280 +\Tree [.\node(root){VP}; VP$^\ast$
   9.281 +                         [.PP [.P on ] 
   9.282 +                              [.NP [.Det the ] [.N mat ] ] ] ]
   9.283 +
   9.284 +\end{scope}
   9.285 +
   9.286 +\draw[->](\subtreeof{root}.140) .. 
   9.287 +  controls +(west:1) and +(east:1) .. (site);
   9.288 +
   9.289 +\end{tikzpicture}
   9.290 +\end{SideBySideExample}
   9.291 +\end{center}
   9.292 +
   9.293 +\noindent Another example for machine translation people:
   9.294 +\begin{center}
   9.295 +\fvset{formatcom=\javerbfont}
   9.296 +\begin{SideBySideExample}
   9.297 +\begin{tikzpicture}
   9.298 +\Tree [.S [.NP [.Det \node(e1){the}; ] 
   9.299 +               [.N \node(e2){cat}; ] ] 
   9.300 +          [.VP [.V \node(e3){sat}; ] 
   9.301 +               [.PP [.P \node(e4){on}; ] 
   9.302 +                    [.NP [.Det \node(e5){the}; ] 
   9.303 +                         [.N \node(e6){mat}; ] ] ] ] ]
   9.304 +
   9.305 +\begin{scope}[yshift=-5in,grow'=up]
   9.306 +\tikzset{every leaf node/.style={font=\ja}}
   9.307 +\Tree [.S [.NP \node(j1){猫が}; ] 
   9.308 +          [.VP [.PP [.NP [.NP \node(j2){マット}; ] 
   9.309 +                         [.Part \node(j3){の}; ]
   9.310 +                         [.NP \node(j4){上}; ] ] 
   9.311 +                    [.P \node(j5){に}; ] ] 
   9.312 +               [.V \node(j6){土}; ] ] ]
   9.313 +\end{scope}
   9.314 +
   9.315 +\begin{scope}[dashed]
   9.316 +\draw (e1)--(j1);
   9.317 +\draw (e2)--(j1);
   9.318 +\draw (e3)..controls +(south:5) and +(north:4)..(j6);
   9.319 +\draw (e4)--(j4);
   9.320 +\draw (e4)--(j5);
   9.321 +\draw (e5)--(j2);
   9.322 +\draw (e6)--(j2);
   9.323 +\end{scope}
   9.324 +
   9.325 +\end{tikzpicture}
   9.326 +\end{SideBySideExample}
   9.327 +\end{center}
   9.328 +
   9.329 +\section{Explicit edges}
   9.330 +
   9.331 +The edge from a parent to a child node is normally automatically drawn
   9.332 +for you, but you can do it yourself with an \verb|\edge| command
   9.333 +\emph{before}\/ the corresponding child node. It is similar to the
   9.334 +TikZ \verb|edge from parent| command.\footnote{Except that a TikZ
   9.335 +\texttt{edge from parent} comes after the child node. I thought it was
   9.336 +more logical to put it before.}
   9.337 +\begin{quote}
   9.338 +\verb|\edge [|\textit{options}\verb|];|
   9.339 +\end{quote}
   9.340 +Again, don't forget the semicolon. The
   9.341 +\verb|[|\textit{options}\verb|]|, which are optional, let you change
   9.342 +the appearance of the edge. You can also add an edge label:
   9.343 +\begin{quote}
   9.344 +\verb|\edge [|\textit{options}\verb|] node [|\textit{options}\verb|] {|\textit{label}\verb|};|
   9.345 +\end{quote}
   9.346 +Typically one will use the \verb|auto| option for edge labels, which
   9.347 +places the label to the side of the edge.
   9.348 +\begin{center}
   9.349 +\begin{SideBySideExample}[xrightmargin=1.25in]
   9.350 +\newcommand{\initial}[1]{\ensuremath{\alpha_{\textrm{\scriptsize #1}}}}
   9.351 +\newcommand{\auxiliary}[1]{\ensuremath{\beta_{\textrm{\scriptsize #1}}}}
   9.352 +
   9.353 +\begin{tikzpicture}[level distance=36pt,sibling distance=12pt]
   9.354 +\Tree [.\initial{sat} 
   9.355 +        \edge node[auto=right]{1}; \initial{cat} 
   9.356 +        \edge[dashed] node[auto=left]{2}; 
   9.357 +        [.\auxiliary{on} 
   9.358 +          \edge node[auto=left]{2}; \initial{mat} ] ]
   9.359 +\end{tikzpicture}
   9.360 +\end{SideBySideExample}
   9.361 +\end{center}
   9.362 +The fact that \verb|auto=left| draws a label on the right and
   9.363 +\verb|auto=right| draws a label on the left makes sense if you think
   9.364 +about the tree growing from the root to the leaves.
   9.365 +
   9.366 +There is a predefined style that draws a ``roof'' over a node, like Qtree's \verb|\qroof|:
   9.367 +\begin{center}
   9.368 +\begin{Example}
   9.369 +\begin{tikzpicture}[level distance=36pt]
   9.370 +\Tree [.S [.NP [.N this ] ] 
   9.371 +          [.VP [.V is ] 
   9.372 +               [.NP \edge[roof]; {a noun phrase 
   9.373 +                                  the complexity of which 
   9.374 +                                  is too great for me to parse} ] ] ]
   9.375 +\end{tikzpicture}
   9.376 +\end{Example}
   9.377 +\end{center}
   9.378 +
   9.379 +\section{Qtree compatibility}
   9.380 +
   9.381 +For basic trees, \tikztree{} can be used as a drop-in replacement for Qtree, but most of Qtree's advanced features are either not accessed in the same way in \tikztree{} or not implemented at all. There is a package \verb|tikz-qtree-compat| which can be loaded to improve compatibility. Supported so far are:
   9.382 +\begin{itemize}
   9.383 +\item Superscripts and subscripts outside of math mode, and \verb|\automath|
   9.384 +\item The \verb|\0|, \verb|\1|, and \verb|\2| commands, and \verb|\qtreeprimes|
   9.385 +\item The \verb|\qroof| command
   9.386 +\end{itemize}
   9.387 +For unsupported commands, warning messages are printed, but at least your file should compile.
   9.388 +
   9.389 +\section*{Acknowledgements}
   9.390 +This was all Dan Gildea's idea. Thanks to Alan Munn for his very helpful suggestions.
   9.391 +
   9.392 +\section*{Contact}
   9.393 +Please send suggestions to \verb|chiang@isi.edu|.
   9.394 +
   9.395 +\end{document}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/exercises/solutions/tikz-qtree.sty	Sun Jun 03 20:15:28 2012 +0200
    10.3 @@ -0,0 +1,4 @@
    10.4 +\RequirePackage{tikz}
    10.5 +\RequirePackage{pgftree}
    10.6 +\input{tikz-qtree.tex}
    10.7 +\endinput
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/exercises/solutions/tikz-qtree.tex	Sun Jun 03 20:15:28 2012 +0200
    11.3 @@ -0,0 +1,181 @@
    11.4 +%    tikz-qtree.tex
    11.5 +%    Version 1.11, 25 Dec 2010
    11.6 +
    11.7 +%    Copyright (C) 2002, 2009 by David Chiang
    11.8 +
    11.9 +%    This program is free software; you can redistribute it and/or modify
   11.10 +%    it under the terms of the GNU General Public License as published by
   11.11 +%    the Free Software Foundation; either version 2 of the License, or
   11.12 +%    (at your option) any later version.
   11.13 +
   11.14 +%    This program is distributed in the hope that it will be useful,
   11.15 +%    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.16 +%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.17 +%    GNU General Public License for more details.
   11.18 +
   11.19 +%    You should have received a copy of the GNU General Public License along
   11.20 +%    with this program; if not, write to the Free Software Foundation, Inc.,
   11.21 +%    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   11.22 +
   11.23 +% New in version 1.11:
   11.24 +% - make options compatible with standard tikz trees
   11.25 +
   11.26 +% New in version 1.1:
   11.27 +
   11.28 +% - sideways trees
   11.29 +
   11.30 +%% These macros facilitate building up an object recursively before
   11.31 +%% putting it into the input stream.
   11.32 +
   11.33 +\newtoks\@result
   11.34 +\def\@call#1#2{\let\@cont=#2\bgroup\@result={}#1}
   11.35 +\def\@return{\global\@result=\@result\egroup\@cont}
   11.36 +
   11.37 +\def\@ifequal#1#2{\edef\testa{#1}\edef\testb{#2}\ifx\testa\testb}
   11.38 +
   11.39 +%% scan a tree: this just scans a subtree and then puts it onto the
   11.40 +%% input stream
   11.41 +
   11.42 +\def\Tree{\@call\@subtree\@Tree}
   11.43 +\def\@Tree{%
   11.44 +%\showthe\@result %debug
   11.45 +\ifpgfpicture % is there a test for tikzpicture?
   11.46 +\pgftree{\the\@result}%
   11.47 +\else
   11.48 +\tikzpicture[baseline]\pgftree{\the\@result}\endtikzpicture
   11.49 +\fi
   11.50 +}
   11.51 +
   11.52 +%% scan a subtree
   11.53 +\newtoks\child@list
   11.54 +\newtoks\root@node
   11.55 +
   11.56 +\def\@subtree[{%
   11.57 +\root@node={}%
   11.58 +\pgfutil@ifnextchar.{\@call\@interior\@@subtree}{\@@@subtree}}
   11.59 +\def\@@subtree{%
   11.60 +\root@node=\@result
   11.61 +\@@@subtree
   11.62 +}
   11.63 +\def\@@@subtree{%
   11.64 +\@call\@children\@@@@subtree
   11.65 +}
   11.66 +\def\@@@@subtree]{%
   11.67 +\child@list=\@result
   11.68 +\pgfutil@ifnextchar.{\@call\@interior\@@@@@subtree}{\@@@@@@subtree}}
   11.69 +\def\@@@@@subtree{%
   11.70 +%%% Check for mismatch.
   11.71 +\@ifequal{\the\root@node}{\pgfutil@empty}%
   11.72 +  \root@node=\@result
   11.73 +\fi
   11.74 +\@ifequal{\the\root@node}{\the\@result}\else
   11.75 +  \message{Warning: mismatched labels, \the\root@node{} and \the\@result.}%
   11.76 +\fi
   11.77 +\@@@@@@subtree
   11.78 +}
   11.79 +\def\@@@@@@subtree{%
   11.80 +\@ifequal{\the\root@node}{\pgfutil@empty}%
   11.81 +\edef\act{\noexpand\@result={\noexpand\pgfsubtree{\noexpand\path coordinate (\noexpand\nodename);}{\the\child@list}}}%
   11.82 +\else
   11.83 +\edef\act{\noexpand\@result={\noexpand\pgfsubtree{\the\root@node}{\the\child@list}}}%
   11.84 +\fi
   11.85 +\act
   11.86 +\@return}
   11.87 +
   11.88 +%% scan a sequence of subtrees or leaves
   11.89 +
   11.90 +\newif\ifscanned@edge
   11.91 +
   11.92 +\def\@children{%
   11.93 +\scanned@edgefalse
   11.94 +\child@list{}%
   11.95 +\@@children}
   11.96 +\def\@@children{%
   11.97 +\pgfutil@ifnextchar]{\@result\child@list\@return}{% end of children
   11.98 +\pgfutil@ifnextchar\edge{% explicit edge
   11.99 +\ifscanned@edge
  11.100 +\message{Warning: more than one edge given for a single child}\let\next\@@children % ignore
  11.101 +\else
  11.102 +\scanned@edgetrue\let\next\@@@children
  11.103 +\fi
  11.104 +\@call\@edge\next}{%
  11.105 +% else, a real node is next
  11.106 +\ifscanned@edge\else % no explicit edge, supply default
  11.107 +\expandafter\child@list\expandafter{\the\child@list{\edge@adapter{}}}%
  11.108 +\fi
  11.109 +\scanned@edgefalse
  11.110 +\pgfutil@ifnextchar[{\@call\@subtree\@@@children}% subtree
  11.111 +{\@call\@leaf\@@@children}% leaf
  11.112 +}}}
  11.113 +\def\@@@children{%
  11.114 +% wrap child inside curly braces
  11.115 +\expandafter\@result\expandafter{\expandafter{\the\@result}}%
  11.116 +\edef\act{\noexpand\child@list{\the\child@list \the\@result}}\act
  11.117 +\@@children
  11.118 +}
  11.119 +
  11.120 +\def\@interior.{\@result{\node[alias=\nodename][every tree node,every internal node]}\@label}
  11.121 +
  11.122 +\def\@leaf{\@call\@label\@@leaf}
  11.123 +\def\@@leaf{\edef\act{\noexpand\@result{\noexpand\pgfsubtree{\noexpand\node[alias=\noexpand\nodename][every tree node,every leaf node]\the\@result}{}}}\act\@return}
  11.124 +
  11.125 +\def\@edge\edge #1;{%
  11.126 +\@result{\edge@adapter{#1}}%
  11.127 +\@return}
  11.128 +\def\edge@adapter#1{%
  11.129 +\let\tikzparentnode\parentnodename
  11.130 +\let\tikzchildnode\nodename
  11.131 +\path edge from parent #1;%
  11.132 +}
  11.133 +
  11.134 +% a label is either text or PGF/TikZ code starting with \node
  11.135 +\def\@label{\pgfutil@ifnextchar\node{\@litlabel}{\@@label}}
  11.136 +\def\@@label#1 {%
  11.137 +\expandafter\@result\expandafter{\the\@result{#1};}%
  11.138 +\@return}
  11.139 +
  11.140 +% try to copy \node command into \@result without stripping braces
  11.141 +\def\@litlabel\node{\@@litlabel}
  11.142 +\def\@@litlabel{\pgfutil@ifnextchar\bgroup{\@@@litlabel}{\@@@@litlabel}}
  11.143 +\def\@@@litlabel#1{\expandafter\@result\expandafter{\the\@result {#1}}\@@litlabel}
  11.144 +\def\@@@@litlabel#1;{\expandafter\@result\expandafter{\the\@result #1;}\@return}
  11.145 +
  11.146 +% predefined edges
  11.147 +
  11.148 +\def\tree@edge#1#2{(#1.\pgftree@parentanchor) -- (#2.\pgftree@childanchor)}
  11.149 +
  11.150 +\def\roof@edge#1#2{\csname roof@edge@\leveldirection\endcsname{#1}{#2}}
  11.151 +\def\roof@edge@down#1#2{(#1.south) -- (#2.north west) -- (#2.north east) -- cycle}
  11.152 +\def\roof@edge@up#1#2{(#1.north) -- (#2.south west) -- (#2.south east) -- cycle}
  11.153 +\def\roof@edge@left#1#2{(#1.west) -- (#2.north east) -- (#2.south east) -- cycle}
  11.154 +\def\roof@edge@right#1#2{(#1.east) -- (#2.north west) -- (#2.south west) -- cycle}
  11.155 +
  11.156 +%%% Options
  11.157 +\pgfkeysgetvalue{/tikz/level distance/.@cmd}{\orig@leveldistance}
  11.158 +\tikzoption{level distance}{\pgfmathsetlength\levelsep{#1}\orig@leveldistance#1\pgfeov}
  11.159 +\pgfkeysgetvalue{/tikz/sibling distance/.@cmd}{\orig@siblingdistance}
  11.160 +\tikzoption{sibling distance}{\pgfmathsetlength\subtreesep{#1}\orig@siblingdistance#1\pgfeov} % different semantics
  11.161 +
  11.162 +% I don't really like this scheme
  11.163 +\pgfkeysgetvalue{/tikz/grow/.@cmd}{\orig@grow}
  11.164 +\tikzoption{grow}{\csname grow@#1\endcsname\orig@grow#1\pgfeov}
  11.165 +\pgfkeysgetvalue{/tikz/grow'/.@cmd}{\orig@growprime}
  11.166 +\tikzoption{grow'}{\csname growprime@#1\endcsname\orig@growprime#1\pgfeov}
  11.167 +\def\grow@up{\def\leveldirection{up}\def\siblingdirection{left}}
  11.168 +\def\grow@down{\def\leveldirection{down}\def\siblingdirection{right}}
  11.169 +\def\growprime@up{\def\leveldirection{up}\def\siblingdirection{right}}
  11.170 +\def\growprime@down{\def\leveldirection{down}\def\siblingdirection{left}}
  11.171 +\def\grow@left{\def\leveldirection{left}\def\siblingdirection{down}}
  11.172 +\def\grow@right{\def\leveldirection{right}\def\siblingdirection{up}}
  11.173 +\def\growprime@left{\def\leveldirection{left}\def\siblingdirection{up}}
  11.174 +\def\growprime@right{\def\leveldirection{right}\def\siblingdirection{down}}
  11.175 +
  11.176 +% defaults appropriate for linguistic trees
  11.177 +\tikzset{every tree node/.style={anchor=base}}
  11.178 +\tikzset{every leaf node/.style={}}
  11.179 +\tikzset{every internal node/.style={}}
  11.180 +\def\tikz@edge@to@parent@path{\tree@edge{\tikzparentnode}{\tikzchildnode}}
  11.181 +
  11.182 +% predefined roof style
  11.183 +\tikzset{roof/.style={edge from parent path=\roof@edge{\tikzparentnode}{\tikzchildnode}}}
  11.184 +