Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First upload.

  • Loading branch information...
commit 622caabefdf4ced7e45450d1c44d522b21fb46c3 1 parent 409a322
Daniel Diaz authored
Showing with 4,007 additions and 0 deletions.
  1. +34 −0 Examples/fibs.hs
  2. +61 −0 HaTeX.cabal
  3. +43 −0 ReleaseNotes
  4. +3 −0  Setup.hs
  5. +13 −0 Text/LaTeX.hs
  6. +43 −0 Text/LaTeX/Base.hs
  7. +737 −0 Text/LaTeX/Base/Commands.hs
  8. +1,023 −0 Text/LaTeX/Base/Commands/Monad.hs
  9. +67 −0 Text/LaTeX/Base/Monad.hs
  10. +6 −0 Text/LaTeX/Base/Parser.hs
  11. +105 −0 Text/LaTeX/Base/Render.hs
  12. +83 −0 Text/LaTeX/Base/Syntax.hs
  13. +75 −0 Text/LaTeX/Base/Types.hs
  14. +141 −0 Text/LaTeX/Base/Warnings.hs
  15. +102 −0 Text/LaTeX/Base/Writer.hs
  16. +13 −0 Text/LaTeX/Monad.hs
  17. +23 −0 Text/LaTeX/Packages.hs
  18. +29 −0 Text/LaTeX/Packages/AMSFonts.hs
  19. +46 −0 Text/LaTeX/Packages/AMSFonts/Monad.hs
  20. +176 −0 Text/LaTeX/Packages/AMSMath.hs
  21. +244 −0 Text/LaTeX/Packages/AMSMath/Monad.hs
  22. +69 −0 Text/LaTeX/Packages/AMSThm.hs
  23. +84 −0 Text/LaTeX/Packages/AMSThm/Monad.hs
  24. +132 −0 Text/LaTeX/Packages/Beamer.hs
  25. +115 −0 Text/LaTeX/Packages/Beamer/Monad.hs
  26. +151 −0 Text/LaTeX/Packages/Color.hs
  27. +107 −0 Text/LaTeX/Packages/Color/Monad.hs
  28. +75 −0 Text/LaTeX/Packages/Hyperref.hs
  29. +81 −0 Text/LaTeX/Packages/Hyperref/Monad.hs
  30. +28 −0 Text/LaTeX/Packages/Inputenc.hs
  31. +45 −0 Text/LaTeX/Packages/Inputenc/Monad.hs
  32. +23 −0 Text/LaTeX/Packages/Monad.hs
  33. +30 −0 license
View
34 Examples/fibs.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import Text.LaTeX.Base.Monad
+
+main :: IO ()
+main = execLaTeXT example >>= renderFile "Fibs.tex"
+
+example :: Monad m => LaTeXT_ m
+example = do
+ documentclass [] article
+ document exampleBody
+
+exampleBody :: Monad m => LaTeXT_ m
+exampleBody = do
+ "This is an example of how "
+ hatex3
+ " works, printing a table of "
+ "the thirteen first elements of the "
+ "Fibonacci sequence."
+ bigskip
+ center $ underline $ textbf "Fibonacci table"
+ center $ tabular Nothing [RightColumn,VerticalLine,LeftColumn] $ do
+ textbf "Fibonacci number" & textbf "Value"
+ lnbk
+ hline
+ foldr (\n l -> do fromString (show n) & fromString (show $ fib n)
+ lnbk
+ l ) (return ()) [0..12]
+
+fibs :: [Int]
+fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
+
+fib :: Int -> Int
+fib = (fibs!!)
View
61 HaTeX.cabal
@@ -0,0 +1,61 @@
+Name: HaTeX
+Version: 3.1.1
+Author: Daniel Díaz
+Category: Text
+Build-type: Simple
+License: BSD3
+License-file: license
+Maintainer: Daniel Díaz (danieldiaz <at> dhelta <dot> net)
+Stability: Experimental
+Homepage: http://dhelta.net/hprojects/HaTeX
+Bug-reports: danieldiaz <at> dhelta <dot> net
+Synopsis: LaTeX code writer.
+Description: HaTeX consists in a set of combinators which allow you to build LaTeX code,
+ following the LaTeX syntax in a type-safe manner.
+ .
+ This allows you to build programs which generates LaTeX code automatically
+ for any purpose you can figure out.
+Cabal-version: >= 1.6
+Tested-with: GHC == 6.12.3 , GHC == 7.0.3
+Extra-source-files:
+ ReleaseNotes
+ -- Examples
+ Examples/fibs.hs
+
+Library
+ Build-depends: base ==4.*
+ , bytestring
+ , transformers ==0.2.*
+ , text
+ GHC-Options: -fno-warn-unrecognised-pragmas
+ Exposed-modules:
+ Text.LaTeX
+ Text.LaTeX.Monad
+ Text.LaTeX.Base
+ Text.LaTeX.Base.Monad
+ Text.LaTeX.Base.Commands
+ Text.LaTeX.Base.Commands.Monad
+ Text.LaTeX.Base.Parser
+ Text.LaTeX.Base.Render
+ Text.LaTeX.Base.Syntax
+ Text.LaTeX.Base.Types
+ Text.LaTeX.Base.Writer
+ Text.LaTeX.Base.Warnings
+ Text.LaTeX.Packages
+ Text.LaTeX.Packages.Monad
+ Text.LaTeX.Packages.AMSFonts
+ Text.LaTeX.Packages.AMSFonts.Monad
+ Text.LaTeX.Packages.AMSMath
+ Text.LaTeX.Packages.AMSMath.Monad
+ Text.LaTeX.Packages.AMSThm
+ Text.LaTeX.Packages.AMSThm.Monad
+ Text.LaTeX.Packages.Beamer
+ Text.LaTeX.Packages.Beamer.Monad
+ Text.LaTeX.Packages.Hyperref
+ Text.LaTeX.Packages.Hyperref.Monad
+ Text.LaTeX.Packages.Inputenc
+ Text.LaTeX.Packages.Inputenc.Monad
+ Text.LaTeX.Packages.Color
+ Text.LaTeX.Packages.Color.Monad
+ Extensions: GeneralizedNewtypeDeriving
+ , OverloadedStrings
View
43 ReleaseNotes
@@ -0,0 +1,43 @@
+HaTeX Release Notes
+-- From version 3.0.0
+
+>>> 3.1.1
+
+- Dependency relaxed from 'mtl == 2.*' to 'transformers == 0.2.*'.
+
+>>> 3.1.0
+
+Highlights:
+
++ Added warnings (See Text.LaTeX.Base.Warnings).
++ Added an "Examples" directory.
++ Num instance for LaTeX and LaTeXT.
++ New package implemented "AMSThm" (See Text.LaTeX.Packages.AMSThm).
+
+Changes by modules:
+
+** Base modules
+* Text.LaTeX.Base.Syntax:
+-- Added Eq instance to LaTeX and TeXArg.
+* Text.LaTeX.Base.Writer:
+-- Added MonadTrans instance to LaTeXT.
+-- New functions: execLaTeXTWarn, liftFun, liftOp.
+* Text.LaTeX.Base.Types:
+-- Added Eq instance to Label.
+* Text.LaTeX.Base:
+-- Added Num instance to LaTeX.
+* Text.LaTeX.Base.Monad:
+-- Added Num instance to LaTeXT.
+* Text.LaTeX.Base.Commands:
+-- New function: between.
+
+** Package modules:
+* Text.LaTeX.Packages.AMSMath
+-- New symbols: (=:) , (/=:) , forall
+ , dagger, ddagger, in_ , ni
+ , (<:) , (<=:)
+ , (>:) , (>=:)
+
+>>> 3.0.0
+
+* First release of the third version of HaTeX.
View
3  Setup.hs
@@ -0,0 +1,3 @@
+import Distribution.Simple
+
+main = defaultMain
View
13 Text/LaTeX.hs
@@ -0,0 +1,13 @@
+
+-- | This module is a re-export of the main modules.
+-- Importing this will you give access to almost all
+-- functionality of the library. It is recommended
+-- to import the @Base@ module and, then, import only
+-- packages you actually need.
+module Text.LaTeX
+ ( module Text.LaTeX.Base
+ , module Text.LaTeX.Packages
+ ) where
+
+import Text.LaTeX.Base
+import Text.LaTeX.Packages
View
43 Text/LaTeX/Base.hs
@@ -0,0 +1,43 @@
+
+{- |
+This module exports those minimal things you need
+to work with HaTeX. Those things are:
+
+* The 'LaTeX' datatype.
+
+* The '<>' operator, to append 'LaTeX' values.
+
+* The "Text.LaTeX.Base.Render" module, to render a 'LaTeX' value into 'Text'.
+
+* The "Text.LaTeX.Base.Types" module, which contains several types used by
+ other modules.
+
+* The "Text.LaTeX.Base.Commands" module, which exports the LaTeX standard commands
+ and environments.
+
+Here is also defined a 'Num' instance for 'LaTeX'.
+-}
+module Text.LaTeX.Base
+ ( LaTeX , (<>)
+ , module Text.LaTeX.Base.Render
+ , module Text.LaTeX.Base.Types
+ , module Text.LaTeX.Base.Commands
+ ) where
+
+import Text.LaTeX.Base.Syntax (LaTeX (..),(<>))
+import Text.LaTeX.Base.Render
+import Text.LaTeX.Base.Types
+import Text.LaTeX.Base.Commands
+
+-- Num instance for LaTeX
+
+-- | Methods 'abs' and 'signum' are undefined. Don't use them!
+instance Num LaTeX where
+ (+) = TeXOp "+"
+ (-) = TeXOp "-"
+ (*) = (<>)
+ negate = (TeXEmpty -)
+ fromInteger = TeXRaw . fromString . show
+ -- Non-defined methods
+ abs _ = "Cannot use \"abs\" Num method with a LaTeX value."
+ signum _ = "Cannot use \"signum\" Num method with a LaTeX value."
View
737 Text/LaTeX/Base/Commands.hs
@@ -0,0 +1,737 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# OPTIONS_HATEX MakeMonadic #-}
+
+-- | LaTeX standard commands and environments.
+module Text.LaTeX.Base.Commands
+ ( -- * Basic functions
+ raw , between
+ -- * Preamble commands
+ , title
+ , author
+ , date
+ , institute
+ , thanks
+ , documentclass
+ , usepackage
+ , linespread
+ -- ** Classes
+ -- *** Document classes
+ , article
+ , proc
+ , report
+ , minimal
+ , book
+ , slides
+ -- *** Class options
+ , draft
+ , titlepage
+ , notitlepage
+ , onecolumn
+ , twocolumn
+ , oneside
+ , twoside
+ , landscape
+ , openright
+ , openany
+ , fleqn
+ , leqno
+ -- ** Paper sizes
+ , 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
+ , hatex_meta
+ , hatex_version
+ -- ** Document layout
+ , newline
+ , lnbk
+ , lnbk_
+ , newpage
+ , cleardoublepage
+ , clearpage
+ , linebreak
+ , nolinebreak
+ , pagebreak
+ , nopagebreak
+ , hspace
+ , hspace_
+ , vspace
+ , stretch
+ , smallskip
+ , bigskip
+ , indent
+ , noindent
+ -- ** Formatting text
+ , verbatim
+ -- *** Fonts
+ , textbf
+ , textit
+ , texttt
+ , textrm
+ , textsf
+ , textmd
+ , textup
+ , textsl
+ , textsc
+ , textnormal
+ , underline
+ , emph
+ -- *** Sizes
+ , tiny
+ , scriptsize
+ , footnotesize
+ , small
+ , normalsize
+ , large
+ , large2
+ , large3
+ , huge
+ , huge2
+ -- ** Environments
+ , equation
+ , equation_
+ , enumerate
+ , itemize
+ , item
+ , flushleft
+ , flushright
+ , center
+ , quote
+ , verse
+ , cite
+ , description
+ -- ** Page numbering
+ , pagenumbering
+ , arabic
+ , roman
+ , roman_
+ , alph
+ , alph_
+ -- ** Boxes
+ , mbox
+ , fbox
+ , parbox
+ , framebox
+ , makebox
+ , raisebox
+ , rule
+ -- * Cross references
+ , label
+ , ref
+ , pageref
+ -- ** Tables
+ , tabular
+ , (&)
+ , hline
+ , cline
+ -- ** Others
+ , footnote
+ , protect
+ , hyphenation
+ , hyp
+ , qts
+ ) where
+
+import Data.String
+import Data.Maybe (catMaybes)
+import Text.LaTeX.Base.Syntax
+import Text.LaTeX.Base.Render
+import Text.LaTeX.Base.Types
+
+-- | 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 :: Text -> LaTeX
+raw = TeXRaw
+
+-- | Calling 'between' @c l1 l2@ puts @c@ between @l1@ and @l2@ and
+-- appends them.
+between :: LaTeX -> LaTeX -> LaTeX -> LaTeX
+between c l1 l2 = l1 <> c <> l2
+
+-- | Generate the title. It normally contains the 'title' name
+-- of your document, the 'author'(s) and 'date'.
+maketitle :: LaTeX
+maketitle = TeXComm "maketitle" []
+
+-- | Set the title of your document.
+title :: LaTeX -> LaTeX
+title t = TeXComm "title" [FixArg t]
+
+-- | Set a date for your document.
+date :: LaTeX -> LaTeX
+date t = TeXComm "date" [FixArg t]
+
+-- | Set the author(s) of the document.
+author :: LaTeX -> LaTeX
+author t = TeXComm "author" [FixArg t]
+
+-- | Set either an institute or an organization
+-- for the document.
+institute :: Maybe LaTeX -> LaTeX -> LaTeX
+institute Nothing l = TeXComm "institute" [FixArg l]
+institute (Just s) l = TeXComm "institute" [OptArg s,FixArg l]
+
+thanks :: LaTeX -> LaTeX
+thanks x = TeXComm "thanks" [FixArg x]
+
+-- | Import a package. First argument is a list of options for
+-- the package named in the second argument.
+usepackage :: [LaTeX] -> String -> LaTeX
+usepackage lopt str = TeXComm "usepackage" [MOptArg lopt ,FixArg $ fromString str]
+
+-- | The @LaTeX@ logo.
+latex :: LaTeX
+latex = TeXComm "LaTeX" []
+
+-- | Start a new line.
+newline :: LaTeX
+newline = TeXComm "newline" []
+
+part :: LaTeX -> LaTeX
+part p = TeXComm "part" [FixArg p]
+
+chapter :: LaTeX -> LaTeX
+chapter c = TeXComm "chapter" [FixArg c]
+
+-- | Start a new section with a given title.
+section :: LaTeX -> LaTeX
+section s = TeXComm "section" [FixArg s]
+
+subsection :: LaTeX -> LaTeX
+subsection sub = TeXComm "subsection" [FixArg sub]
+
+subsubsection :: LaTeX -> LaTeX
+subsubsection sub = TeXComm "subsubsection" [FixArg sub]
+
+paragraph :: LaTeX -> LaTeX
+paragraph p = TeXComm "paragraph" [FixArg p]
+
+subparagraph :: LaTeX -> LaTeX
+subparagraph p = TeXComm "subparagraph" [FixArg p]
+
+-- | Create the table of contents, automatically generated
+-- from your 'section's, 'subsection's, and other related stuff.
+tableofcontents :: LaTeX
+tableofcontents = TeXComm "tableofcontents" []
+
+appendix :: LaTeX
+appendix = TeXComm "appendix" []
+
+item :: Maybe LaTeX -> LaTeX
+item Nothing = TeXCommS "item "
+item (Just opt) = TeXComm "item" [OptArg opt]
+
+equation :: LaTeX -> LaTeX
+equation = TeXEnv "equation" []
+
+equation_ :: LaTeX -> LaTeX
+equation_ = TeXEnv "equation*" []
+
+enumerate :: LaTeX -> LaTeX
+enumerate = TeXEnv "enumerate" []
+
+itemize :: LaTeX -> LaTeX
+itemize = TeXEnv "itemize" []
+
+description :: LaTeX -> LaTeX
+description = TeXEnv "description" []
+
+flushleft :: LaTeX -> LaTeX
+flushleft = TeXEnv "flushleft" []
+
+flushright :: LaTeX -> LaTeX
+flushright = TeXEnv "flushright" []
+
+center :: LaTeX -> LaTeX
+center = TeXEnv "center" []
+
+quote :: LaTeX -> LaTeX
+quote = TeXEnv "quote" []
+
+verse :: LaTeX -> LaTeX
+verse = TeXEnv "verse" []
+
+abstract :: LaTeX -> LaTeX
+abstract = TeXEnv "abstract" []
+
+cite :: LaTeX -> LaTeX
+cite l = TeXComm "cite" [FixArg l]
+
+documentclass :: [LaTeX] -> LaTeX -> LaTeX
+documentclass ls l = TeXComm "documentclass" [MOptArg ls , FixArg l]
+
+article :: LaTeX
+article = "article"
+
+proc:: LaTeX
+proc = "proc"
+
+minimal:: LaTeX
+minimal = "minimal"
+
+report:: LaTeX
+report = "report"
+
+book:: LaTeX
+book = "book"
+
+slides:: LaTeX
+slides = "slides"
+
+a0paper:: LaTeX
+a0paper = "a0paper"
+
+a1paper:: LaTeX
+a1paper = "a1paper"
+
+a2paper:: LaTeX
+a2paper = "a2paper"
+
+a3paper:: LaTeX
+a3paper = "a3paper"
+
+a4paper:: LaTeX
+a4paper = "a4paper"
+
+a5paper:: LaTeX
+a5paper = "a5paper"
+
+a6paper:: LaTeX
+a6paper = "a6paper"
+
+b0paper:: LaTeX
+b0paper = "b0paper"
+
+b1paper:: LaTeX
+b1paper = "b1paper"
+
+b2paper:: LaTeX
+b2paper = "b2paper"
+
+b3paper:: LaTeX
+b3paper = "b3paper"
+
+b4paper:: LaTeX
+b4paper = "b4paper"
+
+b5paper:: LaTeX
+b5paper = "b5paper"
+
+b6paper:: LaTeX
+b6paper = "b6paper"
+
+letterpaper:: LaTeX
+letterpaper = "letterpaper"
+
+executivepaper:: LaTeX
+executivepaper = "executivepaper"
+
+legalpaper:: LaTeX
+legalpaper = "legalpaper"
+
+draft :: LaTeX
+draft = "draft"
+
+-- | Typesets displayed formulae left-aligned instead of centred.
+fleqn:: LaTeX
+fleqn = "fleqn"
+
+-- | Places the numbering of formulae on the left hand side instead of the right.
+leqno:: LaTeX
+leqno = "leqno"
+
+titlepage:: LaTeX
+titlepage = "titlepage"
+
+notitlepage:: LaTeX
+notitlepage = "notitlepage"
+
+onecolumn:: LaTeX
+onecolumn = "onecolumn"
+
+twocolumn:: LaTeX
+twocolumn = "twocolumn"
+
+oneside :: LaTeX
+oneside = "oneside"
+
+twoside:: LaTeX
+twoside = "twoside"
+
+-- | Changes the layout of the document to print in landscape mode
+landscape:: LaTeX
+landscape = "landscape"
+
+-- | Makes chapters begin either only on right hand pages
+openright:: LaTeX
+openright = "openright"
+
+-- | Makes chapters begin on the next page available.
+openany:: LaTeX
+openany = "openany"
+
+document :: LaTeX -> LaTeX
+document = TeXEnv "document" []
+
+pagenumbering :: LaTeX -> LaTeX
+pagenumbering l = TeXComm "pagenumbering" [FixArg l]
+
+-- | Arabic numerals.
+arabic :: LaTeX
+arabic = "arabic"
+
+-- | Lowercase roman numerals.
+roman :: LaTeX
+roman = "roman"
+
+-- | Uppercase roman numerals.
+roman_ :: LaTeX
+roman_ = "Roman"
+
+-- | Lowercase letters.
+alph :: LaTeX
+alph = "alph"
+
+-- | Uppercase letters.
+alph_ :: LaTeX
+alph_ = "Alph"
+
+pagestyle :: LaTeX -> LaTeX
+pagestyle l = TeXComm "pagestyle" [FixArg l]
+
+thispagestyle :: LaTeX -> LaTeX
+thispagestyle l = TeXComm "thispagestyle" [FixArg l]
+
+plain :: LaTeX
+plain = "plain"
+
+headings :: LaTeX
+headings = "headings"
+
+empty :: LaTeX
+empty = "empty"
+
+myheadings :: LaTeX
+myheadings = "myheadings"
+
+-- | Used in conjunction with 'myheadings' for setting both the left and the right heading.
+markboth :: LaTeX -> LaTeX -> LaTeX
+markboth l1 l2 = TeXComm "markboth" [FixArg l1,FixArg l2]
+
+-- | Used in conjunction with 'myheadings' for setting the right heading.
+markright :: LaTeX -> LaTeX
+markright l = TeXComm "markright" [FixArg l]
+
+-- | Start a new line. In a 'tabular', it starts a new row, so use 'newline' instead.
+lnbk :: LaTeX
+lnbk = TeXNewLine False
+
+lnbk_ :: LaTeX
+lnbk_ = TeXNewLine True
+
+hyp :: LaTeX
+hyp = TeXCommS "-"
+
+cleardoublepage :: LaTeX
+cleardoublepage = TeXComm "cleardoublepage" []
+
+clearpage :: LaTeX
+clearpage = TeXComm "clearpage" []
+
+newpage :: LaTeX
+newpage = TeXComm "newpage" []
+
+linebreak :: LaTeX -> LaTeX
+linebreak l = TeXComm "linebreak" [OptArg l]
+
+nolinebreak :: LaTeX -> LaTeX
+nolinebreak l = TeXComm "nolinebreak" [OptArg l]
+
+nopagebreak :: LaTeX -> LaTeX
+nopagebreak l = TeXComm "nopagebreak" [OptArg l]
+
+pagebreak :: LaTeX -> LaTeX
+pagebreak l = TeXComm "pagebreak" [OptArg l]
+
+hyphenation :: LaTeX -> LaTeX
+hyphenation l = TeXComm "hyphenation" [FixArg l]
+
+mbox :: LaTeX -> LaTeX
+mbox l = TeXComm "mbox" [FixArg l]
+
+fbox :: LaTeX -> LaTeX
+fbox l = TeXComm "fbox" [FixArg l]
+
+today :: LaTeX
+today = TeXComm "today" []
+
+tex :: LaTeX
+tex = TeXComm "TeX" []
+
+laTeX2 :: LaTeX
+laTeX2 = TeXComm "LaTeX" []
+
+laTeXe :: LaTeX
+laTeXe = TeXComm "LaTeXe" []
+
+-- | Horizontal dots.
+ldots :: LaTeX
+ldots = TeXComm "ldots" []
+
+-- | Vertical dots.
+vdots :: LaTeX
+vdots = TeXComm "vdots" []
+
+-- | Diagonal dots.
+ddots :: LaTeX
+ddots = TeXComm "ddots" []
+
+-- | Quotation marks.
+qts :: LaTeX -> LaTeX
+qts l = raw "``" <> l <> raw "''"
+
+footnote :: LaTeX -> LaTeX
+footnote l = TeXComm "footnote" [FixArg l]
+
+linespread :: Float -> LaTeX
+linespread f = TeXComm "linespread" [FixArg $ TeXRaw $ render f]
+
+indent :: LaTeX
+indent = TeXComm "indent" []
+
+noindent :: LaTeX
+noindent = TeXComm "noindent" []
+
+hspace :: Measure -> LaTeX
+hspace m = TeXComm "hspace" [FixArg $ TeXRaw $ render m]
+
+hspace_ :: Measure -> LaTeX
+hspace_ m = TeXComm "hspace*" [FixArg $ TeXRaw $ render m]
+
+stretch :: Int -> LaTeX
+stretch n = TeXComm "stretch" [FixArg $ TeXRaw $ render n]
+
+vspace :: Measure -> LaTeX
+vspace m = TeXComm "vspace" [FixArg $ TeXRaw $ render m]
+
+protect :: LaTeX -> LaTeX
+protect l = TeXCommS "protect" <> l
+
+verbatim :: LaTeX -> LaTeX
+verbatim = TeXEnv "verbatim" []
+
+underline :: LaTeX -> LaTeX
+underline l = TeXComm "underline" [FixArg l]
+
+emph :: LaTeX -> LaTeX
+emph l = TeXComm "emph" [FixArg l]
+
+textrm :: LaTeX -> LaTeX
+textrm l = TeXComm "textrm" [FixArg l]
+
+textsf :: LaTeX -> LaTeX
+textsf l = TeXComm "textsf" [FixArg l]
+
+texttt :: LaTeX -> LaTeX
+texttt l = TeXComm "texttt" [FixArg l]
+
+textmd :: LaTeX -> LaTeX
+textmd l = TeXComm "textmd" [FixArg l]
+
+textbf :: LaTeX -> LaTeX
+textbf l = TeXComm "textbf" [FixArg l]
+
+textup :: LaTeX -> LaTeX
+textup l = TeXComm "textup" [FixArg l]
+
+textit :: LaTeX -> LaTeX
+textit l = TeXComm "textit" [FixArg l]
+
+textsl :: LaTeX -> LaTeX
+textsl l = TeXComm "textsl" [FixArg l]
+
+textsc :: LaTeX -> LaTeX
+textsc l = TeXComm "textsc" [FixArg l]
+
+textnormal :: LaTeX -> LaTeX
+textnormal l = TeXComm "textnormal" [FixArg l]
+
+tiny :: LaTeX -> LaTeX
+tiny l = TeXComm "tiny" [FixArg l]
+
+scriptsize :: LaTeX -> LaTeX
+scriptsize l = TeXComm "scriptsize" [FixArg l]
+
+footnotesize :: LaTeX -> LaTeX
+footnotesize l = TeXComm "footnotesize" [FixArg l]
+
+small :: LaTeX -> LaTeX
+small l = TeXComm "small" [FixArg l]
+
+normalsize :: LaTeX -> LaTeX
+normalsize l = TeXComm "normalsize" [FixArg l]
+
+large :: LaTeX -> LaTeX
+large l = TeXComm "large" [FixArg l]
+
+large2 :: LaTeX -> LaTeX
+large2 l = TeXComm "Large" [FixArg l]
+
+large3 :: LaTeX -> LaTeX
+large3 l = TeXComm "LARGE" [FixArg l]
+
+huge :: LaTeX -> LaTeX
+huge l = TeXComm "huge" [FixArg l]
+
+huge2 :: LaTeX -> LaTeX
+huge2 l = TeXComm "Huge" [FixArg l]
+
+smallskip :: LaTeX
+smallskip = TeXComm "smallskip" []
+
+bigskip :: LaTeX
+bigskip = TeXComm "bigskip" []
+
+-- | The 'tabular' environment can be used to typeset tables with optional horizontal and vertical lines.
+tabular :: 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.
+ -> LaTeX -- ^ Table content. See '&', 'lnbk', 'hline' and 'cline'.
+ -> LaTeX -- ^ Resulting table syntax.
+tabular Nothing ts = TeXEnv "tabular" [ FixArg $ TeXRaw $ renderAppend ts ]
+tabular (Just p) ts = TeXEnv "tabular" [ OptArg $ TeXRaw $ render p , FixArg $ TeXRaw $ renderAppend ts ]
+
+-- | Column separator.
+(&) :: LaTeX -> LaTeX -> LaTeX
+(&) = TeXOp "&"
+
+-- | Horizontal line.
+hline :: LaTeX
+hline = TeXCommS "hline "
+
+-- | @cline i j@ writes a partial horizontal line beginning in column i and ending in column j.
+cline :: Int -> Int -> LaTeX
+cline i j = TeXComm "cline" [ FixArg $ TeXRaw $ render i <> "-" <> render j ]
+
+parbox :: Maybe Pos -> Measure -> LaTeX -> LaTeX
+parbox Nothing w t = TeXComm "parbox" [ FixArg $ TeXRaw $ render w
+ , FixArg t]
+parbox (Just p) w t = TeXComm "parbox" [ OptArg $ TeXRaw $ render p
+ , FixArg $ TeXRaw $ render w
+ , FixArg t]
+
+makebox :: Maybe Measure -> Maybe Pos -> LaTeX -> LaTeX
+makebox Nothing Nothing t = TeXComm "makebox" [ FixArg t]
+makebox Nothing (Just p) t = TeXComm "makebox" [ OptArg $ TeXRaw $ render p, FixArg t]
+makebox (Just w) Nothing t = TeXComm "makebox" [ OptArg $ TeXRaw $ render w, FixArg t]
+makebox (Just w) (Just p) t = TeXComm "makebox" [ OptArg $ TeXRaw $ render w
+ , OptArg $ TeXRaw $ render p
+ , FixArg t]
+
+framebox :: Maybe Measure -> Maybe Pos -> LaTeX -> LaTeX
+framebox Nothing Nothing t = TeXComm "framebox" [ FixArg t]
+framebox Nothing (Just p) t = TeXComm "framebox" [ OptArg $ TeXRaw $ render p, FixArg t]
+framebox (Just w) Nothing t = TeXComm "framebox" [ OptArg $ TeXRaw $ render w, FixArg t]
+framebox (Just w) (Just p) t = TeXComm "framebox" [ OptArg $ TeXRaw $ render w
+ , OptArg $ TeXRaw $ render p
+ , FixArg t]
+
+raisebox :: Measure -> Maybe Measure -> Maybe Measure -> LaTeX -> LaTeX
+raisebox l ma mb t = TeXComm "raisebox" $
+ [ FixArg $ TeXRaw $ render l ]
+ ++ fmap (OptArg . TeXRaw . render) (catMaybes [ma,mb])
+ ++ [ FixArg t ]
+
+-- | Produce a simple black box.
+rule :: Maybe Measure -- ^ Optional lifting.
+ -> Measure -- ^ Width.
+ -> Measure -- ^ Height.
+ -> LaTeX
+rule Nothing w h = TeXComm "rule" [ FixArg $ TeXRaw $ render w
+ , FixArg $ TeXRaw $ render h ]
+rule (Just l) w h = TeXComm "rule" [ OptArg $ TeXRaw $ render l
+ , FixArg $ TeXRaw $ render w
+ , FixArg $ TeXRaw $ render h ]
+
+-- HaTeX specific symbols
+
+-- | Print the HaTeX logo.
+hatex :: LaTeX
+hatex = "H"
+ <> hspace (Ex $ negate 0.3)
+ <> textsc "a"
+ <> hspace (Ex $ negate 0.3)
+ <> tex
+
+-- | Print the HaTeX 3 logo.
+hatex3 :: LaTeX
+hatex3 = hatex <> emph (textbf "3")
+
+-- | Print the HaTeX-meta logo.
+hatex_meta :: LaTeX
+hatex_meta = hatex <> emph (textsc "-meta")
+
+-- | Print the HaTeX logo, beside the complete version number.
+hatex_version :: LaTeX
+hatex_version = hatex3
+ <> hspace (Ex $ negate 0.3)
+ <> emph ".1.0"
+
+label :: Label -> LaTeX
+label l = TeXComm "label" [FixArg $ TeXRaw $ render l]
+
+ref :: Label -> LaTeX
+ref l = TeXComm "ref" [FixArg $ TeXRaw $ render l]
+
+pageref :: Label -> LaTeX
+pageref l = TeXComm "pageref" [FixArg $ TeXRaw $ render l]
View
1,023 Text/LaTeX/Base/Commands/Monad.hs
@@ -0,0 +1,1023 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+-- | LaTeX standard commands and environments.
+--
+-- /For contributors: This module was automatically generated by HaTeX-meta./
+-- /So, please, don't make any change here directly, because/
+-- /this is intended to be generated from/
+-- "Text.LaTeX.Base.Commands" /module via HaTeX-meta,/
+-- /and therefore, changes must to be done in these places./
+
+module Text.LaTeX.Base.Commands.Monad
+ ( -- * Basic functions
+ raw , between
+ -- * Preamble commands
+ , title
+ , author
+ , date
+ , institute
+ , thanks
+ , documentclass
+ , usepackage
+ , linespread
+ -- ** Classes
+ -- *** Document classes
+ , article
+ , proc
+ , report
+ , minimal
+ , book
+ , slides
+ -- *** Class options
+ , draft
+ , titlepage
+ , notitlepage
+ , onecolumn
+ , twocolumn
+ , oneside
+ , twoside
+ , landscape
+ , openright
+ , openany
+ , fleqn
+ , leqno
+ -- ** Paper sizes
+ , 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
+ , hatex_meta
+ , hatex_version
+ -- ** Document layout
+ , newline
+ , lnbk
+ , lnbk_
+ , newpage
+ , cleardoublepage
+ , clearpage
+ , linebreak
+ , nolinebreak
+ , pagebreak
+ , nopagebreak
+ , hspace
+ , hspace_
+ , vspace
+ , stretch
+ , smallskip
+ , bigskip
+ , indent
+ , noindent
+ -- ** Formatting text
+ , verbatim
+ -- *** Fonts
+ , textbf
+ , textit
+ , texttt
+ , textrm
+ , textsf
+ , textmd
+ , textup
+ , textsl
+ , textsc
+ , textnormal
+ , underline
+ , emph
+ -- *** Sizes
+ , tiny
+ , scriptsize
+ , footnotesize
+ , small
+ , normalsize
+ , large
+ , large2
+ , large3
+ , huge
+ , huge2
+ -- ** Environments
+ , equation
+ , equation_
+ , enumerate
+ , itemize
+ , item
+ , flushleft
+ , flushright
+ , center
+ , quote
+ , verse
+ , cite
+ , description
+ -- ** Page numbering
+ , pagenumbering
+ , arabic
+ , roman
+ , roman_
+ , alph
+ , alph_
+ -- ** Boxes
+ , mbox
+ , fbox
+ , parbox
+ , framebox
+ , makebox
+ , raisebox
+ , rule
+ -- * Cross references
+ , label
+ , ref
+ , pageref
+ -- ** Tables
+ , tabular
+ , (&)
+ , hline
+ , cline
+ -- ** Others
+ , footnote
+ , protect
+ , hyphenation
+ , hyp
+ , qts
+ ) where
+
+import Text.LaTeX.Base.Writer
+import Text.LaTeX.Base.Render
+import Text.LaTeX.Base.Types
+import qualified Text.LaTeX.Base.Commands as App
+import Text.LaTeX.Base.Commands()
+
+{-|
+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 :: (Monad m) => Text -> LaTeXT_ m
+raw a1 = do textell ( App.raw a1)
+
+{-|
+Calling 'between' @c l1 l2@ puts @c@ between @l1@ and @l2@ and
+ appends them.
+-}
+between :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+between a1 a2 a3
+ = do a1 <- extractLaTeX_ a1
+ a2 <- extractLaTeX_ a2
+ a3 <- extractLaTeX_ a3
+ textell ( App.between a1 a2 a3)
+
+{-|
+Generate the title. It normally contains the 'title' name
+ of your document, the 'author'(s) and 'date'.
+-}
+maketitle :: (Monad m) => LaTeXT_ m
+maketitle = do textell ( App.maketitle)
+
+-- | Set the title of your document.
+
+title :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+title a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.title a1)
+
+-- | Set a date for your document.
+
+date :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+date a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.date a1)
+
+-- | Set the author(s) of the document.
+
+author :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+author a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.author a1)
+
+{-|
+Set either an institute or an organization
+ for the document.
+-}
+institute :: (Monad m) => Maybe (LaTeXT_ m) -> LaTeXT_ m -> LaTeXT_ m
+institute a1 a2
+ = do a1 <- maybe (return Nothing)
+ ((>>= return . Just) . extractLaTeX_)
+ a1
+ a2 <- extractLaTeX_ a2
+ textell ( App.institute a1 a2)
+
+
+thanks :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+thanks a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.thanks a1)
+
+{-|
+Import a package. First argument is a list of options for
+ the package named in the second argument.
+-}
+usepackage :: (Monad m) => [LaTeXT_ m] -> String -> LaTeXT_ m
+usepackage a1 a2
+ = do a1 <- mapM extractLaTeX_ a1
+ textell ( App.usepackage a1 a2)
+
+-- | The @LaTeX@ logo.
+
+latex :: (Monad m) => LaTeXT_ m
+latex = do textell ( App.latex)
+
+-- | Start a new line.
+
+newline :: (Monad m) => LaTeXT_ m
+newline = do textell ( App.newline)
+
+
+part :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+part a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.part a1)
+
+
+chapter :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+chapter a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.chapter a1)
+
+-- | Start a new section with a given title.
+
+section :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+section a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.section a1)
+
+
+subsection :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+subsection a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.subsection a1)
+
+
+subsubsection :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+subsubsection a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.subsubsection a1)
+
+
+paragraph :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+paragraph a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.paragraph a1)
+
+
+subparagraph :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+subparagraph a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.subparagraph a1)
+
+{-|
+Create the table of contents, automatically generated
+ from your 'section's, 'subsection's, and other related stuff.
+-}
+tableofcontents :: (Monad m) => LaTeXT_ m
+tableofcontents = do textell ( App.tableofcontents)
+
+
+appendix :: (Monad m) => LaTeXT_ m
+appendix = do textell ( App.appendix)
+
+
+item :: (Monad m) => Maybe (LaTeXT_ m) -> LaTeXT_ m
+item a1
+ = do a1 <- maybe (return Nothing)
+ ((>>= return . Just) . extractLaTeX_)
+ a1
+ textell ( App.item a1)
+
+
+equation :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+equation a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.equation a1)
+
+
+equation_ :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+equation_ a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.equation_ a1)
+
+
+enumerate :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+enumerate a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.enumerate a1)
+
+
+itemize :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+itemize a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.itemize a1)
+
+
+description :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+description a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.description a1)
+
+
+flushleft :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+flushleft a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.flushleft a1)
+
+
+flushright :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+flushright a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.flushright a1)
+
+
+center :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+center a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.center a1)
+
+
+quote :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+quote a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.quote a1)
+
+
+verse :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+verse a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.verse a1)
+
+
+abstract :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+abstract a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.abstract a1)
+
+
+cite :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+cite a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.cite a1)
+
+
+documentclass :: (Monad m) => [LaTeXT_ m] -> LaTeXT_ m -> LaTeXT_ m
+documentclass a1 a2
+ = do a1 <- mapM extractLaTeX_ a1
+ a2 <- extractLaTeX_ a2
+ textell ( App.documentclass a1 a2)
+
+
+article :: (Monad m) => LaTeXT_ m
+article = do textell ( App.article)
+
+
+proc :: (Monad m) => LaTeXT_ m
+proc = do textell ( App.proc)
+
+
+minimal :: (Monad m) => LaTeXT_ m
+minimal = do textell ( App.minimal)
+
+
+report :: (Monad m) => LaTeXT_ m
+report = do textell ( App.report)
+
+
+book :: (Monad m) => LaTeXT_ m
+book = do textell ( App.book)
+
+
+slides :: (Monad m) => LaTeXT_ m
+slides = do textell ( App.slides)
+
+
+a0paper :: (Monad m) => LaTeXT_ m
+a0paper = do textell ( App.a0paper)
+
+
+a1paper :: (Monad m) => LaTeXT_ m
+a1paper = do textell ( App.a1paper)
+
+
+a2paper :: (Monad m) => LaTeXT_ m
+a2paper = do textell ( App.a2paper)
+
+
+a3paper :: (Monad m) => LaTeXT_ m
+a3paper = do textell ( App.a3paper)
+
+
+a4paper :: (Monad m) => LaTeXT_ m
+a4paper = do textell ( App.a4paper)
+
+
+a5paper :: (Monad m) => LaTeXT_ m
+a5paper = do textell ( App.a5paper)
+
+
+a6paper :: (Monad m) => LaTeXT_ m
+a6paper = do textell ( App.a6paper)
+
+
+b0paper :: (Monad m) => LaTeXT_ m
+b0paper = do textell ( App.b0paper)
+
+
+b1paper :: (Monad m) => LaTeXT_ m
+b1paper = do textell ( App.b1paper)
+
+
+b2paper :: (Monad m) => LaTeXT_ m
+b2paper = do textell ( App.b2paper)
+
+
+b3paper :: (Monad m) => LaTeXT_ m
+b3paper = do textell ( App.b3paper)
+
+
+b4paper :: (Monad m) => LaTeXT_ m
+b4paper = do textell ( App.b4paper)
+
+
+b5paper :: (Monad m) => LaTeXT_ m
+b5paper = do textell ( App.b5paper)
+
+
+b6paper :: (Monad m) => LaTeXT_ m
+b6paper = do textell ( App.b6paper)
+
+
+letterpaper :: (Monad m) => LaTeXT_ m
+letterpaper = do textell ( App.letterpaper)
+
+
+executivepaper :: (Monad m) => LaTeXT_ m
+executivepaper = do textell ( App.executivepaper)
+
+
+legalpaper :: (Monad m) => LaTeXT_ m
+legalpaper = do textell ( App.legalpaper)
+
+
+draft :: (Monad m) => LaTeXT_ m
+draft = do textell ( App.draft)
+
+-- | Typesets displayed formulae left-aligned instead of centred.
+
+fleqn :: (Monad m) => LaTeXT_ m
+fleqn = do textell ( App.fleqn)
+
+-- | Places the numbering of formulae on the left hand side instead of the right.
+
+leqno :: (Monad m) => LaTeXT_ m
+leqno = do textell ( App.leqno)
+
+
+titlepage :: (Monad m) => LaTeXT_ m
+titlepage = do textell ( App.titlepage)
+
+
+notitlepage :: (Monad m) => LaTeXT_ m
+notitlepage = do textell ( App.notitlepage)
+
+
+onecolumn :: (Monad m) => LaTeXT_ m
+onecolumn = do textell ( App.onecolumn)
+
+
+twocolumn :: (Monad m) => LaTeXT_ m
+twocolumn = do textell ( App.twocolumn)
+
+
+oneside :: (Monad m) => LaTeXT_ m
+oneside = do textell ( App.oneside)
+
+
+twoside :: (Monad m) => LaTeXT_ m
+twoside = do textell ( App.twoside)
+
+-- | Changes the layout of the document to print in landscape mode
+
+landscape :: (Monad m) => LaTeXT_ m
+landscape = do textell ( App.landscape)
+
+-- | Makes chapters begin either only on right hand pages
+
+openright :: (Monad m) => LaTeXT_ m
+openright = do textell ( App.openright)
+
+-- | Makes chapters begin on the next page available.
+
+openany :: (Monad m) => LaTeXT_ m
+openany = do textell ( App.openany)
+
+
+document :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+document a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.document a1)
+
+
+pagenumbering :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+pagenumbering a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.pagenumbering a1)
+
+-- | Arabic numerals.
+
+arabic :: (Monad m) => LaTeXT_ m
+arabic = do textell ( App.arabic)
+
+-- | Lowercase roman numerals.
+
+roman :: (Monad m) => LaTeXT_ m
+roman = do textell ( App.roman)
+
+-- | Uppercase roman numerals.
+
+roman_ :: (Monad m) => LaTeXT_ m
+roman_ = do textell ( App.roman_)
+
+-- | Lowercase letters.
+
+alph :: (Monad m) => LaTeXT_ m
+alph = do textell ( App.alph)
+
+-- | Uppercase letters.
+
+alph_ :: (Monad m) => LaTeXT_ m
+alph_ = do textell ( App.alph_)
+
+
+pagestyle :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+pagestyle a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.pagestyle a1)
+
+
+thispagestyle :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+thispagestyle a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.thispagestyle a1)
+
+
+plain :: (Monad m) => LaTeXT_ m
+plain = do textell ( App.plain)
+
+
+headings :: (Monad m) => LaTeXT_ m
+headings = do textell ( App.headings)
+
+
+empty :: (Monad m) => LaTeXT_ m
+empty = do textell ( App.empty)
+
+
+myheadings :: (Monad m) => LaTeXT_ m
+myheadings = do textell ( App.myheadings)
+
+-- | Used in conjunction with 'myheadings' for setting both the left and the right heading.
+
+markboth :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+markboth a1 a2
+ = do a1 <- extractLaTeX_ a1
+ a2 <- extractLaTeX_ a2
+ textell ( App.markboth a1 a2)
+
+-- | Used in conjunction with 'myheadings' for setting the right heading.
+
+markright :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+markright a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.markright a1)
+
+-- | Start a new line. In a 'tabular', it starts a new row, so use 'newline' instead.
+
+lnbk :: (Monad m) => LaTeXT_ m
+lnbk = do textell ( App.lnbk)
+
+
+lnbk_ :: (Monad m) => LaTeXT_ m
+lnbk_ = do textell ( App.lnbk_)
+
+
+hyp :: (Monad m) => LaTeXT_ m
+hyp = do textell ( App.hyp)
+
+
+cleardoublepage :: (Monad m) => LaTeXT_ m
+cleardoublepage = do textell ( App.cleardoublepage)
+
+
+clearpage :: (Monad m) => LaTeXT_ m
+clearpage = do textell ( App.clearpage)
+
+
+newpage :: (Monad m) => LaTeXT_ m
+newpage = do textell ( App.newpage)
+
+
+linebreak :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+linebreak a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.linebreak a1)
+
+
+nolinebreak :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+nolinebreak a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.nolinebreak a1)
+
+
+nopagebreak :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+nopagebreak a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.nopagebreak a1)
+
+
+pagebreak :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+pagebreak a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.pagebreak a1)
+
+
+hyphenation :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+hyphenation a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.hyphenation a1)
+
+
+mbox :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+mbox a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.mbox a1)
+
+
+fbox :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+fbox a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.fbox a1)
+
+
+today :: (Monad m) => LaTeXT_ m
+today = do textell ( App.today)
+
+
+tex :: (Monad m) => LaTeXT_ m
+tex = do textell ( App.tex)
+
+
+laTeX2 :: (Monad m) => LaTeXT_ m
+laTeX2 = do textell ( App.laTeX2)
+
+
+laTeXe :: (Monad m) => LaTeXT_ m
+laTeXe = do textell ( App.laTeXe)
+
+-- | Horizontal dots.
+
+ldots :: (Monad m) => LaTeXT_ m
+ldots = do textell ( App.ldots)
+
+-- | Vertical dots.
+
+vdots :: (Monad m) => LaTeXT_ m
+vdots = do textell ( App.vdots)
+
+-- | Diagonal dots.
+
+ddots :: (Monad m) => LaTeXT_ m
+ddots = do textell ( App.ddots)
+
+-- | Quotation marks.
+
+qts :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+qts a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.qts a1)
+
+
+footnote :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+footnote a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.footnote a1)
+
+
+linespread :: (Monad m) => Float -> LaTeXT_ m
+linespread a1 = do textell ( App.linespread a1)
+
+
+indent :: (Monad m) => LaTeXT_ m
+indent = do textell ( App.indent)
+
+
+noindent :: (Monad m) => LaTeXT_ m
+noindent = do textell ( App.noindent)
+
+
+hspace :: (Monad m) => Measure -> LaTeXT_ m
+hspace a1 = do textell ( App.hspace a1)
+
+
+hspace_ :: (Monad m) => Measure -> LaTeXT_ m
+hspace_ a1 = do textell ( App.hspace_ a1)
+
+
+stretch :: (Monad m) => Int -> LaTeXT_ m
+stretch a1 = do textell ( App.stretch a1)
+
+
+vspace :: (Monad m) => Measure -> LaTeXT_ m
+vspace a1 = do textell ( App.vspace a1)
+
+
+protect :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+protect a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.protect a1)
+
+
+verbatim :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+verbatim a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.verbatim a1)
+
+
+underline :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+underline a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.underline a1)
+
+
+emph :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+emph a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.emph a1)
+
+
+textrm :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textrm a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textrm a1)
+
+
+textsf :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textsf a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textsf a1)
+
+
+texttt :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+texttt a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.texttt a1)
+
+
+textmd :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textmd a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textmd a1)
+
+
+textbf :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textbf a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textbf a1)
+
+
+textup :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textup a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textup a1)
+
+
+textit :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textit a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textit a1)
+
+
+textsl :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textsl a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textsl a1)
+
+
+textsc :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textsc a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textsc a1)
+
+
+textnormal :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+textnormal a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.textnormal a1)
+
+
+tiny :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+tiny a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.tiny a1)
+
+
+scriptsize :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+scriptsize a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.scriptsize a1)
+
+
+footnotesize :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+footnotesize a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.footnotesize a1)
+
+
+small :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+small a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.small a1)
+
+
+normalsize :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+normalsize a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.normalsize a1)
+
+
+large :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+large a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.large a1)
+
+
+large2 :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+large2 a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.large2 a1)
+
+
+large3 :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+large3 a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.large3 a1)
+
+
+huge :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+huge a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.huge a1)
+
+
+huge2 :: (Monad m) => LaTeXT_ m -> LaTeXT_ m
+huge2 a1
+ = do a1 <- extractLaTeX_ a1
+ textell ( App.huge2 a1)
+
+
+smallskip :: (Monad m) => LaTeXT_ m
+smallskip = do textell ( App.smallskip)
+
+
+bigskip :: (Monad m) => LaTeXT_ m
+bigskip = do textell ( App.bigskip)
+
+-- | The 'tabular' environment can be used to typeset tables with optional horizontal and vertical lines.
+
+tabular :: (Monad m) => Maybe Pos -> [TableSpec] -> LaTeXT_ m -> LaTeXT_ m
+tabular a1 a2 a3
+ = do a3 <- extractLaTeX_ a3
+ textell ( App.tabular a1 a2 a3)
+
+
+(&) :: (Monad m) => LaTeXT_ m -> LaTeXT_ m -> LaTeXT_ m
+(&) a1 a2
+ = do a1 <- extractLaTeX_ a1
+ a2 <- extractLaTeX_ a2
+ textell ( (App.&) a1 a2)
+
+-- | Horizontal line.
+
+hline :: (Monad m) => LaTeXT_ m
+hline = do textell ( App.hline)
+
+-- | @cline i j@ writes a partial horizontal line beginning in column i and ending in column j.
+
+cline :: (Monad m) => Int -> Int -> LaTeXT_ m
+cline a1 a2 = do textell ( App.cline a1 a2)
+
+
+parbox :: (Monad m) => Maybe Pos -> Measure -> LaTeXT_ m -> LaTeXT_ m
+parbox a1 a2 a3
+ = do a3 <- extractLaTeX_ a3
+ textell ( App.parbox a1 a2 a3)
+
+
+makebox :: (Monad m) => Maybe Measure -> Maybe Pos -> LaTeXT_ m -> LaTeXT_ m
+makebox a1 a2 a3
+ = do a3 <- extractLaTeX_ a3
+ textell ( App.makebox a1 a2 a3)
+
+
+framebox :: (Monad m) => Maybe Measure -> Maybe Pos -> LaTeXT_ m -> LaTeXT_ m
+framebox a1 a2 a3
+ = do a3 <- extractLaTeX_ a3
+ textell ( App.framebox a1 a2 a3)
+
+
+raisebox :: (Monad m) =>
+ Measure -> Maybe Measure -> Maybe Measure -> LaTeXT_ m -> LaTeXT_ m
+raisebox a1 a2 a3 a4
+ = do a4 <- extractLaTeX_ a4
+ textell ( App.raisebox a1 a2 a3 a4)
+
+-- | Produce a simple black box.
+
+rule :: (Monad m) => Maybe Measure -> Measure -> Measure -> LaTeXT_ m
+rule a1 a2 a3 = do textell ( App.rule a1 a2 a3)
+
+-- | Print the HaTeX logo.
+
+hatex :: (Monad m) => LaTeXT_ m
+hatex = do textell ( App.hatex)
+
+-- | Print the HaTeX 3 logo.
+
+hatex3 :: (Monad m) => LaTeXT_ m
+hatex3 = do textell ( App.hatex3)
+
+-- | Print the HaTeX-meta logo.
+
+hatex_meta :: (Monad m) => LaTeXT_ m
+hatex_meta = do textell ( App.hatex_meta)
+
+-- | Print the HaTeX logo, beside the complete version number.
+
+hatex_version :: (Monad m) => LaTeXT_ m
+hatex_version = do textell ( App.hatex_version)
+
+
+label :: (Monad m) => Label -> LaTeXT_ m
+label a1 = do textell ( App.label a1)
+
+
+ref :: (Monad m) => Label -> LaTeXT_ m
+ref a1 = do textell ( App.ref a1)
+
+
+pageref :: (Monad m) => Label -> LaTeXT_ m
+pageref a1 = do textell ( App.pageref a1)
+
+
View
67 Text/LaTeX/Base/Monad.hs
@@ -0,0 +1,67 @@
+
+{- |
+This module exports those minimal things you need
+to work with HaTeX. Those things are:
+
+* The 'LaTeX' datatype.
+
+* The '<>' operator, to append 'LaTeX' values.
+
+* The "Text.LaTeX.Base.Render" module, to render a 'LaTeX' value into 'Text'.
+
+* The "Text.LaTeX.Base.Types" module, which contains several types used by
+ other modules.
+
+* The "Text.LaTeX.Base.Writer" module, needed to run the 'LaTeXT' monad, and
+ obtain a result of type 'LaTeX'.
+
+* The "Text.LaTeX.Base.Commands.Monad" module, which exports the LaTeX standard commands
+ and environments.
+
+Here is also defined a 'Num' instance for 'LaTeXT'.
+-}
+module Text.LaTeX.Base.Monad
+ ( LaTeX , (<>)
+ , module Text.LaTeX.Base.Render
+ , module Text.LaTeX.Base.Types
+ , module Text.LaTeX.Base.Writer
+ , module Text.LaTeX.Base.Commands.Monad
+ ) where
+
+import Text.LaTeX.Base.Syntax (LaTeX,(<>))
+import Text.LaTeX.Base.Render
+import Text.LaTeX.Base.Types
+import Text.LaTeX.Base.Writer
+import Text.LaTeX.Base.Commands.Monad
+-- Import LaTeX Num instance
+import Text.LaTeX.Base ()
+-- Import 'lift' function
+import Control.Monad.Trans.Class (lift)
+
+-- Num instance for LaTeXT
+
+-- Sadly, we need 'Show' and 'Eq' instances for LaTeXT in order
+-- to do its 'Num' instance.
+
+-- | Don't use it! This instance only exists in order to
+-- define a 'Num' instance to 'LaTeXT'.
+instance Show (LaTeXT m a) where
+ show _ = error "Cannot use \"show\" Show method with a LaTeXT value."
+
+-- | Don't use it! This instance only exists in order to
+-- define a 'Num' instance to 'LaTeXT'.
+instance Eq (LaTeXT m a) where
+ _ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value."
+
+-- | Be careful when using 'fromInteger' over a 'LaTeXT' value,
+-- the returned value of the computation is bottom (i.e. 'undefined').
+-- Methods 'abs' and 'signum' are undefined. Don't use them!
+instance Monad m => Num (LaTeXT m a) where
+ (+) = liftOp (+)
+ (-) = liftOp (-)
+ (*) = (>>)
+ negate = liftFun negate
+ fromInteger = fromString . show
+ -- Non-defined methods
+ abs _ = "Cannot use \"abs\" Num method with a LaTeXT value."
+ signum _ = "Cannot use \"signum\" Num method with a LaTeXT value."
View
6 Text/LaTeX/Base/Parser.hs
@@ -0,0 +1,6 @@
+
+-- | Parser is not yet implemented.
+module Text.LaTeX.Base.Parser
+ (
+ ) where
+
View
105 Text/LaTeX/Base/Render.hs
@@ -0,0 +1,105 @@
+
+{-# LANGUAGE OverloadedStrings #-}
+
+module Text.LaTeX.Base.Render
+ ( -- * Re-exports
+ Text
+ , module Data.String
+ -- * Render class
+ , Render (..)
+ , renderAppend
+ , renderCommas
+ , renderFile
+ , rendertex
+ -- * Reading files
+ , readFileTex
+ ) where
+
+import Data.Text (Text)
+import Text.LaTeX.Base.Syntax
+import Data.String
+import Data.Monoid (Monoid (..))
+import qualified Data.Text.IO as T
+import Data.Text.Encoding
+import Data.List (intersperse)
+import qualified Data.ByteString as B
+
+-- | Class of values that can be transformed to 'Text'.
+-- You mainly will use this to obtain the 'Text' output
+-- of a 'LaTeX' value.
+class Show a => Render a where
+ render :: a -> Text
+ --
+ render = fromString . show
+
+-- | Render every element of a list and append results.
+renderAppend :: Render a => [a] -> Text
+renderAppend = mconcat . fmap render
+
+-- | Render every element of a list and append results,
+-- separated by commas.
+renderCommas :: Render a => [a] -> Text
+renderCommas = mconcat . intersperse "," . fmap render
+
+-- | Use this function to render a 'LaTeX' (or another
+-- one in the 'Render' class) value directly
+-- in a file.
+renderFile :: Render a => FilePath -> a -> IO ()
+renderFile f = B.writeFile f . encodeUtf8 . render
+
+-- | If you are going to insert the content of a file
+-- in your 'LaTeX' data, use this function to ensure
+-- your encoding is correct.
+readFileTex :: FilePath -> IO Text
+readFileTex = fmap decodeUtf8 . B.readFile
+
+-- | If you can transform a value to 'Text', you can
+-- insert that 'Text' in your 'LaTeX' code.
+-- That is what this function does.
+--
+-- /Warning: /'rendertex'/ does not escape LaTeX reserver characters./
+rendertex :: Render a => a -> LaTeX
+rendertex = TeXRaw . render
+
+-- LaTeX instances
+
+instance Render LaTeX where
+ render (TeXRaw t) = t
+ render (TeXComm name []) = "\\" <> fromString name <> "{}"
+ render (TeXComm name args) =
+ "\\"
+ <> fromString name
+ <> renderAppend args
+ render (TeXCommS name) = "\\" <> fromString name
+ render (TeXEnv name args c) =
+ "\\begin{"
+ <> fromString name
+ <> "}"
+ <> renderAppend args
+ <> render c
+ <> "\\end{"
+ <> fromString name
+ <> "}"
+ render (TeXMath l) = "$" <> render l <> "$"
+ render (TeXNewLine b) = " \\\\" <> ( if b then "*" else mempty ) <> " "
+ render (TeXOp sym l1 l2) = render l1 <> fromString sym <> render l2
+ render (TeXBraces l) = "{" <> render l <> "}"
+ 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 <> "}"
+ render (MOptArg []) = mempty
+ render (MOptArg ls) =
+ fromString "["
+ <> renderCommas ls
+ <> fromString "]"
+ render (SymArg l) = "<" <> render l <> ">"
+ render (MSymArg ls) = "<" <> renderCommas ls <> ">"
+
+-- Other instances
+
+instance Render Int where
+instance Render Float where
+
View
83 Text/LaTeX/Base/Syntax.hs
@@ -0,0 +1,83 @@
+
+-- | LaTeX syntax description in the definition of the 'LaTeX' datatype.
+-- If you want to add new commands or environments not defined in
+-- the library, import this module and use 'LaTeX' data constructors.
+module Text.LaTeX.Base.Syntax
+ ( -- * @LaTeX@ datatype
+ LaTeX (..)
+ , braces
+ , TeXArg (..)
+ , (<>)
+ ) where
+
+import Data.Text (Text)
+import Data.Monoid
+import Data.String
+
+-- | A 'LaTeX' object represents some expression written in LaTeX.
+data LaTeX =
+ TeXRaw Text -- ^ Raw text.
+ | TeXComm String [TeXArg] -- ^ Constructor for commands.
+ -- First argument is the name of the command.
+ -- Second, its arguments.
+ | TeXCommS String
+ | TeXEnv String [TeXArg] LaTeX -- ^ Constructor for environments.
+ -- First argument is the name of the environment.
+ -- Second, its arguments.
+ -- Third, its content.
+ | TeXMath LaTeX -- ^ Mathematical expressions.
+ | TeXNewLine Bool -- ^ Newline character.
+ | TeXOp String LaTeX LaTeX -- ^ Operators.
+ | TeXBraces LaTeX -- A expression between braces.
+ | TeXSeq LaTeX LaTeX -- ^ Sequencing of 'LaTeX' expressions.
+ -- Use '<>' preferably.
+ | TeXEmpty -- ^ An empty expression.
+ -- Neutral element of '<>'.
+ deriving (Eq,Show)
+
+-- | Alias for 'TeXBraces'.
+braces :: LaTeX -> LaTeX
+braces = TeXBraces
+
+-- | An argument for a 'LaTeX' command or environment.
+data TeXArg =
+ OptArg LaTeX -- ^ Optional argument.
+ | FixArg LaTeX -- ^ Fixed argument.
+ | MOptArg [LaTeX] -- ^ Multiple optional argument.
+ | SymArg LaTeX -- ^ An argument enclosed between @\<@ and @\>@.
+ | MSymArg [LaTeX] -- ^ Version of 'SymArg' with multiple options.
+ deriving (Eq,Show)
+
+-- Monoid instance for 'LaTeX'.
+
+-- | 'mappend' is strict in its first argument.
+instance Monoid LaTeX where
+ mempty = TeXEmpty
+ mappend TeXEmpty x = x
+ mappend x TeXEmpty = x
+ mappend x y = TeXSeq x y
+
+-- | Alias for 'mappend'.
+(<>) :: Monoid a => a -> a -> a
+(<>) = mappend
+
+-- | 'fromString' escapes LaTeX reserved characters.
+instance IsString LaTeX where
+ fromString = TeXRaw . fromString . protectString
+
+-- | Escape LaTeX reserved characters in a 'String'.
+protectString :: String -> String
+protectString = mconcat . fmap protectChar
+
+protectChar :: Char -> String
+protectChar '#' = "\\#"
+protectChar '$' = "\\$"
+protectChar '%' = "\\%"
+protectChar '^' = "\\^{}"
+protectChar '&' = "\\&"
+protectChar '{' = "\\{"
+protectChar '}' = "\\}"
+protectChar '~' = "\\~{}"
+protectChar '\\' = "\\textbackslash{}"
+protectChar '_' = "\\_{}"
+protectChar x = [x]
View
75 Text/LaTeX/Base/Types.hs
@@ -0,0 +1,75 @@
+
+{-# LANGUAGE OverloadedStrings #-}
+
+module Text.LaTeX.Base.Types (
+ Label
+ , createLabel , labelName
+ , Pos (..)
+ , TableSpec (..)
+ , Measure (..)
+ ) where
+
+import Text.LaTeX.Base.Syntax
+import Text.LaTeX.Base.Render
+
+newtype Label = Label String deriving (Eq, Show)
+
+createLabel :: String -> Label
+createLabel = Label
+
+labelName :: Label -> String
+labelName (Label str) = str
+
+instance Render Label where
+ render (Label str) = fromString str
+
+instance IsString Label where
+ fromString = createLabel
+
+data Pos = Bottom | Center | Top deriving Show
+
+instance Render Pos where
+ render Bottom = "b"
+ render Center = "c"
+ render Top = "t"
+
+data TableSpec =
+ LeftColumn -- ^ Left-justified column.
+ | CenterColumn -- ^ Centered column.
+ | RightColumn -- ^ Right-justified column.
+ | ParColumnTop LaTeX -- ^ Paragraph column with text vertically aligned at the top.
+ | ParColumnMid LaTeX -- ^ Paragraph column with text vertically aligned at the middle. Requires 'array' package.
+ | ParColumnBot LaTeX -- ^ Paragraph column with text vertically aligned at the bottom. Requires 'array' package.
+ | VerticalLine -- ^ Vertical line between two columns.
+ | DVerticalLine -- ^ Double vertical line between two columns.
+ deriving Show
+
+instance Render TableSpec where
+ render LeftColumn = "l"
+ render CenterColumn = "c"
+ render RightColumn = "r"
+ render (ParColumnTop l) = "p" <> render (FixArg l)
+ render (ParColumnMid l) = "m" <> render (FixArg l)
+ render (ParColumnBot l) = "b" <> render (FixArg l)
+ render VerticalLine = "|"
+ render DVerticalLine = "||"
+
+data Measure =
+ Pt Int -- ^ A point is 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm.
+ | Mm Float -- ^ Millimeter.
+ | Cm Float -- ^ Centimeter.
+ | In Float -- ^ Inch.
+ | Ex Float -- ^ The height of an \"x\" in the current font.
+ | Em Float -- ^ The width of an \"M\" in the current font.
+ | CustomMeasure LaTeX -- ^ You can introduce a 'LaTeX' expression as a measure.
+ deriving Show
+
+instance Render Measure where
+ render (Pt x) = render x <> "pt"
+ render (Mm x) = render x <> "mm"
+ render (Cm x) = render x <> "cm"
+ render (In x) = render x <> "in"
+ render (Ex x) = render x <> "ex"
+ render (Em x) = render x <> "em"
+ render (CustomMeasure x) = render x
+
View
141 Text/LaTeX/Base/Warnings.hs
@@ -0,0 +1,141 @@
+
+{-# LANGUAGE OverloadedStrings #-}
+
+module Text.LaTeX.Base.Warnings (
+ -- * Warnings datatype
+ Warning (..)
+ , TeXCheck
+ , check
+ , checkFromFunction
+ -- * Several checkings
+ , checkLabels
+ , checkClass
+ , checkDoc
+ -- * Complete checking
+ , checkAll
+ ) where
+
+import Text.LaTeX.Base.Syntax
+import Control.Monad.Trans.State
+import Data.Text
+import Data.Maybe
+import Control.Arrow
+import Data.Monoid
+
+-- | List of possible warnings.
+data Warning =
+ UnusedLabel Text -- ^ There is an unused label. Argument is its name.
+ | UndefinedLabel Text -- ^ There is a reference to an undefined label. Arguments is the name.
+ --
+ | NoClassSelected -- ^ No class selected with 'documentclass'.
+ | NoDocumentInserted -- ^ No 'document' inserted.
+ --
+ | CustomWarning Text -- ^ Custom warning for custom checkings. Use it as you want.
+ deriving (Eq,Show)
+
+-- | A 'TeXCheck' is a function that checks possible warnings from a 'LaTeX' value.
+-- Use the 'Monoid' instance to combine check functions.
+newtype TeXCheck = TC { check :: LaTeX -> [Warning] -- ^ Apply a checking.
+ }
+-- | Build a 'TeXCheck' from a function.
+checkFromFunction :: (LaTeX -> [Warning]) -> TeXCheck
+checkFromFunction = TC
+
+instance Monoid TeXCheck where
+ mempty = TC $ const []
+ mappend (TC tc1) (TC tc2) = TC $ uncurry mappend . (tc1 &&& tc2)
+
+checkAll :: TeXCheck
+checkAll = mconcat [ checkLabels , checkClass , checkDoc ]
+
+-- Searching for 'documentclass' and 'document'
+
+type BoolSt = State Bool
+
+-- | Check if a document class is specified for the document (using 'documentclass').
+checkClass :: TeXCheck
+checkClass = TC $ \l -> if execState (classcheck l) False then [] else [NoClassSelected]
+
+classcheck :: LaTeX -> BoolSt ()
+classcheck (TeXComm c _) =
+ case c of
+ "documentclass" -> put True
+ _ -> return ()
+classcheck (TeXBraces l) = classcheck l
+classcheck (TeXSeq l1 l2) = classcheck l1 >> classcheck l2
+classcheck _ = return ()
+
+-- | Check if the 'document' environment is called in a 'LaTeX'.
+checkDoc :: TeXCheck
+checkDoc = TC $ \l -> if execState (doccheck l) False then [] else [NoDocumentInserted]
+
+doccheck :: LaTeX -> BoolSt ()
+doccheck (TeXEnv n _ _) =
+ case n of
+ "document" -> put True
+ _ -> return ()
+doccheck (TeXBraces l) = doccheck l
+doccheck (TeXSeq l1 l2) = doccheck l1 >> doccheck l2
+doccheck _ = return ()
+
+-- Checking labels
+
+data LabWarn =
+ RefNoLabel Text
+ | LabelNoRef Text
+ | LabelRef Text
+
+labWarnToWarning :: LabWarn -> Maybe Warning
+labWarnToWarning (RefNoLabel n) = Just $ UndefinedLabel n
+labWarnToWarning (LabelNoRef n) = Just $ UnusedLabel n
+labWarnToWarning _ = Nothing
+
+type LabSt = State [LabWarn]
+
+-- | Checking for unused labels or references tu undefined labels.
+checkLabels :: TeXCheck
+checkLabels = TC $ \l -> catMaybes . fmap labWarnToWarning $ execState (labcheck l) []
+
+labcheck :: LaTeX -> LabSt ()
+labcheck (TeXComm c [FixArg (TeXRaw n)]) =
+ case c of
+ "label" -> newlab n
+ "ref" -> newref n
+ "pageref" -> newref n