module Text.LaTeX.Monad (
LaTeXM
, LaTeX
, lx
, lxany
, lxw
, lxanyw
, nlx
, iolx
, reslx
, genlx , ungenlx
) where
import Control.Monad.Writer
import Data.Monoid
import GHC.Exts
import System.IO.Unsafe
import Text.LaTeX.Result
import Data.String.Combinators(fromShow)
type LaTeXM a = WriterT Result IO a
type LaTeX = LaTeXM ()
nlx :: LaTeXM a -> IO Result
nlx = execWriterT
lx :: Result -> LaTeX
lx = tell
lxany :: Show a => a -> LaTeX
lxany = ungenlx . lxanyw
lxw :: Result -> LaTeXM a
lxw = genlx . lx
lxanyw :: Show b => b -> LaTeXM a
lxanyw = fromShow
iolx :: IO a -> LaTeXM a
iolx = liftIO
reslx :: (Result -> Result) -> (LaTeXM a -> LaTeXM a)
reslx = censor
instance IsString (LaTeXM a) where
fromString = lxw . toResult
instance Show (LaTeXM a) where
show = fromResult . unsafePerformIO . nlx
instance Eq (LaTeXM a) where
x == y = show x == show y
instance Monoid (LaTeXM a) where
mempty = ""
mappend = (>>)
genlx :: LaTeX -> LaTeXM a
genlx = (>> return undefined)
ungenlx :: LaTeXM a -> LaTeX
ungenlx = (>> return ())