Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dharasim/tikzqtrees.jl

Plotting trees using the latex package tikz-qtree
https://github.com/dharasim/tikzqtrees.jl

Last synced: about 1 month ago
JSON representation

Plotting trees using the latex package tikz-qtree

Awesome Lists containing this project

README

        

# TikzQTrees.jl

[![Build Status](https://travis-ci.org/dharasim/TikzQTrees.jl.svg?branch=master)](https://travis-ci.org/dharasim/TikzQTrees.jl)
[![codecov.io](http://codecov.io/github/dharasim/TikzQTrees.jl/coverage.svg?branch=master)](http://codecov.io/github/dharasim/TikzQTrees.jl?branch=master)

Plotting trees using [TikzPictures.jl](https://github.com/JuliaTeX/TikzPictures.jl) and the latex package [tikz-qtree](https://www.ctan.org/pkg/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](https://github.com/JuliaTeX/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`:

```julia
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
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
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](https://github.com/JuliaTeX/TreeView.jl) is a related package that implements a macro `@tree` which is build on top of [TikzGraphs.jl](https://github.com/JuliaTeX/TikzGraphs.jl).