Permalink
Browse files

Add 'Num' instance for 'LaTeXT'. Fixed 'cite' type signature. Exporti…

…ng of 'liftIO'.
  • Loading branch information...
1 parent 1578ba0 commit 75f3cdef6d85089ce0e6e146b2d5a35a991c5d7d Daniel Diaz committed May 18, 2012
Showing with 30 additions and 7 deletions.
  1. +3 −3 HaTeX.cabal
  2. +24 −2 Text/LaTeX/Base.hs
  3. +1 −1 Text/LaTeX/Base/Commands.hs
  4. +1 −0 Text/LaTeX/Base/Writer.hs
  5. +1 −1 Text/LaTeX/Packages/AMSMath.hs
View
@@ -1,14 +1,14 @@
Name: HaTeX
-Version: 3.3
+Version: 3.3.1
Author: Daniel Díaz
Category: Text
Build-type: Simple
License: BSD3
License-file: license
-Maintainer: Daniel Díaz (danieldiaz <at> dhelta <dot> net)
+Maintainer: Daniel Díaz (danieldiaz `at` dhelta `dot` net)
Stability: Experimental
Homepage: http://dhelta.net/hprojects/HaTeX
-Bug-reports: danieldiaz <at> dhelta <dot> net
+Bug-reports: danieldiaz `at` dhelta `dot` net
Synopsis: The Haskell LaTeX library.
Description: As it is said: \"LaTeX is a high-quality typesetting system\". This library provides
a bridge between that system and Haskell (i.e. it is a LaTeX DSL).
View
@@ -17,7 +17,9 @@ to work with HaTeX. Those things are:
* The "Text.LaTeX.Base.Commands" module, which exports the LaTeX standard commands
and environments.
-Here is also defined a 'Num' instance for 'LaTeX'.
+* The "Text.LaTeX.Base.Writer" module, to work with the monad interface of the library.
+
+Here is also defined a 'Num' instance for both 'LaTeX' and 'LaTeXT'.
-}
module Text.LaTeX.Base
( -- * @LaTeX@ datatype
@@ -40,14 +42,15 @@ module Text.LaTeX.Base
) where
import Text.LaTeX.Base.Syntax (LaTeX (..),(<>),protectString,protectText)
+import Text.LaTeX.Base.Class
import Text.LaTeX.Base.Render
import Text.LaTeX.Base.Types
import Text.LaTeX.Base.Commands
import Text.LaTeX.Base.Writer
--
import Data.Monoid
--- Num instance for LaTeX
+-- Num instances for LaTeX and LaTeXT
-- | Methods 'abs' and 'signum' are undefined. Don't use them!
instance Num LaTeX where
@@ -59,3 +62,22 @@ instance Num LaTeX where
-- Non-defined methods
abs _ = error "Cannot use \"abs\" Num method with a LaTeX value."
signum _ = error "Cannot use \"signum\" Num method with a LaTeX value."
+
+-- | Warning: this instance only exist for the 'Num' instance.
+instance Monad m => Eq (LaTeXT m a) where
+ _ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value."
+
+-- | Warning: this instance only exist for the 'Num' instance.
+instance Monad m => Show (LaTeXT m a) where
+ show _ = error "Cannot use \"show\" Show method with a LaTeXT value."
+
+-- | Methods 'abs' and 'signum' are undefined. Don't use them!
+instance Monad m => Num (LaTeXT m a) where
+ (+) = liftOp (+)
+ (-) = liftOp (-)
+ (*) = (>>)
+ negate = (mempty -)
+ fromInteger = fromLaTeX . fromInteger
+ -- Non-defined methods
+ abs _ = error "Cannot use \"abs\" Num method with a LaTeXT value."
+ signum _ = error "Cannot use \"signum\" Num method with a LaTeXT value."
@@ -360,7 +360,7 @@ figure (Just p) = liftL $ TeXEnv "figure" [ OptArg $ TeXRaw $ render p ]
abstract :: LaTeXC l => l -> l
abstract = liftL $ TeXEnv "abstract" []
-cite :: LaTeX -> LaTeX
+cite :: LaTeXC l => l -> l
cite = liftL $ \l -> TeXComm "cite" [FixArg l]
-- Document class
@@ -45,6 +45,7 @@ module Text.LaTeX.Base.Writer
, merror
-- * Re-export
, lift
+ , liftIO
) where
import Control.Monad.Trans.Writer
@@ -184,7 +184,7 @@ epsilon :: LaTeXC l => l
epsilon = comm0 "epsilon"
varepsilon :: LaTeXC l => l
-varepsilon = comm0 "epsilon"
+varepsilon = comm0 "varepsilon"
zeta :: LaTeXC l => l
zeta = comm0 "zeta"

0 comments on commit 75f3cde

Please sign in to comment.