exercises/solutions/tikz-qtree-compat.sty
author Eugen Sawin <sawine@me73.com>
Sun, 10 Jun 2012 05:35:08 +0200
changeset 20 93fd38efa60f
permissions -rw-r--r--
Added some solutions.
sawine@9
     1
%    tikz-qtree-compat.tex
sawine@9
     2
%    Version 1.1, 25 Dec 2009
sawine@9
     3
sawine@9
     4
\RequirePackage{tikz-qtree}
sawine@9
     5
sawine@9
     6
\let\orig@Tree\Tree
sawine@9
     7
\def\Tree{\automath \qtreeprimes@internal \orig@Tree}
sawine@9
     8
sawine@9
     9
\def\qsetw#1{\message{\noexpand\qsetw is not supported, sorry!}}
sawine@9
    10
\def\faketreewidth#1{\message{\noexpand\faketreewidth is not supported, sorry!}}
sawine@9
    11
\def\qbalance{\message{\noexpand\qbalance is not supported, sorry!}}
sawine@9
    12
\def\qframesubtree{\message{\noexpand\qframesubtree is not supported, sorry!}}
sawine@9
    13
sawine@9
    14
% Implement \qroof as a fancy leaf node
sawine@9
    15
\newtoks\@qrooflabel
sawine@9
    16
sawine@9
    17
\def\qroof#1.{%
sawine@9
    18
\begin{tikzpicture}[baseline]
sawine@9
    19
{\pgftransformshift{\pgftree@levelshift}%
sawine@9
    20
\node(qroofbot){#1};}
sawine@9
    21
\@qroof
sawine@9
    22
}
sawine@9
    23
\def\@qroof{\@ifnextchar\egroup{%
sawine@9
    24
% since we are putting the qroof inside a node, we already have an inner sep
sawine@9
    25
% so for the purposes of defining our bounding box, we must eliminate inner sep
sawine@9
    26
\begin{pgfsubpicture}
sawine@9
    27
\node [inner sep=0pt] {\the\@qrooflabel};% 
sawine@9
    28
\end{pgfsubpicture}
sawine@9
    29
\pgfpathrectanglecorners{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}{\pgfpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
sawine@9
    30
\pgfusepath{use as bounding box}%
sawine@9
    31
\node (qrooftop) {\the\@qrooflabel};
sawine@9
    32
\draw \roof@edge{qrooftop}{qroofbot};%
sawine@9
    33
\end{tikzpicture}}
sawine@9
    34
{\@@qroof}}
sawine@9
    35
\def\@@qroof#1{\expandafter\@qrooflabel\expandafter{\the\@qrooflabel #1}\@qroof}
sawine@9
    36
sawine@9
    37
%%% This is lifted straight from qtree.sty
sawine@9
    38
sawine@9
    39
% and another odd convenience:
sawine@9
    40
%
sawine@9
    41
% Make _, ^ go into math mode automatically in the scope of \automath
sawine@9
    42
%
sawine@9
    43
{ % Temporarily change catcodes 
sawine@9
    44
\catcode`\_=\active
sawine@9
    45
\catcode`\^=\active
sawine@9
    46
sawine@9
    47
  \global\def\automath{%
sawine@9
    48
    \catcode`\_=\active
sawine@9
    49
    \catcode`\^=\active
sawine@9
    50
    \def_##1{\@ifnextchar^{\automath@two_{##1}}{\ensuremath{\sb{##1}}}}%
sawine@9
    51
    \def^##1{\@ifnextchar_{\automath@two^{##1}}{\ensuremath{\sp{##1}}}}}
sawine@9
    52
}
sawine@9
    53
\def\automath@two#1#2#3#4{\ensuremath{#1{#2}\relax #3{#4}}}
sawine@9
    54
% Restore default catcodes for ^, _
sawine@9
    55
\def\noautomath{\catcode`\_=8 \catcode`\^=7 }
sawine@9
    56
sawine@9
    57
sawine@9
    58
% Let \0, \1, \2 produce ^0, $'$, $''$
sawine@9
    59
% The \rlap results in better centering of the label (ignoring the
sawine@9
    60
%  superscript)
sawine@9
    61
\def\qtreeprimes@internal{%
sawine@9
    62
  \def\0{\ifmmode ^0\else \rlap{$^0$}\fi}%
sawine@9
    63
  \def\1{\ifmmode '\else \rlap{$'$}\fi}%
sawine@9
    64
  \def\2{\ifmmode ''\else \rlap{$''$}\fi}%
sawine@9
    65
}
sawine@9
    66
sawine@9
    67
% Same commands, but without the \rlap feature
sawine@9
    68
\def\qtreeprimes{%
sawine@9
    69
  \def\0{\ensuremath{^0}}%
sawine@9
    70
  \def\1{\ensuremath{'}}%
sawine@9
    71
  \def\2{\ensuremath{''}}}
sawine@9
    72