HaTeX 3.11.0.1 → 3.12.0.0
raw patch · 6 files changed
+41/−67 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.LaTeX.Base.Writer: instance Monad m => IsString (LaTeXT m a)
- Text.LaTeX.Base.Writer: instance Monad m => LaTeXC (LaTeXT m a)
- Text.LaTeX.Base.Writer: instance Monad m => Monoid (LaTeXT m a)
- Text.LaTeX.Base.Writer: merror :: Monad m => String -> LaTeXT m a -> LaTeXT m b
- Text.LaTeX.Base.Writer: throwError :: Monad m => String -> LaTeXT m a
- Text.LaTeX.Packages.AMSMath: instance Monad m => Eq (LaTeXT m a)
- Text.LaTeX.Packages.AMSMath: instance Monad m => Floating (LaTeXT m a)
- Text.LaTeX.Packages.AMSMath: instance Monad m => Fractional (LaTeXT m a)
- Text.LaTeX.Packages.AMSMath: instance Monad m => Num (LaTeXT m a)
- Text.LaTeX.Packages.AMSMath: instance Monad m => Show (LaTeXT m a)
+ Text.LaTeX.Base.Writer: instance (Monad m, a ~ ()) => IsString (LaTeXT m a)
+ Text.LaTeX.Base.Writer: instance (Monad m, a ~ ()) => LaTeXC (LaTeXT m a)
+ Text.LaTeX.Base.Writer: instance (Monad m, a ~ ()) => Monoid (LaTeXT m a)
+ Text.LaTeX.Packages.AMSMath: instance (Monad m, a ~ ()) => Floating (LaTeXT m a)
+ Text.LaTeX.Packages.AMSMath: instance (Monad m, a ~ ()) => Fractional (LaTeXT m a)
+ Text.LaTeX.Packages.AMSMath: instance (Monad m, a ~ ()) => Num (LaTeXT m a)
+ Text.LaTeX.Packages.AMSMath: instance Eq (LaTeXT m a)
+ Text.LaTeX.Packages.AMSMath: instance Show (LaTeXT m a)
- Text.LaTeX.Base.Writer: runLaTeXM :: LaTeXM a -> (Either String a, LaTeX)
+ Text.LaTeX.Base.Writer: runLaTeXM :: LaTeXM a -> (a, LaTeX)
- Text.LaTeX.Base.Writer: runLaTeXT :: Monad m => LaTeXT m a -> m (Either String a, LaTeX)
+ Text.LaTeX.Base.Writer: runLaTeXT :: Monad m => LaTeXT m a -> m (a, LaTeX)
Files
- Examples/fancyhdr.hs +2/−0
- Examples/tikz.hs +1/−1
- HaTeX.cabal +2/−2
- Text/LaTeX/Base/Parser.hs +7/−5
- Text/LaTeX/Base/Writer.hs +22/−53
- Text/LaTeX/Packages/AMSMath.hs +7/−6
Examples/fancyhdr.hs view
@@ -1,4 +1,6 @@ +{-# LANGUAGE OverloadedStrings #-}+ import Text.LaTeX import Text.LaTeX.Packages.Fancyhdr
Examples/tikz.hs view
@@ -42,6 +42,6 @@ center $ tikzpicture $ draw (Start (pointAtXY 0 1) ->- pointAtXY 0 (-1)) ->> draw (Start (pointAtXY (-0.2) 0) ->- pointAtXY (3*pi) 0 )- ->> scope [TColor Blue, TWidth (Pt 1)] (draw $ bpath (pointAtXY 0 0) $+ ->> scope [TColor $ BasicColor Blue, TWidth (Pt 1)] (draw $ bpath (pointAtXY 0 0) $ mapM_ line [ pointAtXY x (sin x) | x <- [0,0.05 .. 3*pi] ] )
HaTeX.cabal view
@@ -1,5 +1,5 @@ Name: HaTeX -Version: 3.11.0.1 +Version: 3.12.0.0 Author: Daniel Díaz Category: Text, LaTeX Build-type: Simple @@ -89,7 +89,7 @@ Text.LaTeX.Packages.TikZ.Simple Text.LaTeX.Packages.TikZ.Syntax Other-modules: Paths_HaTeX - Default-extensions: OverloadedStrings + Default-extensions: OverloadedStrings, TypeFamilies Other-extensions: CPP ghc-options: -Wall -fno-warn-orphans
Text/LaTeX/Base/Parser.hs view
@@ -28,7 +28,7 @@ import Data.Text (Text) import qualified Data.Text as T -import Control.Applicative ((<|>), (<$>))+import Control.Applicative ((<|>), (<$>),many) import Control.Monad (unless) import Text.LaTeX.Base.Syntax@@ -99,13 +99,15 @@ env = do _ <- char '\\' n <- envName "begin"- skipSpace+ sps <- many $ char ' '+ let lsps = if null sps then mempty else TeXRaw $ T.pack sps as <- cmdArgs b <- envBody n return $ TeXEnv (T.unpack n) (fromMaybe [] as) $- if as == Just []- then TeXBraces mempty <> b- else b+ case as of+ Just [] -> lsps <> TeXBraces mempty <> b+ Nothing -> lsps <> b+ _ -> b envName :: Text -> Parser Text envName k = do
Text/LaTeX/Base/Writer.hs view
@@ -1,4 +1,6 @@ +{-# LANGUAGE TypeFamilies #-} + -- | The writer monad applied to 'LaTeX' values. Useful to compose 'LaTeX' values -- using the @do@ notation: -- @@ -20,7 +22,6 @@ -- > anotherExample :: LaTeXT IO () -- > anotherExample = lift (readFileTex "foo") >>= verbatim -- --- -- This way, it is easy (without carrying arguments) to include IO outputs -- in the LaTeX document, like files, times or random objects. -- @@ -29,8 +30,6 @@ -- -- Of course, you can always use the simpler interface provided by the plain 'LaTeX' type. -- --- Another thing you should know about the LaTeX Writer Monad. Don't try to get values --- from computations with no results (like @raw "foo"@). module Text.LaTeX.Base.Writer ( -- * @LaTeXT@ writer LaTeXT @@ -49,9 +48,6 @@ , rendertexM , liftFun , liftOp - -- * Errors - , throwError - , merror -- * Re-exports , lift , liftIO @@ -76,18 +72,14 @@ -- | 'WriterT' monad transformer applied to 'LaTeX' values. newtype LaTeXT m a = - LaTeXT { unwrapLaTeXT :: WriterT LaTeX m (a,Maybe String) } + LaTeXT { unwrapLaTeXT :: WriterT LaTeX m a } instance Functor f => Functor (LaTeXT f) where - fmap f = LaTeXT . fmap (first f) . unwrapLaTeXT - --- | Pair a value with 'Nothing'. -pairNoth :: a -> (a,Maybe b) -pairNoth x = (x,Nothing) + fmap f = LaTeXT . fmap f . unwrapLaTeXT instance Applicative f => Applicative (LaTeXT f) where - pure = LaTeXT . pure . pairNoth - (LaTeXT f) <*> (LaTeXT x) = LaTeXT $ fmap (first . fst) f <*> x + pure = LaTeXT . pure + (LaTeXT f) <*> (LaTeXT x) = LaTeXT $ f <*> x -- | Type synonym for empty 'LaTeXT' computations. type LaTeXT_ m = LaTeXT m () @@ -99,7 +91,7 @@ -- -- > runLaTeXM = runIdentity . runLaTeXT -- -runLaTeXM :: LaTeXM a -> (Either String a, LaTeX) +runLaTeXM :: LaTeXM a -> (a, LaTeX) runLaTeXM = runIdentity . runLaTeXT -- | A particular case of 'execLaTeXT'. @@ -110,31 +102,25 @@ execLaTeXM = runIdentity . execLaTeXT instance MonadTrans LaTeXT where - lift = LaTeXT . liftM pairNoth . lift + lift = LaTeXT . lift instance Monad m => Monad (LaTeXT m) where - return = LaTeXT . return . pairNoth + return = LaTeXT . return (LaTeXT c) >>= f = LaTeXT $ do - (a,_) <- c + a <- c let LaTeXT c' = f a c' - fail = throwError + fail = return . error instance MonadIO m => MonadIO (LaTeXT m) where liftIO = lift . liftIO -instance Monad m => LaTeXC (LaTeXT m a) where - liftListL f xs = mapM extractLaTeX_ xs >>= merror "liftListL" . textell . f +instance (Monad m, a ~ ()) => LaTeXC (LaTeXT m a) where + liftListL f xs = mapM extractLaTeX_ xs >>= textell . f --- | Running a 'LaTeXT' computation returns the final 'LaTeX' value --- and either a 'String' if the computation didn't contain any value --- or the value itself otherwise. -runLaTeXT :: Monad m => LaTeXT m a -> m (Either String a,LaTeX) -runLaTeXT (LaTeXT c) = runWriterT c >>= ( - \((a,m),l) -> case m of - Nothing -> return (Right a ,l) - Just err -> return (Left err,l) - ) +-- | Running a 'LaTeXT' computation returns the final 'LaTeX' value. +runLaTeXT :: Monad m => LaTeXT m a -> m (a,LaTeX) +runLaTeXT = runWriterT . unwrapLaTeXT -- | This is the usual way to run the 'LaTeXT' monad -- and obtain a 'LaTeX' value. @@ -159,9 +145,7 @@ -- | This function run a 'LaTeXT' computation, -- lifting the result again in the monad. extractLaTeX :: Monad m => LaTeXT m a -> LaTeXT m (a,LaTeX) -extractLaTeX (LaTeXT c) = LaTeXT $ do - ((a,m),l) <- lift $ runWriterT c - return ((a,l),m) +extractLaTeX = LaTeXT . lift . runWriterT . unwrapLaTeXT -- | Executes a 'LaTeXT' computation, embedding it again in -- the 'LaTeXT' monad. @@ -178,7 +162,7 @@ -- | With 'textell' you can append 'LaTeX' values to the -- state of the 'LaTeXT' monad. textell :: Monad m => LaTeX -> LaTeXT m () -textell = LaTeXT . liftM pairNoth . tell +textell = LaTeXT . tell -- | Lift a function over 'LaTeX' values to a function -- acting over the state of a 'LaTeXT' computation. @@ -211,26 +195,11 @@ rendertexM :: (Render a, Monad m) => a -> LaTeXT m () rendertexM = textell . rendertex --- Error throwing - --- | The 'fail' method of the 'LaTeXT' monad. -throwError :: Monad m => String -> LaTeXT m a -throwError = LaTeXT . return . (error &&& Just) - --- | Function 'merror' casts a value contained in a monad @m@ to the --- bottom value of another type. If you try to evaluate this value, you will --- get an error message with the 'String' passed as argument to 'merror'. -merror :: Monad m => String -> LaTeXT m a -> LaTeXT m b -merror = flip (>>) . throwError - -- Overloaded Strings --- | Be careful when using 'fromString' over a 'LaTeXT' value, --- the returned value of the computation is bottom (i.e. 'undefined'). -instance Monad m => IsString (LaTeXT m a) where - fromString = merror "LaTeXT: fromString!" . textell . fromString +instance (Monad m, a ~ ()) => IsString (LaTeXT m a) where + fromString = textell . fromString --- | 'mappend' @=@ '>>'. -instance Monad m => Monoid (LaTeXT m a) where - mempty = throwError "LaTeXT: mempty!" +instance (Monad m, a ~ ()) => Monoid (LaTeXT m a) where + mempty = return () mappend = (>>)
Text/LaTeX/Packages/AMSMath.hs view
@@ -1,5 +1,6 @@-{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings, TypeFamilies #-} + -- | \AMSMath\ support. Also numeric instances ('Num', 'Fractional' and 'Floating') for 'LaTeX' and 'LaTeXT'. module Text.LaTeX.Packages.AMSMath ( -- * AMSMath package @@ -179,17 +180,17 @@ -- | Warning: this instance only exists for the 'Num' instance. -- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Monad m => Eq (LaTeXT m a) where +instance Eq (LaTeXT m a) where _ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value." -- | Warning: this instance only exists for the 'Num' instance. -- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Monad m => Show (LaTeXT m a) where +instance Show (LaTeXT m a) where show _ = error "Cannot use \"show\" Show method with a LaTeXT value." -- | Careful! Method 'signum' is undefined. Don't use it! -- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Monad m => Num (LaTeXT m a) where +instance (Monad m, a ~ ()) => Num (LaTeXT m a) where (+) = liftOp (+) (-) = liftOp (-) (*) = (>>) @@ -201,13 +202,13 @@ -- | Division uses the LaTeX 'frac' command. -- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Monad m => Fractional (LaTeXT m a) where +instance (Monad m, a ~ ()) => Fractional (LaTeXT m a) where (/) = liftOp (/) fromRational = fromLaTeX . fromRational -- | Undefined methods: 'asinh', 'atanh' and 'acosh'. -- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Monad m => Floating (LaTeXT m a) where +instance (Monad m, a ~ ()) => Floating (LaTeXT m a) where pi = pi_ exp = liftFun exp sqrt = liftFun sqrt