HaTeX 3.5 → 3.6
raw patch · 30 files changed
+2007/−1023 lines, 30 filesdep +containersPVP ok
version bump matches the API change (PVP)
Dependencies added: containers
API changes (from Hackage documentation)
- Text.LaTeX.Base.Commands: (%) :: LaTeXC l => l -> Text -> l
- Text.LaTeX.Base.Commands: equation :: LaTeXC l => l -> l
- Text.LaTeX.Base.Commands: equation_ :: LaTeXC l => l -> l
+ Text.LaTeX.Base.Commands: (%:) :: LaTeXC l => l -> Text -> l
+ Text.LaTeX.Base.Commands: multicolumn :: LaTeXC l => Int -> [TableSpec] -> l -> l
+ Text.LaTeX.Base.Commands: verb :: LaTeXC l => Text -> l
+ Text.LaTeX.Base.Render: instance Render a => Render [a]
+ Text.LaTeX.Base.Texy: class Texy t
+ Text.LaTeX.Base.Texy: instance HasResolution a => Texy (Fixed a)
+ Text.LaTeX.Base.Texy: instance Texy Bool
+ Text.LaTeX.Base.Texy: instance Texy Char
+ Text.LaTeX.Base.Texy: instance Texy Double
+ Text.LaTeX.Base.Texy: instance Texy Float
+ Text.LaTeX.Base.Texy: instance Texy Int
+ Text.LaTeX.Base.Texy: instance Texy Integer
+ Text.LaTeX.Base.Texy: instance Texy LaTeX
+ Text.LaTeX.Base.Texy: instance Texy Text
+ Text.LaTeX.Base.Texy: texy :: (Texy t, LaTeXC l) => t -> l
+ Text.LaTeX.Packages.AMSMath: align :: LaTeXC l => [l] -> l
+ Text.LaTeX.Packages.AMSMath: align_ :: LaTeXC l => [l] -> l
+ Text.LaTeX.Packages.AMSMath: eqref :: LaTeXC l => l -> l
+ Text.LaTeX.Packages.AMSMath: equation :: LaTeXC l => l -> l
+ Text.LaTeX.Packages.AMSMath: equation_ :: LaTeXC l => l -> l
+ Text.LaTeX.Packages.AMSMath: instance (Integral a, Texy a) => Texy (Ratio a)
+ Text.LaTeX.Packages.AMSMath: instance (Texy a, Texy b) => Texy (a, b)
+ Text.LaTeX.Packages.AMSMath: instance (Texy a, Texy b, Texy c) => Texy (a, b, c)
+ Text.LaTeX.Packages.AMSMath: instance (Texy a, Texy b, Texy c, Texy d) => Texy (a, b, c, d)
+ Text.LaTeX.Packages.AMSMath: instance Texy a => Texy (Matrix a)
+ Text.LaTeX.Packages.AMSMath: instance Texy a => Texy [a]
+ Text.LaTeX.Packages.AMSMath: nonumber :: LaTeXC l => l
+ Text.LaTeX.Packages.Babel: Brazilian :: Language
+ Text.LaTeX.Packages.Babel: Bulgarian :: Language
+ Text.LaTeX.Packages.Babel: Canadien :: Language
+ Text.LaTeX.Packages.Babel: Czech :: Language
+ Text.LaTeX.Packages.Babel: Dutch :: Language
+ Text.LaTeX.Packages.Babel: English :: Language
+ Text.LaTeX.Packages.Babel: Finnish :: Language
+ Text.LaTeX.Packages.Babel: Francais :: Language
+ Text.LaTeX.Packages.Babel: French :: Language
+ Text.LaTeX.Packages.Babel: FrenchB :: Language
+ Text.LaTeX.Packages.Babel: German :: Language
+ Text.LaTeX.Packages.Babel: Icelandic :: Language
+ Text.LaTeX.Packages.Babel: Italian :: Language
+ Text.LaTeX.Packages.Babel: LangConf :: Language -> [Language] -> LangConf
+ Text.LaTeX.Packages.Babel: Magyar :: Language
+ Text.LaTeX.Packages.Babel: NGerman :: Language
+ Text.LaTeX.Packages.Babel: Portuguese :: Language
+ Text.LaTeX.Packages.Babel: Russian :: Language
+ Text.LaTeX.Packages.Babel: Spanish :: Language
+ Text.LaTeX.Packages.Babel: Ukranian :: Language
+ Text.LaTeX.Packages.Babel: babel :: PackageName
+ Text.LaTeX.Packages.Babel: data LangConf
+ Text.LaTeX.Packages.Babel: data Language
+ Text.LaTeX.Packages.Babel: foreignlanguage :: LaTeXC l => Language -> l -> l
+ Text.LaTeX.Packages.Babel: instance Render Language
+ Text.LaTeX.Packages.Babel: instance Show LangConf
+ Text.LaTeX.Packages.Babel: instance Show Language
+ Text.LaTeX.Packages.Babel: instance Texy Language
+ Text.LaTeX.Packages.Babel: mainLang :: LangConf -> Language
+ Text.LaTeX.Packages.Babel: otherLangs :: LangConf -> [Language]
+ Text.LaTeX.Packages.Babel: otherlanguage :: LaTeXC l => Language -> l -> l
+ Text.LaTeX.Packages.Babel: selectlanguage :: LaTeXC l => Language -> l
+ Text.LaTeX.Packages.Babel: uselanguage :: LaTeXC l => Language -> l
+ Text.LaTeX.Packages.Babel: uselanguageconf :: LaTeXC l => LangConf -> l
+ Text.LaTeX.Packages.Fontenc: OT1 :: FontEnc
+ Text.LaTeX.Packages.Fontenc: T1 :: FontEnc
+ Text.LaTeX.Packages.Fontenc: data FontEnc
+ Text.LaTeX.Packages.Fontenc: fontenc :: PackageName
+ Text.LaTeX.Packages.Fontenc: instance Render FontEnc
+ Text.LaTeX.Packages.Fontenc: instance Show FontEnc
+ Text.LaTeX.Packages.Fontenc: instance Texy FontEnc
+ Text.LaTeX.Packages.Fontenc: useencoding :: LaTeXC l => [FontEnc] -> l
+ Text.LaTeX.Packages.TikZ: tikz :: PackageName
+ Text.LaTeX.Packages.TikZ: tikzpicture :: LaTeXC l => TikZ -> l
+ Text.LaTeX.Packages.TikZ.PathBuilder: bpath :: TPoint -> PathBuilder a -> TPath
+ Text.LaTeX.Packages.TikZ.PathBuilder: circle :: Double -> PathBuilder ()
+ Text.LaTeX.Packages.TikZ.PathBuilder: data PathBuilder a
+ Text.LaTeX.Packages.TikZ.PathBuilder: ellipse :: Double -> Double -> PathBuilder ()
+ Text.LaTeX.Packages.TikZ.PathBuilder: grid :: [GridOption] -> TPoint -> PathBuilder ()
+ Text.LaTeX.Packages.TikZ.PathBuilder: instance Applicative PathBuilder
+ Text.LaTeX.Packages.TikZ.PathBuilder: instance Functor PathBuilder
+ Text.LaTeX.Packages.TikZ.PathBuilder: instance Monad PathBuilder
+ Text.LaTeX.Packages.TikZ.PathBuilder: line :: TPoint -> PathBuilder ()
+ Text.LaTeX.Packages.TikZ.PathBuilder: pcycle :: PathBuilder ()
+ Text.LaTeX.Packages.TikZ.PathBuilder: rectangle :: TPoint -> PathBuilder ()
+ Text.LaTeX.Packages.TikZ.Simple: Black :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Blue :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Circle :: Point -> Double -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: CircleFilled :: Point -> Double -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Colored :: Color -> Figure -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Cyan :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Ellipse :: Point -> Double -> Double -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: EllipseFilled :: Point -> Double -> Double -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Figures :: [Figure] -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Green :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Line :: [Point] -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: LineWidth :: Measure -> Figure -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Magenta :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Polygon :: [Point] -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: PolygonFilled :: [Point] -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Rectangle :: Point -> Double -> Double -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: RectangleFilled :: Point -> Double -> Double -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: Red :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Scale :: Double -> Figure -> Figure
+ Text.LaTeX.Packages.TikZ.Simple: White :: Color
+ Text.LaTeX.Packages.TikZ.Simple: Yellow :: Color
+ Text.LaTeX.Packages.TikZ.Simple: data Color
+ Text.LaTeX.Packages.TikZ.Simple: data Figure
+ Text.LaTeX.Packages.TikZ.Simple: figuretikz :: Figure -> TikZ
+ Text.LaTeX.Packages.TikZ.Simple: tikz :: PackageName
+ Text.LaTeX.Packages.TikZ.Simple: tikzpicture :: LaTeXC l => TikZ -> l
+ Text.LaTeX.Packages.TikZ.Simple: type Point = (Double, Double)
+ Text.LaTeX.Packages.TikZ.Syntax: (->-) :: TPath -> TPoint -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: (->>) :: TikZ -> TikZ -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: Black :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: Blue :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: Circle :: TPath -> Double -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: Clip :: ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: Cyan :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: Cycle :: TPath -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: DimStep :: Measure -> Step
+ Text.LaTeX.Packages.TikZ.Syntax: Draw :: ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: Ellipse :: TPath -> Double -> Double -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: Fill :: ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: Green :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: Grid :: TPath -> [GridOption] -> TPoint -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: GridStep :: Step -> GridOption
+ Text.LaTeX.Packages.TikZ.Syntax: Line :: TPath -> TPoint -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: Magenta :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: PointStep :: TPoint -> Step
+ Text.LaTeX.Packages.TikZ.Syntax: Rectangle :: TPath -> TPoint -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: Red :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: Shade :: ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: Start :: TPoint -> TPath
+ Text.LaTeX.Packages.TikZ.Syntax: TColor :: Color -> Parameter
+ Text.LaTeX.Packages.TikZ.Syntax: TScale :: Double -> Parameter
+ Text.LaTeX.Packages.TikZ.Syntax: TWidth :: Measure -> Parameter
+ Text.LaTeX.Packages.TikZ.Syntax: White :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: XYStep :: Double -> Step
+ Text.LaTeX.Packages.TikZ.Syntax: Yellow :: Color
+ Text.LaTeX.Packages.TikZ.Syntax: clip :: TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: data ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: data Color
+ Text.LaTeX.Packages.TikZ.Syntax: data GridOption
+ Text.LaTeX.Packages.TikZ.Syntax: data Parameter
+ Text.LaTeX.Packages.TikZ.Syntax: data Step
+ Text.LaTeX.Packages.TikZ.Syntax: data TPath
+ Text.LaTeX.Packages.TikZ.Syntax: data TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: data TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: draw :: TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: emptytikz :: TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: fill :: TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: filldraw :: TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render GridOption
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render Parameter
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render Step
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render TPath
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: instance Render TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show ActionType
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show GridOption
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show Parameter
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show Step
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show TPath
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: instance Show TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: lastPoint :: TPath -> TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: path :: [ActionType] -> TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: pointAt :: Measure -> Measure -> TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: pointAtXY :: Double -> Double -> TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: pointAtXYZ :: Double -> Double -> Double -> TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: relPoint :: TPoint -> TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: relPoint_ :: TPoint -> TPoint
+ Text.LaTeX.Packages.TikZ.Syntax: scope :: [Parameter] -> TikZ -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: shade :: TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: shadedraw :: TPath -> TikZ
+ Text.LaTeX.Packages.TikZ.Syntax: startingPoint :: TPath -> TPoint
+ Text.LaTeX.Packages.Trees.Qtree: instance Texy a => Texy (Tree a)
- Text.LaTeX.Base.Commands: verbatim :: LaTeXC l => l -> l
+ Text.LaTeX.Base.Commands: verbatim :: LaTeXC l => Text -> l
- Text.LaTeX.Packages.AMSMath: b2matrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l
+ Text.LaTeX.Packages.AMSMath: b2matrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
- Text.LaTeX.Packages.AMSMath: bmatrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l
+ Text.LaTeX.Packages.AMSMath: bmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
- Text.LaTeX.Packages.AMSMath: pmatrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l
+ Text.LaTeX.Packages.AMSMath: pmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
- Text.LaTeX.Packages.AMSMath: v2matrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l
+ Text.LaTeX.Packages.AMSMath: v2matrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
- Text.LaTeX.Packages.AMSMath: vmatrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l
+ Text.LaTeX.Packages.AMSMath: vmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
Files
- Examples/comments.hs +4/−4
- Examples/fibs.hs +2/−2
- Examples/matrices.hs +1/−1
- Examples/simple.hs +2/−2
- Examples/texy.hs +36/−0
- Examples/tikz.hs +47/−0
- Examples/tikzsimple.hs +25/−0
- HaTeX.cabal +17/−6
- README.md +22/−8
- Text/LaTeX.hs +4/−1
- Text/LaTeX/Base.hs +10/−4
- Text/LaTeX/Base/Class.hs +2/−1
- Text/LaTeX/Base/Commands.hs +907/−865
- Text/LaTeX/Base/Parser.hs +29/−57
- Text/LaTeX/Base/Render.hs +4/−3
- Text/LaTeX/Base/Texy.hs +48/−0
- Text/LaTeX/Base/Types.hs +3/−1
- Text/LaTeX/Base/Writer.hs +31/−1
- Text/LaTeX/Packages.hs +0/−26
- Text/LaTeX/Packages/AMSMath.hs +102/−35
- Text/LaTeX/Packages/AMSThm.hs +3/−1
- Text/LaTeX/Packages/Babel.hs +112/−0
- Text/LaTeX/Packages/Color.hs +10/−3
- Text/LaTeX/Packages/Fontenc.hs +46/−0
- Text/LaTeX/Packages/Inputenc.hs +7/−0
- Text/LaTeX/Packages/TikZ.hs +48/−0
- Text/LaTeX/Packages/TikZ/PathBuilder.hs +94/−0
- Text/LaTeX/Packages/TikZ/Simple.hs +85/−0
- Text/LaTeX/Packages/TikZ/Syntax.hs +300/−0
- Text/LaTeX/Packages/Trees/Qtree.hs +6/−2
Examples/comments.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -import Text.LaTeX.Base +import Text.LaTeX main :: IO () main = execLaTeXT example >>= renderFile "Comments.tex" @@ -13,6 +13,6 @@ exampleBody :: Monad m => LaTeXT_ m exampleBody = do "This is a basic example for testing the " - "comments functionality in HaTeX." % "A short comment here." - "Multi-line comments are separated by lines." % "First line.\nSecond line." - "After a comment, the following code will start in a new line of the output."+ "comments functionality in HaTeX." %: "A short comment here." + "Multi-line comments are separated by lines." %: "First line.\nSecond line." + "After a comment, the following code will start in a new line of the output."
Examples/fibs.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -import Text.LaTeX.Base +import Text.LaTeX main :: IO () main = execLaTeXT example >>= renderFile "Fibs.tex" @@ -23,7 +23,7 @@ textbf "Fibonacci number" & textbf "Value" lnbk hline - foldr (\n l -> do rendertexM n & rendertexM (fib n) + foldr (\n l -> do texy n & texy (fib n) lnbk l ) (return ()) [0 .. 12]
Examples/matrices.hs view
@@ -19,4 +19,4 @@ usepackage [] amsmath theBody :: Monad m => LaTeXT_ m -theBody = equation_ $ pmatrix Nothing $ (identity 5 :: Matrix Int)+theBody = equation_ $ pmatrix Nothing $ (identity 5 :: Matrix Int)
Examples/simple.hs view
@@ -10,7 +10,7 @@ {-# LANGUAGE OverloadedStrings #-} -import Text.LaTeX.Base +import Text.LaTeX -- By executing 'execLaTeXT' you run the 'LaTeXT' monad and make a 'LaTeX' value as output. -- With 'renderFile' you render it to 'Text' and write it in a file. @@ -42,4 +42,4 @@ textbf "Enjoy!" " " -- This is how we nest commands. - textbf (large "Yoohoo!")+ textbf (large "Yoohoo!")
+ Examples/texy.hs view
@@ -0,0 +1,36 @@++{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX++import Text.LaTeX.Packages.Inputenc+import Text.LaTeX.Packages.AMSMath++import Data.Ratio+import Data.Matrix++main :: IO ()+main = renderFile "texy.tex" example++example :: LaTeX+example = thePreamble <> document theBody++thePreamble :: LaTeX+thePreamble =+ documentclass [] article <> usepackage [utf8] inputenc+ <> usepackage [] amsmath+ <> title "Using the Texy Class" <> author "Daniel Díaz"++theBody :: LaTeX+theBody =+ maketitle+ <> "Different types pretty-printed using the " <> texttt "Texy" <> " class:"+ <> itemize theItems++theItems :: LaTeX+theItems = + item Nothing <> math (texy (2 :: Int ,3 :: Integer))+ <> item Nothing <> math (texy [True,False,False])+ <> item Nothing <> math (texy (1 % 2 :: Rational,2.5 :: Float))+ <> item Nothing <> equation_ (texy $ fromList 3 3 [1 .. 9 :: Int])+ <> item Nothing <> math (texy ("This is a String" :: String))
+ Examples/tikz.hs view
@@ -0,0 +1,47 @@++{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX+import Text.LaTeX.Packages.Inputenc+import Text.LaTeX.Packages.TikZ++main :: IO ()+main = execLaTeXT tikztest >>= renderFile "tikz.tex"++tikztest :: LaTeXT IO ()+tikztest = do+ thePreamble+ document theBody++thePreamble :: LaTeXT IO ()+thePreamble = do+ documentclass [] article+ usepackage [utf8] inputenc+ usepackage [] tikz+ author "Daniel Díaz"+ title "Example using TikZ"++theBody :: LaTeXT IO ()+theBody = do+ maketitle+ "Below a picture generated using the TikZ DSL of "+ hatex+ "."+ center $ tikzpicture $ draw $+ Cycle $ Start (pointAtXY 0 0) ->- pointAtXY 1 0 ->- pointAtXY 0 1+ "And some pictures more."+ center $ tikzpicture $+ draw (Rectangle (Start $ pointAtXY 0 0 ) (pointAtXY 1 1))+ ->> fill (Circle (Start $ pointAtXY 1.5 0.5) 0.5)+ ->> shade (Ellipse (Start $ pointAtXY 3 0.5 ) 1 0.5)+ center $ tikzpicture $ draw $+ (Cycle $ Start (pointAtXY 0 0) ->- pointAtXY 1 0 ->- pointAtXY 0 1) ->- pointAtXY 1 1+ "We also show the graph of the "+ emph "sine"+ " function."+ 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) $+ mapM_ line [ pointAtXY x (sin x) | x <- [0,0.05 .. 3*pi] ]+ )
+ Examples/tikzsimple.hs view
@@ -0,0 +1,25 @@++import Text.LaTeX+import Text.LaTeX.Packages.TikZ.Simple++main :: IO ()+main = execLaTeXT tikzsimple >>= renderFile "tikzsimple.tex"++tikzsimple :: LaTeXT IO ()+tikzsimple = thePreamble >> document theBody++thePreamble :: LaTeXT IO ()+thePreamble = do+ documentclass [] article+ usepackage [] tikz++theBody :: LaTeXT IO ()+theBody = center $ tikzpicture $ figuretikz myFigure++myFigure :: Figure+myFigure = Scale 3 $ Figures+ [ RectangleFilled (0,0) 1 1+ , Colored Green $ RectangleFilled (-1,1) 1 1+ , Colored Red $ RectangleFilled ( 0,2) 1 1+ , Colored Blue $ RectangleFilled ( 1,1) 1 1+ ]
HaTeX.cabal view
@@ -1,5 +1,5 @@ Name: HaTeX -Version: 3.5 +Version: 3.6 Author: Daniel Díaz Category: Text Build-type: Simple @@ -31,6 +31,9 @@ Examples/tree.hs Examples/beamer.hs Examples/matrices.hs + Examples/texy.hs + Examples/tikz.hs + Examples/tikzsimple.hs Source-repository head type: git @@ -43,31 +46,39 @@ , text , attoparsec , matrix + , containers Exposed-modules: Text.LaTeX -- Base (Core of the library) Text.LaTeX.Base Text.LaTeX.Base.Class Text.LaTeX.Base.Commands - Text.LaTeX.Base.Render Text.LaTeX.Base.Parser + Text.LaTeX.Base.Render Text.LaTeX.Base.Syntax + Text.LaTeX.Base.Texy Text.LaTeX.Base.Types Text.LaTeX.Base.Writer Text.LaTeX.Base.Warnings -- Packages - Text.LaTeX.Packages Text.LaTeX.Packages.AMSFonts Text.LaTeX.Packages.AMSMath Text.LaTeX.Packages.AMSThm + Text.LaTeX.Packages.Babel Text.LaTeX.Packages.Beamer - Text.LaTeX.Packages.Hyperref - Text.LaTeX.Packages.Inputenc Text.LaTeX.Packages.Color + Text.LaTeX.Packages.Fontenc Text.LaTeX.Packages.Graphicx + Text.LaTeX.Packages.Hyperref + Text.LaTeX.Packages.Inputenc -- Trees Text.LaTeX.Packages.Trees Text.LaTeX.Packages.Trees.Qtree + -- TikZ + Text.LaTeX.Packages.TikZ + Text.LaTeX.Packages.TikZ.PathBuilder + Text.LaTeX.Packages.TikZ.Simple + Text.LaTeX.Packages.TikZ.Syntax Other-modules: Paths_HaTeX Extensions: OverloadedStrings - , CPP+ , CPP
README.md view
@@ -4,20 +4,34 @@ Check a list of examples of usage in the [examples](Examples/) directory. A good starting point may be [simple.hs](Examples/simple.hs). +Run the script using the ``main`` function. +## Installation notes + +To install `HaTeX`, use [cabal-install](http://hackage.haskell.org/package/cabal-install). + + $ cabal install HaTeX + +## HaTeX User's Guide + +The HaTeX User's Guide lives [here](https://github.com/Daniel-Diaz/HaTeX-Guide)... and is also done in Haskell! + +## Contributing + +To contribute to HaTeX, please, visit our code repository in GitHub: + +https://github.com/Daniel-Diaz/HaTeX + ## TODO list * Add more examples. * More testing on the parser. * Add more documentation. -* A more complete `AMSMath` module. Split environment equations. -* Implement more packages (fontenc, geometry, babel, array, ...). +* A more complete `AMSMath` module. +* Implement more packages (geometry, array, ...). * BibTeX support. -## Installation notes - -* To install `HaTeX`, use the typical `cabal install`. - -## HaTeX User's Guide +## Related projects -* The HaTeX User's Guide lives [here](https://github.com/Daniel-Diaz/HaTeX-Guide)... and is also done in Haskell!+* [TeX-my-math](https://github.com/leftaroundabout/Symbolic-math-HaTeX): Experimental library to ease the production +of mathematical expressions using HaTeX.
Text/LaTeX.hs view
@@ -7,9 +7,12 @@ -- module and, then, only the packages you need (instead -- of all of them), this module has been upgraded supporting -- it. +-- +-- For this reason, the module @Text.LaTeX.Packages@ no longer +-- exists. module Text.LaTeX ( -- * Base module module Text.LaTeX.Base ) where -import Text.LaTeX.Base+import Text.LaTeX.Base
Text/LaTeX/Base.hs view
@@ -18,6 +18,10 @@ and environments. * The "Text.LaTeX.Base.Writer" module, to work with the monad interface of the library. + +* The "Text.LaTeX.Base.Texy" module, which exports the 'Texy' class. Useful to pretty-print + values in LaTeX form. + -} module Text.LaTeX.Base ( -- * @LaTeX@ datatype @@ -29,6 +33,7 @@ , module Text.LaTeX.Base.Types , module Text.LaTeX.Base.Commands , module Text.LaTeX.Base.Writer + , module Text.LaTeX.Base.Texy -- * External re-exports -- -- | Since the 'Monoid' instance is the only way to append 'LaTeX' @@ -39,11 +44,12 @@ #endif ) where -import Text.LaTeX.Base.Syntax (LaTeX (..), TeXArg (..),(<>),protectString,protectText) -import Text.LaTeX.Base.Class +-- Internal modules +import Text.LaTeX.Base.Syntax (LaTeX,(<>),protectString,protectText) import Text.LaTeX.Base.Render import Text.LaTeX.Base.Types import Text.LaTeX.Base.Commands import Text.LaTeX.Base.Writer --- -import Data.Monoid+import Text.LaTeX.Base.Texy +-- External modules +import Data.Monoid
Text/LaTeX/Base/Class.hs view
@@ -66,7 +66,8 @@ comm0 :: LaTeXC l => String -> l comm0 str = fromLaTeX $ TeXComm str [] --- | Like 'comm0' but using 'commS'. +-- | Like 'comm0' but using 'commS', i.e. no \"{}\" will be inserted to protect +-- the command's end. -- -- > commS = fromLaTeX . TeXCommS --
Text/LaTeX/Base/Commands.hs view
@@ -1,865 +1,907 @@-{-# LANGUAGE OverloadedStrings #-} - --- | LaTeX standard commands and environments. -module Text.LaTeX.Base.Commands - ( -- * Basic functions - raw , between , comment , (%) - -- * Preamble commands - , title - , author - , date - , institute - , thanks - , documentclass - , usepackage - , linespread - -- ** Classes - -- *** Document classes - , article - , proc - , report - , minimal - , book - , slides - -- *** Class options - , ClassOption (..) - , customopt - , draft - , titlepage - , notitlepage - , onecolumn - , twocolumn - , oneside - , twoside - , landscape - , openright - , openany - , fleqn - , leqno - -- ** Paper sizes - , PaperType (..) - , a0paper - , a1paper - , a2paper - , a3paper - , a4paper - , a5paper - , a6paper - , b0paper - , b1paper - , b2paper - , b3paper - , b4paper - , b5paper - , b6paper - , letterpaper - , executivepaper - , legalpaper - -- ** Page styles - , pagestyle - , thispagestyle - , plain - , headings - , empty - , myheadings - , markboth - , markright - -- * Body commands - , document - , maketitle - -- ** Document structure - , tableofcontents - , abstract - , appendix - -- *** Sections - , part - , chapter - , section - , subsection - , subsubsection - , paragraph - , subparagraph - -- ** Logos & symbols - , today - , tex - , latex - , laTeX2 - , laTeXe - , ldots - , vdots - , ddots - -- *** HaTeX specific - , hatex - , hatex3 - , version - , hatex_version - -- ** Document layout - , par - , newline - , lnbk - , lnbk_ - , newpage - , cleardoublepage - , clearpage - , linebreak - , nolinebreak - , pagebreak - , nopagebreak - , hspace - , hspace_ - , vspace - , hfill - , vfill - , stretch - , smallskip - , bigskip - , indent - , noindent - -- *** Document measures - , textwidth - , linewidth - -- ** Formatting text - , verbatim - -- *** Fonts - -- - -- Different font styles. - , textbf - , textit - , texttt - , textrm - , textsf - , textmd - , textup - , textsl - , textsc - , textnormal - , underline - , emph - -- *** Sizes - -- - -- | Sizes are sorted from smallest to biggest. - , tiny - , scriptsize - , footnotesize - , small - , normalsize - , large - , large2 - , large3 - , huge - , huge2 - -- ** Environments - , equation - , equation_ - , enumerate - , itemize - , item - , flushleft - , flushright - , center - , quote - , verse - , cite - , description - , minipage - , figure - -- ** Page numbering - , pagenumbering - , arabic - , roman - , roman_ - , alph - , alph_ - -- ** Boxes - , mbox - , fbox - , parbox - , framebox - , makebox - , raisebox - , rule - -- ** Cross references - , caption - , label - , ref - , pageref - -- ** Tables - , tabular - , (&) - , hline - , cline - -- ** Others - , footnote - , protect - , hyphenation - , hyp - , qts - ) where - -import Data.String -import Data.Maybe (catMaybes) -import Data.Text (toLower) -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types -import Data.Version -import Data.List (intercalate) --- -import Paths_HaTeX - --- | Insert a raw piece of 'Text'. --- This functions doesn't care about @LaTeX@ reserved characters, --- it insert the text just as it is received. -raw :: LaTeXC l => Text -> l -raw = fromLaTeX . TeXRaw - --- | Calling 'between' @c l1 l2@ puts @c@ between @l1@ and @l2@ and --- appends them. -between :: Monoid m => m -> m -> m -> m -between c l1 l2 = l1 <> c <> l2 - --- | Create a comment. -comment :: LaTeXC l => Text -> l -comment = fromLaTeX . TeXComment - --- | This operator appends a comment after a expression. --- For example: --- --- > textbf "I'm just an example." % "Insert a few words here." --- --- Since you are writing in Haskell, you may not need to output comments --- as you can add them in the Haskell source. I added this feature --- for completeness. -(%) :: LaTeXC l => l -> Text -> l -(%) l = (l <>) . comment - --- | Generate the title. It normally contains the 'title' name --- of your document, the 'author'(s) and 'date'. -maketitle :: LaTeXC l => l -maketitle = comm0 "maketitle" - --- | Set the title of your document. -title :: LaTeXC l => l -> l -title = liftL $ \t -> TeXComm "title" [FixArg t] - --- | Set a date for your document. -date :: LaTeXC l => l -> l -date = liftL $ \t -> TeXComm "date" [FixArg t] - --- | Set the author(s) of the document. -author :: LaTeXC l => l -> l -author = liftL $ \t -> TeXComm "author" [FixArg t] - --- | Set either an institute or an organization --- for the document. -institute :: LaTeXC l => Maybe l -> l -> l -institute Nothing = liftL $ \l -> TeXComm "institute" [FixArg l] -institute (Just s) = liftL2 (\l1 l2 -> TeXComm "institute" [OptArg l1,FixArg l2]) s - -thanks :: LaTeXC l => l -> l -thanks = liftL $ \l -> TeXComm "thanks" [FixArg l] - --- | Import a package. First argument is a list of options for --- the package named in the second argument. -usepackage :: LaTeXC l => [l] -> PackageName -> l -usepackage ls pn = liftListL (\ls -> TeXComm "usepackage" [MOptArg ls ,FixArg $ fromString pn]) ls - --- | The @LaTeX@ logo. -latex :: LaTeXC l => l -latex = comm0 "LaTeX" - --- | Start a new paragraph -par :: LaTeXC l => l -par = comm0 "par" - --- | Start a new line. -newline :: LaTeXC l => l -newline = comm0 "newline" - -part :: LaTeXC l => l -> l -part = liftL $ \p -> TeXComm "part" [FixArg p] - -chapter :: LaTeXC l => l -> l -chapter = liftL $ \c -> TeXComm "chapter" [FixArg c] - --- | Start a new section with a given title. -section :: LaTeXC l => l -> l -section = liftL $ \s -> TeXComm "section" [FixArg s] - -subsection :: LaTeXC l => l -> l -subsection = liftL $ \sub -> TeXComm "subsection" [FixArg sub] - -subsubsection :: LaTeXC l => l -> l -subsubsection = liftL $ \sub -> TeXComm "subsubsection" [FixArg sub] - -paragraph :: LaTeXC l => l -> l -paragraph = liftL $ \p -> TeXComm "paragraph" [FixArg p] - -subparagraph :: LaTeXC l => l -> l -subparagraph = liftL $ \p -> TeXComm "subparagraph" [FixArg p] - --- | Create the table of contents, automatically generated --- from your 'section's, 'subsection's, and other related stuff. -tableofcontents :: LaTeXC l => l -tableofcontents = comm0 "tableofcontents" - -appendix :: LaTeXC l => l -appendix = comm0 "appendix" - -item :: LaTeXC l => Maybe l -> l -item Nothing = commS "item " -item (Just opt) = liftL (\opt -> TeXComm "item" [OptArg opt]) opt - -equation :: LaTeXC l => l -> l -equation = liftL $ TeXEnv "equation" [] - -equation_ :: LaTeXC l => l -> l -equation_ = liftL $ TeXEnv "equation*" [] - -enumerate :: LaTeXC l => l -> l -enumerate = liftL $ TeXEnv "enumerate" [] - -itemize :: LaTeXC l => l -> l -itemize = liftL $ TeXEnv "itemize" [] - -description :: LaTeXC l => l -> l -description = liftL $ TeXEnv "description" [] - -flushleft :: LaTeXC l => l -> l -flushleft = liftL $ TeXEnv "flushleft" [] - -flushright :: LaTeXC l => l -> l -flushright = liftL $ TeXEnv "flushright" [] - -center :: LaTeXC l => l -> l -center = liftL $ TeXEnv "center" [] - -quote :: LaTeXC l => l -> l -quote = liftL $ TeXEnv "quote" [] - -verse :: LaTeXC l => l -> l -verse = liftL $ TeXEnv "verse" [] - --- | Minipage environment. -minipage :: LaTeXC l => - Maybe Pos -- ^ Optional position - -> l -- ^ Width - -> l -- ^ Minipage content - -> l -minipage Nothing = liftL2 $ \ts -> TeXEnv "minipage" [ FixArg ts ] -minipage (Just p) = liftL2 $ \ts -> TeXEnv "minipage" [ OptArg $ rendertex p , FixArg ts ] - --- | Figure environment. -figure :: LaTeXC l => - Maybe Pos -- ^ Optional position - -> l -- ^ Figure content - -> l -figure Nothing = liftL $ TeXEnv "figure" [] -figure (Just p) = liftL $ TeXEnv "figure" [ OptArg $ TeXRaw $ render p ] - -abstract :: LaTeXC l => l -> l -abstract = liftL $ TeXEnv "abstract" [] - -cite :: LaTeXC l => l -> l -cite = liftL $ \l -> TeXComm "cite" [FixArg l] - --- Document class - --- | A class option to be passed to the 'documentclass' function. -data ClassOption = - Draft - | TitlePage - | NoTitlePage - | OneColumn - | TwoColumn - | OneSide - | TwoSide - | Landscape - | OpenRight - | OpenAny - | Fleqn - | Leqno - | FontSize Measure - | Paper PaperType - | CustomOption String - deriving Show - -instance Render ClassOption where - render (FontSize m) = render m - render (Paper pt) = toLower (render pt) <> "paper" - render (CustomOption str) = fromString str - render co = toLower $ fromString $ show co - -customopt :: String -> ClassOption -customopt = CustomOption - -instance IsString ClassOption where - fromString = customopt - --- | LaTeX available paper types. -data PaperType = - A0 | A1 | A2 | A3 | A4 | A5 | A6 - | B0 | B1 | B2 | B3 | B4 | B5 | B6 - | Letter | Executive | Legal - deriving Show - -instance Render PaperType where - --- | Set the document class. Needed in all documents. -documentclass :: LaTeXC l => - [ClassOption] -- ^ Class options - -> ClassName -- ^ Class name - -> l -documentclass opts cn = fromLaTeX $ TeXComm "documentclass" [MOptArg $ fmap rendertex opts , FixArg $ fromString cn] - -article :: ClassName -article = "article" - -proc :: ClassName -proc = "proc" - -minimal :: ClassName -minimal = "minimal" - -report :: ClassName -report = "report" - -book :: ClassName -book = "book" - -slides :: ClassName -slides = "slides" - -a0paper :: ClassOption -a0paper = Paper A0 - -a1paper :: ClassOption -a1paper = Paper A1 - -a2paper :: ClassOption -a2paper = Paper A2 - -a3paper :: ClassOption -a3paper = Paper A3 - -a4paper :: ClassOption -a4paper = Paper A4 - -a5paper :: ClassOption -a5paper = Paper A5 - -a6paper :: ClassOption -a6paper = Paper A6 - -b0paper :: ClassOption -b0paper = Paper B0 - -b1paper :: ClassOption -b1paper = Paper B1 - -b2paper :: ClassOption -b2paper = Paper B2 - -b3paper :: ClassOption -b3paper = Paper B3 - -b4paper :: ClassOption -b4paper = Paper B4 - -b5paper :: ClassOption -b5paper = Paper B5 - -b6paper :: ClassOption -b6paper = Paper B6 - -letterpaper :: ClassOption -letterpaper = Paper Letter - -executivepaper :: ClassOption -executivepaper = Paper Executive - -legalpaper :: ClassOption -legalpaper = Paper Legal - -draft :: ClassOption -draft = Draft - --- | Typesets displayed formulae left-aligned instead of centred. -fleqn :: ClassOption -fleqn = Fleqn - --- | Places the numbering of formulae on the left hand side instead of the right. -leqno :: ClassOption -leqno = Leqno - -titlepage :: ClassOption -titlepage = TitlePage - -notitlepage :: ClassOption -notitlepage = NoTitlePage - -onecolumn :: ClassOption -onecolumn = OneColumn - -twocolumn :: ClassOption -twocolumn = TwoColumn - -oneside :: ClassOption -oneside = OneSide - -twoside :: ClassOption -twoside = TwoSide - --- | Changes the layout of the document to print in landscape mode -landscape :: ClassOption -landscape = Landscape - --- | Makes chapters begin either only on right hand pages -openright :: ClassOption -openright = OpenRight - --- | Makes chapters begin on the next page available. -openany :: ClassOption -openany = OpenAny - -document :: LaTeXC l => l -> l -document = liftL $ TeXEnv "document" [] - -pagenumbering :: LaTeXC l => l -> l -pagenumbering = liftL $ \l -> TeXComm "pagenumbering" [FixArg l] - --- | Arabic numerals. -arabic :: LaTeXC l => l -arabic = fromLaTeX "arabic" - --- | Lowercase roman numerals. -roman :: LaTeXC l => l -roman = fromLaTeX "roman" - --- | Uppercase roman numerals. -roman_ :: LaTeXC l => l -roman_ = fromLaTeX "Roman" - --- | Lowercase letters. -alph :: LaTeXC l => l -alph = fromLaTeX "alph" - --- | Uppercase letters. -alph_ :: LaTeXC l => l -alph_ = fromLaTeX "Alph" - -pagestyle :: LaTeXC l => l -> l -pagestyle = liftL $ \l -> TeXComm "pagestyle" [FixArg l] - -thispagestyle :: LaTeXC l => l -> l -thispagestyle = liftL $ \l -> TeXComm "thispagestyle" [FixArg l] - -plain :: LaTeXC l => l -plain = fromLaTeX "plain" - -headings :: LaTeXC l => l -headings = fromLaTeX "headings" - -empty :: LaTeXC l => l -empty = fromLaTeX "empty" - -myheadings :: LaTeXC l => l -myheadings = fromLaTeX "myheadings" - --- | Used in conjunction with 'myheadings' for setting both the left and the right heading. -markboth :: LaTeXC l => l -> l -> l -markboth = liftL2 $ \l1 l2 -> TeXComm "markboth" [FixArg l1 , FixArg l2] - --- | Used in conjunction with 'myheadings' for setting the right heading. -markright :: LaTeXC l => l -> l -markright = liftL $ \l -> TeXComm "markright" [FixArg l] - --- | Start a new line. In a 'tabular', it starts a new row, so use 'newline' instead. -lnbk :: LaTeXC l => l -lnbk = fromLaTeX $ TeXLineBreak Nothing False - -lnbk_ :: LaTeXC l => l -lnbk_ = fromLaTeX $ TeXLineBreak Nothing True - -hyp :: LaTeXC l => l -hyp = fromLaTeX $ TeXCommS "-" - -cleardoublepage :: LaTeXC l => l -cleardoublepage = comm0 "cleardoublepage" - -clearpage :: LaTeXC l => l -clearpage = comm0 "clearpage" - -newpage :: LaTeXC l => l -newpage = comm0 "newpage" - -linebreak :: LaTeXC l => l -> l -linebreak = liftL $ \l -> TeXComm "linebreak" [OptArg l] - -nolinebreak :: LaTeXC l => l -> l -nolinebreak = liftL $ \l -> TeXComm "nolinebreak" [OptArg l] - -nopagebreak :: LaTeXC l => l -> l -nopagebreak = liftL $ \l -> TeXComm "nopagebreak" [OptArg l] - -pagebreak :: LaTeXC l => l -> l -pagebreak = liftL $ \l -> TeXComm "pagebreak" [OptArg l] - -hyphenation :: LaTeXC l => l -> l -hyphenation = liftL $ \l -> TeXComm "hyphenation" [FixArg l] - -mbox :: LaTeXC l => l -> l -mbox = liftL $ \l -> TeXComm "mbox" [FixArg l] - -fbox :: LaTeXC l => l -> l -fbox = liftL $ \l -> TeXComm "fbox" [FixArg l] - -today :: LaTeXC l => l -today = comm0 "today" - -tex :: LaTeXC l => l -tex = comm0 "TeX" - -laTeX2 :: LaTeXC l => l -laTeX2 = comm0 "LaTeX" - -laTeXe :: LaTeXC l => l -laTeXe = comm0 "LaTeXe" - --- | Horizontal dots. -ldots :: LaTeXC l => l -ldots = comm0 "ldots" - --- | Vertical dots. -vdots :: LaTeXC l => l -vdots = comm0 "vdots" - --- | Diagonal dots. -ddots :: LaTeXC l => l -ddots = comm0 "ddots" - --- | Quotation marks. -qts :: LaTeXC l => l -> l -qts l = between l (raw "``") (raw "''") - -footnote :: LaTeXC l => l -> l -footnote = liftL $ \l -> TeXComm "footnote" [FixArg l] - -linespread :: LaTeXC l => Float -> l -linespread x = fromLaTeX $ TeXComm "linespread" [FixArg $ rendertex x] - -indent :: LaTeXC l => l -indent = comm0 "indent" - -noindent :: LaTeXC l => l -noindent = comm0 "noindent" - -hspace :: LaTeXC l => Measure -> l -hspace m = fromLaTeX $ TeXComm "hspace" [FixArg $ rendertex m] - -hspace_ :: LaTeXC l => Measure -> l -hspace_ m = fromLaTeX $ TeXComm "hspace*" [FixArg $ rendertex m] - -stretch :: LaTeXC l => Int -> l -stretch n = fromLaTeX $ TeXComm "stretch" [FixArg $ rendertex n] - -vspace :: LaTeXC l => Measure -> l -vspace m = fromLaTeX $ TeXComm "vspace" [FixArg $ rendertex m] - --- | Fill out all available horizontal space. -hfill :: LaTeXC l => l -hfill = comm0 "hfill" - --- | Fill out all available vertical space. -vfill :: LaTeXC l => l -vfill = comm0 "vfill" - -protect :: LaTeXC l => l -> l -protect l = commS "protect" <> l - -textwidth :: LaTeXC l => l -textwidth = comm0 "textwidth" - -linewidth :: LaTeXC l => l -linewidth = comm0 "linewidth" - -verbatim :: LaTeXC l => l -> l -verbatim = liftL $ TeXEnv "verbatim" [] - -underline :: LaTeXC l => l -> l -underline = liftL $ \l -> TeXComm "underline" [FixArg l] - -emph :: LaTeXC l => l -> l -emph = liftL $ \l -> TeXComm "emph" [FixArg l] - -textrm :: LaTeXC l => l -> l -textrm = liftL $ \l -> TeXComm "textrm" [FixArg l] - -textsf :: LaTeXC l => l -> l -textsf = liftL $ \l -> TeXComm "textsf" [FixArg l] - --- | Set the given argument to monospaced font. -texttt :: LaTeXC l => l -> l -texttt = liftL $ \l -> TeXComm "texttt" [FixArg l] - -textmd :: LaTeXC l => l -> l -textmd = liftL $ \l -> TeXComm "textmd" [FixArg l] - --- | Set the given argument to bold font face. -textbf :: LaTeXC l => l -> l -textbf = liftL $ \l -> TeXComm "textbf" [FixArg l] - -textup :: LaTeXC l => l -> l -textup = liftL $ \l -> TeXComm "textup" [FixArg l] - --- Set the given argument to italic font face. -textit :: LaTeXC l => l -> l -textit = liftL $ \l -> TeXComm "textit" [FixArg l] - -textsl :: LaTeXC l => l -> l -textsl = liftL $ \l -> TeXComm "textsl" [FixArg l] - --- | Set the given argument to small caps format. -textsc :: LaTeXC l => l -> l -textsc = liftL $ \l -> TeXComm "textsc" [FixArg l] - -textnormal :: LaTeXC l => l -> l -textnormal = liftL $ \l -> TeXComm "textnormal" [FixArg l] - -tiny :: LaTeXC l => l -> l -tiny = liftL $ \l -> TeXComm "tiny" [FixArg l] - -scriptsize :: LaTeXC l => l -> l -scriptsize = liftL $ \l -> TeXComm "scriptsize" [FixArg l] - -footnotesize :: LaTeXC l => l -> l -footnotesize = liftL $ \l -> TeXComm "footnotesize" [FixArg l] - -small :: LaTeXC l => l -> l -small = liftL $ \l -> TeXComm "small" [FixArg l] - -normalsize :: LaTeXC l => l -> l -normalsize = liftL $ \l -> TeXComm "normalsize" [FixArg l] - -large :: LaTeXC l => l -> l -large = liftL $ \l -> TeXComm "large" [FixArg l] - -large2 :: LaTeXC l => l -> l -large2 = liftL $ \l -> TeXComm "Large" [FixArg l] - -large3 :: LaTeXC l => l -> l -large3 = liftL $ \l -> TeXComm "LARGE" [FixArg l] - -huge :: LaTeXC l => l -> l -huge = liftL $ \l -> TeXComm "huge" [FixArg l] - -huge2 :: LaTeXC l => l -> l -huge2 = liftL $ \l -> TeXComm "Huge" [FixArg l] - -smallskip :: LaTeXC l => l -smallskip = comm0 "smallskip" - -bigskip :: LaTeXC l => l -bigskip = comm0 "bigskip" - --- | The 'tabular' environment can be used to typeset tables with optional horizontal and vertical lines. -tabular :: LaTeXC l => - Maybe Pos -- ^ This optional parameter can be used to specify the vertical position of the table. - -- Defaulted to 'Center'. - -> [TableSpec] -- ^ Table specification of columns and vertical lines. - -> l -- ^ Table content. See '&', 'lnbk', 'hline' and 'cline'. - -> l -- ^ Resulting table syntax. -tabular Nothing ts = liftL $ TeXEnv "tabular" [ FixArg $ TeXRaw $ renderAppend ts ] -tabular (Just p) ts = liftL $ TeXEnv "tabular" [ OptArg $ TeXRaw $ render p , FixArg $ TeXRaw $ renderAppend ts ] - --- | Column separator. -(&) :: LaTeXC l => l -> l -> l -(&) = liftL2 $ TeXOp "&" - --- | Horizontal line. -hline :: LaTeXC l => l -hline = commS "hline " - --- | @cline i j@ writes a partial horizontal line beginning in column @i@ and ending in column @j@. -cline :: LaTeXC l => Int -> Int -> l -cline i j = fromLaTeX $ TeXComm "cline" [ FixArg $ TeXRaw $ render i <> "-" <> render j ] - -parbox :: LaTeXC l => Maybe Pos -> Measure -> l -> l -parbox Nothing w = liftL $ \t -> TeXComm "parbox" [ FixArg $ rendertex w , FixArg t ] -parbox (Just p) w = liftL $ \t -> TeXComm "parbox" [ OptArg $ TeXRaw $ render p - , FixArg $ TeXRaw $ render w - , FixArg t ] - -makebox :: LaTeXC l => Maybe Measure -> Maybe Pos -> l -> l -makebox Nothing Nothing = liftL $ \t -> TeXComm "makebox" [ FixArg t ] -makebox (Just w) Nothing = liftL $ \t -> TeXComm "makebox" [ OptArg $ TeXRaw $ render w - , FixArg t ] -makebox Nothing (Just p) = liftL $ \t -> TeXComm "makebox" [ OptArg $ TeXRaw $ render p - , FixArg t ] -makebox (Just w) (Just p) = liftL $ \t -> TeXComm "makebox" [ OptArg $ TeXRaw $ render w - , OptArg $ TeXRaw $ render p - , FixArg t ] - -framebox :: LaTeXC l => Maybe Measure -> Maybe Pos -> l -> l -framebox Nothing Nothing = liftL $ \t -> TeXComm "framebox" [ FixArg t ] -framebox (Just w) Nothing = liftL $ \t -> TeXComm "framebox" [ OptArg $ TeXRaw $ render w - , FixArg t ] -framebox Nothing (Just p) = liftL $ \t -> TeXComm "framebox" [ OptArg $ TeXRaw $ render p - , FixArg t ] -framebox (Just w) (Just p) = liftL $ \t -> TeXComm "framebox" [ OptArg $ TeXRaw $ render w - , OptArg $ TeXRaw $ render p - , FixArg t ] - -raisebox :: LaTeXC l => Measure -> Maybe Measure -> Maybe Measure -> l -> l -raisebox m ma mb = liftL $ \l -> TeXComm "raisebox" $ - [ FixArg $ rendertex m ] - ++ fmap (OptArg . rendertex) (catMaybes [ma,mb]) - ++ [ FixArg l ] - --- | Produce a simple black box. -rule :: LaTeXC l => - Maybe Measure -- ^ Optional lifting. - -> Measure -- ^ Width. - -> Measure -- ^ Height. - -> l -rule Nothing w h = fromLaTeX $ TeXComm "rule" [ FixArg $ TeXRaw $ render w - , FixArg $ TeXRaw $ render h ] -rule (Just l) w h = fromLaTeX $ TeXComm "rule" [ OptArg $ TeXRaw $ render l - , FixArg $ TeXRaw $ render w - , FixArg $ TeXRaw $ render h ] - --- HaTeX specific symbols - --- | Print the HaTeX logo. -hatex :: LaTeXC l => l -hatex = mbox $ "H" - <> hspace (Ex $ negate 0.3) - <> textsc "a" - <> hspace (Ex $ negate 0.3) - <> tex - --- | Print the HaTeX 3 logo. -hatex3 :: LaTeXC l => l -hatex3 = hatex <> emph (textbf "3") - --- | Print the HaTeX logo, beside the complete version number. -hatex_version :: LaTeXC l => l -hatex_version = hatex - <> emph (textbf $ rendertex x) - <> hspace (Ex $ negate 0.3) - <> emph ("." <> fromString (intercalate "." $ fmap show xs)) - where - (x:xs) = versionBranch version - -caption :: LaTeXC l => l -> l -caption = liftL $ \l -> TeXComm "caption" [FixArg l] - -label :: LaTeXC l => l -> l -label = liftL $ \l -> TeXComm "label" [FixArg $ TeXRaw $ render l] - -ref :: LaTeXC l => l -> l -ref = liftL $ \l -> TeXComm "ref" [FixArg $ TeXRaw $ render l] - -pageref :: LaTeXC l => l -> l -pageref = liftL $ \l -> TeXComm "pageref" [FixArg $ TeXRaw $ render l] +{-# LANGUAGE OverloadedStrings #-}++-- | LaTeX standard commands and environments.+module Text.LaTeX.Base.Commands+ ( -- * Basic functions+ raw , between , comment , (%:)+ -- * Preamble commands+ , title+ , author+ , date+ , institute+ , thanks+ , documentclass+ , usepackage+ , linespread+ -- ** Classes+ -- *** Document classes+ , article+ , proc+ , report+ , minimal+ , book+ , slides+ -- *** Class options+ , ClassOption (..)+ , customopt+ , draft+ , titlepage+ , notitlepage+ , onecolumn+ , twocolumn+ , oneside+ , twoside+ , landscape+ , openright+ , openany+ , fleqn+ , leqno+ -- ** Paper sizes+ , PaperType (..)+ , a0paper+ , a1paper+ , a2paper+ , a3paper+ , a4paper+ , a5paper+ , a6paper+ , b0paper+ , b1paper+ , b2paper+ , b3paper+ , b4paper+ , b5paper+ , b6paper+ , letterpaper+ , executivepaper+ , legalpaper+ -- ** Page styles+ , pagestyle+ , thispagestyle+ , plain+ , headings+ , empty+ , myheadings+ , markboth+ , markright+ -- * Body commands+ , document+ , maketitle+ -- ** Document structure+ , tableofcontents+ , abstract+ , appendix+ -- *** Sections+ , part+ , chapter+ , section+ , subsection+ , subsubsection+ , paragraph+ , subparagraph+ -- ** Logos & symbols+ , today+ , tex+ , latex+ , laTeX2+ , laTeXe+ , ldots+ , vdots+ , ddots+ -- *** HaTeX specific+ , hatex+ , hatex3+ , version+ , hatex_version+ -- ** Document layout+ , par+ , newline+ , lnbk+ , lnbk_+ , newpage+ , cleardoublepage+ , clearpage+ , linebreak+ , nolinebreak+ , pagebreak+ , nopagebreak+ , hspace+ , hspace_+ , vspace+ , hfill+ , vfill+ , stretch+ , smallskip+ , bigskip+ , indent+ , noindent+ -- *** Document measures+ , textwidth+ , linewidth+ -- ** Formatting text+ , verbatim , verb+ -- *** Fonts+ --+ -- Different font styles.+ , textbf+ , textit+ , texttt+ , textrm+ , textsf+ , textmd+ , textup+ , textsl+ , textsc+ , textnormal+ , underline+ , emph+ -- *** Sizes+ --+ -- | Sizes are sorted from smallest to biggest.+ , tiny+ , scriptsize+ , footnotesize+ , small+ , normalsize+ , large+ , large2+ , large3+ , huge+ , huge2+ -- ** Environments+ -- | Math environments, such as @equation@, defined in "Text.LaTeX.Packages.AMSMath".+ , enumerate+ , itemize+ , item+ , flushleft+ , flushright+ , center+ , quote+ , verse+ , cite+ , description+ , minipage+ , figure+ -- ** Page numbering+ , pagenumbering+ , arabic+ , roman+ , roman_+ , alph+ , alph_+ -- ** Boxes+ , mbox+ , fbox+ , parbox+ , framebox+ , makebox+ , raisebox+ , rule+ -- ** Cross references+ , caption+ , label+ , ref+ , pageref+ -- ** Tables+ , tabular+ , (&)+ , hline+ , cline+ , multicolumn+ -- ** Others+ , footnote+ , protect+ , hyphenation+ , hyp+ , qts+ ) where++import Data.String+import Data.Maybe (isNothing, catMaybes)+import Data.Text (toLower)+import qualified Data.Text as T+import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types+import Data.Version+import Data.List (find, intercalate)+--+import Paths_HaTeX++-- | Insert a raw piece of 'Text'.+-- This functions doesn't care about @LaTeX@ reserved characters,+-- it insert the text just as it is received.+raw :: LaTeXC l => Text -> l+raw = fromLaTeX . TeXRaw++-- | Calling 'between' @c l1 l2@ puts @c@ between @l1@ and @l2@ and+-- appends them.+between :: Monoid m => m -> m -> m -> m+between c l1 l2 = l1 <> c <> l2++-- | Create a comment.+comment :: LaTeXC l => Text -> l+comment = fromLaTeX . TeXComment++-- | This operator appends a comment after a expression.+-- For example:+--+-- > textbf "I'm just an example." %: "Insert a few words here."+--+-- Since you are writing in Haskell, you may not need to output comments+-- as you can add them in the Haskell source. I added this feature+-- for completeness.+(%:) :: LaTeXC l => l -> Text -> l+(%:) l = (l <>) . comment++-- | Generate the title. It normally contains the 'title' name+-- of your document, the 'author'(s) and 'date'.+maketitle :: LaTeXC l => l+maketitle = comm0 "maketitle"++-- | Set the title of your document.+title :: LaTeXC l => l -> l+title = liftL $ \t -> TeXComm "title" [FixArg t]++-- | Set a date for your document.+date :: LaTeXC l => l -> l+date = liftL $ \t -> TeXComm "date" [FixArg t]++-- | Set the author(s) of the document.+author :: LaTeXC l => l -> l+author = liftL $ \t -> TeXComm "author" [FixArg t]++-- | Set either an institute or an organization+-- for the document.+institute :: LaTeXC l => Maybe l -> l -> l+institute Nothing = liftL $ \l -> TeXComm "institute" [FixArg l]+institute (Just s) = liftL2 (\l1 l2 -> TeXComm "institute" [OptArg l1,FixArg l2]) s++thanks :: LaTeXC l => l -> l+thanks = liftL $ \l -> TeXComm "thanks" [FixArg l]++-- | Import a package. First argument is a list of options for+-- the package named in the second argument.+usepackage :: LaTeXC l => [l] -> PackageName -> l+usepackage ls pn = liftListL (\ls -> TeXComm "usepackage" [MOptArg ls ,FixArg $ fromString pn]) ls++-- | The @LaTeX@ logo.+latex :: LaTeXC l => l+latex = comm0 "LaTeX"++-- | Start a new paragraph+par :: LaTeXC l => l+par = comm0 "par"++-- | Start a new line.+newline :: LaTeXC l => l+newline = comm0 "newline"++part :: LaTeXC l => l -> l+part = liftL $ \p -> TeXComm "part" [FixArg p]++chapter :: LaTeXC l => l -> l+chapter = liftL $ \c -> TeXComm "chapter" [FixArg c]++-- | Start a new section with a given title.+section :: LaTeXC l => l -> l+section = liftL $ \s -> TeXComm "section" [FixArg s]++subsection :: LaTeXC l => l -> l+subsection = liftL $ \sub -> TeXComm "subsection" [FixArg sub]++subsubsection :: LaTeXC l => l -> l+subsubsection = liftL $ \sub -> TeXComm "subsubsection" [FixArg sub]++paragraph :: LaTeXC l => l -> l+paragraph = liftL $ \p -> TeXComm "paragraph" [FixArg p]++subparagraph :: LaTeXC l => l -> l+subparagraph = liftL $ \p -> TeXComm "subparagraph" [FixArg p]++-- | Create the table of contents, automatically generated+-- from your 'section's, 'subsection's, and other related stuff.+tableofcontents :: LaTeXC l => l+tableofcontents = comm0 "tableofcontents"++appendix :: LaTeXC l => l+appendix = comm0 "appendix"++item :: LaTeXC l => Maybe l -> l+item Nothing = commS "item "+item (Just opt) = liftL (\opt -> TeXComm "item" [OptArg opt]) opt++enumerate :: LaTeXC l => l -> l+enumerate = liftL $ TeXEnv "enumerate" []++itemize :: LaTeXC l => l -> l+itemize = liftL $ TeXEnv "itemize" []++description :: LaTeXC l => l -> l+description = liftL $ TeXEnv "description" []++flushleft :: LaTeXC l => l -> l+flushleft = liftL $ TeXEnv "flushleft" []++flushright :: LaTeXC l => l -> l+flushright = liftL $ TeXEnv "flushright" []++center :: LaTeXC l => l -> l+center = liftL $ TeXEnv "center" []++quote :: LaTeXC l => l -> l+quote = liftL $ TeXEnv "quote" []++verse :: LaTeXC l => l -> l+verse = liftL $ TeXEnv "verse" []++-- | Minipage environment.+minipage :: LaTeXC l =>+ Maybe Pos -- ^ Optional position+ -> l -- ^ Width+ -> l -- ^ Minipage content+ -> l+minipage Nothing = liftL2 $ \ts -> TeXEnv "minipage" [ FixArg ts ]+minipage (Just p) = liftL2 $ \ts -> TeXEnv "minipage" [ OptArg $ rendertex p , FixArg ts ]++-- | Figure environment.+figure :: LaTeXC l =>+ Maybe Pos -- ^ Optional position+ -> l -- ^ Figure content+ -> l+figure Nothing = liftL $ TeXEnv "figure" []+figure (Just p) = liftL $ TeXEnv "figure" [ OptArg $ TeXRaw $ render p ]++abstract :: LaTeXC l => l -> l+abstract = liftL $ TeXEnv "abstract" []++cite :: LaTeXC l => l -> l+cite = liftL $ \l -> TeXComm "cite" [FixArg l]++-- Document class++-- | A class option to be passed to the 'documentclass' function.+data ClassOption =+ Draft+ | TitlePage+ | NoTitlePage+ | OneColumn+ | TwoColumn+ | OneSide+ | TwoSide+ | Landscape+ | OpenRight+ | OpenAny+ | Fleqn+ | Leqno+ | FontSize Measure+ | Paper PaperType+ | CustomOption String+ deriving Show++instance Render ClassOption where+ render (FontSize m) = render m+ render (Paper pt) = toLower (render pt) <> "paper"+ render (CustomOption str) = fromString str+ render co = toLower $ fromString $ show co++customopt :: String -> ClassOption+customopt = CustomOption++instance IsString ClassOption where+ fromString = customopt++-- | LaTeX available paper types.+data PaperType =+ A0 | A1 | A2 | A3 | A4 | A5 | A6+ | B0 | B1 | B2 | B3 | B4 | B5 | B6+ | Letter | Executive | Legal+ deriving Show++instance Render PaperType where++-- | Set the document class. Needed in all documents.+documentclass :: LaTeXC l =>+ [ClassOption] -- ^ Class options+ -> ClassName -- ^ Class name+ -> l+documentclass opts cn = fromLaTeX $ TeXComm "documentclass" [MOptArg $ fmap rendertex opts , FixArg $ fromString cn]++article :: ClassName+article = "article"++proc :: ClassName+proc = "proc"++minimal :: ClassName+minimal = "minimal"++report :: ClassName+report = "report"++book :: ClassName+book = "book"++slides :: ClassName+slides = "slides"++a0paper :: ClassOption+a0paper = Paper A0++a1paper :: ClassOption+a1paper = Paper A1++a2paper :: ClassOption+a2paper = Paper A2++a3paper :: ClassOption+a3paper = Paper A3++a4paper :: ClassOption+a4paper = Paper A4++a5paper :: ClassOption+a5paper = Paper A5++a6paper :: ClassOption+a6paper = Paper A6++b0paper :: ClassOption+b0paper = Paper B0++b1paper :: ClassOption+b1paper = Paper B1++b2paper :: ClassOption+b2paper = Paper B2++b3paper :: ClassOption+b3paper = Paper B3++b4paper :: ClassOption+b4paper = Paper B4++b5paper :: ClassOption+b5paper = Paper B5++b6paper :: ClassOption+b6paper = Paper B6++letterpaper :: ClassOption+letterpaper = Paper Letter++executivepaper :: ClassOption+executivepaper = Paper Executive++legalpaper :: ClassOption+legalpaper = Paper Legal++draft :: ClassOption+draft = Draft++-- | Typesets displayed formulae left-aligned instead of centred.+fleqn :: ClassOption+fleqn = Fleqn++-- | Places the numbering of formulae on the left hand side instead of the right.+leqno :: ClassOption+leqno = Leqno++titlepage :: ClassOption+titlepage = TitlePage++notitlepage :: ClassOption+notitlepage = NoTitlePage++onecolumn :: ClassOption+onecolumn = OneColumn++twocolumn :: ClassOption+twocolumn = TwoColumn++oneside :: ClassOption+oneside = OneSide++twoside :: ClassOption+twoside = TwoSide++-- | Changes the layout of the document to print in landscape mode+landscape :: ClassOption+landscape = Landscape++-- | Makes chapters begin either only on right hand pages+openright :: ClassOption+openright = OpenRight++-- | Makes chapters begin on the next page available.+openany :: ClassOption+openany = OpenAny++document :: LaTeXC l => l -> l+document = liftL $ TeXEnv "document" []++pagenumbering :: LaTeXC l => l -> l+pagenumbering = liftL $ \l -> TeXComm "pagenumbering" [FixArg l]++-- | Arabic numerals.+arabic :: LaTeXC l => l+arabic = fromLaTeX "arabic"++-- | Lowercase roman numerals.+roman :: LaTeXC l => l+roman = fromLaTeX "roman"++-- | Uppercase roman numerals.+roman_ :: LaTeXC l => l+roman_ = fromLaTeX "Roman"++-- | Lowercase letters.+alph :: LaTeXC l => l+alph = fromLaTeX "alph"++-- | Uppercase letters.+alph_ :: LaTeXC l => l+alph_ = fromLaTeX "Alph"++pagestyle :: LaTeXC l => l -> l+pagestyle = liftL $ \l -> TeXComm "pagestyle" [FixArg l]++thispagestyle :: LaTeXC l => l -> l+thispagestyle = liftL $ \l -> TeXComm "thispagestyle" [FixArg l]++plain :: LaTeXC l => l+plain = fromLaTeX "plain"++headings :: LaTeXC l => l+headings = fromLaTeX "headings"++empty :: LaTeXC l => l+empty = fromLaTeX "empty"++myheadings :: LaTeXC l => l+myheadings = fromLaTeX "myheadings"++-- | Used in conjunction with 'myheadings' for setting both the left and the right heading.+markboth :: LaTeXC l => l -> l -> l+markboth = liftL2 $ \l1 l2 -> TeXComm "markboth" [FixArg l1 , FixArg l2]++-- | Used in conjunction with 'myheadings' for setting the right heading.+markright :: LaTeXC l => l -> l+markright = liftL $ \l -> TeXComm "markright" [FixArg l]++-- | Start a new line. In a 'tabular', it starts a new row, so use 'newline' instead.+lnbk :: LaTeXC l => l+lnbk = fromLaTeX $ TeXLineBreak Nothing False++lnbk_ :: LaTeXC l => l+lnbk_ = fromLaTeX $ TeXLineBreak Nothing True++hyp :: LaTeXC l => l+hyp = fromLaTeX $ TeXCommS "-"++cleardoublepage :: LaTeXC l => l+cleardoublepage = comm0 "cleardoublepage"++clearpage :: LaTeXC l => l+clearpage = comm0 "clearpage"++newpage :: LaTeXC l => l+newpage = comm0 "newpage"++linebreak :: LaTeXC l => l -> l+linebreak = liftL $ \l -> TeXComm "linebreak" [OptArg l]++nolinebreak :: LaTeXC l => l -> l+nolinebreak = liftL $ \l -> TeXComm "nolinebreak" [OptArg l]++nopagebreak :: LaTeXC l => l -> l+nopagebreak = liftL $ \l -> TeXComm "nopagebreak" [OptArg l]++pagebreak :: LaTeXC l => l -> l+pagebreak = liftL $ \l -> TeXComm "pagebreak" [OptArg l]++hyphenation :: LaTeXC l => l -> l+hyphenation = liftL $ \l -> TeXComm "hyphenation" [FixArg l]++mbox :: LaTeXC l => l -> l+mbox = liftL $ \l -> TeXComm "mbox" [FixArg l]++fbox :: LaTeXC l => l -> l+fbox = liftL $ \l -> TeXComm "fbox" [FixArg l]++today :: LaTeXC l => l+today = comm0 "today"++tex :: LaTeXC l => l+tex = comm0 "TeX"++laTeX2 :: LaTeXC l => l+laTeX2 = comm0 "LaTeX"++laTeXe :: LaTeXC l => l+laTeXe = comm0 "LaTeXe"++-- | Horizontal dots.+ldots :: LaTeXC l => l+ldots = comm0 "ldots"++-- | Vertical dots.+vdots :: LaTeXC l => l+vdots = comm0 "vdots"++-- | Diagonal dots.+ddots :: LaTeXC l => l+ddots = comm0 "ddots"++-- | Quotation marks.+qts :: LaTeXC l => l -> l+qts l = between l (raw "``") (raw "''")++footnote :: LaTeXC l => l -> l+footnote = liftL $ \l -> TeXComm "footnote" [FixArg l]++linespread :: LaTeXC l => Float -> l+linespread x = fromLaTeX $ TeXComm "linespread" [FixArg $ rendertex x]++indent :: LaTeXC l => l+indent = comm0 "indent"++noindent :: LaTeXC l => l+noindent = comm0 "noindent"++hspace :: LaTeXC l => Measure -> l+hspace m = fromLaTeX $ TeXComm "hspace" [FixArg $ rendertex m]++hspace_ :: LaTeXC l => Measure -> l+hspace_ m = fromLaTeX $ TeXComm "hspace*" [FixArg $ rendertex m]++stretch :: LaTeXC l => Int -> l+stretch n = fromLaTeX $ TeXComm "stretch" [FixArg $ rendertex n]++vspace :: LaTeXC l => Measure -> l+vspace m = fromLaTeX $ TeXComm "vspace" [FixArg $ rendertex m]++-- | Fill out all available horizontal space.+hfill :: LaTeXC l => l+hfill = comm0 "hfill"++-- | Fill out all available vertical space.+vfill :: LaTeXC l => l+vfill = comm0 "vfill"++protect :: LaTeXC l => l -> l+protect l = commS "protect" <> l++textwidth :: LaTeXC l => l+textwidth = comm0 "textwidth"++linewidth :: LaTeXC l => l+linewidth = comm0 "linewidth"++-- | The point of 'verbatim' is to include text that will+-- /not/ be parsed as LaTeX in any way at all, but should simply+-- appear as given in the document, in a separate display+-- in typewriter font.+verbatim :: LaTeXC l => Text -> l+verbatim = liftL (TeXEnv "verbatim" []) . raw++-- | Include text, as given and in typewriter, but in-line.+-- Note that, for LaTeX-specific technical reasons, verbatim+-- text can generally only be used \"at the top level\", not+-- in e.g. section titles or other command-arguments.+--+-- Unlike 'verbatim', which LaTeX implements as an ordinary environment,+-- its command 'verb' uses a syntax trick to avoid braking its parsing+-- when the literal text contains a closing brace: rather than using braces+-- at all, the first character after @\\verb@ will be the right delimiter as well.+-- Translating this method to HaTeX wouldn't really make sense since Haskell+-- has string literals with their own escaping possibilities; instead, we make+-- it secure by automatically choosing a delimiter that does not turn up +-- in the given string.+verb :: LaTeXC l => Text -> l+verb vbStr = case find (isNothing . (`T.find`vbStr) . (==))+ $ "`'\"|=-~$#+/!^_;:,." ++ ['0'..'9'] ++ ['A'..'B'] ++ ['a'..'b']+ of Just delim -> let d = T.singleton delim+ in raw $ T.concat [ "\\verb", d, vbStr, d ]+ Nothing -> let (lpart, rpart)+ = T.splitAt (T.length vbStr `quot` 2) vbStr+ in verb lpart <> verb rpart+ -- If all suitable delimiter characters are already used in the verbatim+ -- string (which really should never happen as this is intended for **short**+ -- in-line displays!) then split the verbatim string in two sections; at+ -- some point they will necessarily lack some of the characters.++underline :: LaTeXC l => l -> l+underline = liftL $ \l -> TeXComm "underline" [FixArg l]++emph :: LaTeXC l => l -> l+emph = liftL $ \l -> TeXComm "emph" [FixArg l]++textrm :: LaTeXC l => l -> l+textrm = liftL $ \l -> TeXComm "textrm" [FixArg l]++textsf :: LaTeXC l => l -> l+textsf = liftL $ \l -> TeXComm "textsf" [FixArg l]++-- | Set the given argument to monospaced font.+texttt :: LaTeXC l => l -> l+texttt = liftL $ \l -> TeXComm "texttt" [FixArg l]++textmd :: LaTeXC l => l -> l+textmd = liftL $ \l -> TeXComm "textmd" [FixArg l]++-- | Set the given argument to bold font face.+textbf :: LaTeXC l => l -> l+textbf = liftL $ \l -> TeXComm "textbf" [FixArg l]++textup :: LaTeXC l => l -> l+textup = liftL $ \l -> TeXComm "textup" [FixArg l]++-- Set the given argument to italic font face.+textit :: LaTeXC l => l -> l+textit = liftL $ \l -> TeXComm "textit" [FixArg l]++textsl :: LaTeXC l => l -> l+textsl = liftL $ \l -> TeXComm "textsl" [FixArg l]++-- | Set the given argument to small caps format.+textsc :: LaTeXC l => l -> l+textsc = liftL $ \l -> TeXComm "textsc" [FixArg l]++textnormal :: LaTeXC l => l -> l+textnormal = liftL $ \l -> TeXComm "textnormal" [FixArg l]++--------------------+-- Standard sizes --+--------------------++sizecomm :: LaTeXC l => String -> l -> l+sizecomm str = liftL $ \l -> TeXBraces $ comm0 str <> l++tiny :: LaTeXC l => l -> l+tiny = sizecomm "tiny"++scriptsize :: LaTeXC l => l -> l+scriptsize = sizecomm "scriptsize"++footnotesize :: LaTeXC l => l -> l+footnotesize = sizecomm "footnotesize"++small :: LaTeXC l => l -> l+small = sizecomm "small"++normalsize :: LaTeXC l => l -> l+normalsize = sizecomm "normalsize"++large :: LaTeXC l => l -> l+large = sizecomm "large"++large2 :: LaTeXC l => l -> l+large2 = sizecomm "Large"++large3 :: LaTeXC l => l -> l+large3 = sizecomm "LARGE"++huge :: LaTeXC l => l -> l+huge = sizecomm "huge"++huge2 :: LaTeXC l => l -> l+huge2 = sizecomm "Huge"++--------------------++smallskip :: LaTeXC l => l+smallskip = comm0 "smallskip"++bigskip :: LaTeXC l => l+bigskip = comm0 "bigskip"++-- | The 'tabular' environment can be used to typeset tables with optional horizontal and vertical lines.+tabular :: LaTeXC l =>+ Maybe Pos -- ^ This optional parameter can be used to specify the vertical position of the table.+ -- Defaulted to 'Center'.+ -> [TableSpec] -- ^ Table specification of columns and vertical lines.+ -> l -- ^ Table content. See '&', 'lnbk', 'hline' and 'cline'.+ -> l -- ^ Resulting table syntax.+tabular Nothing ts = liftL $ TeXEnv "tabular" [ FixArg $ TeXRaw $ renderAppend ts ]+tabular (Just p) ts = liftL $ TeXEnv "tabular" [ OptArg $ TeXRaw $ render p , FixArg $ TeXRaw $ renderAppend ts ]++-- | Column separator.+(&) :: LaTeXC l => l -> l -> l+(&) = liftL2 $ TeXOp "&"++-- | Horizontal line.+hline :: LaTeXC l => l+hline = commS "hline "++-- | Cell taking multiple columns.+multicolumn :: LaTeXC l => Int -> [TableSpec] -> l -> l+multicolumn n c = liftL $ \l -> TeXComm "multicolumn"+ [ FixArg $ rendertex n+ , FixArg . TeXRaw $ renderAppend c+ , FixArg l+ ]++-- | @cline i j@ writes a partial horizontal line beginning in column @i@ and ending in column @j@.+cline :: LaTeXC l => Int -> Int -> l+cline i j = fromLaTeX $ TeXComm "cline" [ FixArg $ TeXRaw $ render i <> "-" <> render j ]++parbox :: LaTeXC l => Maybe Pos -> Measure -> l -> l+parbox Nothing w = liftL $ \t -> TeXComm "parbox" [ FixArg $ rendertex w , FixArg t ]+parbox (Just p) w = liftL $ \t -> TeXComm "parbox" [ OptArg $ TeXRaw $ render p+ , FixArg $ TeXRaw $ render w+ , FixArg t ]++makebox :: LaTeXC l => Maybe Measure -> Maybe Pos -> l -> l+makebox Nothing Nothing = liftL $ \t -> TeXComm "makebox" [ FixArg t ]+makebox (Just w) Nothing = liftL $ \t -> TeXComm "makebox" [ OptArg $ TeXRaw $ render w+ , FixArg t ]+makebox Nothing (Just p) = liftL $ \t -> TeXComm "makebox" [ OptArg $ TeXRaw $ render p+ , FixArg t ]+makebox (Just w) (Just p) = liftL $ \t -> TeXComm "makebox" [ OptArg $ TeXRaw $ render w+ , OptArg $ TeXRaw $ render p+ , FixArg t ] ++framebox :: LaTeXC l => Maybe Measure -> Maybe Pos -> l -> l+framebox Nothing Nothing = liftL $ \t -> TeXComm "framebox" [ FixArg t ]+framebox (Just w) Nothing = liftL $ \t -> TeXComm "framebox" [ OptArg $ TeXRaw $ render w+ , FixArg t ]+framebox Nothing (Just p) = liftL $ \t -> TeXComm "framebox" [ OptArg $ TeXRaw $ render p+ , FixArg t ]+framebox (Just w) (Just p) = liftL $ \t -> TeXComm "framebox" [ OptArg $ TeXRaw $ render w+ , OptArg $ TeXRaw $ render p+ , FixArg t ]++raisebox :: LaTeXC l => Measure -> Maybe Measure -> Maybe Measure -> l -> l+raisebox m ma mb = liftL $ \l -> TeXComm "raisebox" $+ [ FixArg $ rendertex m ]+ ++ fmap (OptArg . rendertex) (catMaybes [ma,mb])+ ++ [ FixArg l ]++-- | Produce a simple black box.+rule :: LaTeXC l =>+ Maybe Measure -- ^ Optional lifting.+ -> Measure -- ^ Width.+ -> Measure -- ^ Height.+ -> l+rule Nothing w h = fromLaTeX $ TeXComm "rule" [ FixArg $ TeXRaw $ render w+ , FixArg $ TeXRaw $ render h ]+rule (Just l) w h = fromLaTeX $ TeXComm "rule" [ OptArg $ TeXRaw $ render l+ , FixArg $ TeXRaw $ render w+ , FixArg $ TeXRaw $ render h ]++-- HaTeX specific symbols++-- | Print the HaTeX logo.+hatex :: LaTeXC l => l+hatex = mbox $ "H"+ <> hspace (Ex $ negate 0.3)+ <> textsc "a"+ <> hspace (Ex $ negate 0.3)+ <> tex++-- | Print the HaTeX 3 logo.+hatex3 :: LaTeXC l => l+hatex3 = hatex <> emph (textbf "3")++-- | Print the HaTeX logo, beside the complete version number.+hatex_version :: LaTeXC l => l+hatex_version = hatex+ <> emph (textbf $ rendertex x)+ <> hspace (Ex $ negate 0.3)+ <> emph ("." <> fromString (intercalate "." $ fmap show xs))+ where+ (x:xs) = versionBranch version++caption :: LaTeXC l => l -> l+caption = liftL $ \l -> TeXComm "caption" [FixArg l]++label :: LaTeXC l => l -> l+label = liftL $ \l -> TeXComm "label" [FixArg $ TeXRaw $ render l]++ref :: LaTeXC l => l -> l+ref = liftL $ \l -> TeXComm "ref" [FixArg $ TeXRaw $ render l]++pageref :: LaTeXC l => l -> l+pageref = liftL $ \l -> TeXComm "pageref" [FixArg $ TeXRaw $ render l]
Text/LaTeX/Base/Parser.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} ------------------------------------------------------------------------------- -- | -- Module : Text/LaTeX/Base/Parser.hs @@ -112,7 +113,7 @@ text2 = do _ <- char ']' t <- try (text <|> return (TeXRaw T.empty)) - return $ TeXRaw endlessSq <> t + return $ TeXRaw (T.pack "]") <> t ------------------------------------------------------------------------ -- Environment @@ -121,12 +122,13 @@ environment = choice [anonym, env] anonym :: Parser LaTeX - anonym = char oBr >> - TeXBraces . mconcat <$> block `manyTill` char eBr + anonym = char '{' >> + TeXBraces . mconcat <$> block `manyTill` char '}' env :: Parser LaTeX env = do - n <- envName begin + _ <- char '\\' + n <- envName "begin" as <- cmdArgs b <- envBody n return $ TeXEnv (T.unpack n) as b @@ -134,22 +136,21 @@ envName :: Text -> Parser Text envName k = do _ <- string k - _ <- char oBr - n <- A.takeTill (== eBr) - _ <- char eBr + _ <- char '{' + n <- A.takeTill (== '}') + _ <- char '}' -- Is not this brace already taken by the takeTill? return n envBody :: Text -> Parser LaTeX envBody n = mconcat <$> block `manyTill` endenv - where endenv = try $ string (end `T.snoc` oBr <> n - `T.snoc` eBr) + where endenv = try $ string ("\\end{" <> n <> "}") ------------------------------------------------------------------------ -- Command ------------------------------------------------------------------------ command :: Parser LaTeX command = do - _ <- char bsl + _ <- char '\\' mbX <- peekChar case mbX of Nothing -> return TeXEmpty @@ -166,7 +167,7 @@ -- Command Arguments ------------------------------------------------------------------------ cmdArgs :: Parser [TeXArg] - cmdArgs = try (whitespace >> string emptyArg >> return [FixArg TeXEmpty]) + cmdArgs = try (whitespace >> string "{}" >> return [FixArg TeXEmpty]) <|> many1 cmdArg <|> return [] @@ -175,8 +176,8 @@ whitespace c <- char '[' <|> char '{' let e = case c of - '[' -> endlessSq - '{' -> endlessBr + '[' -> "]" + '{' -> "}" _ -> error "this cannot happen!" b <- mconcat <$> block `manyTill` string e case c of @@ -196,8 +197,8 @@ special = do x <- anyChar case x of - '(' -> math Parentheses endPa - '[' -> math Square endSq + '(' -> math Parentheses "\\)" + '[' -> math Square "\\]" '{' -> lbrace '}' -> rbrace '|' -> vert @@ -209,10 +210,10 @@ ------------------------------------------------------------------------ lbreak :: Parser LaTeX lbreak = do - y <- try (char oSq <|> char str <|> return ' ') + y <- try (char '[' <|> char '*' <|> return ' ') case y of '[' -> linebreak False - '*' -> do z <- try (char oSq <|> return ' ') + '*' -> do z <- try (char '[' <|> return ' ') case z of '[' -> linebreak True _ -> return (TeXLineBreak Nothing True) @@ -220,9 +221,9 @@ linebreak :: Bool -> Parser LaTeX linebreak t = do m <- measure - _ <- char eSq - s <- try (char str <|> return ' ') - return $ TeXLineBreak (Just m) (t || s == str) + _ <- char ']' + s <- try (char '*' <|> return ' ') + return $ TeXLineBreak (Just m) (t || s == '*') measure :: Parser Measure measure = try (double >>= unit) @@ -260,8 +261,8 @@ ------------------------------------------------------------------------ dolMath :: Parser LaTeX dolMath = do - _ <- char dol - b <- mconcat <$> block `manyTill` char dol + _ <- char '$' + b <- mconcat <$> block `manyTill` char '$' return $ TeXMath Dollar b -- [] math :: MathType -> Text -> Parser LaTeX @@ -274,7 +275,7 @@ ------------------------------------------------------------------------ comment :: Parser LaTeX comment = do - _ <- char per + _ <- char '%' c <- A.takeTill (== '\n') e <- atEnd unless e (char '\n' >>= \_ -> return ()) @@ -284,43 +285,14 @@ -- Helpers ------------------------------------------------------------------------ isSpecial :: Char -> Bool - isSpecial = (`elem` specials) -- [bsl, oSq, oPa, oBr, eBr] - - begin, end :: Text - begin = T.pack "\\begin" - end = T.pack "\\end" + isSpecial = (`elem` specials) -- ['\\', '[', '(', '{', '}'] endCmd :: Char -> Bool - endCmd = flip elem symbols - - nul, eol, spc :: Char - nul = '\0' - eol = '\n' - spc = ' ' - - oBr, eBr, oSq, eSq, oPa, ePa, bsl, dol, per, str :: Char - oBr = '{' - eBr = '}' - oSq = '[' - eSq = ']' - oPa = '(' - ePa = ')' - bsl = '\\' - dol = '$' - per = '%' - str = '*' - - endPa, endSq, endlessBr, endlessSq :: Text - endPa = T.pack "\\)" - endSq = T.pack "\\]" - endlessBr = T.pack "}" - endlessSq = T.pack "]" - - emptyArg :: Text - emptyArg = T.pack "{}" + endCmd c = notLowercaseAlph && notUppercaseAlph + where c' = fromEnum c + notLowercaseAlph = c' < fromEnum 'a' || c' > fromEnum 'z' + notUppercaseAlph = c' < fromEnum 'A' || c' > fromEnum 'Z' - symbols :: String - symbols = [nul, eol, spc, oBr, eBr, eSq, oSq, oPa, ePa, bsl, dol, per] specials :: String specials = "'(),.-\"!^$&#{}%~|/:;=[]\\` "
Text/LaTeX/Base/Render.hs view
@@ -139,8 +139,6 @@ render (TeXSeq l1 l2) = render l1 <> render l2 render TeXEmpty = mempty - - instance Render TeXArg where render (OptArg l) = "[" <> render l <> "]" render (FixArg l) = "{" <> render l <> "}" @@ -154,4 +152,7 @@ instance Render Int where instance Render Integer where instance Render Float where -instance Render Double where+instance Render Double where + +instance Render a => Render [a] where + render xs = "[" <> renderCommas xs <> "]"
+ Text/LaTeX/Base/Texy.hs view
@@ -0,0 +1,48 @@++-- | 'Texy' class, as proposed in <http://deltadiaz.blogspot.com.es/2013/04/hatex-36-proposal-texy-class.html>.+module Text.LaTeX.Base.Texy (+ -- * Texy class+ Texy (..)+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Commands+--+import Numeric+import Data.Fixed+import Data.List (intersperse)++-- | Class of types that can be pretty-printed as 'LaTeX' values.+class Texy t where+ texy :: LaTeXC l => t -> l++-- Basic instances++instance Texy LaTeX where+ texy = fromLaTeX++instance Texy Text where+ texy = raw . protectText++instance Texy Int where+ texy = rendertex++instance Texy Integer where+ texy = rendertex++instance Texy Float where+ texy x = fromString $ showFFloat Nothing x ""++instance Texy Double where+ texy x = fromString $ showFFloat Nothing x ""++instance Texy Char where+ texy c = fromString ['`' , c , '`']++instance HasResolution a => Texy (Fixed a) where+ texy = fromString . show++instance Texy Bool where+ texy = fromString . show
Text/LaTeX/Base/Types.hs view
@@ -21,6 +21,7 @@ -- | Package names are represented by a 'String'. type PackageName = String +-- | Type of labels. newtype Label = Label String deriving (Eq, Show) -- | Create a label from its name. @@ -53,6 +54,7 @@ render HCenter = "c" render HRight = "r" +-- | Type of table specifications. data TableSpec = LeftColumn -- ^ Left-justified column. | CenterColumn -- ^ Centered column. @@ -72,4 +74,4 @@ render (ParColumnMid l) = "m" <> render (FixArg l) render (ParColumnBot l) = "b" <> render (FixArg l) render VerticalLine = "|" - render DVerticalLine = "||"+ render DVerticalLine = "||"
Text/LaTeX/Base/Writer.hs view
@@ -18,8 +18,9 @@ -- Since 'LaTeXT' is a monad transformer, you can do also: -- -- > anotherExample :: LaTeXT IO () --- > anotherExample = lift (readFile "foo") >>= verbatim . fromString +-- > 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. -- @@ -27,6 +28,9 @@ -- or any other user-defined feature. -- -- 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 @@ -64,12 +68,14 @@ -- import Control.Monad (liftM) +-- | 'WriterT' monad transformer applied to 'LaTeX' values. newtype LaTeXT m a = LaTeXT { unwrapLaTeXT :: WriterT LaTeX m (a,Maybe String) } instance Functor f => Functor (LaTeXT f) where fmap f (LaTeXT c) = LaTeXT $ fmap (first f) c +-- | Pair a value with 'Nothing'. pairNoth :: a -> (a,Maybe b) pairNoth x = (x,Nothing) @@ -77,6 +83,7 @@ pure = LaTeXT . pure . pairNoth (LaTeXT f) <*> (LaTeXT x) = LaTeXT $ fmap (first . fst) f <*> x +-- | Type synonym for empty 'LaTeXT' computations. type LaTeXT_ m = LaTeXT m () instance MonadTrans LaTeXT where @@ -96,6 +103,9 @@ instance Monad m => LaTeXC (LaTeXT m a) where liftListL f xs = mapM extractLaTeX_ xs >>= merror "liftListL" . 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 @@ -105,6 +115,16 @@ -- | This is the usual way to run the 'LaTeXT' monad -- and obtain a 'LaTeX' value. +-- +-- > execLaTeXT = liftM snd . runLaTeXT +-- +-- If @anExample@ is defined as above (at the top of this module +-- documentation), use the following to get the LaTeX value +-- generated out. +-- +-- > myLaTeX :: Monad m => m LaTeX +-- > myLaTeX = execLaTeXT anExample +-- execLaTeXT :: Monad m => LaTeXT m a -> m LaTeX execLaTeXT = liftM snd . runLaTeXT @@ -120,6 +140,15 @@ ((a,m),l) <- lift $ runWriterT c return ((a,l),m) +-- | Executes a 'LaTeXT' computation, embedding it again in +-- the 'LaTeXT' monad. +-- +-- > extractLaTeX_ = liftM snd . extractLaTeX +-- +-- This function was heavily used in the past by HaTeX-meta +-- to generate those @.Monad@ modules. The current purpose +-- is to implement the 'LaTeXC' instance of 'LaTeXT', which +-- is closely related. extractLaTeX_ :: Monad m => LaTeXT m a -> LaTeXT m LaTeX extractLaTeX_ = liftM snd . extractLaTeX @@ -161,6 +190,7 @@ -- Error throwing +-- | The 'fail' method of the 'LaTeXT' monad. throwError :: Monad m => String -> LaTeXT m a throwError = LaTeXT . return . (error &&& Just)
− Text/LaTeX/Packages.hs
@@ -1,26 +0,0 @@- --- | Re-export of all packages. -module Text.LaTeX.Packages - ( -- * Encoding packages - module Text.LaTeX.Packages.Inputenc - -- * Cross-reference packages - , module Text.LaTeX.Packages.Hyperref - -- * Presentation packages - , module Text.LaTeX.Packages.Beamer - -- * Mathematics packages - , module Text.LaTeX.Packages.AMSMath - , module Text.LaTeX.Packages.AMSFonts - , module Text.LaTeX.Packages.AMSThm - -- * Graphics packages - , module Text.LaTeX.Packages.Color - , module Text.LaTeX.Packages.Graphicx - ) where - -import Text.LaTeX.Packages.Inputenc -import Text.LaTeX.Packages.Hyperref -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 -import Text.LaTeX.Packages.Graphicx
Text/LaTeX/Packages/AMSMath.hs view
@@ -4,8 +4,12 @@ module Text.LaTeX.Packages.AMSMath ( -- * AMSMath package amsmath - -- * AMSMath functions + -- * Math Environments , math, mathDisplay + , equation , equation_ + , align , align_ + -- ** Referencing + , eqref , nonumber -- * Symbols and utilities -- | The unicode approximations do, of course, not reliably represent how -- LaTeX renders these symbols. @@ -97,8 +101,14 @@ import Text.LaTeX.Base import Text.LaTeX.Base.Syntax +import Text.LaTeX.Base.Render(render) import Text.LaTeX.Base.Class --- Matrices +import Text.LaTeX.Base.Commands (raw,between,label,lnbk,(&)) +import Text.LaTeX.Base.Types + +-- External imports +import Data.List +import Data.Ratio import Data.Matrix -- | AMSMath package. @@ -208,32 +218,58 @@ atanh = error "Function 'atabh' is not defined in AMSMath!" acosh = error "Function 'acosh' is not defined in AMSMath!" +-- | A reference to a numbered equation. Use with a 'label' defined in the +-- scope of the equation refered to. +eqref :: LaTeXC l => l -> l +eqref = liftL $ \l -> TeXComm "eqref" [FixArg . TeXRaw $ render l] + +-- | Prevent an equation from being numbered, where the environment would by default do that. +nonumber :: LaTeXC l => l +nonumber = comm0 "nonumber" + +-- | A numbered mathematical equation (or otherwise math expression). +equation :: LaTeXC l => l -> l +equation = liftL $ TeXEnv "equation" [] + +-- | The unnumbered variant of 'equation'. +equation_ :: LaTeXC l => l -> l +equation_ = liftL $ TeXEnv "equation*" [] + +-- | An array of aligned equations. Use '&' to specify the points that should +-- horizontally match. Each equation is numbered, unless prevented by 'nonumber'. +align :: LaTeXC l => [l] -> l +align = liftL(TeXEnv "align" []) . mconcat . intersperse lnbk + +-- | The unnumbered variant of 'align'. +align_ :: LaTeXC l => [l] -> l +align_ = liftL(TeXEnv "align*" []) . mconcat . intersperse lnbk + ------------------------------------- ------- Symbols and utilities ------- -- | Surround a LaTeX math expression by parentheses whose height -- automatically matches the expression's. Translates to @\\left(...\\right)@. autoParens :: LaTeXC l => l -> l -autoParens x = comm0 "left(" <> x <> comm0 "right)" +autoParens x = commS "left(" <> x <> commS "right)" -- | Like 'autoParens', but with square brackets. Equivalent to @'autoBrackets'\"[\"\"]\"@. autoSquareBrackets :: LaTeXC l => l -> l -autoSquareBrackets x = comm0 "left[" <> x <> comm0 "right]" +autoSquareBrackets x = commS "left[" <> x <> commS "right]" -- | Like 'autoParens', but with curly brackets. autoBraces :: LaTeXC l => l -> l -autoBraces x = comm0 "left"<>"{" <> x <> comm0 "right"<>"}" +autoBraces x = commS "left"<>"{" <> x <> commS "right"<>"}" -- | Like 'autoParens', but with angle brackets 〈 ... 〉. Equivalent to @'autoBrackets' 'langle' 'rangle'@. autoAngleBrackets :: LaTeXC l => l -> l -autoAngleBrackets x = comm0 "left"<>langle <> x <> comm0 "right"<>rangle +autoAngleBrackets x = commS "left"<>langle <> x <> commS "right"<>rangle -- | Use custom LaTeX expressions as auto-scaled delimiters to surround math. -- Suitable delimiters include |...| (absolute value), ‖...‖ (norm, -- 'dblPipe'), ⌊...⌋ (round-off Gauss brackets, 'lfloor' / 'rfloor') etc.. autoBrackets :: LaTeXC l => LaTeX -> LaTeX -> l -> l autoBrackets lBrack rBrack x - = comm0 "left" <> braces (fromLaTeX lBrack) <> x <> comm0 "right" <> braces (fromLaTeX rBrack) + = commS "left" <> braces (fromLaTeX lBrack) <> x <> commS "right" <> braces (fromLaTeX rBrack) -- | Left angle bracket, 〈. langle :: LaTeXC l => l @@ -374,7 +410,7 @@ times :: LaTeXC l => l -> l -> l times = between $ comm0 "times" --- | Division operator (. +-- | Division operator. div_ :: LaTeXC l => l -> l -> l div_ = between $ comm0 "div" @@ -737,55 +773,86 @@ ------------------------------------- ------------- Matrices -------------- -matrix2tex :: Render a => Matrix a -> LaTeX +matrix2tex :: (Texy a, LaTeXC l) => Matrix a -> l matrix2tex m = mconcat - [ foldr1 (&) [ rendertex $ m ! (i,j) + [ foldr1 (&) [ texy $ m ! (i,j) | j <- [1 .. ncols m] ] <> lnbk | i <- [1 .. nrows m] ] --- | LaTeX rendering of a matrix using @pmatrix@.Optional argument sets the alignment --- of the cells. Default (providing 'Nothing') is centered. +toMatrix :: (Texy a, LaTeXC l) => String -> Maybe HPos -> Matrix a -> l +toMatrix str Nothing = liftL (TeXEnv str []) . matrix2tex +toMatrix str (Just p) = liftL (TeXEnv (str ++ "*") [OptArg $ rendertex p]) . matrix2tex + +-- | LaTeX rendering of a matrix using @pmatrix@ and a custom function to render cells. +-- Optional argument sets the alignment of the cells. Default (providing 'Nothing') +-- is centered. -- -- > ( M ) -- -pmatrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l -pmatrix Nothing = fromLaTeX . TeXEnv "pmatrix" [] . matrix2tex -pmatrix (Just p) = fromLaTeX . TeXEnv "pmatrix*" [OptArg $ rendertex p] . matrix2tex +pmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l +pmatrix = toMatrix "pmatrix" --- | LaTeX rendering of a matrix using @bmatrix@. Optional argument sets the alignment --- of the cells. Default (providing 'Nothing') is centered. +-- | LaTeX rendering of a matrix using @bmatrix@ and a custom function to render cells. +-- Optional argument sets the alignment of the cells. Default (providing 'Nothing') +-- is centered. -- -- > [ M ] -- -bmatrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l -bmatrix Nothing = fromLaTeX . TeXEnv "bmatrix" [] . matrix2tex -bmatrix (Just p) = fromLaTeX . TeXEnv "bmatrix*" [OptArg $ rendertex p] . matrix2tex +bmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l +bmatrix = toMatrix "bmatrix" --- | LaTeX rendering of a matrix using @Bmatrix@. Optional argument sets the alignment --- of the cells. Default (providing 'Nothing') is centered. +-- | LaTeX rendering of a matrix using @Bmatrix@ and a custom function to render cells. +-- Optional argument sets the alignment of the cells. Default (providing 'Nothing') +-- is centered. -- -- > { M } -- -b2matrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l -b2matrix Nothing = fromLaTeX . TeXEnv "Bmatrix" [] . matrix2tex -b2matrix (Just p) = fromLaTeX . TeXEnv "Bmatrix*" [OptArg $ rendertex p] . matrix2tex +b2matrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l +b2matrix = toMatrix "Bmatrix" --- | LaTeX rendering of a matrix using @vmatrix@. Optional argument sets the alignment --- of the cells. Default (providing 'Nothing') is centered. +-- | LaTeX rendering of a matrix using @vmatrix@ and a custom function to render cells. +-- Optional argument sets the alignment of the cells. Default (providing 'Nothing') +-- is centered. -- -- > | M | -- -vmatrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l -vmatrix Nothing = fromLaTeX . TeXEnv "vmatrix" [] . matrix2tex -vmatrix (Just p) = fromLaTeX . TeXEnv "vmatrix*" [OptArg $ rendertex p] . matrix2tex +vmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l +vmatrix = toMatrix "vmatrix" --- | LaTeX rendering of a matrix using @Vmatrix@. Optional argument sets the alignment --- of the cells. Default (providing 'Nothing') is centered. +-- | LaTeX rendering of a matrix using @Vmatrix@ and a custom function to render cells. +-- Optional argument sets the alignment of the cells. Default (providing 'Nothing') +-- is centered. -- -- > || M || -- -v2matrix :: (Render a, LaTeXC l) => Maybe HPos -> Matrix a -> l -v2matrix Nothing = fromLaTeX . TeXEnv "Vmatrix" [] . matrix2tex -v2matrix (Just p) = fromLaTeX . TeXEnv "Vmatrix*" [OptArg $ rendertex p] . matrix2tex+v2matrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l +v2matrix = toMatrix "Vmatrix" + +------------------------------------- +---------- Texy instances ----------- + +-- | Instance defined in "Text.LaTeX.Packages.AMSMath". +instance (Integral a, Texy a) => Texy (Ratio a) where + texy x = frac (texy $ numerator x) (texy $ denominator x) + +-- | Instance defined in "Text.LaTeX.Packages.AMSMath". +instance (Texy a, Texy b) => Texy (a,b) where + texy (x,y) = autoParens $ texy x <> "," <> texy y + +-- | Instance defined in "Text.LaTeX.Packages.AMSMath". +instance (Texy a, Texy b, Texy c) => Texy (a,b,c) where + texy (x,y,z) = autoParens $ texy x <> "," <> texy y <> "," <> texy z + +-- | Instance defined in "Text.LaTeX.Packages.AMSMath". +instance (Texy a, Texy b, Texy c, Texy d) => Texy (a,b,c,d) where + texy (a,b,c,d) = autoParens $ texy a <> "," <> texy b <> "," <> texy c <> "," <> texy d + +-- | Instance defined in "Text.LaTeX.Packages.AMSMath". +instance Texy a => Texy (Matrix a) where + texy = pmatrix Nothing + +-- | Instance defined in "Text.LaTeX.Packages.AMSMath". +instance Texy a => Texy [a] where + texy = autoSquareBrackets . mconcat . intersperse "," . fmap texy
Text/LaTeX/Packages/AMSThm.hs view
@@ -38,6 +38,7 @@ newtheorem :: LaTeXC l => String -> l -> l newtheorem str = liftL $ \l -> TeXComm "newtheorem" [ FixArg $ fromString str , FixArg l ] +-- | Use a environment created by 'newtheorem'. theorem :: LaTeXC l => String -> l -> l theorem str = liftL $ TeXEnv str [] @@ -51,6 +52,7 @@ qedhere :: LaTeXC l => l qedhere = comm0 "qedhere" +-- | Different styles for 'theorem's. data TheoremStyle = Plain | Definition @@ -66,4 +68,4 @@ -- | Set the theorem style. Call this function in the preamble. theoremstyle :: LaTeXC l => TheoremStyle -> l -theoremstyle thmsty = fromLaTeX $ TeXComm "theoremstyle" [ FixArg $ TeXRaw $ render thmsty ]+theoremstyle thmsty = fromLaTeX $ TeXComm "theoremstyle" [ FixArg $ TeXRaw $ render thmsty ]
+ Text/LaTeX/Packages/Babel.hs view
@@ -0,0 +1,112 @@++{-# LANGUAGE OverloadedStrings #-}++-- | The @babel@ package is used to write documents in languages+-- other than US English.+--+-- CTAN page for babel: <http://ctan.org/pkg/babel>.+module Text.LaTeX.Packages.Babel (+ -- * Babel package+ babel+ -- * Babel languages+ , Language (..)+ , uselanguage+ , LangConf (..)+ , uselanguageconf + -- * Babel commands and environments+ , selectlanguage+ , otherlanguage+ , foreignlanguage+ ) where++import Text.LaTeX.Base+import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+--+import Data.Text (toLower)++-- Babel package+ +-- | Babel package. When writing in a single language, the simplest+-- way of using it is with 'uselanguage'.+--+-- In the preamble, use the following (if your language of choice is Spanish):+--+-- > uselanguage Spanish+--+-- To see a list of available languages, check the 'Language' type.+--+babel :: PackageName+babel = "babel"++-- Babel languages++-- | Languages.+data Language =+ Bulgarian -- ^ Bulgarian.+ | Brazilian -- ^ Brazilian Portuguese.+ | Canadien -- ^ Canadian French.+ | Czech -- ^ Czech.+ | Dutch -- ^ Dutch.+ | English -- ^ English.+ | Finnish -- ^ Finnish.+ | Francais -- ^ Parisian French.+ | French -- ^ French.+ | FrenchB -- ^ French.+ | German -- ^ Old German.+ | NGerman -- ^ New German.+ | Icelandic -- ^ Icelandic.+ | Italian -- ^ Italian.+ | Magyar -- ^ Hungarian.+ | Portuguese -- ^ Portuguese.+ | Russian -- ^ Russian.+ | Spanish -- ^ Spanish.+ | Ukranian -- ^ Ukranian.+ deriving Show++instance Render Language where+ render = toLower . fromString . show++instance Texy Language where+ texy = texy . render++-- | Import the 'babel' package using a given 'Language'.+--+-- > uselanguage l = usepackage [texy l] babel+--+-- If you are using more than one language, consider to use+-- 'uselanguageconf'.+uselanguage :: LaTeXC l => Language -> l+uselanguage ln = usepackage [texy ln] babel++-- | Language configuration. You may use one with 'uselanguageconf'.+data LangConf = LangConf { mainLang :: Language , otherLangs :: [Language] }+ deriving Show++-- | Import the 'label' package using a given language+-- configuration, featuring a main language and some+-- others. For example:+--+-- > uselanguageconf $ LangConf English [German]+--+-- This will use English as main language, and German+-- as secondary.+uselanguageconf :: LaTeXC l => LangConf -> l+uselanguageconf lc = usepackage xs babel+ where+ x = "main=" <> texy (mainLang lc)+ xs = x : fmap texy (otherLangs lc)++-- | Switch to a given 'Language'.+selectlanguage :: LaTeXC l => Language -> l+selectlanguage ln = fromLaTeX $ TeXComm "selectlanguage" [FixArg $ texy ln]++-- | Use a 'Language' locally.+otherlanguage :: LaTeXC l => Language -> l -> l+otherlanguage ln = liftL $ TeXEnv "otherlanguage" [FixArg $ texy ln]++-- | The function 'foreignlanguage' takes two arguments; the second argument is a+-- phrase to be typeset according to the rules of the language named in its first+-- argument.+foreignlanguage :: LaTeXC l => Language -> l -> l+foreignlanguage ln = liftL $ \l -> TeXComm "foreignlanguage" [OptArg $ texy ln, FixArg l]
Text/LaTeX/Packages/Color.hs view
@@ -1,6 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} +-- | Make your documents colorful using this module. +-- +-- Different functionalities are provided, like changing the color of +-- the text and the paper, or creating colorful boxes. module Text.LaTeX.Packages.Color ( -- * Color package pcolor @@ -28,6 +32,7 @@ import Text.LaTeX.Base.Types -- import Data.Monoid +import Data.Text (toLower) -- | The 'pcolor' package. -- @@ -49,14 +54,14 @@ usenames :: LaTeXC l => l usenames = "usenames" --- - +-- | Color specification. data ColSpec = DefColor Color | ModColor ColorModel | DvipsColor ColorName deriving Show +-- | Basic colors. data Color = Red | Green @@ -68,6 +73,7 @@ | White deriving Show +-- | Specify your own color using one of the different color models. data ColorModel = RGB Float Float Float | RGB255 Int Int Int @@ -76,6 +82,7 @@ | CMYK Float Float Float Float deriving Show +-- | Other predefined colors. data ColorName = Apricot | Aquamarine | Bittersweet | BlueGreen | BlueViolet | BrickRed @@ -100,7 +107,7 @@ deriving Show instance Render Color where - render = fromString . show + render = toLower . fromString . show instance Render ColorModel where render (RGB r g b) = mconcat [ "[rgb]{" , renderCommas [r,g,b] , "}" ]
+ Text/LaTeX/Packages/Fontenc.hs view
@@ -0,0 +1,46 @@++{-# LANGUAGE OverloadedStrings #-}++-- | Select new font encodings using the @fontenc@ package.+module Text.LaTeX.Packages.Fontenc (+ -- * Fontenc package+ fontenc+ -- * Font encodings+ , FontEnc (..)+ , useencoding+ ) where++import Text.LaTeX.Base+import Text.LaTeX.Base.Class++-- Fontenc package++-- | The @fontenc@ package.+-- It is recommended to use the 'useencoding' function+-- to import it.+fontenc :: PackageName+fontenc = "fontenc"++-- Font encodings++-- | Font encodings.+data FontEnc = T1 | OT1 deriving Show++instance Render FontEnc where+ render T1 = "T1"+ render OT1 = "OT1"++instance Texy FontEnc where+ texy = texy . render++-- | In the preamble, select encodings to use in your document.+-- The last one will be the default encoding. Example:+--+-- > useencoding [T1]+--+-- It imports the @fontenc@ package. In fact:+--+-- > useencoding xs = usepackage (fmap texy xs) fontenc+--+useencoding :: LaTeXC l => [FontEnc] -> l+useencoding xs = usepackage (fmap texy xs) fontenc
Text/LaTeX/Packages/Inputenc.hs view
@@ -1,6 +1,13 @@ {-# LANGUAGE OverloadedStrings #-} +-- | This package is of vital importance if you use non-ASCII characters in your document. +-- For example, if the name of the author is /Ángela/, the /Á/ character will not appear correctly in the +-- output when I call 'maketitle'. To solve this problem, use: +-- +-- > usepackage [utf8] inputenc +-- +-- And make sure that your Haskell source is encoded in UTF-8. module Text.LaTeX.Packages.Inputenc ( -- * Inputenc package inputenc
+ Text/LaTeX/Packages/TikZ.hs view
@@ -0,0 +1,48 @@++-- | Ti/k/Z ist /kein/ Zeichenprogramm.+--+-- Ti/k/Z is a frontend for PGF (Portable Graphics Format), a package for creating graphics+-- using scripts embedded in a LaTeX document.+--+-- Using this library you will be able to generate Ti/k/Z scripts using Haskell functions.+--+-- The interface given here is pretty close to the original Ti/k/Z interface. Another+-- layer of abstraction is given in "Text.LaTeX.Packages.TikZ.Simple", module built+-- from the entities exported here. Usually, one chooses one of the interfaces and+-- work with it. However, if you want to use both of them, you will have to use+-- qualified imports or you will get name clashes.+--+-- Also, the module exported here, "Text.LaTeX.Packages.TikZ.PathBuilder", provides+-- an interface to create paths (see 'TPath') using monads.+--+-- Once you have generated a Ti/k/Z script, use 'tikzpicture' to include it in a LaTeX+-- document.+module Text.LaTeX.Packages.TikZ (+ -- * TikZ package+ tikz+ -- * TikZ modules+ , module Text.LaTeX.Packages.TikZ.Syntax+ , module Text.LaTeX.Packages.TikZ.PathBuilder+ -- * Insertion in LaTeX+ , tikzpicture+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Types+import Text.LaTeX.Base.Render+import Text.LaTeX.Packages.TikZ.Syntax+import Text.LaTeX.Packages.TikZ.PathBuilder++-- | Import the 'tikz' package to use the functions exported+-- by this module. For example, adding this line to your+-- document preamble:+--+-- > usepackage [] tikz+--+tikz :: PackageName+tikz = "tikz"++-- | Transform a Ti/k/Z script to a 'LaTeX' block.+tikzpicture :: LaTeXC l => TikZ -> l+tikzpicture = fromLaTeX . TeXEnv "tikzpicture" [] . rendertex
+ Text/LaTeX/Packages/TikZ/PathBuilder.hs view
@@ -0,0 +1,94 @@++-- | This module provides a monadic interface to build 'TPath' values.+-- It does so using 'PathBuilder's. The construction of a 'PathBuilder'+-- is equivalent to the construction of a 'TPath' by hand, but with+-- a sometimes more convenient syntax.+--+-- For example, this path corresponds to a triangle:+--+-- > trianglePath :: TPath+-- > trianglePath = bpath (pointAtXY (-1) 0) $ do+-- > line $ pointAtXY 1 0+-- > line $ pointAtXY 0 1+-- > pcycle+--+-- The equivalent syntax created by hand would be:+--+-- > trianglePath :: TPath+-- > trianglePath = Cycle $ Start (pointAtXY (-1) 0) ->- pointAtXY 1 0 ->- pointAtXY 0 1+--+-- The 'Cycle' constructor at the beginning may seem unintuitive, since we are building+-- the path from left to right. In the 'PathBuilder' monad, the instructions are always+-- written in order.+--+module Text.LaTeX.Packages.TikZ.PathBuilder (+ -- * Path builder+ PathBuilder+ , bpath+ -- * Builder functions+ , line+ , pcycle+ , rectangle+ , circle+ , ellipse+ , grid+ ) where++import Text.LaTeX.Packages.TikZ.Syntax+import Control.Monad.Trans.State+import Control.Applicative++data PathState = PS { currentPath :: TPath }++-- | Use a /path builder/ to construct a value of type 'TPath'.+-- Use 'bpath' for this purpose.+data PathBuilder a = PB { pathBuilder :: State PathState a }++-- Instances++instance Functor PathBuilder where+ fmap f (PB st) = PB $ fmap f st++instance Applicative PathBuilder where+ pure = PB . pure+ (PB f) <*> (PB x) = PB $ f <*> x++instance Monad PathBuilder where+ return = pure+ (PB x) >>= f = PB $ x >>= pathBuilder . f++--++applyToPath :: (TPath -> TPath) -> PathBuilder ()+applyToPath f = PB $ modify $ \ps -> ps { currentPath = f (currentPath ps) }++pcycle :: PathBuilder ()+pcycle = applyToPath Cycle++-- | Line from the current point to the given one.+line :: TPoint -> PathBuilder ()+line p = applyToPath $ (`Line`p)++-- | Rectangle with the current point as one cornder and the given point+-- as the opposite corner.+rectangle :: TPoint -> PathBuilder ()+rectangle p = applyToPath $ (`Rectangle`p)++-- | Circle with the given radius centered at the current point.+circle :: Double -> PathBuilder ()+circle r = applyToPath $ (`Circle`r)++-- | Ellipse with width and height described by the arguments and centered+-- at the current point.+ellipse :: Double -- ^ Half width of the ellipse.+ -> Double -- ^ Half height of the ellipse.+ -> PathBuilder ()+ellipse r1 r2 = applyToPath $ \x -> Ellipse x r1 r2++grid :: [GridOption] -> TPoint -> PathBuilder ()+grid xs p = applyToPath $ \x -> Grid x xs p++-- | Build a path using a /starting point/ and a 'PathBuilder'.+bpath :: TPoint -> PathBuilder a -> TPath+bpath p pb = currentPath $ execState (pathBuilder pb) (PS $ Start p)+
+ Text/LaTeX/Packages/TikZ/Simple.hs view
@@ -0,0 +1,85 @@++-- | A simple interface to create Ti/k/Z graphics. Just build pictures using+-- the 'Figure' data constructors, and get the Ti/k/Z script using the function+-- 'figuretikz'. Use the function 'tikzpicture' to insert the Ti/k/Z script in+-- the LaTeX document. And do not forget to import the 'tikz' package in the+-- preamble.+--+-- Please, note that this module is not intended to be imported in the same module+-- than Text.LaTeX.Packages.TikZ. This module is itself a self-contained /alternative/+-- of that module. If still want to use both modules, please, use qualified imports+-- to avoid name clashes.+--+-- In the /Examples/ directory of the source distribution, the file @tikzsimple.hs@+-- contains a complete example of usage of this module. Below you can see a picture+-- along with the code it came from.+--+-- <<http://daniel-diaz.github.com/projects/hatex/tikzsimple.png>>+--+-- > myFigure :: Figure+-- > myFigure = Scale 2 $ Figures+-- > [ RectangleFilled (0,0) 1 1+-- > , Colored Green $ RectangleFilled (-1,1) 1 1+-- > , Colored Red $ RectangleFilled ( 0,2) 1 1+-- > , Colored Blue $ RectangleFilled ( 1,1) 1 1+-- > ]+--+module Text.LaTeX.Packages.TikZ.Simple (+ -- TikZ package+ tikz+ -- * Figures+ , Figure (..)+ , Point+ , Color (..)+ -- * Figure scripting+ , figuretikz+ , tikzpicture+ ) where++import Text.LaTeX.Base.Types (Measure)+import Text.LaTeX.Packages.TikZ (TikZ,Color,tikzpicture,emptytikz,tikz)+import qualified Text.LaTeX.Packages.TikZ as T++-- | A point in the plane.+type Point = (Double,Double)++-- | A figure in the plane.+data Figure =+ Line [Point] -- ^ Line along a list of points.+ | Polygon [Point] -- ^ Line along a list of points, but the last point will be joined+ -- with the first one.+ | PolygonFilled [Point] -- ^ Same as 'Polygon', but the inner side will be filled with color.+ | Rectangle Point Double Double -- ^ Rectangle with top-right corner at the given point and+ -- width and height given by the other parameters.+ | RectangleFilled Point Double Double -- ^ Same as 'Rectangle', but filled with color.+ | Circle Point Double -- ^ Circle centered at the given point with the given radius.+ | CircleFilled Point Double -- ^ As in 'Circle', but it will be filled with some color.+ | Ellipse Point Double Double -- ^ Ellipse centered at the given point with width and+ -- height given by the other parameters.+ | EllipseFilled Point Double Double -- ^ Same as 'Ellipse', but filled with some color.+ | Colored Color Figure -- ^ Color for the given 'Figure'.+ | LineWidth Measure Figure -- ^ Line width for the given 'Figure'.+ | Scale Double Figure -- ^ Scaling of the given 'Figure' by a factor.+ | Figures [Figure] -- ^ A figure composed by a list of figures.++castpoint :: Point -> T.TPoint+castpoint (x,y) = T.pointAtXY x y++-- | Translate a 'Figure' to a 'TikZ' script.+figuretikz :: Figure -> TikZ+figuretikz (Line []) = emptytikz+figuretikz (Line (p:ps)) = T.draw $ foldl (\y x -> y T.->- castpoint x) (T.Start $ castpoint p) ps+figuretikz (Polygon []) = emptytikz+figuretikz (Polygon (p:ps)) = T.draw $ T.Cycle $ foldl (\y x -> y T.->- castpoint x) (T.Start $ castpoint p) ps+figuretikz (PolygonFilled []) = emptytikz+figuretikz (PolygonFilled (p:ps)) = T.fill $ T.Cycle $ foldl (\y x -> y T.->- castpoint x) (T.Start $ castpoint p) ps+figuretikz (Rectangle p w h) = T.draw $ T.Rectangle (T.Start $ castpoint p) $ T.relPoint $ castpoint (w,-h)+figuretikz (RectangleFilled p w h) = T.fill $ T.Rectangle (T.Start $ castpoint p) $ T.relPoint $ castpoint (w,-h)+figuretikz (Circle p r) = T.draw $ T.Circle (T.Start $ castpoint p) r+figuretikz (CircleFilled p r) = T.fill $ T.Circle (T.Start $ castpoint p) r+figuretikz (Ellipse p r1 r2) = T.draw $ T.Ellipse (T.Start $ castpoint p) (r1/2) (r2/2)+figuretikz (EllipseFilled p r1 r2) = T.fill $ T.Ellipse (T.Start $ castpoint p) r1 r2+figuretikz (Colored c f) = T.scope [T.TColor c] $ figuretikz f+figuretikz (LineWidth m f) = T.scope [T.TWidth m] $ figuretikz f+figuretikz (Scale q f) = T.scope [T.TScale q] $ figuretikz f+figuretikz (Figures fs) = foldr (\x y -> figuretikz x T.->> y) emptytikz fs
+ Text/LaTeX/Packages/TikZ/Syntax.hs view
@@ -0,0 +1,300 @@++{-# LANGUAGE OverloadedStrings #-}++-- | This module defines the syntax of a Ti/k/Z script.+--+-- To generate a Ti/k/Z script, first create a 'TPath' using+-- data constructors, or alternatively, use a 'PathBuilder'+-- from the "Text.LaTeX.Packages.TikZ.PathBuilder" module.+--+-- Once a 'TPath' is created, use 'path' to render a picture+-- from it. Use 'scope' to apply some parameters to your picture,+-- such line width or color.+module Text.LaTeX.Packages.TikZ.Syntax (+ -- * Points+ TPoint+ , pointAt , pointAtXY , pointAtXYZ+ , relPoint , relPoint_+ -- * Paths+ -- ** Types+ , TPath (..)+ , GridOption (..)+ , Step (..)+ -- ** Critical points+ , startingPoint+ , lastPoint+ -- ** Functions+ , (->-)+ -- * Parameters+ , Parameter (..)+ , Color (..)+ -- * TikZ+ , TikZ+ , emptytikz+ , path+ , scope+ , ActionType (..)+ , (->>)+ -- * Sugar+ , draw , fill , clip , shade+ , filldraw , shadedraw+ ) where+ +import Text.LaTeX.Base.Types+import Text.LaTeX.Base.Render+import Text.LaTeX.Packages.Color+-- TODO: Extend colors to anything accepted in TikZ.+import Data.Monoid+import Data.Foldable (foldMap)+import qualified Data.Sequence as S++-- POINTS++-- | A point in TikZ.+data TPoint =+ DimPoint Measure Measure+ | XYPoint Double Double+ | XYZPoint Double Double Double+ | RelPoint TPoint+ | RelPoint_ TPoint+ deriving Show++instance Render TPoint where+ render (DimPoint x y) = "(" <> renderCommas [x,y] <> ")"+ render (XYPoint x y) = "(" <> renderCommas [x,y] <> ")"+ render (XYZPoint x y z) = "(" <> renderCommas [x,y,z] <> ")"+ render (RelPoint p) = "++" <> render p+ render (RelPoint_ p) = "+" <> render p++pointAt :: Measure -> Measure -> TPoint+pointAt = DimPoint++pointAtXY :: Double -> Double -> TPoint+pointAtXY = XYPoint++pointAtXYZ :: Double -> Double -> Double -> TPoint+pointAtXYZ = XYZPoint++-- | Makes a point relative to the previous one.+relPoint :: TPoint -> TPoint+relPoint (RelPoint x) = RelPoint x+relPoint (RelPoint_ x) = RelPoint x+relPoint p = RelPoint p++relPoint_ :: TPoint -> TPoint+relPoint_ (RelPoint x) = RelPoint_ x+relPoint_ (RelPoint_ x) = RelPoint_ x+relPoint_ p = RelPoint_ p++-- PATHS++-- | Type for TikZ paths. Every 'TPath' has two fundamental points: the /starting point/+-- and the /last point/.+-- The starting point is set using the 'Start' constructor.+-- The last point then is modified by the other constructors.+-- Below a explanation of each one of them.+-- Note that both starting point and last point may coincide.+-- You can use the functions 'startingPoint' and 'lastPoint' to calculate them.+-- After creating a 'TPath', use 'path' to do something useful with it.+data TPath =+ Start TPoint -- ^ Let @y = Start p@.+ --+ -- /Operation:/ Set the starting point of a path.+ --+ -- /Last point:/ The last point of @y@ is @p@.+ | Cycle TPath -- ^ Let @y = Cycle x@.+ --+ -- /Operation:/ Close a path with a line from the last point of @x@ to+ -- the starting point of @x@.+ --+ -- /Last point:/ The last point of @y@ is the starting point of @x@.+ | Line TPath TPoint -- ^ Let @y = Line x p@.+ --+ -- /Operation:/ Extend the current path from the last point of @x@+ -- in a straight line to @p@.+ --+ -- /Last point:/ The last point of @y@ is @p@.+ | Rectangle TPath TPoint -- ^ Let @y = Rectangle x p@.+ --+ -- /Operation:/ Define a rectangle using the last point of+ -- @x@ as one corner and @p@ as the another corner.+ --+ -- /Last point:/ The last point of @y@ is @p@.+ | Circle TPath Double -- ^ Let @y = Circle x r@.+ --+ -- /Operation:/ Define a circle with center at the last point+ -- of x and radius @r@.+ --+ -- /Last point:/ The last point of @y@ is the same as the last+ -- point of @x@.+ | Ellipse TPath Double Double -- ^ Let @y = Ellipse x r1 r2@.+ --+ -- /Operation:/ Define a ellipse with center at the last+ -- point of @x@, width the double of @r1@ and height+ -- the double of @r2@.+ --+ -- /Last point:/ The last point of @y@ is the same as the+ -- last point of @x@.+ | Grid TPath [GridOption] TPoint+ deriving Show++data GridOption =+ GridStep Step+ deriving Show++data Step =+ DimStep Measure+ | XYStep Double+ | PointStep TPoint+ deriving Show++instance Render TPath where+ render (Start p) = render p+ render (Cycle p) = render p <> " -- cycle"+ render (Line p1 p2) = render p1 <> " -- " <> render p2+ render (Rectangle p1 p2) = render p1 <> " rectangle " <> render p2+ render (Circle p r) = render p <> " circle (" <> render r <> ")"+ render (Ellipse p r1 r2) = render p <> " ellipse (" <> render r1 <> " and " <> render r2 <> ")"+ render (Grid p1 [] p2) = render p1 <> " grid " <> render p2+ render (Grid p1 xs p2) = render p1 <> " grid " <> render xs <> " " <> render p2++instance Render GridOption where+ render (GridStep s) = "step=" <> render s++instance Render Step where+ render (DimStep m) = render m+ render (XYStep q) = render q+ render (PointStep p) = render p++-- Starting and Last points++-- | Calculate the starting point of a 'TPath'.+startingPoint :: TPath -> TPoint+startingPoint (Start p) = p+startingPoint (Cycle x) = startingPoint x+startingPoint (Line x _) = startingPoint x+startingPoint (Rectangle x _) = startingPoint x+startingPoint (Circle x _) = startingPoint x+startingPoint (Ellipse x _ _) = startingPoint x+startingPoint (Grid x _ _) = startingPoint x++-- | Calculate the last point of a 'TPath'.+lastPoint :: TPath -> TPoint+lastPoint (Start p) = p+lastPoint (Cycle x) = startingPoint x+lastPoint (Line _ p) = p+lastPoint (Rectangle _ p) = p+lastPoint (Circle x _) = lastPoint x+lastPoint (Ellipse x _ _) = lastPoint x+lastPoint (Grid _ _ p) = p++-- Path builders++-- | Alias of 'Line'.+(->-) :: TPath -> TPoint -> TPath+(->-) = Line++-- Parameters++-- | Parameters to use in a 'scope' to change how things+-- are rendered within that scope.+data Parameter =+ TWidth Measure+ | TColor Color+ | TScale Double+ deriving Show++renderPair :: Render a => Text -> a -> Text+renderPair x y = x <> "=" <> render y++instance Render Parameter where+ render (TWidth m) = renderPair "line width" m+ render (TColor c) = renderPair "color" c+ render (TScale q) = renderPair "scale" q++-- TikZ++-- | A Ti/k/Z script.+data TikZ =+ PathAction [ActionType] TPath+ | Scope [Parameter] TikZ+ | TikZSeq (S.Seq TikZ)+ deriving Show++-- | Different types of actions that can be performed+-- with a 'TPath'. See 'path' for more information.+data ActionType = Draw | Fill | Clip | Shade deriving Show++-- | Just an empty script.+emptytikz :: TikZ+emptytikz = TikZSeq mempty++instance Render TikZ where+ render (PathAction ts p) = "\\path" <> render ts <> " " <> render p <> " ; "+ render (Scope ps t) = "\\begin{scope}" <> render ps <> render t <> "\\end{scope}"+ render (TikZSeq ts) = foldMap render ts++instance Render ActionType where+ render Draw = "draw"+ render Fill = "fill"+ render Clip = "clip"+ render Shade = "shade"++-- | A path can be used in different ways.+--+-- * 'Draw': Just draw the path.+--+-- * 'Fill': Fill the area inside the path.+--+-- * 'Clip': Clean everything outside the path.+--+-- * 'Shade': Shade the area inside the path.+--+-- It is possible to stack different effects in the list.+--+-- Example of usage:+--+-- > path [Draw] $ Start (pointAtXY 0 0) ->- pointAtXY 1 1+--+-- Most common usages are exported as functions. See+-- 'draw', 'fill', 'clip', 'shade', 'filldraw' and+-- 'shadedraw'.+path :: [ActionType] -> TPath -> TikZ+path = PathAction++-- | Applies a scope to a TikZ script.+scope :: [Parameter] -> TikZ -> TikZ+scope = Scope++-- | Sequence two TikZ scripts.+(->>) :: TikZ -> TikZ -> TikZ+(TikZSeq s1) ->> (TikZSeq s2) = TikZSeq (s1 <> s2)+(TikZSeq s) ->> a = TikZSeq $ s S.|> a+a ->> (TikZSeq s) = TikZSeq $ a S.<| s+a ->> b = TikZSeq $ a S.<| S.singleton b++-- SUGAR++-- | Equivalent to @path [Draw]@.+draw :: TPath -> TikZ+draw = path [Draw]++-- | Equivalent to @path [Fill]@.+fill :: TPath -> TikZ+fill = path [Fill]++-- | Equivalent to @path [Clip]@.+clip :: TPath -> TikZ+clip = path [Clip]++-- | Equivalent to @path [Shade]@.+shade :: TPath -> TikZ+shade = path [Shade]++-- | Equivalent to @path [Fill,Draw]@.+filldraw :: TPath -> TikZ+filldraw = path [Fill,Draw]++-- | Equivalent to @path [Shade,Draw]@.+shadedraw :: TPath -> TikZ+shadedraw = path [Shade,Draw]
Text/LaTeX/Packages/Trees/Qtree.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} -- | Tree interface using the @qtree@ package. --- An example is of usage is provided in the /examples/ directory of +-- An example of usage is provided in the /examples/ directory of -- the source distribution. module Text.LaTeX.Packages.Trees.Qtree ( -- * Tree re-export @@ -40,6 +40,10 @@ tree :: LaTeXC l => (a -> l) -> Tree a -> l tree f t = commS "Tree" <> " " <> tree_ f t +-- | Instance defined in "Text.LaTeX.Packages.Trees.Qtree". +instance Texy a => Texy (Tree a) where + texy = tree texy + -- | This function works as 'tree', but use 'render' as rendering function. rendertree :: (Render a, LaTeXC l) => Tree a -> l -rendertree = tree (raw . protectText . render)+rendertree = tree (raw . protectText . render)