HaTeX 3.0.0 → 3.1.0
raw patch · 24 files changed
+704/−60 lines, 24 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.LaTeX.Base: instance Num LaTeX
+ Text.LaTeX.Base.Commands: between :: LaTeX -> LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Base.Commands.Monad: between :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Base.Monad: instance Eq (LaTeXT m a)
+ Text.LaTeX.Base.Monad: instance Monad m => Num (LaTeXT m a)
+ Text.LaTeX.Base.Monad: instance Show (LaTeXT m a)
+ Text.LaTeX.Base.Syntax: instance Eq LaTeX
+ Text.LaTeX.Base.Syntax: instance Eq TeXArg
+ Text.LaTeX.Base.Types: instance Eq Label
+ Text.LaTeX.Base.Types: instance IsString Label
+ Text.LaTeX.Base.Types: labelName :: Label -> String
+ Text.LaTeX.Base.Warnings: CustomWarning :: Text -> Warning
+ Text.LaTeX.Base.Warnings: NoClassSelected :: Warning
+ Text.LaTeX.Base.Warnings: NoDocumentInserted :: Warning
+ Text.LaTeX.Base.Warnings: UndefinedLabel :: Text -> Warning
+ Text.LaTeX.Base.Warnings: UnusedLabel :: Text -> Warning
+ Text.LaTeX.Base.Warnings: check :: TeXCheck -> LaTeX -> [Warning]
+ Text.LaTeX.Base.Warnings: checkAll :: TeXCheck
+ Text.LaTeX.Base.Warnings: checkClass :: TeXCheck
+ Text.LaTeX.Base.Warnings: checkDoc :: TeXCheck
+ Text.LaTeX.Base.Warnings: checkFromFunction :: (LaTeX -> [Warning]) -> TeXCheck
+ Text.LaTeX.Base.Warnings: checkLabels :: TeXCheck
+ Text.LaTeX.Base.Warnings: data TeXCheck
+ Text.LaTeX.Base.Warnings: data Warning
+ Text.LaTeX.Base.Warnings: instance Eq Warning
+ Text.LaTeX.Base.Warnings: instance Monoid TeXCheck
+ Text.LaTeX.Base.Warnings: instance Show Warning
+ Text.LaTeX.Base.Writer: execLaTeXTWarn :: Monad m => LaTeXT m a -> m (LaTeX, [Warning])
+ Text.LaTeX.Base.Writer: instance MonadTrans LaTeXT
+ Text.LaTeX.Base.Writer: liftFun :: Monad m => (LaTeX -> LaTeX) -> (LaTeXT m a -> LaTeXT m a)
+ Text.LaTeX.Base.Writer: liftOp :: Monad m => (LaTeX -> LaTeX -> LaTeX) -> (LaTeXT m a -> LaTeXT m a -> LaTeXT m a)
+ Text.LaTeX.Packages.AMSMath: (<:) :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: (<=:) :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: (=:, /=:) :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: (>:) :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: (>=:) :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: dagger :: LaTeX
+ Text.LaTeX.Packages.AMSMath: ddagger :: LaTeX
+ Text.LaTeX.Packages.AMSMath: forall :: LaTeX
+ Text.LaTeX.Packages.AMSMath: in_ :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: ni :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath: notin :: LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSMath.Monad: (/=:) :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: (<:) :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: (<=:) :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: (=:) :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: (>:) :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: (>=:) :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: dagger :: Monad m => LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: ddagger :: Monad m => LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: forall :: Monad m => LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: in_ :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: ni :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSMath.Monad: notin :: Monad m => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSThm: CustomThmStyle :: String -> TheoremStyle
+ Text.LaTeX.Packages.AMSThm: Definition :: TheoremStyle
+ Text.LaTeX.Packages.AMSThm: Plain :: TheoremStyle
+ Text.LaTeX.Packages.AMSThm: Remark :: TheoremStyle
+ Text.LaTeX.Packages.AMSThm: amsthm :: String
+ Text.LaTeX.Packages.AMSThm: data TheoremStyle
+ Text.LaTeX.Packages.AMSThm: instance Render TheoremStyle
+ Text.LaTeX.Packages.AMSThm: instance Show TheoremStyle
+ Text.LaTeX.Packages.AMSThm: newtheorem :: String -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSThm: proof :: Maybe LaTeX -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSThm: qedhere :: LaTeX
+ Text.LaTeX.Packages.AMSThm: theorem :: String -> LaTeX -> LaTeX
+ Text.LaTeX.Packages.AMSThm: theoremstyle :: TheoremStyle -> LaTeX
+ Text.LaTeX.Packages.AMSThm.Monad: CustomThmStyle :: String -> TheoremStyle
+ Text.LaTeX.Packages.AMSThm.Monad: Definition :: TheoremStyle
+ Text.LaTeX.Packages.AMSThm.Monad: Plain :: TheoremStyle
+ Text.LaTeX.Packages.AMSThm.Monad: Remark :: TheoremStyle
+ Text.LaTeX.Packages.AMSThm.Monad: amsthm :: String
+ Text.LaTeX.Packages.AMSThm.Monad: data TheoremStyle
+ Text.LaTeX.Packages.AMSThm.Monad: newtheorem :: Monad m => String -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSThm.Monad: proof :: Monad m => Maybe (LaTeXT_ m) -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSThm.Monad: qedhere :: Monad m => LaTeXT_ m
+ Text.LaTeX.Packages.AMSThm.Monad: theorem :: Monad m => String -> LaTeXT_ m -> LaTeXT_ m
+ Text.LaTeX.Packages.AMSThm.Monad: theoremstyle :: Monad m => TheoremStyle -> LaTeXT_ m
- Text.LaTeX.Base.Writer: execLaTeXT :: Functor m => LaTeXT m a -> m LaTeX
+ Text.LaTeX.Base.Writer: execLaTeXT :: Monad m => LaTeXT m a -> m LaTeX
- Text.LaTeX.Packages.Beamer: beamer :: LaTeX
+ Text.LaTeX.Packages.Beamer: beamer :: String
- Text.LaTeX.Packages.Beamer.Monad: beamer :: Monad m => LaTeXT_ m
+ Text.LaTeX.Packages.Beamer.Monad: beamer :: String
Files
- Examples/fibs.hs +34/−0
- HaTeX.cabal +11/−4
- ReleaseNotes +33/−0
- Text/LaTeX.hs +1/−1
- Text/LaTeX/Base.hs +16/−1
- Text/LaTeX/Base/Commands.hs +22/−15
- Text/LaTeX/Base/Commands/Monad.hs +29/−17
- Text/LaTeX/Base/Monad.hs +33/−0
- Text/LaTeX/Base/Syntax.hs +3/−4
- Text/LaTeX/Base/Types.hs +10/−3
- Text/LaTeX/Base/Warnings.hs +141/−0
- Text/LaTeX/Base/Writer.hs +56/−10
- Text/LaTeX/Packages.hs +2/−0
- Text/LaTeX/Packages/AMSFonts.hs +2/−0
- Text/LaTeX/Packages/AMSMath.hs +62/−1
- Text/LaTeX/Packages/AMSMath/Monad.hs +86/−0
- Text/LaTeX/Packages/AMSThm.hs +69/−0
- Text/LaTeX/Packages/AMSThm/Monad.hs +84/−0
- Text/LaTeX/Packages/Beamer.hs +3/−2
- Text/LaTeX/Packages/Beamer/Monad.hs +2/−2
- Text/LaTeX/Packages/Color.hs +1/−0
- Text/LaTeX/Packages/Hyperref.hs +1/−0
- Text/LaTeX/Packages/Inputenc.hs +1/−0
- Text/LaTeX/Packages/Monad.hs +2/−0
+ Examples/fibs.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX.Base.Monad++main :: IO ()+main = execLaTeXT example >>= renderFile "Fibs.tex"++example :: Monad m => LaTeXT_ m+example = do+ documentclass [] article+ document exampleBody++exampleBody :: Monad m => LaTeXT_ m+exampleBody = do+ "This is an example of how "+ hatex3+ " works, printing a table of "+ "the thirteen first elements of the "+ "Fibonacci sequence."+ bigskip+ center $ underline $ textbf "Fibonacci table"+ center $ tabular Nothing [RightColumn,VerticalLine,LeftColumn] $ do+ textbf "Fibonacci number" & textbf "Value"+ lnbk+ hline+ foldr (\n l -> do fromString (show n) & fromString (show $ fib n)+ lnbk+ l ) (return ()) [0..12]++fibs :: [Int]+fibs = 1 : 1 : zipWith (+) fibs (tail fibs)++fib :: Int -> Int+fib = (fibs!!)
HaTeX.cabal view
@@ -1,11 +1,11 @@ Name: HaTeX -Version: 3.0.0+Version: 3.1.0 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 @@ -17,13 +17,17 @@ for any purpose you can figure out. Cabal-version: >= 1.6 Tested-with: GHC == 6.12.3 , GHC == 7.0.3-Extra-source-files: ReleaseNotes+Extra-source-files:+ ReleaseNotes+ -- Examples+ Examples/fibs.hs Library Build-depends: base ==4.* , bytestring , mtl ==2.* - , text + , text+ GHC-Options: -fno-warn-unrecognised-pragmas Exposed-modules: Text.LaTeX Text.LaTeX.Monad @@ -36,12 +40,15 @@ Text.LaTeX.Base.Syntax Text.LaTeX.Base.Types Text.LaTeX.Base.Writer+ Text.LaTeX.Base.Warnings Text.LaTeX.Packages Text.LaTeX.Packages.Monad Text.LaTeX.Packages.AMSFonts Text.LaTeX.Packages.AMSFonts.Monad Text.LaTeX.Packages.AMSMath Text.LaTeX.Packages.AMSMath.Monad+ Text.LaTeX.Packages.AMSThm+ Text.LaTeX.Packages.AMSThm.Monad Text.LaTeX.Packages.Beamer Text.LaTeX.Packages.Beamer.Monad Text.LaTeX.Packages.Hyperref
ReleaseNotes view
@@ -1,5 +1,38 @@ HaTeX Release Notes -- From version 3.0.0 ++>>> 3.1.0++Highlights:+++ Added warnings (See Text.LaTeX.Base.Warnings).++ Added an "Examples" directory.++ Num instance for LaTeX and LaTeXT.++ New package implemented "AMSThm" (See Text.LaTeX.Packages.AMSThm).++Changes by modules:++** Base modules+* Text.LaTeX.Base.Syntax:+-- Added Eq instance to LaTeX and TeXArg.+* Text.LaTeX.Base.Writer:+-- Added MonadTrans instance to LaTeXT.+-- New functions: execLaTeXTWarn, liftFun, liftOp.+* Text.LaTeX.Base.Types:+-- Added Eq instance to Label.+* Text.LaTeX.Base:+-- Added Num instance to LaTeX.+* Text.LaTeX.Base.Monad:+-- Added Num instance to LaTeXT.+* Text.LaTeX.Base.Commands:+-- New function: between.++** Package modules:+* Text.LaTeX.Packages.AMSMath+-- New symbols: (=:) , (/=:) , forall+ , dagger, ddagger, in_ , ni+ , (<:) , (<=:)+ , (>:) , (>=:) >>> 3.0.0
Text/LaTeX.hs view
@@ -3,7 +3,7 @@ -- Importing this will you give access to almost all -- functionality of the library. It is recommended -- to import the @Base@ module and, then, import only--- packages you will need. +-- packages you actually need. module Text.LaTeX ( module Text.LaTeX.Base , module Text.LaTeX.Packages
Text/LaTeX/Base.hs view
@@ -14,6 +14,8 @@ * The "Text.LaTeX.Base.Commands" module, which exports the LaTeX standard commands and environments.++Here is also defined a 'Num' instance for 'LaTeX'. -} module Text.LaTeX.Base ( LaTeX , (<>) @@ -22,7 +24,20 @@ , module Text.LaTeX.Base.Commands ) where -import Text.LaTeX.Base.Syntax (LaTeX,(<>)) +import Text.LaTeX.Base.Syntax (LaTeX (..),(<>)) import Text.LaTeX.Base.Render import Text.LaTeX.Base.Types import Text.LaTeX.Base.Commands++-- Num instance for LaTeX++-- | Methods 'abs' and 'signum' are undefined. Don't use them!+instance Num LaTeX where+ (+) = TeXOp "+"+ (-) = TeXOp "-"+ (*) = (<>)+ negate = (TeXEmpty -)+ fromInteger = TeXRaw . fromString . show+ -- Non-defined methods+ abs _ = "Cannot use \"abs\" Num method with a LaTeX value."+ signum _ = "Cannot use \"signum\" Num method with a LaTeX value."
Text/LaTeX/Base/Commands.hs view
@@ -1,8 +1,10 @@ {-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HATEX MakeMonadic #-} -- | LaTeX standard commands and environments. module Text.LaTeX.Base.Commands- ( raw+ ( -- * Basic functions+ raw , between -- * Preamble commands , title , author@@ -154,10 +156,6 @@ , roman_ , alph , alph_- -- ** Cross references- , label- , ref- , pageref -- ** Boxes , mbox , fbox@@ -166,6 +164,10 @@ , makebox , raisebox , rule+ -- * Cross references+ , label+ , ref+ , pageref -- ** Tables , tabular , (&)@@ -191,6 +193,11 @@ raw :: Text -> LaTeX raw = TeXRaw +-- | Calling 'between' @c l1 l2@ puts @c@ between @l1@ and @l2@ and+-- appends them.+between :: LaTeX -> LaTeX -> LaTeX -> LaTeX+between c l1 l2 = l1 <> c <> l2+ -- | Generate the title. It normally contains the 'title' name -- of your document, the 'author'(s) and 'date'. maketitle :: LaTeX@@ -300,15 +307,6 @@ cite :: LaTeX -> LaTeX cite l = TeXComm "cite" [FixArg l] -ref :: Label -> LaTeX-ref l = TeXComm "ref" [FixArg $ TeXRaw $ render l]--label :: Label -> LaTeX-label l = TeXComm "label" [FixArg $ TeXRaw $ render l]--pageref :: Label -> LaTeX-pageref l = TeXComm "pageref" [FixArg $ TeXRaw $ render l]- documentclass :: [LaTeX] -> LaTeX -> LaTeX documentclass ls l = TeXComm "documentclass" [MOptArg ls , FixArg l] @@ -727,4 +725,13 @@ hatex_version :: LaTeX hatex_version = hatex3 <> hspace (Ex $ negate 0.3)- <> emph ".0.0"+ <> emph ".1.0"++label :: Label -> LaTeX+label l = TeXComm "label" [FixArg $ TeXRaw $ render l]++ref :: Label -> LaTeX+ref l = TeXComm "ref" [FixArg $ TeXRaw $ render l]++pageref :: Label -> LaTeX+pageref l = TeXComm "pageref" [FixArg $ TeXRaw $ render l]
Text/LaTeX/Base/Commands/Monad.hs view
@@ -9,7 +9,8 @@ -- /and therefore, changes must to be done in these places./ module Text.LaTeX.Base.Commands.Monad - ( raw + ( -- * Basic functions + raw , between -- * Preamble commands , title , author @@ -161,10 +162,6 @@ , roman_ , alph , alph_ - -- ** Cross references - , label - , ref - , pageref -- ** Boxes , mbox , fbox @@ -173,6 +170,10 @@ , makebox , raisebox , rule + -- * Cross references + , label + , ref + , pageref -- ** Tables , tabular , (&) @@ -201,6 +202,17 @@ raw a1 = do textell ( App.raw a1) {-| +Calling 'between' @c l1 l2@ puts @c@ between @l1@ and @l2@ and + appends them. +-} +between :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +between a1 a2 a3 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + a3 <- extractLaTeX_ a3 + textell ( App.between a1 a2 a3) + +{-| Generate the title. It normally contains the 'title' name of your document, the 'author'(s) and 'date'. -} @@ -400,18 +412,6 @@ textell ( App.cite a1) -ref :: (Monad m) => Label -> LaTeXT_ m -ref a1 = do textell ( App.ref a1) - - -label :: (Monad m) => Label -> LaTeXT_ m -label a1 = do textell ( App.label a1) - - -pageref :: (Monad m) => Label -> LaTeXT_ m -pageref a1 = do textell ( App.pageref a1) - - documentclass :: (Monad m) => [LaTeXT_ m] -> LaTeXT_ m -> LaTeXT_ m documentclass a1 a2 = do a1 <- mapM extractLaTeX_ a1 @@ -1007,5 +1007,17 @@ hatex_version :: (Monad m) => LaTeXT_ m hatex_version = do textell ( App.hatex_version) + + +label :: (Monad m) => Label -> LaTeXT_ m +label a1 = do textell ( App.label a1) + + +ref :: (Monad m) => Label -> LaTeXT_ m +ref a1 = do textell ( App.ref a1) + + +pageref :: (Monad m) => Label -> LaTeXT_ m +pageref a1 = do textell ( App.pageref a1)
Text/LaTeX/Base/Monad.hs view
@@ -17,6 +17,8 @@ * The "Text.LaTeX.Base.Commands.Monad" module, which exports the LaTeX standard commands and environments.++Here is also defined a 'Num' instance for 'LaTeXT'. -} module Text.LaTeX.Base.Monad ( LaTeX , (<>) @@ -31,4 +33,35 @@ import Text.LaTeX.Base.Types import Text.LaTeX.Base.Writer import Text.LaTeX.Base.Commands.Monad+-- Import LaTeX Num instance+import Text.LaTeX.Base ()+-- Import 'lift' function+import Control.Monad.Trans (lift) +-- Num instance for LaTeXT++-- Sadly, we need 'Show' and 'Eq' instances for LaTeXT in order+-- to do its 'Num' instance.++-- | Don't use it! This instance only exists in order to+-- define a 'Num' instance to 'LaTeXT'.+instance Show (LaTeXT m a) where+ show _ = error "Cannot use \"show\" Show method with a LaTeXT value."++-- | Don't use it! This instance only exists in order to+-- define a 'Num' instance to 'LaTeXT'.+instance Eq (LaTeXT m a) where+ _ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value."++-- | Be careful when using 'fromInteger' over a 'LaTeXT' value,+-- the returned value of the computation is bottom (i.e. 'undefined').+-- Methods 'abs' and 'signum' are undefined. Don't use them!+instance Monad m => Num (LaTeXT m a) where+ (+) = liftOp (+)+ (-) = liftOp (-)+ (*) = (>>)+ negate = liftFun negate+ fromInteger = fromString . show+ -- Non-defined methods+ abs _ = "Cannot use \"abs\" Num method with a LaTeXT value."+ signum _ = "Cannot use \"signum\" Num method with a LaTeXT value."
Text/LaTeX/Base/Syntax.hs view
@@ -33,7 +33,7 @@ -- Use '<>' preferably. | TeXEmpty -- ^ An empty expression. -- Neutral element of '<>'. - deriving Show+ deriving (Eq,Show) -- | Alias for 'TeXBraces'. braces :: LaTeX -> LaTeX@@ -46,7 +46,7 @@ | MOptArg [LaTeX] -- ^ Multiple optional argument. | SymArg LaTeX -- ^ An argument enclosed between @\<@ and @\>@. | MSymArg [LaTeX] -- ^ Version of 'SymArg' with multiple options. - deriving Show + deriving (Eq,Show) -- Monoid instance for 'LaTeX'. @@ -80,5 +80,4 @@ protectChar '~' = "\\~{}" protectChar '\\' = "\\textbackslash{}" protectChar '_' = "\\_{}" -protectChar x = [x] - +protectChar x = [x]
Text/LaTeX/Base/Types.hs view
@@ -3,7 +3,7 @@ module Text.LaTeX.Base.Types ( Label- , createLabel+ , createLabel , labelName , Pos (..) , TableSpec (..) , Measure (..)@@ -12,14 +12,20 @@ import Text.LaTeX.Base.Syntax import Text.LaTeX.Base.Render -newtype Label = Label String deriving Show+newtype Label = Label String deriving (Eq, Show) createLabel :: String -> Label-createLabel str = Label str+createLabel = Label +labelName :: Label -> String+labelName (Label str) = str+ instance Render Label where render (Label str) = fromString str +instance IsString Label where+ fromString = createLabel+ data Pos = Bottom | Center | Top deriving Show instance Render Pos where@@ -66,3 +72,4 @@ render (Ex x) = render x <> "ex" render (Em x) = render x <> "em" render (CustomMeasure x) = render x+
+ Text/LaTeX/Base/Warnings.hs view
@@ -0,0 +1,141 @@++{-# LANGUAGE OverloadedStrings #-}++module Text.LaTeX.Base.Warnings (+ -- * Warnings datatype+ Warning (..)+ , TeXCheck+ , check+ , checkFromFunction+ -- * Several checkings+ , checkLabels+ , checkClass+ , checkDoc+ -- * Complete checking+ , checkAll+ ) where++import Text.LaTeX.Base.Syntax+import Control.Monad.State+import Data.Text+import Data.Maybe+import Control.Arrow+import Data.Monoid++-- | List of possible warnings.+data Warning =+ UnusedLabel Text -- ^ There is an unused label. Argument is its name.+ | UndefinedLabel Text -- ^ There is a reference to an undefined label. Arguments is the name.+ --+ | NoClassSelected -- ^ No class selected with 'documentclass'.+ | NoDocumentInserted -- ^ No 'document' inserted.+ --+ | CustomWarning Text -- ^ Custom warning for custom checkings. Use it as you want.+ deriving (Eq,Show)++-- | A 'TeXCheck' is a function that checks possible warnings from a 'LaTeX' value.+-- Use the 'Monoid' instance to combine check functions.+newtype TeXCheck = TC { check :: LaTeX -> [Warning] -- ^ Apply a checking.+ }+-- | Build a 'TeXCheck' from a function.+checkFromFunction :: (LaTeX -> [Warning]) -> TeXCheck+checkFromFunction = TC++instance Monoid TeXCheck where+ mempty = TC $ const []+ mappend (TC tc1) (TC tc2) = TC $ uncurry mappend . (tc1 &&& tc2)++checkAll :: TeXCheck+checkAll = mconcat [ checkLabels , checkClass , checkDoc ]++-- Searching for 'documentclass' and 'document'++type BoolSt = State Bool++-- | Check if a document class is specified for the document (using 'documentclass').+checkClass :: TeXCheck+checkClass = TC $ \l -> if execState (classcheck l) False then [] else [NoClassSelected]++classcheck :: LaTeX -> BoolSt ()+classcheck (TeXComm c _) =+ case c of+ "documentclass" -> put True+ _ -> return ()+classcheck (TeXBraces l) = classcheck l+classcheck (TeXSeq l1 l2) = classcheck l1 >> classcheck l2+classcheck _ = return ()++-- | Check if the 'document' environment is called in a 'LaTeX'.+checkDoc :: TeXCheck+checkDoc = TC $ \l -> if execState (doccheck l) False then [] else [NoDocumentInserted]++doccheck :: LaTeX -> BoolSt ()+doccheck (TeXEnv n _ _) =+ case n of+ "document" -> put True+ _ -> return ()+doccheck (TeXBraces l) = doccheck l+doccheck (TeXSeq l1 l2) = doccheck l1 >> doccheck l2+doccheck _ = return ()++-- Checking labels++data LabWarn =+ RefNoLabel Text+ | LabelNoRef Text+ | LabelRef Text++labWarnToWarning :: LabWarn -> Maybe Warning+labWarnToWarning (RefNoLabel n) = Just $ UndefinedLabel n+labWarnToWarning (LabelNoRef n) = Just $ UnusedLabel n+labWarnToWarning _ = Nothing++type LabSt = State [LabWarn]++-- | Checking for unused labels or references tu undefined labels.+checkLabels :: TeXCheck+checkLabels = TC $ \l -> catMaybes . fmap labWarnToWarning $ execState (labcheck l) []++labcheck :: LaTeX -> LabSt ()+labcheck (TeXComm c [FixArg (TeXRaw n)]) =+ case c of+ "label" -> newlab n+ "ref" -> newref n+ "pageref" -> newref n+labcheck (TeXEnv _ _ l) = labcheck l+labcheck (TeXMath l) = labcheck l+labcheck (TeXOp _ l1 l2) = labcheck l1 >> labcheck l2+labcheck (TeXBraces l) = labcheck l+labcheck (TeXSeq l1 l2) = labcheck l1 >> labcheck l2+labcheck _ = return ()++newlab :: Text -> LabSt ()+newlab n = do+ st <- get+ let addLab :: Text -> [LabWarn] -> [LabWarn]+ addLab n [] = [LabelNoRef n]+ addLab n l@(x:xs) = let ys = x : addLab n xs in+ case x of+ RefNoLabel m -> if n == m then LabelRef n : xs+ else ys+ LabelNoRef m -> if n == m then l+ else ys+ LabelRef m -> if n == m then l+ else ys+ put $ addLab n st++newref :: Text -> LabSt ()+newref n = do+ st <- get+ let addRef :: Text -> [LabWarn] -> [LabWarn]+ addRef n [] = [RefNoLabel n]+ addRef n l@(x:xs) = let ys = x : addRef n xs in+ case x of+ RefNoLabel m -> if n == m then l+ else ys+ LabelNoRef m -> if n == m then LabelRef n : xs+ else ys+ LabelRef m -> if n == m then l+ else ys+ put $ addRef n st+
Text/LaTeX/Base/Writer.hs view
@@ -6,25 +6,34 @@ LaTeXT , LaTeXT_ , runLaTeXT - , execLaTeXT + , execLaTeXT+ , execLaTeXTWarn , extractLaTeX , extractLaTeX_- , textell + , textell+ , liftFun+ , liftOp ) where - + import Control.Monad.Writer +import Control.Monad.State import Control.Applicative+import Control.Arrow import Data.String -- import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Render +import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Warnings (Warning,checkAll,check)+--+import Control.Monad (liftM) --- | Newtype wrapper over the 'WriterT' monad transformer, with 'LaTeX' --- as writer state. newtype LaTeXT m a = LaTeXT { unwrapLaTeXT :: WriterT LaTeX m a } deriving (Functor,Applicative,Monad,MonadIO) +instance MonadTrans LaTeXT where+ lift = LaTeXT . lift+ type LaTeXT_ m = LaTeXT m () runLaTeXT :: LaTeXT m a -> m (a,LaTeX) @@ -32,23 +41,60 @@ -- | This is the usual way to run the 'LaTeXT' monad -- and obtain a 'LaTeX' value. -execLaTeXT :: Functor m => LaTeXT m a -> m LaTeX -execLaTeXT = fmap snd . runLaTeXT +execLaTeXT :: Monad m => LaTeXT m a -> m LaTeX +execLaTeXT = liftM snd . runLaTeXT +-- | Version of 'execLaTeXT' with possible warning messages.+-- This function applies 'checkAll' to the 'LaTeX' output.+execLaTeXTWarn :: Monad m => LaTeXT m a -> m (LaTeX,[Warning])+execLaTeXTWarn = liftM (id &&& check checkAll) . execLaTeXT+ -- | 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 . lift . runLaTeXT extractLaTeX_ :: Monad m => LaTeXT m a -> LaTeXT m LaTeX -extractLaTeX_ = (>>= return . snd) . LaTeXT . lift . runLaTeXT+extractLaTeX_ = liftM snd . extractLaTeX -- | With 'textell' you can append 'LaTeX' values to the -- state of the 'LaTeXT' monad. textell :: Monad m => LaTeX -> LaTeXT m () textell = LaTeXT . tell +-- | Lift a function over 'LaTeX' values to a function+-- acting over the state of a 'LaTeXT' computation.+liftFun :: Monad m+ => (LaTeX -> LaTeX)+ -> (LaTeXT m a -> LaTeXT m a)+liftFun f ml = do+ (a,l') <- lift $ do+ (a,l) <- runLaTeXT ml+ let l' = f l+ return (a,l')+ textell l'+ return a++-- | Lift an operator over 'LaTeX' values to an operator+-- acting over the state of two 'LaTeXT' computations.+--+-- /Note: The returned value is the one returned by the/+-- /second argument of the lifted operator./+liftOp :: Monad m+ => (LaTeX -> LaTeX -> LaTeX)+ -> (LaTeXT m a -> LaTeXT m a -> LaTeXT m a)+liftOp op ml1 ml2 = do+ (a,l') <- lift $ do+ (_,l1) <- runLaTeXT ml1+ (a,l2) <- runLaTeXT ml2+ let l' = l1 `op` l2+ return (a,l')+ textell l'+ return a+ -- 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 = (>> return undefined) . textell . fromString + fromString = (>> return undefined) . textell . fromString
Text/LaTeX/Packages.hs view
@@ -9,6 +9,7 @@ -- * Mathematics packages , module Text.LaTeX.Packages.AMSMath , module Text.LaTeX.Packages.AMSFonts+ , module Text.LaTeX.Packages.AMSThm -- * Graphics packages , module Text.LaTeX.Packages.Color ) where @@ -18,4 +19,5 @@ import Text.LaTeX.Packages.Beamer import Text.LaTeX.Packages.AMSMath import Text.LaTeX.Packages.AMSFonts+import Text.LaTeX.Packages.AMSThm import Text.LaTeX.Packages.Color
Text/LaTeX/Packages/AMSFonts.hs view
@@ -1,4 +1,6 @@ +{-# OPTIONS_HATEX MakeMonadic #-}+ module Text.LaTeX.Packages.AMSFonts ( -- * AMSFonts package amsfonts
Text/LaTeX/Packages/AMSMath.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HATEX MakeMonadic #-} module Text.LaTeX.Packages.AMSMath ( -- * AMSMath package@@ -9,13 +10,22 @@ -- ** Superscript and subscript , (^:) , (!:) -- ** Function symbols+ -- | Some symbols are preceded with /t/ to be distinguished from+ -- predefined Haskell entities (like 'sin' and 'cos'). , tsin , arcsin , tcos , arccos , ttan , arctan , texp , tlog , ln+ -- ** Operator symbols+ , (=:) , (/=:)+ , (>:) , (>=:)+ , (<:) , (<=:)+ , in_ , ni , notin -- ** Other symbols , to+ , forall+ , dagger, ddagger -- * Fonts , mathbf , mathrm@@ -26,7 +36,7 @@ ) where import Text.LaTeX.Base.Syntax-import Text.LaTeX.Base.Commands (raw)+import Text.LaTeX.Base.Commands (raw,between) -- | AMSMath package. -- Example:@@ -87,11 +97,62 @@ ln :: LaTeX ln = TeXComm "ln" [] +---- Operator symbols++-- | Negative form of an operator.+notop :: (LaTeX -> LaTeX -> LaTeX)+ -> (LaTeX -> LaTeX -> LaTeX)+notop op =+ \l1 l2 ->+ (l1 <> TeXCommS "not") `op` l2++infix 4 =: , /=:++(=:),(/=:) :: LaTeX -> LaTeX -> LaTeX+(=:) = TeXOp "="+(/=:) = notop (=:)++-- | Greater.+(>:) :: LaTeX -> LaTeX -> LaTeX+(>:) = TeXOp ">"++-- | Greater or equal.+(>=:) :: LaTeX -> LaTeX -> LaTeX+(>=:) = between $ TeXComm "geq" []++-- | Lesser.+(<:) :: LaTeX -> LaTeX -> LaTeX+(<:) = TeXOp "<"++-- | Lesser or equal.+(<=:) :: LaTeX -> LaTeX -> LaTeX+(<=:) = between $ TeXComm "leq" []++in_ :: LaTeX -> LaTeX -> LaTeX+in_ = between $ TeXComm "in" []++ni :: LaTeX -> LaTeX -> LaTeX+ni = between $ TeXComm "ni" []++notin :: LaTeX -> LaTeX -> LaTeX+notin = between $ TeXComm "notin" []+ ---- Other symbols -- | A right-arrow. to :: LaTeX to = TeXComm "to" []++forall :: LaTeX+forall = TeXComm "forall" []++-- | Dagger symbol.+dagger :: LaTeX+dagger = TeXComm "dagger" []++-- | Double dagger symbol.+ddagger :: LaTeX+ddagger = TeXComm "ddagger" [] ------------------------------------- ------------ Math Fonts -------------
Text/LaTeX/Packages/AMSMath/Monad.hs view
@@ -17,13 +17,22 @@ -- ** Superscript and subscript , (^:) , (!:) -- ** Function symbols + -- | Some symbols are preceded with /t/ to be distinguished from + -- predefined Haskell entities (like 'sin' and 'cos'). , tsin , arcsin , tcos , arccos , ttan , arctan , texp , tlog , ln + -- ** Operator symbols + , (=:) , (/=:) + , (>:) , (>=:) + , (<:) , (<=:) + , in_ , ni , notin -- ** Other symbols , to + , forall + , dagger, ddagger -- * Fonts , mathbf , mathrm @@ -114,10 +123,87 @@ ln :: (Monad m) => LaTeXT_ m ln = do textell ( App.ln) + +(=:) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +(=:) a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( (App.=:) a1 a2) + + +(/=:) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +(/=:) a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( (App./=:) a1 a2) + + +(>:) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +(>:) a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( (App.>:) a1 a2) + + +(>=:) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +(>=:) a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( (App.>=:) a1 a2) + + +(<:) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +(<:) a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( (App.<:) a1 a2) + + +(<=:) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +(<=:) a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( (App.<=:) a1 a2) + + +in_ :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +in_ a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( App.in_ a1 a2) + + +ni :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +ni a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( App.ni a1 a2) + + +notin :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m +notin a1 a2 + = do a1 <- extractLaTeX_ a1 + a2 <- extractLaTeX_ a2 + textell ( App.notin a1 a2) + -- | A right-arrow. to :: (Monad m) => LaTeXT_ m to = do textell ( App.to) + + +forall :: (Monad m) => LaTeXT_ m +forall = do textell ( App.forall) + +-- | Dagger symbol. + +dagger :: (Monad m) => LaTeXT_ m +dagger = do textell ( App.dagger) + +-- | Double dagger symbol. + +ddagger :: (Monad m) => LaTeXT_ m +ddagger = do textell ( App.ddagger) mathbf :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+ Text/LaTeX/Packages/AMSThm.hs view
@@ -0,0 +1,69 @@++{-# OPTIONS_HATEX MakeMonadic #-}+{-# LANGUAGE OverloadedStrings #-}++-- | Package for theorem environments.+module Text.LaTeX.Packages.AMSThm+ ( -- * AMSThm package+ amsthm+ -- * AMSThm functions+ , newtheorem+ , theorem+ , proof+ , qedhere+ , TheoremStyle (..)+ , theoremstyle+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Render++-- | AMSThm package.+-- Example:+--+-- > usepackage [] amsthm+amsthm :: String+amsthm = "amsthm"++-- | Create a new 'theorem' environment type.+-- Arguments are environment name (this will be the argument+-- when using the 'theorem' function) and the displayed title.+--+-- For example:+--+-- > newtheorem "prop" "Proposition"+--+-- > theorem "prop" "This is it."+newtheorem :: String -> LaTeX -> LaTeX+newtheorem str l = TeXComm "newtheorem" [ FixArg $ fromString str , FixArg l ]++theorem :: String -> LaTeX -> LaTeX+theorem str l = TeXEnv str [] l++-- | The 'proof' environment. The first optional argument+-- is used to put a custom title to the proof.+proof :: Maybe LaTeX -> LaTeX -> LaTeX+proof Nothing l = TeXEnv "proof" [ ] l+proof (Just n) l = TeXEnv "proof" [ OptArg n ] l++-- | Insert the /QED/ symbol.+qedhere :: LaTeX+qedhere = TeXComm "qedhere" []++data TheoremStyle =+ Plain+ | Definition+ | Remark+ | CustomThmStyle String+ deriving Show++instance Render TheoremStyle where+ render Plain = "plain"+ render Definition = "definition"+ render Remark = "remark"+ render (CustomThmStyle str) = fromString str++-- | Set the theorem style. Call this function in the preamble.+theoremstyle :: TheoremStyle -> LaTeX+theoremstyle thmsty = TeXComm "theoremstyle" [ FixArg $ TeXRaw $ render thmsty ]+
+ Text/LaTeX/Packages/AMSThm/Monad.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE OverloadedStrings #-} + +-- | Package for theorem environments. +-- +-- /For contributors: This module was automatically generated by HaTeX-meta./ +-- /So, please, don't make any change here directly, because/ +-- /this is intended to be generated from/ +-- "Text.LaTeX.Packages.AMSThm" /module via HaTeX-meta,/ +-- /and therefore, changes must to be done in these places./ + +module Text.LaTeX.Packages.AMSThm.Monad + ( -- * AMSThm package + amsthm + -- * AMSThm functions + , newtheorem + , theorem + , proof + , qedhere + , TheoremStyle (..) + , theoremstyle + ) where + +import Text.LaTeX.Base.Writer +import Text.LaTeX.Base.Render +import Text.LaTeX.Base.Types +import qualified Text.LaTeX.Packages.AMSThm as App +import Text.LaTeX.Packages.AMSThm(TheoremStyle) + +{-| +AMSThm package. + Example: + +> usepackage [] amsthm + +-} +amsthm :: String +amsthm = App.amsthm + +{-| +Create a new 'theorem' environment type. + Arguments are environment name (this will be the argument + when using the 'theorem' function) and the displayed title. +For example: + +> newtheorem "prop" "Proposition" + + +> theorem "prop" "This is it." + +-} +newtheorem :: (Monad m) => String -> LaTeXT_ m -> LaTeXT_ m +newtheorem a1 a2 + = do a2 <- extractLaTeX_ a2 + textell ( App.newtheorem a1 a2) + + +theorem :: (Monad m) => String -> LaTeXT_ m -> LaTeXT_ m +theorem a1 a2 + = do a2 <- extractLaTeX_ a2 + textell ( App.theorem a1 a2) + +{-| +The 'proof' environment. The first optional argument + is used to put a custom title to the proof. +-} +proof :: (Monad m) => Maybe (LaTeXT_ m) -> LaTeXT_ m -> LaTeXT_ m +proof a1 a2 + = do a1 <- maybe (return Nothing) + ((>>= return . Just) . extractLaTeX_) + a1 + a2 <- extractLaTeX_ a2 + textell ( App.proof a1 a2) + +-- | Insert the /QED/ symbol. + +qedhere :: (Monad m) => LaTeXT_ m +qedhere = do textell ( App.qedhere) + +-- | Set the theorem style. Call this function in the preamble. + +theoremstyle :: (Monad m) => TheoremStyle -> LaTeXT_ m +theoremstyle a1 = do textell ( App.theoremstyle a1) + +
Text/LaTeX/Packages/Beamer.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HATEX MakeMonadic #-} module Text.LaTeX.Packages.Beamer ( -- * Beamer package @@ -27,7 +28,7 @@ -- | The 'beamer' document class. Importing a package is not required. Example: -- -- > documentclass [] beamer -beamer :: LaTeX +beamer :: String beamer = "beamer" -- | A presentation is composed of a sequence of frames. Each frame is created with this function.
Text/LaTeX/Packages/Beamer/Monad.hs view
@@ -40,8 +40,8 @@ > documentclass [] beamer -} -beamer :: (Monad m) => LaTeXT_ m -beamer = do textell ( App.beamer) +beamer :: String +beamer = App.beamer -- | A presentation is composed of a sequence of frames. Each frame is created with this function.
Text/LaTeX/Packages/Color.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HATEX MakeMonadic #-} module Text.LaTeX.Packages.Color ( -- * Color package
Text/LaTeX/Packages/Hyperref.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HATEX MakeMonadic #-} module Text.LaTeX.Packages.Hyperref ( -- * Hyperref package
Text/LaTeX/Packages/Inputenc.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_HATEX MakeMonadic #-} module Text.LaTeX.Packages.Inputenc ( -- * Inputenc package
Text/LaTeX/Packages/Monad.hs view
@@ -9,6 +9,7 @@ -- * Mathematics packages , module Text.LaTeX.Packages.AMSMath.Monad , module Text.LaTeX.Packages.AMSFonts.Monad+ , module Text.LaTeX.Packages.AMSThm.Monad -- * Graphics packages , module Text.LaTeX.Packages.Color.Monad ) where @@ -18,4 +19,5 @@ import Text.LaTeX.Packages.Beamer.Monad import Text.LaTeX.Packages.AMSMath.Monad import Text.LaTeX.Packages.AMSFonts.Monad+import Text.LaTeX.Packages.AMSThm.Monad import Text.LaTeX.Packages.Color.Monad