forked from Daniel-Diaz/HaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trees implemented. There is not monad version yet.
- Loading branch information
Daniel Diaz
committed
Apr 14, 2012
1 parent
d16697f
commit 3b274f2
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
module Text.LaTeX.Packages.Trees ( | ||
-- * Tree | ||
Tree (..) | ||
) where | ||
|
||
-- | Tree datatype. | ||
data Tree a = | ||
Leaf a -- ^ Leafs are non-empty. | ||
| Node (Maybe a) [Tree a] -- ^ Node values are optional. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Text.LaTeX.Packages.Trees.Qtree ( | ||
-- * Tree to LaTeX rendering | ||
tree | ||
, rendertree | ||
) where | ||
|
||
import Text.LaTeX.Base | ||
import Text.LaTeX.Base.Syntax | ||
import Text.LaTeX.Packages.Trees | ||
-- | ||
import Data.Monoid | ||
import Data.List (intersperse) | ||
|
||
tree_ :: (a -> LaTeX) -> Tree a -> LaTeX | ||
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 :: (a -> LaTeX) -> Tree a -> LaTeX | ||
tree f t = TeXCommS "Tree" <> " " <> tree_ f t | ||
|
||
rendertree :: Render a => Tree a -> LaTeX | ||
rendertree = tree rendertex |