1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/exercises/solutions/tikz-qtree-compat.sty Sun Jun 03 20:15:28 2012 +0200
1.3 @@ -0,0 +1,72 @@
1.4 +% tikz-qtree-compat.tex
1.5 +% Version 1.1, 25 Dec 2009
1.6 +
1.7 +\RequirePackage{tikz-qtree}
1.8 +
1.9 +\let\orig@Tree\Tree
1.10 +\def\Tree{\automath \qtreeprimes@internal \orig@Tree}
1.11 +
1.12 +\def\qsetw#1{\message{\noexpand\qsetw is not supported, sorry!}}
1.13 +\def\faketreewidth#1{\message{\noexpand\faketreewidth is not supported, sorry!}}
1.14 +\def\qbalance{\message{\noexpand\qbalance is not supported, sorry!}}
1.15 +\def\qframesubtree{\message{\noexpand\qframesubtree is not supported, sorry!}}
1.16 +
1.17 +% Implement \qroof as a fancy leaf node
1.18 +\newtoks\@qrooflabel
1.19 +
1.20 +\def\qroof#1.{%
1.21 +\begin{tikzpicture}[baseline]
1.22 +{\pgftransformshift{\pgftree@levelshift}%
1.23 +\node(qroofbot){#1};}
1.24 +\@qroof
1.25 +}
1.26 +\def\@qroof{\@ifnextchar\egroup{%
1.27 +% since we are putting the qroof inside a node, we already have an inner sep
1.28 +% so for the purposes of defining our bounding box, we must eliminate inner sep
1.29 +\begin{pgfsubpicture}
1.30 +\node [inner sep=0pt] {\the\@qrooflabel};%
1.31 +\end{pgfsubpicture}
1.32 +\pgfpathrectanglecorners{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}{\pgfpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
1.33 +\pgfusepath{use as bounding box}%
1.34 +\node (qrooftop) {\the\@qrooflabel};
1.35 +\draw \roof@edge{qrooftop}{qroofbot};%
1.36 +\end{tikzpicture}}
1.37 +{\@@qroof}}
1.38 +\def\@@qroof#1{\expandafter\@qrooflabel\expandafter{\the\@qrooflabel #1}\@qroof}
1.39 +
1.40 +%%% This is lifted straight from qtree.sty
1.41 +
1.42 +% and another odd convenience:
1.43 +%
1.44 +% Make _, ^ go into math mode automatically in the scope of \automath
1.45 +%
1.46 +{ % Temporarily change catcodes
1.47 +\catcode`\_=\active
1.48 +\catcode`\^=\active
1.49 +
1.50 + \global\def\automath{%
1.51 + \catcode`\_=\active
1.52 + \catcode`\^=\active
1.53 + \def_##1{\@ifnextchar^{\automath@two_{##1}}{\ensuremath{\sb{##1}}}}%
1.54 + \def^##1{\@ifnextchar_{\automath@two^{##1}}{\ensuremath{\sp{##1}}}}}
1.55 +}
1.56 +\def\automath@two#1#2#3#4{\ensuremath{#1{#2}\relax #3{#4}}}
1.57 +% Restore default catcodes for ^, _
1.58 +\def\noautomath{\catcode`\_=8 \catcode`\^=7 }
1.59 +
1.60 +
1.61 +% Let \0, \1, \2 produce ^0, $'$, $''$
1.62 +% The \rlap results in better centering of the label (ignoring the
1.63 +% superscript)
1.64 +\def\qtreeprimes@internal{%
1.65 + \def\0{\ifmmode ^0\else \rlap{$^0$}\fi}%
1.66 + \def\1{\ifmmode '\else \rlap{$'$}\fi}%
1.67 + \def\2{\ifmmode ''\else \rlap{$''$}\fi}%
1.68 +}
1.69 +
1.70 +% Same commands, but without the \rlap feature
1.71 +\def\qtreeprimes{%
1.72 + \def\0{\ensuremath{^0}}%
1.73 + \def\1{\ensuremath{'}}%
1.74 + \def\2{\ensuremath{''}}}
1.75 +