module Text.LaTeX.Packages.Trees.Qtree (
module Text.LaTeX.Packages.Trees
, qtree
, tree
, rendertree
) where
import Text.LaTeX.Base
import Text.LaTeX.Base.Class
import Text.LaTeX.Packages.Trees
import Data.List (intersperse)
qtree :: PackageName
qtree = "qtree"
tree_ :: LaTeXC l => (a -> l) -> Tree a -> l
tree_ f (Leaf x) = braces $ f x
tree_ f (Node mx ts) =
mconcat [ "["
, maybe mempty (("." <>) . braces . f) mx
, " "
, mconcat $ intersperse " " $ fmap (tree_ f) ts
, " ]"
]
tree :: LaTeXC l => (a -> l) -> Tree a -> l
tree f t = commS "Tree" <> " " <> tree_ f t
instance Texy a => Texy (Tree a) where
texy = tree texy
rendertree :: (Render a, LaTeXC l) => Tree a -> l
rendertree = tree (raw . protectText . render)