# Changes between Version 3 and Version 4 of TreeMagic

Ignore:
Timestamp:
Oct 30, 2011, 4:44:46 PM (6 years ago)
Comment:

--

### Legend:

Unmodified
 v3 For example the tree [[Image(http://common.jle.cc/features/tree.png)]] [[Image(http://common.jle.cc/features/tree.png)]] is generated by the code: }}} * Trees now can simply be written as terms, for example 'f(g(a,b),h(c))'. Then we have * Trees now can simply be written as terms, for example '''f(g(a,b),h(c))''' for the tree [[Image(http://common.jle.cc/features/tree_simple.png)]] Then we have {{{ %!begin{tree}{magic:023916255455191981} }}} * We again press ('''alt+enter''') to invoke Tree Magic, then the Tikz tree is automatically generated and inserted in the document as follows: * We again press ('''alt+enter''') to invoke Tree Magic. Then the corresponding Tikz code is generated and inserted in the document: {{{ %!begin{tree}{magic:023916255455191981} }}} [[Image(http://common.jle.cc/features/tree_simple.png)]] * Here the whole Latex source code of this example: {{{ \documentclass{article} * [wiki:Development] \usepackage{tikz} \usetikzlibrary{arrows,backgrounds,calc,trees} \begin{document} \thispagestyle{empty} \begin{tikzpicture}[thick,level distance=12mm, paint/.style={very thick,draw=#1!50!black,fill=#1,opacity=.3}] %!begin{tree}{magic:023916255455191981} %f(g(a,b),h(c)) \node (f) {f} child { node (g) {g} child { node (a) {a} } child { node (b) {b} } } child { node (h) {h} child { node (c) {c} } }; \begin{pgfonlayer}{background} \end{pgfonlayer} %!end{tree}{magic:023916255455191981} \end{tikzpicture} \end{document} }}} == Highlighting parts of the tree == * We continue the previous example. To highlight a the nodes {g,a,b}, simply write '''highlight[paint=red](g, a, b)''' {{{ %!begin{tree}{magic:023916255455191981} %f(g(a,b),h(c)) %highlight[paint=red](g,a,b) ... generated code ... %!end{tree}{magic:023916255455191981} }}} Then press ('''alt+enter''') to invoke Tree Magic, and you obtain the tree: [[Image(http://common.jle.cc/features/tree.png)]] * Of course we can highlight multiple parts of the tree: {{{ %!begin{tree}{magic:023916255455191981} %f(g(a,b),h(c)) %highlight[paint=red](g,a,b) %highlight[paint=blue](f,g,h,c,h) ... generated code ... %!end{tree}{magic:023916255455191981} }}} Then press ('''alt+enter''') to invoke Tree Magic, and you obtain the tree: [[Image(http://common.jle.cc/features/tree_highlight.png)]] == Complex nodes (math mode) == * To create complex nodes (e.g. with mathematical formulas), we can surround the node with braces ('{' and '}') or quotes ('"'). * For example, {{{ %{$f^2(x)$}({$g_h$}(a,b),{h+3}(c)) %highlight[paint=red](g_h,a,b) %highlight[paint=blue](f^2x,g_h,h+3,c,h+3) }}} will result in the tree: [[Image(http://common.jle.cc/features/tree_math.png)]] * Note the naming of the nodes in the highlight section! You find more on the naming of nodes in the following section. == Node naming == * By default, the names of the nodes are derived from the content of the nodes by removing all symbols '()[]{}\$'. Thus the node '''$f!^2(x)$''' will be named '''f!^2x'''. * You may use custom names by '''node:name'''. For example '''{$f!^2(x)$}:root''' will assign the name 'root' to the node. Then the code: {{{ %{$f^2(x)$}:root({$g_h$}(a,b),{h+3}(c)) %highlight[paint=red](g_h,a,b) %highlight[paint=blue](root,g_h,h+3,c,h+3) }}} results in the same picture as above, but now we use 'root' to refer to '$f!^2(x)\$' in the highlight section. * You can use these names to refer to the nodes from Tikz. For example to add an arrow from 'c' to the root, add {{{ \draw [->,very thick] (c) to[bend right=80] (root); }}} after the Tree Magic section. This results in: [[Image(http://common.jle.cc/features/tree_naming.png)]] == Tikz options == * You may pass Tikz drawing options to a node via '[options]' after the node name. For example: {{{ %f[rectangle,fill=green!50,draw=green!50!black](g(a,b),h(c)) %highlight[paint=red](g,a,b) }}} will result in: [[Image(http://common.jle.cc/features/tree_options.png)]] * We can provide more Tikz options as follows: {{{ %f([options1] [options2] g [options3](a,b),h(c)) }}} which results in the following options being passed to child 'g': {{{ ... [options1] child [options2] { node [options3] (g) {g} ... }}}