Skip to content

Plotting trees using the latex package tikz-qtree

Notifications You must be signed in to change notification settings

dharasim/TikzQTrees.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TikzQTrees.jl

Build Status codecov.io

Plotting trees using TikzPictures.jl and the latex package tikz-qtree.

Installation

Install the latest version of this package by:

(v0.7) pkg> add https://github.com/dharasim/TikzQTrees.jl#master

TikzQTrees is build on top of TikzPictures.jl. If you can install TikzPictures, you should also be able to use TikzQTrees.

Usage

The package implements a wrapper type TikzQTree of tree data types which implement the functions

  • value(tree) that returns the value of the root of the tree, and
  • children(tree) that returns an iterator over the children of the root of the tree.

It also provides SimpleTree, an example of a type that can be wrapped into TikzQTree:

mutable struct SimpleTree{T}
    value    :: T
    children :: Vector{SimpleTree{T}}
end

TikzQTrees are converted into TikzPictures to show them in the Juno plot pane and IJulia notebooks. In the REPL, the tex code of the tikz-qtree is printed.

julia> using TikzQTrees, TikzPictures

julia> tree = SimpleTree("root", [SimpleTree("left"), SimpleTree("right")]);

julia> TikzQTree(tree)
[.root left right ]

julia> save(SVG("test_tree"), TikzPicture(TikzQTree(tree)))

The saved plot is:

One more thing

This package additionally provides the macro @qtree for pretty printing of Julia's syntax trees:

julia> qt = @qtree a * (b+c) == a*b + a*c
[.{==} [.{*} {a} [.{+} {b} {c} ] ] [.{+} [.{*} {a} {b} ] [.{*} {a} {c} ] ] ]

julia> save(SVG("distributivity"), TikzPicture(qt))

TreeView.jl is a related package that implements a macro @tree which is build on top of TikzGraphs.jl.

About

Plotting trees using the latex package tikz-qtree

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages