HaTeX 1.0.0 → 1.0.1
raw patch · 9 files changed
+206/−124 lines, 9 filesdep +string-combinatorsPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: string-combinators
API changes (from Hackage documentation)
- Text.LaTeX.Define: keys :: LaTeX -> LaTeX
- Text.LaTeX.Define: listOpts :: [LaTeX] -> LaTeX
- Text.LaTeX.Define: space :: LaTeX
- Text.LaTeX.Result: bfinal :: Result -> Result
- Text.LaTeX.Result: bs :: Result -> Result
- Text.LaTeX.Result: comm :: Result -> Result
- Text.LaTeX.Result: ds :: Result -> Result
- Text.LaTeX.Result: ks :: Result -> Result
- Text.LaTeX.Result: pfinal :: Result -> Result
- Text.LaTeX.Result: sep :: Result -> Result
+ Text.LaTeX.Monad: instance Monoid (LaTeXM a)
- Text.LaTeX.Arguments: type Word = String
+ Text.LaTeX.Arguments: type Word = LaTeX
- Text.LaTeX.Commands: skip :: Float -> LaTeX
+ Text.LaTeX.Commands: skip :: LaTeX -> LaTeX
Files
- HaTeX.cabal +18/−7
- Text/LaTeX.hs +5/−3
- Text/LaTeX/Arguments.hs +7/−1
- Text/LaTeX/Commands.hs +108/−32
- Text/LaTeX/Define.hs +17/−25
- Text/LaTeX/IO.hs +1/−0
- Text/LaTeX/Monad.hs +35/−5
- Text/LaTeX/Packages.hs +6/−4
- Text/LaTeX/Result.hs +9/−47
HaTeX.cabal view
@@ -1,5 +1,5 @@ Name: HaTeX -Version: 1.0.0 +Version: 1.0.1 Author: Daniel Díaz License: BSD3 License-file: license @@ -10,21 +10,32 @@ You can write LaTeX files using this package. See Text.LaTeX for a brief introduction. . - It's a first version, - and documentation is in process, - but you can test the library and report me any bug or suggestion at: + You can test the library and report me any bug or suggestion at: . lazy.ddiaz\@gmail.com . Also, if you have an example where you use HaTeX, you could send it to my email. Thank you. + . + Changes from last version: + . + * Added new documentation. + . + * Added string combinators for omit some definitions + . + * Deleted some unnecessary definitions. Extensions: OverloadedStrings , FlexibleInstances , TypeSynonymInstances Build-type: Simple -Build-depends: base >= 4 && < 5 , mtl , dstring , to-string-class , filepath -Cabal-version: >= 1.2.3 +Build-depends: base >= 4 && < 5 + , mtl + , dstring + , to-string-class + , string-combinators + , filepath +Cabal-version: >= 1.6 Tested-with: GHC == 6.12.1 Exposed-modules: Text.LaTeX - , Text.LaTeX.Macro , Text.LaTeX.IO + , Text.LaTeX.Macro , Text.LaTeX.Commands , Text.LaTeX.Packages , Text.LaTeX.Arguments
Text/LaTeX.hs view
@@ -13,7 +13,7 @@ -- ** Enriching your text -- $guide4 - -- ** Performing IO actions + -- ** Performing IO computations -- $guide5 -- * HaTeX related functions @@ -28,8 +28,8 @@ , module Text.LaTeX.Arguments , module Text.LaTeX.Packages , module Text.LaTeX.Commands - , module Text.LaTeX.IO , module Text.LaTeX.Macro + , module Text.LaTeX.IO ) where import Text.LaTeX.Monad @@ -52,7 +52,7 @@ -- | Your HaTeX version. hatexVersion :: LaTeX -hatexVersion = do textbf "1" ; ".0.0" +hatexVersion = do textbf "1" ; ".0.1" -- | Export the 'Result' of a 'LaTeX' sequence in a /.tex/ file. export :: @@ -154,6 +154,8 @@ Applying the function to only part of the text, we achieve modify just that part. -} + +-- Performing IO computations {- $guide5 To includes an 'IO' computation in 'LaTeX' monad, use 'iolx'.
Text/LaTeX/Arguments.hs view
@@ -47,9 +47,12 @@ , headings , empty -- * Meters + -- ** Width and Height , Width, Lift, Extend , width, height, depth , totalheight + -- $measures + -- ** Measures , mm , cm , inch , pt , em , ex ) where @@ -73,7 +76,7 @@ type Date = LaTeX -type Word = String +type Word = LaTeX type Marker = LaTeX @@ -205,6 +208,9 @@ totalheight :: LaTeX totalheight = comm0_ "totalheight" + +-- $measures +-- #Measures# mm :: Float -> LaTeX mm = (>>"mm") . lxany
Text/LaTeX/Commands.hs view
@@ -11,8 +11,8 @@ -- * Document Environment , document -- * Text order - , pfbk , lnbk , lnbk_ + , pfbk , newpage , linebreak , nolinebreak , pagebreak , nopagebreak @@ -78,6 +78,7 @@ , textbf , textit , textsc , textnormal -- ** Size + -- $fontsize , tiny , scriptsize , footnotesize , small , normalsize @@ -112,8 +113,14 @@ , phantom ) where -import Data.List +import Prelude hiding (unwords) +import Data.List (intersperse) +import GHC.Exts (fromString) +import Data.Monoid (mappend) +import Data.String.Combinators (braces,unwords,between + ,mid ,newline,brackets) + import Text.LaTeX.Monad import Text.LaTeX.Define import Text.LaTeX.Arguments @@ -131,52 +138,63 @@ string :: String -> LaTeX string = mapM_ char +-- | Delimites between quotes a text. qts :: LaTeX -> LaTeX -qts x = do "``" - x - "''" +qts = between "``" "''" ldots :: LaTeX ldots = comm0 "ldots" -- +-- | In header, determines the document class. documentclass :: [ClassOption] -> Class -> LaTeX documentclass = comm4 "documentclass" +-- | In header, import a package. usepackage :: [PackageOption] -> Package -> LaTeX usepackage = comm4 "usepackage" +-- | In header, determines page style. pagestyle :: Style -> LaTeX pagestyle = comm1 "pagestyle" --- | A local version of 'pagestyle'. +-- | A local version of 'pagestyle', to use for any page. thispagestyle :: Style -> LaTeX thispagestyle = comm1 "thispagestyle" +-- | In header, especifies the document's author. author :: Name -> LaTeX author = comm1 "author" +-- | In header, especifies the document's title. title :: Title -> LaTeX title = comm1 "title" +-- | In header, inserts a date of writing. +-- If you don't specify one, it takes the date of export. date :: Date -> LaTeX date = comm1 "date" +-- Document environment + document :: LaTeX -> LaTeX document = env "document" -- Text Order -pfbk :: LaTeX -pfbk = "\n\n" - +-- | Starts a new line. lnbk :: LaTeX lnbk = comm0_ "\\" +-- | Starts a new paragraph. +pfbk :: LaTeX +pfbk = newline >> newline + lnbk_ :: LaTeX lnbk_ = comm0_ "\\*" +-- | Starts a new page. newpage :: LaTeX newpage = comm0 "newpage" @@ -207,33 +225,37 @@ -- Importing include :: FilePath -> LaTeX -include = comm1 "include" . lx . toResult +include = comm1 "include" . fromString includeonly :: [FilePath] -> LaTeX -includeonly = comm1 "includeonly" . mapM_ (lx . toResult) . intersperse "," +includeonly = comm1 "includeonly" . mapM_ fromString . intersperse "," input :: FilePath -> LaTeX -input = comm1 "input" . lx . toResult +input = comm1 "input" . fromString -- Hyphenation hyphenation :: [Word] -> LaTeX -hyphenation = comm1 "hyphenation" . lx . toResult . unwords +hyphenation = comm1 "hyphenation" . unwords hyp :: LaTeX hyp = comm0 "-" -- Ready-Made Strings +-- | Writes current date. today :: LaTeX today = comm0 "today" +-- | TeX nice word. tex :: LaTeX tex = comm0 "TeX" +-- | LaTeX nice word. latex :: LaTeX latex = comm0 "LaTeX" +-- | LaTeX2e nice word. latexe :: LaTeX latexe = comm0 "LaTeXe" @@ -309,9 +331,11 @@ appendix :: LaTeX appendix = comm0 "appendix" +-- | Generates the title page. maketitle :: LaTeX maketitle = comm0 "maketitle" +-- | Generates the table of contents. tableofcontents :: LaTeX tableofcontents = comm0 "tableofcontents" @@ -339,14 +363,17 @@ -- Footnotes +-- | Adds a given text to the page's footnote. footnote :: Text -> LaTeX footnote = comm1 "footnote" -- Emphasized +-- | Underlines a text. underline :: Text -> LaTeX underline = comm1 "underline" +-- | Emphasizes a text. emph :: Text -> LaTeX emph = comm1 "emph" @@ -364,38 +391,52 @@ item :: [ItemOption] -> LaTeX item = comm3 "item" +-- | Left alignment. flushleft :: LaTeX -> LaTeX flushleft = env "flushleft" +-- | Right alignment. flushright :: LaTeX -> LaTeX flushright = env "flushright" +-- | Center alignment. center :: LaTeX -> LaTeX center = env "center" +-- | Quote from a text. quote :: LaTeX -> LaTeX quote = env "quote" +-- | Like 'quote', but indenting the first line of each paragraph. quotation :: LaTeX -> LaTeX quotation = env "quotation" verse :: LaTeX -> LaTeX verse = env "verse" +-- | Use 'abstract' to create an abstract, containing the argument's text. abstract :: LaTeX -> LaTeX abstract = env "abstract" +-- | A text within the 'verbatim' environment has monospaced font +-- and no commands or environments will be executed. verbatim :: LaTeX -> LaTeX verbatim = env "verbatim" +-- | Like 'verbatim', but it makes visible the spaces. verbatim_ :: LaTeX -> LaTeX verbatim_ = env "verbatim*" +sep :: LaTeX -> LaTeX +sep = between "|" "|" + +-- | An inline version of 'verbatim'. verb :: LaTeX -> LaTeX -verb = (comm0_ "verb" >>) . reslx sep +verb = (comm0_ "verb" >>) . sep +-- | An inline version of 'verbatim_'. verb_ :: LaTeX -> LaTeX -verb_ = (comm0_ "verb*" >>) . reslx sep +verb_ = (comm0_ "verb*" >>) . sep -- Floating Bodies @@ -490,8 +531,11 @@ -- Font Sizes +-- $fontsize +-- Differents fonts size are sorted from lowest to highest. + tiny :: LaTeX -> LaTeX -tiny = comm8 "tinty" +tiny = comm8 "tiny" scriptsize :: LaTeX -> LaTeX scriptsize = comm8 "scriptsize" @@ -530,24 +574,30 @@ linespread :: Float -> LaTeX linespread = comm1 "linespread" . lxany +-- | Creates an horizontal spaces with length specified by the argument. +-- See "Text.LaTeX.Arguments#Measures" to create a correct argument. hspace :: LaTeX -> LaTeX hspace = comm1 "hspace" +-- | Same as 'hspace', but it ignores start or end of lines. hspace_ :: LaTeX -> LaTeX hspace_ = comm1 "hspace*" +-- | Vertical version of 'hspace'. Useful to separate two paragraphs. vspace :: LaTeX -> LaTeX vspace = comm1 "vspace" +-- | Same as 'vspace', but it ignores start or end of pages. vspace_ :: LaTeX -> LaTeX vspace_ = comm1 "vspace*" stretch :: Int -> LaTeX stretch = comm1 "stretch" . lxany -skip :: Float -> LaTeX -skip x = do lnbk - lx . bs . toResult $ show x +-- | Like 'vspace', but for lines of the same paragraph. +-- 'bigskip' and 'smallskip' use 'skip' with predefined arguments. +skip :: LaTeX -> LaTeX +skip = mappend lnbk . brackets bigskip :: LaTeX bigskip = comm0 "bigskip" @@ -567,16 +617,16 @@ fbox = comm1 "fbox" parbox :: [Char] -> Width -> LaTeX -> LaTeX -parbox c = comm9 "parbox" (if null c then [] else [lx $ toResult c]) +parbox c = comm9 "parbox" (if null c then [] else [fromString c]) minipage :: [Char] -> Width -> LaTeX -> LaTeX -minipage c = env3 "minipage" (if null c then [] else [lx $ toResult c]) +minipage c = env3 "minipage" (if null c then [] else [fromString c]) makebox :: [Width] -> [Char] -> LaTeX -> LaTeX -makebox w c = comm10 "makebox" w (if null c then [] else [lx $ toResult c]) +makebox w c = comm10 "makebox" w (if null c then [] else [fromString c]) framebox :: [Width] -> [Char] -> LaTeX -> LaTeX -framebox w c = comm10 "framebox" w (if null c then [] else [lx $ toResult c]) +framebox w c = comm10 "framebox" w (if null c then [] else [fromString c]) raisebox :: Lift -> [Extend] -> [Extend] -> LaTeX -> LaTeX raisebox = comm11 "raisebox" @@ -594,26 +644,49 @@ type Tabular = LaTeX cjustified :: Width -> LaTeX -cjustified = ("p">>) . keys +cjustified = ("p">>) . braces csep :: LaTeX -> LaTeX -csep = ("@">>) . keys +csep = ("@">>) . braces +-- | The 'tabular' environment can be used to creates tables. +-- +-- * First argument specifies vertical position: +-- @\"c\"@ (center), +-- @\"t\"@ (top) and +-- @\"b\"@ (bottom). +-- Example: @[\"t\"]@ +-- +-- * Second argument specifies table's format: +-- @\"l\"@ (left-aligned text column), +-- @\"r\"@ (right-aligned text column), +-- @\"c\"@ (center text column), +-- 'cjustified' (justified text column) and +-- @\"|\"@ (vertical line). +-- Example: @\"|l|r|\"@ +-- +-- * Third argument refers to table's content: +-- 'hline' inserts an horizontal line, +-- 'cline' inserts a partial horizontal line, +-- ('&') separates columns and +-- ('//') separates rows. tabular :: [LaTeX] -> LaTeX -> LaTeX -> Tabular tabular = env3 "tabular" (&) :: LaTeX -> LaTeX -> LaTeX -x & y = do x ; " & " ; y +(&) = mid " & " (//) :: LaTeX -> LaTeX -> LaTeX -x // y = do x - lnbk ; "\n" - y +(//) = mid $ lnbk >> newline +-- | Insert an horizontal line in a 'tabular'. hline :: LaTeX hline = comm0 "hline" -cline :: Int -> Int -> LaTeX +-- | Insert a partial horizontal line in a 'tabular'. +cline :: Int -- ^ Start column + -> Int -- ^ End column + -> LaTeX cline n m = comm1 "cline" $ lxany n - lxany m multicolumn :: Int -> LaTeX -> LaTeX -> LaTeX @@ -621,9 +694,12 @@ type LxMatrix = [[LaTeX]] +-- | A matrix version of 'tabular'. +-- First and second arguments are equal. +-- The generated 'tabular' has the same rows and columns as the matrix. matrixTab :: [LaTeX] -> LaTeX -> LxMatrix -> Tabular -matrixTab p spec = tabular p spec . foldr1 (//) . map (foldr1 (&)) --- CAUTION: Error with empty matrix! +matrixTab p spec m = let f = tabular p spec . foldr1 (//) . map (foldr1 (&)) + in if sum (map length m) == 0 then "" else f m
Text/LaTeX/Define.hs view
@@ -1,11 +1,7 @@ module Text.LaTeX.Define ( - -- * Some @LaTeX@ Utils - space - , keys - , listOpts -- * Defining Commands - , comm0_ + comm0_ , comm0 , comm1 , comm2 @@ -28,31 +24,27 @@ import Control.Monad.Writer import Data.List (intersperse) +import Data.String.Combinators (braces,comma,brackets) + import Text.LaTeX.Monad import Text.LaTeX.Result -space :: LaTeX -space = " " - -keys :: LaTeX -> LaTeX -keys = reslx ks - listOpts :: [LaTeX] -> LaTeX listOpts [] = "" -listOpts xs = reslx bs . sequence_ . intersperse "," $ xs +listOpts xs = brackets . sequence_ . intersperse comma $ xs -- comm0_ :: LaTeX -> LaTeX -comm0_ = reslx comm +comm0_ = mappend "\\" comm0 :: LaTeX -> LaTeX comm0 n = do comm0_ n - "{}" + braces "" comm1 :: LaTeX -> LaTeX -> LaTeX comm1 n x = do comm0_ n - keys x + braces x comm2 :: LaTeX -> LaTeX -> [LaTeX] -> LaTeX comm2 n x opts = do comm1 n x @@ -64,41 +56,41 @@ comm4 :: LaTeX -> [LaTeX] -> LaTeX -> LaTeX comm4 n opts x = do comm3 n opts - keys x + braces x comm5 :: LaTeX -> LaTeX -> LaTeX -> LaTeX comm5 n x y = do comm1 n x - keys y + braces y comm6 :: LaTeX -> LaTeX -> [LaTeX] -> LaTeX -> LaTeX comm6 n x opts y = do comm2 n x opts - keys y + braces y comm7 :: LaTeX -> LaTeX -> [LaTeX] -> LaTeX -> LaTeX -> LaTeX comm7 n x opts y z = do comm6 n x opts y - keys z + braces z comm8 :: LaTeX -> LaTeX -> LaTeX -comm8 n x = keys $ do comm0 n - x +comm8 n x = braces $ do comm0 n + x comm9 :: LaTeX -> [LaTeX] -> LaTeX -> LaTeX -> LaTeX comm9 n opts x y = do comm4 n opts x - keys y + braces y comm10 :: LaTeX -> [LaTeX] -> [LaTeX] -> LaTeX -> LaTeX comm10 n opts1 opts2 x = do comm3 n opts1 listOpts opts2 - keys x + braces x comm11 :: LaTeX -> LaTeX -> [LaTeX] -> [LaTeX] -> LaTeX -> LaTeX comm11 n x opts1 opts2 y = do comm2 n x opts1 listOpts opts2 - keys y + braces y comm12 :: LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX comm12 n x y z = do comm5 n x y - keys z + braces z env :: LaTeX -> LaTeX -> LaTeX env t x = do comm1 "begin" t
Text/LaTeX/IO.hs view
@@ -1,5 +1,6 @@ -- | Some 'IO' computations on 'LaTeX' monad. +-- These functions are similar to those you can find in "System.IO". module Text.LaTeX.IO where import System.IO
Text/LaTeX/Monad.hs view
@@ -21,8 +21,28 @@ import System.IO.Unsafe import Text.LaTeX.Result +import Data.String.Combinators(fromShow) + ---------------------------- +-- | 'LaTeXM' is the monad that represents LaTeX code. +-- Bind operator plays as concatenator. +-- +-- Instances of 'LaTeXM' @a@: +-- +-- * 'IsString' +-- +-- * 'Show' (unsafe) +-- +-- * 'Eq' (unsafe) +-- +-- * 'Num' +-- +-- * 'Fractional' +-- +-- * 'Floating' +-- +-- * 'Monoid' type LaTeXM a = WriterT Result IO a type LaTeX = LaTeXM () @@ -30,27 +50,33 @@ ---------------------------- -- Running the Monad +-- | Run a 'LaTeXM' computation, returning his result. nlx :: LaTeXM a -> IO Result nlx = execWriterT ---------------------------- +-- | Write a result. lx :: Result -> LaTeX lx = tell +-- | Write anything of 'Show' class. lxany :: Show a => a -> LaTeX -lxany = lx . toResult . show +lxany = ungenlx . lxanyw +-- | Like 'lx', but returns an undefined value. lxw :: Result -> LaTeXM a -lxw x = do lx x - return undefined +lxw = genlx . lx +-- | Like 'lxany', but returns an undefined value. lxanyw :: Show b => b -> LaTeXM a -lxanyw = lxw . toResult . show +lxanyw = fromShow +-- | Performs an 'IO' computation, returning his value in the 'LaTeXM' monad. iolx :: IO a -> LaTeXM a iolx = liftIO +-- | Transform a 'Result' modifier in a 'LaTeXM' modifier. reslx :: (Result -> Result) -> (LaTeXM a -> LaTeXM a) reslx = censor @@ -63,7 +89,11 @@ instance Eq (LaTeXM a) where x == y = show x == show y --- +instance Monoid (LaTeXM a) where + mempty = "" + mappend = (>>) + +-- Generalizing genlx :: LaTeX -> LaTeXM a genlx = (>> return undefined)
Text/LaTeX/Packages.hs view
@@ -131,6 +131,8 @@ import Data.List (intersperse) import Data.Monoid +import Data.String.Combinators (braces,fromShow,between) + import Text.LaTeX.Monad import Text.LaTeX.Define import Text.LaTeX.Arguments @@ -268,7 +270,7 @@ rgb :: Float -> Float -> Float -> Color rgb r g b = do "[rgb]" - lx . ks . mconcat . intersperse (toResult ",") $ map (toResult . show) [r,g,b] + braces . lx . mconcat . intersperse (toResult ",") $ map fromShow [r,g,b] pagecolor :: Color -> LaTeX pagecolor = (comm0_ "pagecolor" >>) @@ -357,7 +359,7 @@ amsmath = "amsmath" math :: MathTerm -> LaTeX -math = reslx ds +math = between "$" "$" equation :: MathTerm -> LaTeX equation = env "equation" @@ -372,10 +374,10 @@ text = comm1 "text" (^:) :: MathTerm -> MathTerm -> MathTerm -x ^: y = do x ; "^" ; keys y +x ^: y = do x ; "^" ; braces y (!:) :: MathTerm -> MathTerm -> MathTerm -x !: y = do x ; "_" ; keys y +x !: y = do x ; "_" ; braces y lim :: MathTerm lim = comm0 "lim"
Text/LaTeX/Result.hs view
@@ -6,14 +6,6 @@ , fromResult -- * Special Characters , resCharsStr - -- * Manipulating Results - , pfinal - , bfinal - , comm - , ks - , bs - , sep - , ds ) where import Data.Monoid @@ -21,10 +13,16 @@ import Data.String.ToString (toString) import GHC.Exts (fromString) --- Result Type (MUST be a Monoid) -- +import Data.String.Combinators +-- Result Type +-------------- +-- Instances needed: Monoid, IsString, ToString + type Result = DString +-- + toResult :: String -> Result toResult = fromString @@ -33,41 +31,8 @@ ------------------------------------ -inStart :: Result -> (Result -> Result) -inStart = mappend - -inEnd :: Result -> (Result -> Result) -inEnd = flip mappend - -inBoth :: Result -> Result -> (Result -> Result) -inBoth r0 r1 x = mconcat [r0,x,r1] - --- - -pfinal :: Result -> Result -pfinal = inEnd $ toResult "\n\n" - -bfinal :: Result -> Result -bfinal = inEnd $ toResult "{}" - -comm :: Result -> Result -comm = inStart $ toResult "\\" - -ks :: Result -> Result -ks = inBoth (toResult "{") (toResult "}") - -bs :: Result -> Result -bs = inBoth (toResult "[") (toResult "]") - -sep :: Result -> Result -sep = inBoth (toResult "|") (toResult "|") - -ds :: Result -> Result -ds = inBoth (toResult "$") (toResult "$") - -resCharsStr_ :: [(Char,String)] -resCharsStr_ = - [ ('#',"\\#") +resCharsStr :: [(Char,Result)] +resCharsStr = [ ('#',"\\#") , ('$',"\\$") , ('%',"\\%") , ('^',"\\^{}") @@ -77,8 +42,5 @@ , ('}',"\\}") , ('~',"\\~{}") , ('\\',"\\textbackslash") ] - -resCharsStr :: [(Char,Result)] -resCharsStr = map (\(x,y) -> (x,toResult y)) resCharsStr_