HaTeX 3.13.1.0 → 3.14.0.0
raw patch · 36 files changed
+3257/−3208 lines, 36 filesdep ~textsetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: text
API changes (from Hackage documentation)
+ Text.LaTeX.Base.Syntax: MParArg :: [LaTeX] -> TeXArg
+ Text.LaTeX.Base.Syntax: ParArg :: LaTeX -> TeXArg
- Text.LaTeX.Base.Parser: Expect :: !String -> Message
+ Text.LaTeX.Base.Parser: Expect :: SrictNotUnpackedString -> Message
- Text.LaTeX.Base.Parser: Message :: !String -> Message
+ Text.LaTeX.Base.Parser: Message :: SrictNotUnpackedString -> Message
- Text.LaTeX.Base.Parser: SysUnExpect :: !String -> Message
+ Text.LaTeX.Base.Parser: SysUnExpect :: SrictNotUnpackedString -> Message
- Text.LaTeX.Base.Parser: UnExpect :: !String -> Message
+ Text.LaTeX.Base.Parser: UnExpect :: SrictNotUnpackedString -> Message
Files
- CHANGELOG.md +18/−1
- Examples/beamer.hs +38/−38
- Examples/comments.hs +18/−18
- Examples/fibs.hs +34/−34
- Examples/matrices.hs +22/−22
- Examples/simple.hs +45/−45
- Examples/tree.hs +40/−40
- HaTeX.cabal +12/−2
- README.md +66/−68
- ReleaseNotes +91/−91
- Setup.hs +2/−2
- Text/LaTeX.hs +102/−102
- Text/LaTeX/Base.hs +59/−59
- Text/LaTeX/Base/Class.hs +92/−92
- Text/LaTeX/Base/Parser.hs +1/−4
- Text/LaTeX/Base/Pretty.hs +2/−0
- Text/LaTeX/Base/Render.hs +172/−170
- Text/LaTeX/Base/Syntax.hs +328/−317
- Text/LaTeX/Base/Types.hs +81/−81
- Text/LaTeX/Base/Warnings.hs +146/−146
- Text/LaTeX/Base/Writer.hs +208/−208
- Text/LaTeX/Packages/AMSFonts.hs +34/−34
- Text/LaTeX/Packages/AMSMath.hs +904/−904
- Text/LaTeX/Packages/AMSThm.hs +71/−71
- Text/LaTeX/Packages/Beamer.hs +158/−158
- Text/LaTeX/Packages/Color.hs +166/−166
- Text/LaTeX/Packages/Graphicx.hs +108/−108
- Text/LaTeX/Packages/Hyperref.hs +80/−80
- Text/LaTeX/Packages/Inputenc.hs +35/−35
- Text/LaTeX/Packages/Trees.hs +28/−28
- Text/LaTeX/Packages/Trees/Qtree.hs +48/−48
- license +30/−30
- parsertest/example4.tex +8/−0
- parsertest/example5.tex +4/−0
- parsertest/parsertest.hs +6/−5
- test/Main.hs +0/−1
CHANGELOG.md view
@@ -1,5 +1,22 @@ -# From 3.13.0.1 to 3.13.1.0+# HaTeX Changelog++This is the logchange of HaTeX. It might not be exhaustive.+For a full list of changes, see the commit history of the+git repository:++https://github.com/Daniel-Diaz/HaTeX/commits/master++# Changelog by versions++## From 3.13.1.0 to 3.14.0.0++* Fixed link in cabal file.+* Added support for arguments delimited by parenthesis (experimental).+* More tests on parsing.+* Parser now backtracks when failing in argument parsing.++## From 3.13.0.1 to 3.13.1.0 * New function ``matrixTabular`` to create tables from matrices. * Modified LaTeX Monoid instance to make monoid laws hold.
Examples/beamer.hs view
@@ -1,38 +1,38 @@- -{-# LANGUAGE OverloadedStrings #-} - -import Text.LaTeX -import Text.LaTeX.Packages.Beamer -import Text.LaTeX.Packages.Inputenc - -main :: IO () -main = execLaTeXT beamerExample >>= renderFile "beamer.tex" - -beamerExample :: Monad m => LaTeXT_ m -beamerExample = thePreamble >> document theBody - -thePreamble :: Monad m => LaTeXT_ m -thePreamble = do - -- To start using beamer, set the document class to be 'beamer'. - documentclass [] beamer - usepackage [utf8] inputenc - author "Daniel Díaz" - title "Beamer example using HaTeX" - -- Use a theme to improve the aspect of your slides. - usetheme CambridgeUS - -theBody :: Monad m => LaTeXT_ m -theBody = do - -- Each slide is a call to the function 'frame' with the content of the slide. - frame maketitle - frame $ do - frametitle "Example with block" - "Here comes " - alert [FromSlide 2] "the block!" - uncover [FromSlide 5] " Ha! I was hiding here!" - pause - pause - block "The block" $ do - pause - "The content of the block appears after a pause." - uncover [FromSlide 6] $ center "And that's it!" ++{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX+import Text.LaTeX.Packages.Beamer+import Text.LaTeX.Packages.Inputenc++main :: IO ()+main = execLaTeXT beamerExample >>= renderFile "beamer.tex"++beamerExample :: Monad m => LaTeXT_ m+beamerExample = thePreamble >> document theBody++thePreamble :: Monad m => LaTeXT_ m+thePreamble = do+ -- To start using beamer, set the document class to be 'beamer'.+ documentclass [] beamer+ usepackage [utf8] inputenc+ author "Daniel Díaz"+ title "Beamer example using HaTeX"+ -- Use a theme to improve the aspect of your slides.+ usetheme CambridgeUS++theBody :: Monad m => LaTeXT_ m+theBody = do+ -- Each slide is a call to the function 'frame' with the content of the slide.+ frame maketitle+ frame $ do+ frametitle "Example with block"+ "Here comes "+ alert [FromSlide 2] "the block!"+ uncover [FromSlide 5] " Ha! I was hiding here!"+ pause+ pause+ block "The block" $ do+ pause+ "The content of the block appears after a pause."+ uncover [FromSlide 6] $ center "And that's it!"
Examples/comments.hs view
@@ -1,18 +1,18 @@-{-# LANGUAGE OverloadedStrings #-} - -import Text.LaTeX - -main :: IO () -main = execLaTeXT example >>= renderFile "Comments.tex" - -example :: Monad m => LaTeXT_ m -example = do - documentclass [] article - document exampleBody - -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." +{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX++main :: IO ()+main = execLaTeXT example >>= renderFile "Comments.tex"++example :: Monad m => LaTeXT_ m+example = do+ documentclass [] article+ document exampleBody++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."
Examples/fibs.hs view
@@ -1,34 +1,34 @@-{-# LANGUAGE OverloadedStrings #-} - -import Text.LaTeX - -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 texy n & texy (fib n) - lnbk - l ) (return ()) [0 .. 12] - -fibs :: [Int] -fibs = 1 : 1 : zipWith (+) fibs (tail fibs) - -fib :: Int -> Int -fib = (fibs!!) +{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX++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 texy n & texy (fib n)+ lnbk+ l ) (return ()) [0 .. 12]++fibs :: [Int]+fibs = 1 : 1 : zipWith (+) fibs (tail fibs)++fib :: Int -> Int+fib = (fibs!!)
Examples/matrices.hs view
@@ -1,22 +1,22 @@- -import Text.LaTeX -import Text.LaTeX.Packages.AMSMath - -import Data.Matrix - -main :: IO () -main = execLaTeXT matrices >>= renderFile "matrices.tex" - -matrices :: Monad m => LaTeXT_ m -matrices = do - thePreamble - document theBody - -thePreamble :: Monad m => LaTeXT_ m -thePreamble = do - documentclass [] article - -- You need to import 'amsmath' to use 'pmatrix'. - usepackage [] amsmath - -theBody :: Monad m => LaTeXT_ m -theBody = equation_ $ pmatrix Nothing $ (identity 5 :: Matrix Int) ++import Text.LaTeX+import Text.LaTeX.Packages.AMSMath++import Data.Matrix++main :: IO ()+main = execLaTeXT matrices >>= renderFile "matrices.tex"++matrices :: Monad m => LaTeXT_ m+matrices = do+ thePreamble+ document theBody++thePreamble :: Monad m => LaTeXT_ m+thePreamble = do+ documentclass [] article+ -- You need to import 'amsmath' to use 'pmatrix'.+ usepackage [] amsmath++theBody :: Monad m => LaTeXT_ m+theBody = equation_ $ pmatrix Nothing $ (identity 5 :: Matrix Int)
Examples/simple.hs view
@@ -1,45 +1,45 @@- -{- Simple example - -This example is intended to be as simple as possible, but containing the most significant parts. - -The Overloaded Strings language extension is quite handy because it allows you to write text without -using 'fromString' everywhere. - --} - -{-# LANGUAGE OverloadedStrings #-} - -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. -main :: IO () -main = execLaTeXT simple >>= renderFile "simple.tex" - --- It's a good idea to separate the preamble of the body. -simple :: Monad m => LaTeXT_ m -simple = do - thePreamble - document theBody - --- Preamble with some basic info. -thePreamble :: Monad m => LaTeXT_ m -thePreamble = do - documentclass [] article - author "Daniel Diaz" - title "Simple example" - --- Body with a section. -theBody :: Monad m => LaTeXT_ m -theBody = do - maketitle - section "Hello" - "This is a simple example using the " - hatex - " library. " - -- 'textbf' turns characters to bold font (as you already may know). - textbf "Enjoy!" - " " - -- This is how we nest commands. - textbf (large "Yoohoo!") ++{- Simple example++This example is intended to be as simple as possible, but containing the most significant parts.++The Overloaded Strings language extension is quite handy because it allows you to write text without+using 'fromString' everywhere.++-}++{-# LANGUAGE OverloadedStrings #-}++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.+main :: IO ()+main = execLaTeXT simple >>= renderFile "simple.tex"++-- It's a good idea to separate the preamble of the body.+simple :: Monad m => LaTeXT_ m+simple = do+ thePreamble+ document theBody++-- Preamble with some basic info.+thePreamble :: Monad m => LaTeXT_ m+thePreamble = do+ documentclass [] article+ author "Daniel Diaz"+ title "Simple example"++-- Body with a section.+theBody :: Monad m => LaTeXT_ m+theBody = do+ maketitle+ section "Hello"+ "This is a simple example using the "+ hatex+ " library. "+ -- 'textbf' turns characters to bold font (as you already may know).+ textbf "Enjoy!"+ " "+ -- This is how we nest commands.+ textbf (large "Yoohoo!")
Examples/tree.hs view
@@ -1,41 +1,41 @@- -{-# LANGUAGE OverloadedStrings #-} - -import Text.LaTeX.Base -import Text.LaTeX.Packages.Trees.Qtree -import Text.LaTeX.Packages.Inputenc - -treeExample1 :: Tree String -treeExample1 = Node (Just "Root") [Leaf "Leaf 1",Leaf "Leaf 2"] - -treeExample2 :: Tree Int -treeExample2 = Node (Just 0) [Node Nothing [Leaf 1,Leaf 2] , Leaf 3] - -treeExample3 :: Tree LaTeX -treeExample3 = Node (Just $ textbf $ textit "Bold and italic") - [ Leaf $ textbf "Bold" - , Leaf $ textit "Italic" - ] - --- Main - -main :: IO () -main = renderFile "tree.tex" example - -example :: LaTeX -example = thePreamble <> document theBody - -thePreamble :: LaTeX -thePreamble = - documentclass [] article - <> usepackage [] qtree - <> usepackage [utf8] inputenc - <> title "Examples with trees" - <> author "Daniel Díaz" - -theBody :: LaTeX -theBody = - maketitle - <> tree fromString treeExample1 - <> rendertree treeExample2 ++{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX.Base+import Text.LaTeX.Packages.Trees.Qtree+import Text.LaTeX.Packages.Inputenc++treeExample1 :: Tree String+treeExample1 = Node (Just "Root") [Leaf "Leaf 1",Leaf "Leaf 2"]++treeExample2 :: Tree Int+treeExample2 = Node (Just 0) [Node Nothing [Leaf 1,Leaf 2] , Leaf 3]++treeExample3 :: Tree LaTeX+treeExample3 = Node (Just $ textbf $ textit "Bold and italic")+ [ Leaf $ textbf "Bold"+ , Leaf $ textit "Italic"+ ]++-- Main++main :: IO ()+main = renderFile "tree.tex" example++example :: LaTeX+example = thePreamble <> document theBody++thePreamble :: LaTeX+thePreamble =+ documentclass [] article+ <> usepackage [] qtree+ <> usepackage [utf8] inputenc+ <> title "Examples with trees"+ <> author "Daniel Díaz"++theBody :: LaTeX+theBody =+ maketitle+ <> tree fromString treeExample1+ <> rendertree treeExample2 <> tree id treeExample3
HaTeX.cabal view
@@ -1,5 +1,5 @@ Name: HaTeX -Version: 3.13.1.0 +Version: 3.14.0.0 Author: Daniel Díaz Category: Text, LaTeX Build-type: Simple @@ -27,7 +27,7 @@ Browse the @examples@ directory in the source distribution to see some simple examples. It might help you to get started. The HaTeX User's Guide is available at <https://github.com/Daniel-Diaz/hatex-guide/blob/master/README.md>. - We also have a mailing list (http://projects.haskell.org/cgi-bin/mailman/listinfo/hatex) + We also have a mailing list (<http://projects.haskell.org/cgi-bin/mailman/listinfo/hatex>) and an IRC channel (@#hatex@). If you just want to read a short introduction, read the "Text.LaTeX" module. . @@ -121,3 +121,13 @@ , tasty , QuickCheck , tasty-quickcheck + ghc-options: -Wall -fno-warn-orphans +Test-Suite parser-tests + Default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: parsertest + main-is: parsertest.hs + build-depends: base == 4.* + , HaTeX + , text + ghc-options: -Wall
README.md view
@@ -1,68 +1,66 @@-# The HaTeX library - -HaTeX is a Haskell library that implements the *LaTeX syntax*. - -Check a list of examples of usage in the [Examples](https://github.com/Daniel-Diaz/HaTeX/tree/master/Examples) directory. -A good starting point may be [simple.hs](https://github.com/Daniel-Diaz/HaTeX/blob/master/Examples/simple.hs). -Run any example script executing the ``main`` function. - -## Installation notes - -To install `HaTeX`, use [cabal-install](http://hackage.haskell.org/package/cabal-install). - - $ cabal update - $ cabal install HaTeX - -This will install the latest official release (recommended). -If you want to try a newer version, use _git_ to clone the code contained -in this repository. - - $ git clone git@github.com:Daniel-Diaz/HaTeX.git - $ cd HaTeX - $ cabal install - -However, note that the API may be unstable and is subject to any kind of change. -In the other hand, this package follows the [_Package Versioning Policy_](http://www.haskell.org/haskellwiki/Package_versioning_policy), -so it is unlikely to suffer from API breakages if you follow it too when importing the library. - -See the [Hackage page of HaTeX](http://hackage.haskell.org/package/HaTeX) to browse older versions. - -## Travis automatic build - -[](https://travis-ci.org/Daniel-Diaz/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! -It is free source and anybody can contribute to it. Doing so, you will help current and future users! - -A downloadable version (not necessarily the last version, but most likely) -can be found [here](http://daniel-diaz.github.com/projects/hatex/hatex-guide.pdf). -To be sure that you are reading the last version, go to the github repository of the guide and follow instructions -to build it. It is fairly easy. - -## Community and Contributions - -There are many ways to get involved in the HaTeX project. - -* Fork the [GitHub repository](https://github.com/Daniel-Diaz/HaTeX). -* Report bugs or make suggestions opening a ticket in the [Issue Tracker](https://github.com/Daniel-Diaz/HaTeX/issues). -* Help us to improve and extend our [hatex-guide](https://github.com/Daniel-Diaz/hatex-guide). -* Join the [Mailing List](http://projects.haskell.org/cgi-bin/mailman/listinfo/hatex) for help or announcements of the -last developments. -* Drop by the IRC channel at `#hatex`. - -## TODO list - -* Add more examples. -* More testing on the parser (See [#15](https://github.com/Daniel-Diaz/HaTeX/issues/15)). - This includes adding more test cases to the [parsertest folder](https://github.com/Daniel-Diaz/HaTeX/tree/master/parsertest). -* Add more documentation. -* BibTeX support. - -## Related projects - -* [TeX-my-math](https://github.com/leftaroundabout/Symbolic-math-HaTeX): Experimental library to ease the production -of mathematical expressions using HaTeX. -* [haskintex](http://daniel-diaz.github.io/projects/haskintex): Tool to use Haskell and in particular the HaTeX library -within a LaTeX file. +# The HaTeX library++HaTeX is a Haskell library that implements the *LaTeX syntax*.++Check a list of examples of usage in the [Examples](https://github.com/Daniel-Diaz/HaTeX/tree/master/Examples) directory.+A good starting point may be [simple.hs](https://github.com/Daniel-Diaz/HaTeX/blob/master/Examples/simple.hs).+Run any example script executing the ``main`` function.++## Installation notes++To install `HaTeX`, use [cabal-install](http://hackage.haskell.org/package/cabal-install).++ $ cabal update+ $ cabal install HaTeX++This will install the latest official release (recommended).+If you want to try a newer version, use _git_ to clone the code contained+in this repository.++ $ git clone git@github.com:Daniel-Diaz/HaTeX.git+ $ cd HaTeX+ $ cabal install++However, note that the API may be unstable and is subject to any kind of change.+In the other hand, this package follows the [_Package Versioning Policy_](http://www.haskell.org/haskellwiki/Package_versioning_policy),+so it is unlikely to suffer from API breakages if you follow it too when importing the library.++See the [Hackage page of HaTeX](http://hackage.haskell.org/package/HaTeX) to browse older versions.++## Travis automatic build++[](https://travis-ci.org/Daniel-Diaz/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!+It is free source and anybody can contribute to it. Doing so, you will help current and future users!++A downloadable version (not necessarily the last version, but most likely)+can be found [here](http://daniel-diaz.github.com/projects/hatex/hatex-guide.pdf).+To be sure that you are reading the last version, go to the github repository of the guide and follow instructions+to build it. It is fairly easy.++## Community and Contributions++There are many ways to get involved in the HaTeX project.++* Fork the [GitHub repository](https://github.com/Daniel-Diaz/HaTeX).+* Report bugs or make suggestions opening a ticket in the [Issue Tracker](https://github.com/Daniel-Diaz/HaTeX/issues).+* Help us to improve and extend our [hatex-guide](https://github.com/Daniel-Diaz/hatex-guide).+* Join the [Mailing List](http://projects.haskell.org/cgi-bin/mailman/listinfo/hatex) for help or announcements of the+latest developments.+* Drop by the IRC channel at `#hatex`.++## TODO list++* Add more examples.+* Add more documentation.+* BibTeX support.++## Related projects++* [TeX-my-math](https://github.com/leftaroundabout/Symbolic-math-HaTeX): Experimental library to ease the production+of mathematical expressions using HaTeX.+* [haskintex](http://daniel-diaz.github.io/projects/haskintex): Tool to use Haskell and in particular the HaTeX library+within a LaTeX file.
ReleaseNotes view
@@ -1,91 +1,91 @@-HaTeX Release Notes --- From version 3.0.0 - ->>> 3.4 - -- Num instance for LaTeXT. -- New re-exports: liftIO. -- Relaxed transformers package dependency to: >= 0.2.2 && < 0.4 -- Changed infix rule of (=:) and (/=:). -- More documentation notes. -- New functions: hfill, vfill. -- The internal representation of LaTeXT has changed to prevent - a set of errors. -- Changes in Text.LaTeX. -- Several minor fixes. - ->>> 3.3 - -- New functions 'protectString' and 'protectText'. -- New function 'rendertexM'. -- New environments: 'figure' and 'caption'. -- New example: simple.hs. -- Updated version of transfomers to 0.3.*. -- Trees implemented: datatype and Qtree package. -- Render instances for Integer and Double. -- New docs. -- Class system implemented. Monad modules dropped. - ->>> 3.2.0.1 - -- This version only fix the patch that makes HaTeX compatible with GHC 7.4. - ->>> 3.2 - -Highlights: - -+ Parser implemented (New dependency on parsec). -+ Greek alphabet added to AMSMath. -+ New LaTeX package: graphicx. -+ Function 'documentclass' changed. - -Other changes: - -- Dependency changed from mtl to transformers. -- New commands: par, textwidth and linewidth. -- New environment: minipage. -- Compatibility with GHC 7.4 (with CPP extension). -- Function 'lift' is now re-exported in Text.LaTeX.Base.Writer module. -- New function 'renderChars' in the Render module. -- ReadMe edited, now with ToDo list. - ->>> 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. +HaTeX Release Notes+-- From version 3.0.0++>>> 3.4++- Num instance for LaTeXT.+- New re-exports: liftIO.+- Relaxed transformers package dependency to: >= 0.2.2 && < 0.4+- Changed infix rule of (=:) and (/=:).+- More documentation notes.+- New functions: hfill, vfill.+- The internal representation of LaTeXT has changed to prevent+ a set of errors.+- Changes in Text.LaTeX.+- Several minor fixes.++>>> 3.3++- New functions 'protectString' and 'protectText'.+- New function 'rendertexM'.+- New environments: 'figure' and 'caption'.+- New example: simple.hs.+- Updated version of transfomers to 0.3.*.+- Trees implemented: datatype and Qtree package.+- Render instances for Integer and Double.+- New docs.+- Class system implemented. Monad modules dropped.++>>> 3.2.0.1++- This version only fix the patch that makes HaTeX compatible with GHC 7.4.++>>> 3.2++Highlights:+++ Parser implemented (New dependency on parsec).++ Greek alphabet added to AMSMath.++ New LaTeX package: graphicx.++ Function 'documentclass' changed.++Other changes:++- Dependency changed from mtl to transformers.+- New commands: par, textwidth and linewidth.+- New environment: minipage.+- Compatibility with GHC 7.4 (with CPP extension).+- Function 'lift' is now re-exported in Text.LaTeX.Base.Writer module.+- New function 'renderChars' in the Render module.+- ReadMe edited, now with ToDo list.++>>> 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.
Setup.hs view
@@ -1,3 +1,3 @@-import Distribution.Simple - +import Distribution.Simple+ main = defaultMain
Text/LaTeX.hs view
@@ -1,102 +1,102 @@- --- | This module is a re-export of the Base module. --- You may find it shorter to import. Below you can --- also find a short overview of HaTeX. --- --- Historically, this module also exported the Packages --- module. But, since it's more common to import the Base --- 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 re-export - module Text.LaTeX.Base - -- * An overview of HaTeX - - -- $ove - - -- ** The @LaTeX@ type - - -- $type - - -- ** Rendering LaTeX code - - -- $rnd - - -- ** Using more features - - -- $pkgs - - -- ** More from HaTeX - - -- $bey - - -- ** Using monads - - -- $wrt - - -- ** Examples - - -- $exm - ) where - -import Text.LaTeX.Base - --- $ove --- HaTeX is a library that implements the LaTeX syntax for both rendering and parsing. - -{- $type -The core type is called 'LaTeX'. Values of this type are always a syntactically correct -piece of LaTeX code, which we call a LaTeX /block/. To append blocks, we use the 'Monoid' -class. Thus, the operator '<>' appends blocks. To generate blocks, we use functions. -Basic functions are defined in the "Text.LaTeX.Base.Commands" module. Roughly speaking, -it contains functions to generate blocks containing LaTeX commands and environments that -are always defined. In the other hand, 'LaTeX' is an instance of the 'IsString' class. -This allow us to insert LaTeX code containing simple text by just writing it as a 'String' -and enabling the @OverlaodedStrings@ language extension. --} - -{- $rnd -Once you have a 'LaTeX' block built, the function 'render' will turn it into 'Text'. If -your intention is to write the output in a file, use 'renderFile' to write the LaTeX -code output directly into that file. --} - -{- $pkgs -Apart from the core commands and environments, HaTeX offers more functions to generate LaTeX -blocks containing more exotic things. These functions are categorized by LaTeX packages. For example, -those commands and environments that come from the LaTeX @babel@ package are under the module -"Text.LaTeX.Packages.Babel", and those that come from the @graphicx@ package are under "Text.LaTeX.Packages.Graphicx". -Import each package individually to use them. -This way, is easier to guess where to look for a particular function, and easier to detect -if a particular feature is missing. --} - -{- $bey -Beyond the implementation of existing LaTeX packages, -HaTeX also provides some useful functions to build LaTeX code blocks from Haskell values. -The Texy class allows you to pretty-print Haskell values to LaTeX blocks. This includes numbers, matrices, -vectors or trees. HaTeX also features some modules dedicated to the generation of TikZ scripts -(see "Text.LaTeX.Packages.TikZ.Simple"). -Everything you need to generate LaTeX code using Haskell should be included in this library. -If some feature is missing, the GitHub issue list is waiting for you <https://github.com/Daniel-Diaz/HaTeX/issues>. --} - -{- $wrt -LaTeX blocks can also be managed by the 'LaTeXT' monad transformer. Similar to the 'WriterT' monad, -it stores and append values from a 'Monoid', in this case, the 'Monoid' of the 'LaTeX' values. -Both interfaces are fused into one under the 'LaTeXC' class, the class of LaTeX blocks. -Particular documentation of each feature can be found in the corresponding module. -Further explanation of the library and its concepts can be found in the /HaTeX User's Guide/ -(<https://github.com/Daniel-Diaz/hatex-guide/blob/master/README.md>). --} - -{- $exm -Some examples can be found in the source code, under the /Examples/ directory. In particular, the example -contained in the file @simple.hs@ is intended to be read by new users of the library. -If you have any question regarding one of the examples, there is something you want to ask about -HaTeX, or for anything you would like to discuss, we have a mailing list at <http://projects.haskell.org/cgi-bin/mailman/listinfo/hatex>. --} ++-- | This module is a re-export of the Base module.+-- You may find it shorter to import. Below you can+-- also find a short overview of HaTeX.+--+-- Historically, this module also exported the Packages+-- module. But, since it's more common to import the Base+-- 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 re-export+ module Text.LaTeX.Base+ -- * An overview of HaTeX++ -- $ove++ -- ** The @LaTeX@ type++ -- $type++ -- ** Rendering LaTeX code++ -- $rnd++ -- ** Using more features++ -- $pkgs++ -- ** More from HaTeX++ -- $bey++ -- ** Using monads++ -- $wrt++ -- ** Examples++ -- $exm+ ) where++import Text.LaTeX.Base++-- $ove+-- HaTeX is a library that implements the LaTeX syntax for both rendering and parsing.++{- $type+The core type is called 'LaTeX'. Values of this type are always a syntactically correct+piece of LaTeX code, which we call a LaTeX /block/. To append blocks, we use the 'Monoid'+class. Thus, the operator '<>' appends blocks. To generate blocks, we use functions.+Basic functions are defined in the "Text.LaTeX.Base.Commands" module. Roughly speaking,+it contains functions to generate blocks containing LaTeX commands and environments that+are always defined. In the other hand, 'LaTeX' is an instance of the 'IsString' class.+This allow us to insert LaTeX code containing simple text by just writing it as a 'String'+and enabling the @OverlaodedStrings@ language extension.+-}++{- $rnd+Once you have a 'LaTeX' block built, the function 'render' will turn it into 'Text'. If+your intention is to write the output in a file, use 'renderFile' to write the LaTeX+code output directly into that file.+-}++{- $pkgs+Apart from the core commands and environments, HaTeX offers more functions to generate LaTeX+blocks containing more exotic things. These functions are categorized by LaTeX packages. For example,+those commands and environments that come from the LaTeX @babel@ package are under the module+"Text.LaTeX.Packages.Babel", and those that come from the @graphicx@ package are under "Text.LaTeX.Packages.Graphicx".+Import each package individually to use them.+This way, is easier to guess where to look for a particular function, and easier to detect+if a particular feature is missing.+-}++{- $bey+Beyond the implementation of existing LaTeX packages,+HaTeX also provides some useful functions to build LaTeX code blocks from Haskell values.+The Texy class allows you to pretty-print Haskell values to LaTeX blocks. This includes numbers, matrices,+vectors or trees. HaTeX also features some modules dedicated to the generation of TikZ scripts+(see "Text.LaTeX.Packages.TikZ.Simple").+Everything you need to generate LaTeX code using Haskell should be included in this library.+If some feature is missing, the GitHub issue list is waiting for you <https://github.com/Daniel-Diaz/HaTeX/issues>.+-}++{- $wrt+LaTeX blocks can also be managed by the 'LaTeXT' monad transformer. Similar to the 'WriterT' monad,+it stores and append values from a 'Monoid', in this case, the 'Monoid' of the 'LaTeX' values.+Both interfaces are fused into one under the 'LaTeXC' class, the class of LaTeX blocks.+Particular documentation of each feature can be found in the corresponding module.+Further explanation of the library and its concepts can be found in the /HaTeX User's Guide/+(<https://github.com/Daniel-Diaz/hatex-guide/blob/master/README.md>).+-}++{- $exm+Some examples can be found in the source code, under the /Examples/ directory. In particular, the example+contained in the file @simple.hs@ is intended to be read by new users of the library.+If you have any question regarding one of the examples, there is something you want to ask about+HaTeX, or for anything you would like to discuss, we have a mailing list at <http://projects.haskell.org/cgi-bin/mailman/listinfo/hatex>.+-}
Text/LaTeX/Base.hs view
@@ -1,59 +1,59 @@- -{-# LANGUAGE CPP #-} - -{- | -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. - -* 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 - LaTeX - -- * Escaping reserved characters - , protectString , protectText - -- * Internal re-exports - , module Text.LaTeX.Base.Render - , module Text.LaTeX.Base.Types - , module Text.LaTeX.Base.Commands - , module Text.LaTeX.Base.Writer - , module Text.LaTeX.Base.Texy - -- * Monoids - -- - -- | Since the 'Monoid' instance is the only way to append 'LaTeX' - -- values, a re-export of the 'Monoid' class is given here for convenience. - , Monoid (..) - , (<>) - ) where - --- Internal modules -import Text.LaTeX.Base.Syntax - ( LaTeX -#if __GLASGOW_HASKELL__ < 704 - , (<>) -#endif - , protectString - , protectText) -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types -import Text.LaTeX.Base.Commands -import Text.LaTeX.Base.Writer -import Text.LaTeX.Base.Texy --- External modules -import Data.Monoid ++{-# LANGUAGE CPP #-}++{- |+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.++* 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+ LaTeX+ -- * Escaping reserved characters+ , protectString , protectText+ -- * Internal re-exports+ , module Text.LaTeX.Base.Render+ , module Text.LaTeX.Base.Types+ , module Text.LaTeX.Base.Commands+ , module Text.LaTeX.Base.Writer+ , module Text.LaTeX.Base.Texy+ -- * Monoids+ --+ -- | Since the 'Monoid' instance is the only way to append 'LaTeX'+ -- values, a re-export of the 'Monoid' class is given here for convenience.+ , Monoid (..)+ , (<>)+ ) where++-- Internal modules+import Text.LaTeX.Base.Syntax+ ( LaTeX+#if __GLASGOW_HASKELL__ < 704+ , (<>)+#endif+ , protectString+ , protectText)+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types+import Text.LaTeX.Base.Commands+import Text.LaTeX.Base.Writer+import Text.LaTeX.Base.Texy+-- External modules+import Data.Monoid
Text/LaTeX/Base/Class.hs view
@@ -1,92 +1,92 @@- -{-# OPTIONS_GHC -fno-warn-name-shadowing #-} - --- | Definition of the 'LaTeXC' class, used to combine the classic applicative and --- the latter monadic interfaces of /HaTeX 3/. The user can define new instances --- as well, adding flexibility to the way /HaTeX/ is used. -module Text.LaTeX.Base.Class ( - LaTeXC (..) - , Monoid (..) - -- * Combinators - -- ** From @LaTeX@ - , fromLaTeX - -- ** Lifting - -- | Lifting functions from 'LaTeX' functions to functions over any instance of 'LaTeXC'. - -- In general, the implementation is as follows: - -- - -- > liftLN f x1 ... xN = liftListL (\[x1,...,xN] -> f x1 ... xN) [x1,...,xN] - -- - , liftL - , liftL2 - , liftL3 - -- ** Others - , comm0 - , comm1 - , commS - , braces - ) where - -import Text.LaTeX.Base.Syntax -import Data.Monoid -import Data.String - --- | This is the class of 'LaTeX' code generators. It has 'Monoid' and 'IsString' as --- superclasses. -class (Monoid l,IsString l) => LaTeXC l where - -- | This method must take a function that combines a list of 'LaTeX' values into a new one, - -- and creates a function that combines @l@-typed values. The combining function can be - -- seen as a function with 0 or more 'LaTeX' arguments with a 'LaTeX' value as output. - liftListL :: ([LaTeX] -> LaTeX) -> [l] -> l - --- | This instance just sets @liftListL = id@. -instance LaTeXC LaTeX where - liftListL = id - --- COMBINATORS - --- | Map a 'LaTeX' value to its equivalent in any 'LaTeXC' instance. -fromLaTeX :: LaTeXC l => LaTeX -> l -fromLaTeX l = liftListL (\_ -> l) [] - --- | Lift a inner function of 'LaTeX' values into any 'LaTeXC' instance. -liftL :: LaTeXC l => (LaTeX -> LaTeX) -> l -> l -liftL f x = liftListL (\[x] -> f x) [x] - --- | Variant of 'liftL' with a two arguments function. -liftL2 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -liftL2 f x y = liftListL (\[x,y] -> f x y) [x,y] - --- | Variant of 'liftL' with a three arguments function. -liftL3 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -liftL3 f x y z = liftListL (\[x,y,z] -> f x y z) [x,y,z] - --- | A simple (without arguments) and handy command generator --- using the name of the command. --- --- > comm0 str = fromLaTeX $ TeXComm str [] --- -comm0 :: LaTeXC l => String -> l -comm0 str = fromLaTeX $ TeXComm str [] - --- | A one parameter command generator using the name of the command. --- The parameter will be rendered as a fixed argument. --- --- > comm1 str = liftL $ \l -> TeXComm str [FixArg l] --- -comm1 :: LaTeXC l => String -> l -> l -comm1 str = liftL $ \l -> TeXComm str [FixArg l] - --- | Like 'comm0' but using 'TeXCommS', i.e. no \"{}\" will be inserted to protect --- the command's end. --- --- > commS = fromLaTeX . TeXCommS --- -commS :: LaTeXC l => String -> l -commS = fromLaTeX . TeXCommS - --- | A lifted version of the 'TeXBraces' constructor. --- --- > braces = liftL TeXBraces --- -braces :: LaTeXC l => l -> l -braces = liftL TeXBraces ++{-# OPTIONS_GHC -fno-warn-name-shadowing #-}++-- | Definition of the 'LaTeXC' class, used to combine the classic applicative and+-- the latter monadic interfaces of /HaTeX 3/. The user can define new instances+-- as well, adding flexibility to the way /HaTeX/ is used.+module Text.LaTeX.Base.Class (+ LaTeXC (..)+ , Monoid (..)+ -- * Combinators+ -- ** From @LaTeX@+ , fromLaTeX+ -- ** Lifting+ -- | Lifting functions from 'LaTeX' functions to functions over any instance of 'LaTeXC'.+ -- In general, the implementation is as follows:+ --+ -- > liftLN f x1 ... xN = liftListL (\[x1,...,xN] -> f x1 ... xN) [x1,...,xN]+ --+ , liftL+ , liftL2+ , liftL3+ -- ** Others+ , comm0+ , comm1+ , commS+ , braces+ ) where++import Text.LaTeX.Base.Syntax+import Data.Monoid+import Data.String++-- | This is the class of 'LaTeX' code generators. It has 'Monoid' and 'IsString' as+-- superclasses.+class (Monoid l,IsString l) => LaTeXC l where+ -- | This method must take a function that combines a list of 'LaTeX' values into a new one,+ -- and creates a function that combines @l@-typed values. The combining function can be+ -- seen as a function with 0 or more 'LaTeX' arguments with a 'LaTeX' value as output.+ liftListL :: ([LaTeX] -> LaTeX) -> [l] -> l++-- | This instance just sets @liftListL = id@.+instance LaTeXC LaTeX where+ liftListL = id++-- COMBINATORS++-- | Map a 'LaTeX' value to its equivalent in any 'LaTeXC' instance.+fromLaTeX :: LaTeXC l => LaTeX -> l+fromLaTeX l = liftListL (\_ -> l) []++-- | Lift a inner function of 'LaTeX' values into any 'LaTeXC' instance.+liftL :: LaTeXC l => (LaTeX -> LaTeX) -> l -> l+liftL f x = liftListL (\[x] -> f x) [x]++-- | Variant of 'liftL' with a two arguments function.+liftL2 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX) -> l -> l -> l+liftL2 f x y = liftListL (\[x,y] -> f x y) [x,y]++-- | Variant of 'liftL' with a three arguments function.+liftL3 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l+liftL3 f x y z = liftListL (\[x,y,z] -> f x y z) [x,y,z]++-- | A simple (without arguments) and handy command generator+-- using the name of the command.+--+-- > comm0 str = fromLaTeX $ TeXComm str []+--+comm0 :: LaTeXC l => String -> l+comm0 str = fromLaTeX $ TeXComm str []++-- | A one parameter command generator using the name of the command.+-- The parameter will be rendered as a fixed argument.+--+-- > comm1 str = liftL $ \l -> TeXComm str [FixArg l]+--+comm1 :: LaTeXC l => String -> l -> l+comm1 str = liftL $ \l -> TeXComm str [FixArg l]++-- | Like 'comm0' but using 'TeXCommS', i.e. no \"{}\" will be inserted to protect+-- the command's end.+--+-- > commS = fromLaTeX . TeXCommS+--+commS :: LaTeXC l => String -> l+commS = fromLaTeX . TeXCommS++-- | A lifted version of the 'TeXBraces' constructor.+--+-- > braces = liftL TeXBraces+--+braces :: LaTeXC l => l -> l+braces = liftL TeXBraces
Text/LaTeX/Base/Parser.hs view
@@ -160,9 +160,6 @@ then special else do c <- takeTill endCmd- -- if c `elem` ["begin","end"]- -- then fail $ "Command not allowed: " ++ T.unpack c- -- else maybe (TeXCommS $ T.unpack c) (TeXComm $ T.unpack c) <$> cmdArgs maybe (TeXCommS $ T.unpack c) (TeXComm $ T.unpack c) <$> cmdArgs ------------------------------------------------------------------------@@ -170,7 +167,7 @@ ------------------------------------------------------------------------ cmdArgs :: Parser (Maybe [TeXArg]) cmdArgs = try (string "{}" >> return (Just []))- <|> fmap Just (many1 cmdArg)+ <|> fmap Just (try $ many1 cmdArg) <|> return Nothing cmdArg :: Parser TeXArg
Text/LaTeX/Base/Pretty.hs view
@@ -64,6 +64,8 @@ else list $ fmap docLaTeX ls docTeXArg (SymArg l) = docTeXArg $ MSymArg [l] docTeXArg (MSymArg ls) = encloseSep (char '<') (char '>') (char ',') $ fmap docLaTeX ls+docTeXArg (ParArg l) = docTeXArg $ MParArg [l]+docTeXArg (MParArg ls) = encloseSep (char '(') (char ')') (char ',') $ fmap docLaTeX ls -- | Pretty print a 'LaTeX' value. It produces a more human-friendly output than 'render'. --
Text/LaTeX/Base/Render.hs view
@@ -1,170 +1,172 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | The final purpose of this module is to render a Text value --- from a 'LaTeX' value. The interface is abstracted via a typeclass --- so you can cast to 'Text' other types as well. Also, some other --- handy 'Text'-related functions are defined. -module Text.LaTeX.Base.Render - ( -- * Re-exports - Text - , module Data.String - -- * Render class - , Render (..) - , renderAppend - , renderChars - , renderCommas - , renderFile - , rendertex - -- * Reading files - , readFileTex - -- * Util - , showFloat - ) where - -import Data.Text (Text,lines,unlines) -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Data.String -import Data.Text.Encoding -import Data.List (intersperse) -import qualified Data.ByteString as B -import Data.Word (Word8) -import Numeric (showFFloat) - --- | Class of values that can be transformed to 'Text'. --- You mainly will use this to obtain the 'Text' output --- of a 'LaTeX' value. If you are going to write the result --- in a file, consider to use 'renderFile'. --- --- Consider also to use 'rendertex' to get 'Render'able values --- into 'LaTeX' blocks. --- --- If you want to make a type instance of 'Render' and you already --- have a 'Show' instance, you can use the default instance. --- --- > render = fromString . show --- -class Show a => Render a where - render :: a -> Text - -- - render = fromString . show - --- | This instance escapes LaTeX reserved characters. -instance Render Text where - render = protectText - --- | 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 the given 'Char'. -renderChars :: Render a => Char -> [a] -> Text -renderChars c = mconcat . intersperse (fromString [c]) . fmap render - --- | Render every element of a list and append results, --- separated by commas. -renderCommas :: Render a => [a] -> Text -renderCommas = renderChars ',' - --- | 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 reserved characters./ --- /Use /'protectText'/ to escape them./ -rendertex :: (Render a,LaTeXC l) => a -> l -rendertex = fromLaTeX . TeXRaw . render - --- Render instances - -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 - --- 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 Dollar l) = "$" <> render l <> "$" - render (TeXMath Square l) = "\\[" <> render l <> "\\]" - render (TeXMath Parentheses l) = "\\(" <> render l <> "\\)" - - render (TeXLineBreak m b) = "\\\\" <> maybe mempty (\x -> "[" <> render x <> "]") m <> ( if b then "*" else mempty ) - - render (TeXBraces l) = "{" <> render l <> "}" - - render (TeXComment c) = - let xs = Data.Text.lines c - in if null xs then "%\n" - else Data.Text.unlines $ fmap ("%" <>) xs - - 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) = "[" <> renderCommas ls <> "]" - render (SymArg l) = "<" <> render l <> ">" - render (MSymArg ls) = "<" <> renderCommas ls <> ">" - --- Other instances - --- | Show a signed floating number using standard decimal notation using 5 decimals. -showFloat :: RealFloat a => a -> String -showFloat x = showFFloat (Just 5) x [] - -instance Render Int where -instance Render Integer where -instance Render Float where - render = fromString . showFloat -instance Render Double where - render = fromString . showFloat -instance Render Word8 where - --- | 'Render' instance for 'Bool'. It satisfies @render True = "true"@ and @render False = "false"@. -instance Render Bool where - render True = "true" - render _ = "false" - -instance Render a => Render [a] where - render xs = "[" <> renderCommas xs <> "]" ++{-# LANGUAGE OverloadedStrings #-}++-- | The final purpose of this module is to render a Text value+-- from a 'LaTeX' value. The interface is abstracted via a typeclass+-- so you can cast to 'Text' other types as well. Also, some other+-- handy 'Text'-related functions are defined.+module Text.LaTeX.Base.Render+ ( -- * Re-exports+ Text+ , module Data.String+ -- * Render class+ , Render (..)+ , renderAppend+ , renderChars+ , renderCommas+ , renderFile+ , rendertex+ -- * Reading files+ , readFileTex+ -- * Util+ , showFloat+ ) where++import Data.Text (Text,lines,unlines)+import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Data.String+import Data.Text.Encoding+import Data.List (intersperse)+import qualified Data.ByteString as B+import Data.Word (Word8)+import Numeric (showFFloat)++-- | Class of values that can be transformed to 'Text'.+-- You mainly will use this to obtain the 'Text' output+-- of a 'LaTeX' value. If you are going to write the result+-- in a file, consider to use 'renderFile'.+--+-- Consider also to use 'rendertex' to get 'Render'able values+-- into 'LaTeX' blocks.+--+-- If you want to make a type instance of 'Render' and you already+-- have a 'Show' instance, you can use the default instance.+--+-- > render = fromString . show+--+class Show a => Render a where+ render :: a -> Text+ --+ render = fromString . show++-- | This instance escapes LaTeX reserved characters.+instance Render Text where+ render = protectText++-- | 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 the given 'Char'.+renderChars :: Render a => Char -> [a] -> Text+renderChars c = mconcat . intersperse (fromString [c]) . fmap render++-- | Render every element of a list and append results,+-- separated by commas.+renderCommas :: Render a => [a] -> Text+renderCommas = renderChars ','++-- | 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 reserved characters./+-- /Use /'protectText'/ to escape them./+rendertex :: (Render a,LaTeXC l) => a -> l+rendertex = fromLaTeX . TeXRaw . render++-- Render instances++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++-- 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 Dollar l) = "$" <> render l <> "$"+ render (TeXMath Square l) = "\\[" <> render l <> "\\]"+ render (TeXMath Parentheses l) = "\\(" <> render l <> "\\)"++ render (TeXLineBreak m b) = "\\\\" <> maybe mempty (\x -> "[" <> render x <> "]") m <> ( if b then "*" else mempty )++ render (TeXBraces l) = "{" <> render l <> "}"++ render (TeXComment c) =+ let xs = Data.Text.lines c+ in if null xs then "%\n"+ else Data.Text.unlines $ fmap ("%" <>) xs++ 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) = "[" <> renderCommas ls <> "]"+ render (SymArg l) = "<" <> render l <> ">"+ render (MSymArg ls) = "<" <> renderCommas ls <> ">"+ render (ParArg l) = "(" <> render l <> ")"+ render (MParArg ls) = "(" <> renderCommas ls <> ")"++-- Other instances++-- | Show a signed floating number using standard decimal notation using 5 decimals.+showFloat :: RealFloat a => a -> String+showFloat x = showFFloat (Just 5) x []++instance Render Int where+instance Render Integer where+instance Render Float where+ render = fromString . showFloat+instance Render Double where+ render = fromString . showFloat+instance Render Word8 where++-- | 'Render' instance for 'Bool'. It satisfies @render True = "true"@ and @render False = "false"@.+instance Render Bool where+ render True = "true"+ render _ = "false"++instance Render a => Render [a] where+ render xs = "[" <> renderCommas xs <> "]"
Text/LaTeX/Base/Syntax.hs view
@@ -1,317 +1,328 @@- -{-# LANGUAGE CPP, DeriveDataTypeable #-} - --- | 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 - Measure (..) - , MathType (..) - , LaTeX (..) - , TeXArg (..) - , (<>) - -- * Escaping reserved characters - , protectString - , protectText - -- * Syntax analysis - , matchCommand - , lookForCommand - , matchEnv - , lookForEnv - , texmap - , texmapM - -- ** Utils - , getBody - , getPreamble - ) where - -import Data.Text (Text,pack) -import qualified Data.Text -import Data.Monoid -import Data.String -import Control.Applicative -import Control.Monad (replicateM) -import Data.Functor.Identity (runIdentity) -import Data.Typeable -import Test.QuickCheck - --- | Measure units defined in LaTeX. Use 'CustomMeasure' to use commands like 'textwidth'. --- For instance: --- --- > rule Nothing (CustomMeasure linewidth) (Pt 2) --- --- This will create a black box (see 'rule') as wide as the text and two points tall. --- -data Measure = - Pt Double -- ^ A point is 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm. - | Mm Double -- ^ Millimeter. - | Cm Double -- ^ Centimeter. - | In Double -- ^ Inch. - | Ex Double -- ^ The height of an \"x\" in the current font. - | Em Double -- ^ The width of an \"M\" in the current font. - | CustomMeasure LaTeX -- ^ You can introduce a 'LaTeX' expression as a measure. - deriving (Eq, Show) - --- | Different types of syntax for mathematical expressions. -data MathType = Parentheses | Square | Dollar - deriving (Eq,Show) - --- | Type of @LaTeX@ blocks. -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 -- ^ Constructor for commands with no arguments. - -- When rendering, no space or @{}@ will be added at - -- the end. - | TeXEnv String [TeXArg] LaTeX -- ^ Constructor for environments. - -- First argument is the name of the environment. - -- Second, its arguments. - -- Third, its content. - | TeXMath MathType LaTeX -- ^ Mathematical expressions. - | TeXLineBreak (Maybe Measure) Bool -- ^ Line break command. - | TeXBraces LaTeX -- ^ A expression between braces. - | TeXComment Text -- ^ Comments. - | TeXSeq LaTeX LaTeX -- ^ Sequencing of 'LaTeX' expressions. - -- Use '<>' preferably. - | TeXEmpty -- ^ An empty block. - -- /Neutral element/ of '<>'. - deriving (Eq,Show,Typeable) - --- | An argument for a 'LaTeX' command or environment. -data TeXArg = - FixArg LaTeX -- ^ Fixed argument. - | OptArg LaTeX -- ^ Optional 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'. - --- | Method 'mappend' is strict in both arguments (except in the case when the first argument is 'TeXEmpty'). -instance Monoid LaTeX where - mempty = TeXEmpty - mappend TeXEmpty x = x - mappend x TeXEmpty = x - -- This equation is to make 'mappend' associative. - mappend (TeXSeq x y) z = TeXSeq x $ mappend y z - -- - mappend x y = TeXSeq x y - --- Since GHC starting from 7.4 provides (<>) as synonym to 'mappend' (see "Data.Monoid"), --- we avoid an overlapping definition with a CPP conditional. -#if __GLASGOW_HASKELL__ < 704 --- | Alias for 'mappend'. -(<>) :: Monoid a => a -> a -> a -(<>) = mappend -#endif - --- | Method 'fromString' escapes LaTeX reserved characters using 'protectString'. -instance IsString LaTeX where - fromString = TeXRaw . fromString . protectString - --- | Escape LaTeX reserved characters in a 'String'. -protectString :: String -> String -protectString = mconcat . fmap protectChar - --- | Escape LaTeX reserved characters in a 'Text'. -protectText :: Text -> Text -protectText = Data.Text.concatMap (fromString . protectChar) - -protectChar :: Char -> String -protectChar '#' = "\\#" -protectChar '$' = "\\$" -protectChar '%' = "\\%" -protectChar '^' = "\\^{}" -protectChar '&' = "\\&" -protectChar '{' = "\\{" -protectChar '}' = "\\}" -protectChar '~' = "\\~{}" -protectChar '\\' = "\\textbackslash{}" -protectChar '_' = "\\_{}" -protectChar x = [x] - --- Syntax analysis - --- | Look into a 'LaTeX' syntax tree to find any call to the command with --- the given name. It returns a list of arguments with which this command --- is called. --- --- > lookForCommand = (fmap snd .) . matchCommand . (==) --- --- If the returned list is empty, the command was not found. However, --- if the list contains empty lists, those are callings to the command --- with no arguments. --- --- For example --- --- > lookForCommand "author" l --- --- would look for the argument passed to the @\\author@ command in @l@. -lookForCommand :: String -- ^ Name of the command. - -> LaTeX -- ^ LaTeX syntax tree. - -> [[TeXArg]] -- ^ List of arguments passed to the command. -lookForCommand = (fmap snd .) . matchCommand . (==) - --- | Traverse a 'LaTeX' syntax tree and returns the commands (see 'TeXComm' and --- 'TeXCommS') that matches the condition and their arguments in each call. -matchCommand :: (String -> Bool) -> LaTeX -> [(String,[TeXArg])] -matchCommand f (TeXComm str as) = - let xs = concatMap (matchCommandArg f) as - in if f str then (str,as) : xs else xs -matchCommand f (TeXCommS str) = if f str then [(str,[])] else [] -matchCommand f (TeXEnv _ as l) = - let xs = concatMap (matchCommandArg f) as - in xs ++ matchCommand f l -matchCommand f (TeXMath _ l) = matchCommand f l -matchCommand f (TeXBraces l) = matchCommand f l -matchCommand f (TeXSeq l1 l2) = matchCommand f l1 ++ matchCommand f l2 -matchCommand _ _ = [] - -matchCommandArg :: (String -> Bool) -> TeXArg -> [(String,[TeXArg])] -matchCommandArg f (OptArg l ) = matchCommand f l -matchCommandArg f (FixArg l ) = matchCommand f l -matchCommandArg f (MOptArg ls) = concatMap (matchCommand f) ls -matchCommandArg f (SymArg l ) = matchCommand f l -matchCommandArg f (MSymArg ls) = concatMap (matchCommand f) ls - --- | Similar to 'lookForCommand', but applied to environments. --- It returns a list with arguments passed and content of the --- environment in each call. --- --- > lookForEnv = (fmap (\(_,as,l) -> (as,l)) .) . matchEnv . (==) --- -lookForEnv :: String -> LaTeX -> [([TeXArg],LaTeX)] -lookForEnv = (fmap (\(_,as,l) -> (as,l)) .) . matchEnv . (==) - --- | Traverse a 'LaTeX' syntax tree and returns the environments (see --- 'TeXEnv') that matches the condition, their arguments and their content --- in each call. -matchEnv :: (String -> Bool) -> LaTeX -> [(String,[TeXArg],LaTeX)] -matchEnv f (TeXComm _ as) = concatMap (matchEnvArg f) as -matchEnv f (TeXEnv str as l) = - let xs = concatMap (matchEnvArg f) as - ys = matchEnv f l - zs = xs ++ ys - in if f str then (str,as,l) : zs else zs -matchEnv f (TeXMath _ l) = matchEnv f l -matchEnv f (TeXBraces l) = matchEnv f l -matchEnv f (TeXSeq l1 l2) = matchEnv f l1 ++ matchEnv f l2 -matchEnv _ _ = [] - -matchEnvArg :: (String -> Bool) -> TeXArg -> [(String,[TeXArg],LaTeX)] -matchEnvArg f (OptArg l ) = matchEnv f l -matchEnvArg f (FixArg l ) = matchEnv f l -matchEnvArg f (MOptArg ls) = concatMap (matchEnv f) ls -matchEnvArg f (SymArg l ) = matchEnv f l -matchEnvArg f (MSymArg ls) = concatMap (matchEnv f) ls - --- | The function 'texmap' looks for subexpressions that match a given --- condition and applies a function to them. --- --- > texmap c f = runIdentity . texmapM c (pure . f) -texmap :: (LaTeX -> Bool) -- ^ Condition. - -> (LaTeX -> LaTeX) -- ^ Function to apply when the condition matches. - -> LaTeX -> LaTeX -texmap c f = runIdentity . texmapM c (pure . f) - --- | Version of 'texmap' where the function returns values in a 'Monad'. -texmapM :: (Applicative m, Monad m) - => (LaTeX -> Bool) -- ^ Condition. - -> (LaTeX -> m LaTeX) -- ^ Function to apply when the condition matches. - -> LaTeX -> m LaTeX -texmapM c f = go - where - go l@(TeXComm str as) = if c l then f l else TeXComm str <$> mapM go' as - go l@(TeXEnv str as b) = if c l then f l else TeXEnv str <$> mapM go' as <*> go b - go l@(TeXMath t b) = if c l then f l else TeXMath t <$> go b - go l@(TeXBraces b) = if c l then f l else TeXBraces <$> go b - go l@(TeXSeq l1 l2) = if c l then f l else liftA2 TeXSeq (go l1) (go l2) - go l = if c l then f l else pure l - -- - go' (FixArg l ) = FixArg <$> go l - go' (OptArg l ) = OptArg <$> go l - go' (MOptArg ls) = MOptArg <$> mapM go ls - go' (SymArg l ) = SymArg <$> go l - go' (MSymArg ls) = MSymArg <$> mapM go ls - --- | Extract the content of the 'document' environment, if present. -getBody :: LaTeX -> Maybe LaTeX -getBody l = - case lookForEnv "document" l of - ((_,b):_) -> Just b - _ -> Nothing - --- | Extract the preamble of a 'LaTeX' document (everything before the 'document' --- environment). It could be empty. -getPreamble :: LaTeX -> LaTeX -getPreamble (TeXEnv "document" _ _) = mempty -getPreamble (TeXSeq l1 l2) = getPreamble l1 <> getPreamble l2 -getPreamble l = l - ---------------------------------------- --- LaTeX Arbitrary instance - -arbitraryChar :: Gen Char -arbitraryChar = elements $ - ['A'..'Z'] - ++ ['a'..'z'] - ++ "\n-+*/!\"$%&(){}^_.,:;'#@<>?\\ " - --- | Utility for the instance of 'LaTeX' to 'Arbitrary'. --- We generate a short sequence of characters and --- escape reserved characters with 'protectText'. -arbitraryRaw :: Gen Text -arbitraryRaw = do - n <- choose (1,20) - protectText . pack <$> replicateM n arbitraryChar - --- | Generator for names of command and environments. --- We use only alphabetical characters. -arbitraryName :: Gen String -arbitraryName = do - n <- choose (1,10) - replicateM n $ elements $ ['a' .. 'z'] ++ ['A' .. 'Z'] - -instance Arbitrary Measure where - arbitrary = do - n <- choose (0,5) - let f = [Pt,Mm,Cm,In,Ex,Em] !! n - f <$> arbitrary - -instance Arbitrary LaTeX where - arbitrary = do - -- We give more chances to 'TeXRaw'. - -- This results in arbitrary 'LaTeX' values - -- not getting too large. - n <- choose (0,16 :: Int) - case n of - 0 -> pure TeXEmpty - 1 -> do m <- choose (0,5) - TeXComm <$> arbitraryName <*> vectorOf m arbitrary - 2 -> TeXCommS <$> arbitraryName - 3 -> do m <- choose (0,5) - TeXEnv <$> arbitraryName <*> vectorOf m arbitrary <*> arbitrary - 4 -> do m <- choose (0,2) - let t = [Parentheses,Square,Dollar] !! m - TeXMath <$> pure t <*> arbitrary - 5 -> TeXLineBreak <$> arbitrary <*> arbitrary - 6 -> TeXBraces <$> arbitrary - 7 -> TeXComment <$> arbitraryRaw - 8 -> TeXSeq <$> arbitrary <*> arbitrary - _ -> TeXRaw <$> arbitraryRaw - -instance Arbitrary TeXArg where - arbitrary = do - n <- choose (0,4 :: Int) - case n of - 0 -> OptArg <$> arbitrary - 1 -> do m <- choose (1,5) - MOptArg <$> vectorOf m arbitrary - 2 -> SymArg <$> arbitrary - 3 -> do m <- choose (1,5) - MSymArg <$> vectorOf m arbitrary - _ -> FixArg <$> arbitrary ++{-# LANGUAGE CPP, DeriveDataTypeable #-}++-- | 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+ Measure (..)+ , MathType (..)+ , LaTeX (..)+ , TeXArg (..)+ , (<>)+ -- * Escaping reserved characters+ , protectString+ , protectText+ -- * Syntax analysis+ , matchCommand+ , lookForCommand+ , matchEnv+ , lookForEnv+ , texmap+ , texmapM+ -- ** Utils+ , getBody+ , getPreamble+ ) where++import Data.Text (Text,pack)+import qualified Data.Text+import Data.Monoid+import Data.String+import Control.Applicative+import Control.Monad (replicateM)+import Data.Functor.Identity (runIdentity)+import Data.Typeable+import Test.QuickCheck++-- | Measure units defined in LaTeX. Use 'CustomMeasure' to use commands like 'textwidth'.+-- For instance:+--+-- > rule Nothing (CustomMeasure linewidth) (Pt 2)+--+-- This will create a black box (see 'rule') as wide as the text and two points tall.+--+data Measure =+ Pt Double -- ^ A point is 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm.+ | Mm Double -- ^ Millimeter.+ | Cm Double -- ^ Centimeter.+ | In Double -- ^ Inch.+ | Ex Double -- ^ The height of an \"x\" in the current font.+ | Em Double -- ^ The width of an \"M\" in the current font.+ | CustomMeasure LaTeX -- ^ You can introduce a 'LaTeX' expression as a measure.+ deriving (Eq, Show)++-- | Different types of syntax for mathematical expressions.+data MathType = Parentheses | Square | Dollar+ deriving (Eq,Show)++-- | Type of @LaTeX@ blocks.+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 -- ^ Constructor for commands with no arguments.+ -- When rendering, no space or @{}@ will be added at+ -- the end.+ | TeXEnv String [TeXArg] LaTeX -- ^ Constructor for environments.+ -- First argument is the name of the environment.+ -- Second, its arguments.+ -- Third, its content.+ | TeXMath MathType LaTeX -- ^ Mathematical expressions.+ | TeXLineBreak (Maybe Measure) Bool -- ^ Line break command.+ | TeXBraces LaTeX -- ^ A expression between braces.+ | TeXComment Text -- ^ Comments.+ | TeXSeq LaTeX LaTeX -- ^ Sequencing of 'LaTeX' expressions.+ -- Use '<>' preferably.+ | TeXEmpty -- ^ An empty block.+ -- /Neutral element/ of '<>'.+ deriving (Eq,Show,Typeable)++-- | An argument for a 'LaTeX' command or environment.+data TeXArg =+ FixArg LaTeX -- ^ Fixed argument.+ | OptArg LaTeX -- ^ Optional argument.+ | MOptArg [LaTeX] -- ^ Multiple optional argument.+ | SymArg LaTeX -- ^ An argument enclosed between @\<@ and @\>@.+ | MSymArg [LaTeX] -- ^ Version of 'SymArg' with multiple options.+ | ParArg LaTeX -- ^ An argument enclosed between @(@ and @)@.+ | MParArg [LaTeX] -- ^ Version of 'ParArg' with multiple options.+ deriving (Eq,Show)++-- Monoid instance for 'LaTeX'.++-- | Method 'mappend' is strict in both arguments (except in the case when the first argument is 'TeXEmpty').+instance Monoid LaTeX where+ mempty = TeXEmpty+ mappend TeXEmpty x = x+ mappend x TeXEmpty = x+ -- This equation is to make 'mappend' associative.+ mappend (TeXSeq x y) z = TeXSeq x $ mappend y z+ --+ mappend x y = TeXSeq x y++-- Since GHC starting from 7.4 provides (<>) as synonym to 'mappend' (see "Data.Monoid"),+-- we avoid an overlapping definition with a CPP conditional.+#if __GLASGOW_HASKELL__ < 704+-- | Alias for 'mappend'.+(<>) :: Monoid a => a -> a -> a+(<>) = mappend+#endif++-- | Method 'fromString' escapes LaTeX reserved characters using 'protectString'.+instance IsString LaTeX where+ fromString = TeXRaw . fromString . protectString++-- | Escape LaTeX reserved characters in a 'String'.+protectString :: String -> String+protectString = mconcat . fmap protectChar++-- | Escape LaTeX reserved characters in a 'Text'.+protectText :: Text -> Text+protectText = Data.Text.concatMap (fromString . protectChar)++protectChar :: Char -> String+protectChar '#' = "\\#"+protectChar '$' = "\\$"+protectChar '%' = "\\%"+protectChar '^' = "\\^{}"+protectChar '&' = "\\&"+protectChar '{' = "\\{"+protectChar '}' = "\\}"+protectChar '~' = "\\~{}"+protectChar '\\' = "\\textbackslash{}"+protectChar '_' = "\\_{}"+protectChar x = [x]++-- Syntax analysis++-- | Look into a 'LaTeX' syntax tree to find any call to the command with+-- the given name. It returns a list of arguments with which this command+-- is called.+--+-- > lookForCommand = (fmap snd .) . matchCommand . (==)+--+-- If the returned list is empty, the command was not found. However,+-- if the list contains empty lists, those are callings to the command+-- with no arguments.+--+-- For example+--+-- > lookForCommand "author" l+--+-- would look for the argument passed to the @\\author@ command in @l@.+lookForCommand :: String -- ^ Name of the command.+ -> LaTeX -- ^ LaTeX syntax tree.+ -> [[TeXArg]] -- ^ List of arguments passed to the command.+lookForCommand = (fmap snd .) . matchCommand . (==)++-- | Traverse a 'LaTeX' syntax tree and returns the commands (see 'TeXComm' and+-- 'TeXCommS') that matches the condition and their arguments in each call.+matchCommand :: (String -> Bool) -> LaTeX -> [(String,[TeXArg])]+matchCommand f (TeXComm str as) =+ let xs = concatMap (matchCommandArg f) as+ in if f str then (str,as) : xs else xs+matchCommand f (TeXCommS str) = if f str then [(str,[])] else []+matchCommand f (TeXEnv _ as l) =+ let xs = concatMap (matchCommandArg f) as+ in xs ++ matchCommand f l+matchCommand f (TeXMath _ l) = matchCommand f l+matchCommand f (TeXBraces l) = matchCommand f l+matchCommand f (TeXSeq l1 l2) = matchCommand f l1 ++ matchCommand f l2+matchCommand _ _ = []++matchCommandArg :: (String -> Bool) -> TeXArg -> [(String,[TeXArg])]+matchCommandArg f (OptArg l ) = matchCommand f l+matchCommandArg f (FixArg l ) = matchCommand f l+matchCommandArg f (MOptArg ls) = concatMap (matchCommand f) ls+matchCommandArg f (SymArg l ) = matchCommand f l+matchCommandArg f (MSymArg ls) = concatMap (matchCommand f) ls+matchCommandArg f (ParArg l ) = matchCommand f l+matchCommandArg f (MParArg ls) = concatMap (matchCommand f) ls++-- | Similar to 'lookForCommand', but applied to environments.+-- It returns a list with arguments passed and content of the+-- environment in each call.+--+-- > lookForEnv = (fmap (\(_,as,l) -> (as,l)) .) . matchEnv . (==)+--+lookForEnv :: String -> LaTeX -> [([TeXArg],LaTeX)]+lookForEnv = (fmap (\(_,as,l) -> (as,l)) .) . matchEnv . (==)++-- | Traverse a 'LaTeX' syntax tree and returns the environments (see+-- 'TeXEnv') that matches the condition, their arguments and their content+-- in each call.+matchEnv :: (String -> Bool) -> LaTeX -> [(String,[TeXArg],LaTeX)]+matchEnv f (TeXComm _ as) = concatMap (matchEnvArg f) as+matchEnv f (TeXEnv str as l) =+ let xs = concatMap (matchEnvArg f) as+ ys = matchEnv f l+ zs = xs ++ ys+ in if f str then (str,as,l) : zs else zs+matchEnv f (TeXMath _ l) = matchEnv f l+matchEnv f (TeXBraces l) = matchEnv f l+matchEnv f (TeXSeq l1 l2) = matchEnv f l1 ++ matchEnv f l2+matchEnv _ _ = []++matchEnvArg :: (String -> Bool) -> TeXArg -> [(String,[TeXArg],LaTeX)]+matchEnvArg f (OptArg l ) = matchEnv f l+matchEnvArg f (FixArg l ) = matchEnv f l+matchEnvArg f (MOptArg ls) = concatMap (matchEnv f) ls+matchEnvArg f (SymArg l ) = matchEnv f l+matchEnvArg f (MSymArg ls) = concatMap (matchEnv f) ls+matchEnvArg f (ParArg l ) = matchEnv f l+matchEnvArg f (MParArg ls) = concatMap (matchEnv f) ls++-- | The function 'texmap' looks for subexpressions that match a given+-- condition and applies a function to them.+--+-- > texmap c f = runIdentity . texmapM c (pure . f)+texmap :: (LaTeX -> Bool) -- ^ Condition.+ -> (LaTeX -> LaTeX) -- ^ Function to apply when the condition matches.+ -> LaTeX -> LaTeX+texmap c f = runIdentity . texmapM c (pure . f)++-- | Version of 'texmap' where the function returns values in a 'Monad'.+texmapM :: (Applicative m, Monad m)+ => (LaTeX -> Bool) -- ^ Condition.+ -> (LaTeX -> m LaTeX) -- ^ Function to apply when the condition matches.+ -> LaTeX -> m LaTeX+texmapM c f = go+ where+ go l@(TeXComm str as) = if c l then f l else TeXComm str <$> mapM go' as+ go l@(TeXEnv str as b) = if c l then f l else TeXEnv str <$> mapM go' as <*> go b+ go l@(TeXMath t b) = if c l then f l else TeXMath t <$> go b+ go l@(TeXBraces b) = if c l then f l else TeXBraces <$> go b+ go l@(TeXSeq l1 l2) = if c l then f l else liftA2 TeXSeq (go l1) (go l2)+ go l = if c l then f l else pure l+ --+ go' (FixArg l ) = FixArg <$> go l+ go' (OptArg l ) = OptArg <$> go l+ go' (MOptArg ls) = MOptArg <$> mapM go ls+ go' (SymArg l ) = SymArg <$> go l+ go' (MSymArg ls) = MSymArg <$> mapM go ls+ go' (ParArg l ) = ParArg <$> go l+ go' (MParArg ls) = MParArg <$> mapM go ls++-- | Extract the content of the 'document' environment, if present.+getBody :: LaTeX -> Maybe LaTeX+getBody l =+ case lookForEnv "document" l of+ ((_,b):_) -> Just b+ _ -> Nothing++-- | Extract the preamble of a 'LaTeX' document (everything before the 'document'+-- environment). It could be empty.+getPreamble :: LaTeX -> LaTeX+getPreamble (TeXEnv "document" _ _) = mempty+getPreamble (TeXSeq l1 l2) = getPreamble l1 <> getPreamble l2+getPreamble l = l++---------------------------------------+-- LaTeX Arbitrary instance++arbitraryChar :: Gen Char+arbitraryChar = elements $+ ['A'..'Z']+ ++ ['a'..'z']+ ++ "\n-+*/!\"$%&(){}^_.,:;'#@<>?\\ "++-- | Utility for the instance of 'LaTeX' to 'Arbitrary'.+-- We generate a short sequence of characters and+-- escape reserved characters with 'protectText'.+arbitraryRaw :: Gen Text+arbitraryRaw = do+ n <- choose (1,20)+ protectText . pack <$> replicateM n arbitraryChar++-- | Generator for names of command and environments.+-- We use only alphabetical characters.+arbitraryName :: Gen String+arbitraryName = do+ n <- choose (1,10)+ replicateM n $ elements $ ['a' .. 'z'] ++ ['A' .. 'Z']++instance Arbitrary Measure where+ arbitrary = do+ n <- choose (0,5)+ let f = [Pt,Mm,Cm,In,Ex,Em] !! n+ f <$> arbitrary++instance Arbitrary LaTeX where+ arbitrary = do+ -- We give more chances to 'TeXRaw'.+ -- This results in arbitrary 'LaTeX' values+ -- not getting too large.+ n <- choose (0,16 :: Int)+ case n of+ 0 -> pure TeXEmpty+ 1 -> do m <- choose (0,5)+ TeXComm <$> arbitraryName <*> vectorOf m arbitrary+ 2 -> TeXCommS <$> arbitraryName+ 3 -> do m <- choose (0,5)+ TeXEnv <$> arbitraryName <*> vectorOf m arbitrary <*> arbitrary+ 4 -> do m <- choose (0,2)+ let t = [Parentheses,Square,Dollar] !! m+ TeXMath <$> pure t <*> arbitrary+ 5 -> TeXLineBreak <$> arbitrary <*> arbitrary+ 6 -> TeXBraces <$> arbitrary+ 7 -> TeXComment <$> arbitraryRaw+ 8 -> TeXSeq <$> arbitrary <*> arbitrary+ _ -> TeXRaw <$> arbitraryRaw++instance Arbitrary TeXArg where+ arbitrary = do+ n <- choose (0,6 :: Int)+ case n of+ 0 -> OptArg <$> arbitrary+ 1 -> do m <- choose (1,5)+ MOptArg <$> vectorOf m arbitrary+ 2 -> SymArg <$> arbitrary+ 3 -> do m <- choose (1,5)+ MSymArg <$> vectorOf m arbitrary+ 4 -> ParArg <$> arbitrary+ 5 -> do m <- choose (1,5)+ MParArg <$> vectorOf m arbitrary+ _ -> FixArg <$> arbitrary
Text/LaTeX/Base/Types.hs view
@@ -1,81 +1,81 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | Some types shared along the library. -module Text.LaTeX.Base.Types ( - ClassName - , PackageName - , PageStyle - , Label - , createLabel , labelName - , Pos (..) , HPos (..) - , TableSpec (..) - , Measure (..) - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Render - --- | Class names are represented by a 'String'. -type ClassName = String - --- | Package names are represented by a 'String'. -type PackageName = String - --- | Page styles are represented by a 'String'. -type PageStyle = String - --- | Type of labels. -newtype Label = Label String deriving (Eq, Show) - --- | Create a label from its name. -createLabel :: String -> Label -createLabel = Label - --- | Get the name of a label. -labelName :: Label -> String -labelName (Label str) = str - -instance Render Label where - render (Label str) = fromString str - -instance IsString Label where - fromString = createLabel - --- | Vertical position. -data Pos = Bottom | Center | Top deriving Show - -instance Render Pos where - render Bottom = "b" - render Center = "c" - render Top = "t" - --- | Horizontal position. -data HPos = HLeft | HCenter | HRight deriving Show - -instance Render HPos where - render HLeft = "l" - render HCenter = "c" - render HRight = "r" - --- | Type of table specifications. -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 = "||" ++{-# LANGUAGE OverloadedStrings #-}++-- | Some types shared along the library.+module Text.LaTeX.Base.Types (+ ClassName+ , PackageName+ , PageStyle+ , Label+ , createLabel , labelName+ , Pos (..) , HPos (..)+ , TableSpec (..)+ , Measure (..)+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Render++-- | Class names are represented by a 'String'.+type ClassName = String++-- | Package names are represented by a 'String'.+type PackageName = String++-- | Page styles are represented by a 'String'.+type PageStyle = String++-- | Type of labels.+newtype Label = Label String deriving (Eq, Show)++-- | Create a label from its name.+createLabel :: String -> Label+createLabel = Label++-- | Get the name of a label.+labelName :: Label -> String+labelName (Label str) = str++instance Render Label where+ render (Label str) = fromString str++instance IsString Label where+ fromString = createLabel++-- | Vertical position.+data Pos = Bottom | Center | Top deriving Show++instance Render Pos where+ render Bottom = "b"+ render Center = "c"+ render Top = "t"++-- | Horizontal position.+data HPos = HLeft | HCenter | HRight deriving Show++instance Render HPos where+ render HLeft = "l"+ render HCenter = "c"+ render HRight = "r"++-- | Type of table specifications.+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 = "||"
Text/LaTeX/Base/Warnings.hs view
@@ -1,146 +1,146 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | This module provides functionality for check a 'LaTeX' value for --- possibly undesired things (like the call to an undefined label), --- returning 'Warning's. These are called 'Warning's because they --- never terminate the program execution. -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) - --- | Check with 'checkLabels', 'checkClass' and 'checkDoc'. -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 - _ -> return () -labcheck (TeXEnv _ _ l) = labcheck l -labcheck (TeXMath _ l) = labcheck l -labcheck (TeXBraces l) = labcheck l -labcheck (TeXSeq l1 l2) = labcheck l1 >> labcheck l2 -labcheck _ = return () - -newlab :: Text -> LabSt () -newlab t = do - st <- get - let addLab :: Text -> [LabWarn] -> [LabWarn] - addLab n [] = [LabelNoRef n] - addLab n l@(x:xs) = let ys = x : addLab n xs in - case x of - RefNoLabel m -> if n == m then LabelRef n : xs - else ys - LabelNoRef m -> if n == m then l - else ys - LabelRef m -> if n == m then l - else ys - put $ addLab t st - -newref :: Text -> LabSt () -newref t = do - st <- get - let addRef :: Text -> [LabWarn] -> [LabWarn] - addRef n [] = [RefNoLabel n] - addRef n l@(x:xs) = let ys = x : addRef n xs in - case x of - RefNoLabel m -> if n == m then l - else ys - LabelNoRef m -> if n == m then LabelRef n : xs - else ys - LabelRef m -> if n == m then l - else ys - put $ addRef t st - ++{-# LANGUAGE OverloadedStrings #-}++-- | This module provides functionality for check a 'LaTeX' value for+-- possibly undesired things (like the call to an undefined label),+-- returning 'Warning's. These are called 'Warning's because they+-- never terminate the program execution.+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)++-- | Check with 'checkLabels', 'checkClass' and 'checkDoc'.+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+ _ -> return ()+labcheck (TeXEnv _ _ l) = labcheck l+labcheck (TeXMath _ l) = labcheck l+labcheck (TeXBraces l) = labcheck l+labcheck (TeXSeq l1 l2) = labcheck l1 >> labcheck l2+labcheck _ = return ()++newlab :: Text -> LabSt ()+newlab t = do+ st <- get+ let addLab :: Text -> [LabWarn] -> [LabWarn]+ addLab n [] = [LabelNoRef n]+ addLab n l@(x:xs) = let ys = x : addLab n xs in+ case x of+ RefNoLabel m -> if n == m then LabelRef n : xs+ else ys+ LabelNoRef m -> if n == m then l+ else ys+ LabelRef m -> if n == m then l+ else ys+ put $ addLab t st++newref :: Text -> LabSt ()+newref t = do+ st <- get+ let addRef :: Text -> [LabWarn] -> [LabWarn]+ addRef n [] = [RefNoLabel n]+ addRef n l@(x:xs) = let ys = x : addRef n xs in+ case x of+ RefNoLabel m -> if n == m then l+ else ys+ LabelNoRef m -> if n == m then LabelRef n : xs+ else ys+ LabelRef m -> if n == m then l+ else ys+ put $ addRef t st+
Text/LaTeX/Base/Writer.hs view
@@ -1,208 +1,208 @@- -{-# LANGUAGE TypeFamilies #-} - --- | The writer monad applied to 'LaTeX' values. Useful to compose 'LaTeX' values --- using the @do@ notation: --- --- > anExample :: Monad m => LaTeXT m () --- > anExample = do --- > documentclass [] article --- > author "Daniel Monad" --- > title "LaTeX and do notation" --- > document $ do --- > maketitle --- > section "Some words" --- > "Using " ; texttt "do" ; " notation " --- > "you avoid many ocurrences of the " --- > texttt "(<>)" ; " operator and a lot of " --- > "parentheses. With the cost of a monad." --- --- Since 'LaTeXT' is a monad transformer, you can do also: --- --- > anotherExample :: LaTeXT IO () --- > anotherExample = lift (readFileTex "foo") >>= verbatim --- --- This way, it is easy (without carrying arguments) to include IO outputs --- in the LaTeX document, like files, times or random objects. --- --- Another approach could be to have custom counters, label management --- or any other user-defined feature. --- --- Of course, you can always use the simpler interface provided by the plain 'LaTeX' type. --- -module Text.LaTeX.Base.Writer - ( -- * @LaTeXT@ writer - LaTeXT - , runLaTeXT - , execLaTeXT - -- ** Synonyms - , LaTeXT_ - , LaTeXM - , runLaTeXM - , execLaTeXM - -- * Utils - , execLaTeXTWarn - , extractLaTeX - , extractLaTeX_ - , textell - , rendertexM - , liftFun - , liftOp - -- * Re-exports - , lift - , liftIO - ) where - --- base -import Control.Applicative -import Control.Monad (liftM) -import Control.Arrow -import Data.String -import Data.Monoid --- transformers -import Control.Monad.Trans.Writer -import Control.Monad.IO.Class -import Control.Monad.Trans.Class -import Data.Functor.Identity --- HaTeX -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Warnings (Warning,checkAll,check) - --- | 'WriterT' monad transformer applied to 'LaTeX' values. -newtype LaTeXT m a = - LaTeXT { unwrapLaTeXT :: WriterT LaTeX m a } - -instance Functor f => Functor (LaTeXT f) where - fmap f = LaTeXT . fmap f . unwrapLaTeXT - -instance Applicative f => Applicative (LaTeXT f) where - pure = LaTeXT . pure - (LaTeXT f) <*> (LaTeXT x) = LaTeXT $ f <*> x - --- | Type synonym for empty 'LaTeXT' computations. -type LaTeXT_ m = LaTeXT m () - --- | The 'LaTeXT' monad transformed applied to 'Identity'. -type LaTeXM = LaTeXT Identity - --- | A particular case of 'runLaTeXT'. --- --- > runLaTeXM = runIdentity . runLaTeXT --- -runLaTeXM :: LaTeXM a -> (a, LaTeX) -runLaTeXM = runIdentity . runLaTeXT - --- | A particular case of 'execLaTeXT'. --- --- > execLaTeXM = runIdentity . execLaTeXT --- -execLaTeXM :: LaTeXM a -> LaTeX -execLaTeXM = runIdentity . execLaTeXT - -instance MonadTrans LaTeXT where - lift = LaTeXT . lift - -instance Monad m => Monad (LaTeXT m) where - return = LaTeXT . return - (LaTeXT c) >>= f = LaTeXT $ do - a <- c - let LaTeXT c' = f a - c' - fail = return . error - -instance MonadIO m => MonadIO (LaTeXT m) where - liftIO = lift . liftIO - -instance (Monad m, a ~ ()) => LaTeXC (LaTeXT m a) where - liftListL f xs = mapM extractLaTeX_ xs >>= textell . f - --- | Running a 'LaTeXT' computation returns the final 'LaTeX' value. -runLaTeXT :: Monad m => LaTeXT m a -> m (a,LaTeX) -runLaTeXT = runWriterT . unwrapLaTeXT - --- | This is the usual way to run the 'LaTeXT' monad --- and obtain a 'LaTeX' value. --- --- > 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 - --- | Version of 'execLaTeXT' with possible warning messages. --- This function applies 'checkAll' to the 'LaTeX' output. -execLaTeXTWarn :: Monad m => LaTeXT m a -> m (LaTeX,[Warning]) -execLaTeXTWarn = liftM (id &&& check checkAll) . execLaTeXT - --- | This function run a 'LaTeXT' computation, --- lifting the result again in the monad. -extractLaTeX :: Monad m => LaTeXT m a -> LaTeXT m (a,LaTeX) -extractLaTeX = LaTeXT . lift . runWriterT . unwrapLaTeXT - --- | 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 - --- | With 'textell' you can append 'LaTeX' values to the --- state of the 'LaTeXT' monad. -textell :: Monad m => LaTeX -> LaTeXT m () -textell = LaTeXT . tell - --- | Lift a function over 'LaTeX' values to a function --- acting over the state of a 'LaTeXT' computation. -liftFun :: Monad m - => (LaTeX -> LaTeX) - -> (LaTeXT m a -> LaTeXT m a) -liftFun f (LaTeXT c) = LaTeXT $ do - (p,l) <- lift $ runWriterT c - tell $ f l - return p - --- | Lift an operator over 'LaTeX' values to an operator --- acting over the state of two 'LaTeXT' computations. --- --- /Note: The returned value is the one returned by the/ --- /second argument of the lifted operator./ -liftOp :: Monad m - => (LaTeX -> LaTeX -> LaTeX) - -> (LaTeXT m a -> LaTeXT m b -> LaTeXT m b) -liftOp op (LaTeXT c) (LaTeXT c') = LaTeXT $ do - (_,l) <- lift $ runWriterT c - (p,l') <- lift $ runWriterT c' - tell $ l `op` l' - return p - --- | Just like 'rendertex', but with 'LaTeXT' output. --- --- > rendertexM = textell . rendertex --- -rendertexM :: (Render a, Monad m) => a -> LaTeXT m () -rendertexM = textell . rendertex - --- Overloaded Strings - -instance (Monad m, a ~ ()) => IsString (LaTeXT m a) where - fromString = textell . fromString - --- Monoids - -instance (Monad m, a ~ ()) => Monoid (LaTeXT m a) where - mempty = return () - mappend = (>>) - ++{-# LANGUAGE TypeFamilies #-}++-- | The writer monad applied to 'LaTeX' values. Useful to compose 'LaTeX' values+-- using the @do@ notation:+--+-- > anExample :: Monad m => LaTeXT m ()+-- > anExample = do+-- > documentclass [] article+-- > author "Daniel Monad"+-- > title "LaTeX and do notation"+-- > document $ do+-- > maketitle+-- > section "Some words"+-- > "Using " ; texttt "do" ; " notation "+-- > "you avoid many ocurrences of the "+-- > texttt "(<>)" ; " operator and a lot of "+-- > "parentheses. With the cost of a monad."+--+-- Since 'LaTeXT' is a monad transformer, you can do also:+--+-- > anotherExample :: LaTeXT IO ()+-- > anotherExample = lift (readFileTex "foo") >>= verbatim+--+-- This way, it is easy (without carrying arguments) to include IO outputs+-- in the LaTeX document, like files, times or random objects.+--+-- Another approach could be to have custom counters, label management+-- or any other user-defined feature.+--+-- Of course, you can always use the simpler interface provided by the plain 'LaTeX' type.+--+module Text.LaTeX.Base.Writer+ ( -- * @LaTeXT@ writer+ LaTeXT+ , runLaTeXT+ , execLaTeXT+ -- ** Synonyms+ , LaTeXT_+ , LaTeXM+ , runLaTeXM+ , execLaTeXM+ -- * Utils+ , execLaTeXTWarn+ , extractLaTeX+ , extractLaTeX_+ , textell+ , rendertexM+ , liftFun+ , liftOp+ -- * Re-exports+ , lift+ , liftIO+ ) where++-- base+import Control.Applicative+import Control.Monad (liftM)+import Control.Arrow+import Data.String+import Data.Monoid+-- transformers+import Control.Monad.Trans.Writer+import Control.Monad.IO.Class+import Control.Monad.Trans.Class+import Data.Functor.Identity+-- HaTeX+import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Warnings (Warning,checkAll,check)++-- | 'WriterT' monad transformer applied to 'LaTeX' values.+newtype LaTeXT m a =+ LaTeXT { unwrapLaTeXT :: WriterT LaTeX m a }++instance Functor f => Functor (LaTeXT f) where+ fmap f = LaTeXT . fmap f . unwrapLaTeXT++instance Applicative f => Applicative (LaTeXT f) where+ pure = LaTeXT . pure+ (LaTeXT f) <*> (LaTeXT x) = LaTeXT $ f <*> x++-- | Type synonym for empty 'LaTeXT' computations.+type LaTeXT_ m = LaTeXT m ()++-- | The 'LaTeXT' monad transformed applied to 'Identity'.+type LaTeXM = LaTeXT Identity++-- | A particular case of 'runLaTeXT'.+--+-- > runLaTeXM = runIdentity . runLaTeXT+--+runLaTeXM :: LaTeXM a -> (a, LaTeX)+runLaTeXM = runIdentity . runLaTeXT++-- | A particular case of 'execLaTeXT'.+--+-- > execLaTeXM = runIdentity . execLaTeXT+--+execLaTeXM :: LaTeXM a -> LaTeX+execLaTeXM = runIdentity . execLaTeXT++instance MonadTrans LaTeXT where+ lift = LaTeXT . lift++instance Monad m => Monad (LaTeXT m) where+ return = LaTeXT . return+ (LaTeXT c) >>= f = LaTeXT $ do + a <- c+ let LaTeXT c' = f a+ c'+ fail = return . error++instance MonadIO m => MonadIO (LaTeXT m) where+ liftIO = lift . liftIO++instance (Monad m, a ~ ()) => LaTeXC (LaTeXT m a) where+ liftListL f xs = mapM extractLaTeX_ xs >>= textell . f++-- | Running a 'LaTeXT' computation returns the final 'LaTeX' value.+runLaTeXT :: Monad m => LaTeXT m a -> m (a,LaTeX)+runLaTeXT = runWriterT . unwrapLaTeXT++-- | This is the usual way to run the 'LaTeXT' monad+-- and obtain a 'LaTeX' value.+--+-- > 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++-- | Version of 'execLaTeXT' with possible warning messages.+-- This function applies 'checkAll' to the 'LaTeX' output.+execLaTeXTWarn :: Monad m => LaTeXT m a -> m (LaTeX,[Warning])+execLaTeXTWarn = liftM (id &&& check checkAll) . execLaTeXT++-- | This function run a 'LaTeXT' computation,+-- lifting the result again in the monad.+extractLaTeX :: Monad m => LaTeXT m a -> LaTeXT m (a,LaTeX)+extractLaTeX = LaTeXT . lift . runWriterT . unwrapLaTeXT++-- | 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++-- | With 'textell' you can append 'LaTeX' values to the+-- state of the 'LaTeXT' monad.+textell :: Monad m => LaTeX -> LaTeXT m ()+textell = LaTeXT . tell++-- | Lift a function over 'LaTeX' values to a function+-- acting over the state of a 'LaTeXT' computation.+liftFun :: Monad m+ => (LaTeX -> LaTeX)+ -> (LaTeXT m a -> LaTeXT m a)+liftFun f (LaTeXT c) = LaTeXT $ do+ (p,l) <- lift $ runWriterT c+ tell $ f l+ return p++-- | Lift an operator over 'LaTeX' values to an operator+-- acting over the state of two 'LaTeXT' computations.+--+-- /Note: The returned value is the one returned by the/+-- /second argument of the lifted operator./+liftOp :: Monad m+ => (LaTeX -> LaTeX -> LaTeX)+ -> (LaTeXT m a -> LaTeXT m b -> LaTeXT m b)+liftOp op (LaTeXT c) (LaTeXT c') = LaTeXT $ do+ (_,l) <- lift $ runWriterT c+ (p,l') <- lift $ runWriterT c'+ tell $ l `op` l'+ return p++-- | Just like 'rendertex', but with 'LaTeXT' output.+--+-- > rendertexM = textell . rendertex+--+rendertexM :: (Render a, Monad m) => a -> LaTeXT m ()+rendertexM = textell . rendertex++-- Overloaded Strings++instance (Monad m, a ~ ()) => IsString (LaTeXT m a) where+ fromString = textell . fromString++-- Monoids++instance (Monad m, a ~ ()) => Monoid (LaTeXT m a) where+ mempty = return ()+ mappend = (>>)+
Text/LaTeX/Packages/AMSFonts.hs view
@@ -1,34 +1,34 @@- --- | Module for the package @amsfonts@. -module Text.LaTeX.Packages.AMSFonts - ( -- * AMSFonts package - amsfonts - -- * Fonts - , mathbb - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Types - --- | AMSFonts package. --- Example: --- --- > usepackage [] amsfonts -amsfonts :: ClassName -amsfonts = "amsfonts" - --- - --- | This font is useful for representing sets like --- R (real numbers) or Z (integers). For instance: --- --- > "The set of real numbers are represented by " <> mathbb "R" <> "." --- --- Or in monadic form: --- --- > "The set of real numbers are represented by " >> mathbb "R" >> "." --- --- /Note the use of overloaded strings./ -mathbb :: LaTeXC l => l -> l -mathbb = liftL $ \l -> TeXComm "mathbb" [FixArg l] ++-- | Module for the package @amsfonts@.+module Text.LaTeX.Packages.AMSFonts+ ( -- * AMSFonts package+ amsfonts+ -- * Fonts+ , mathbb+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Types++-- | AMSFonts package.+-- Example:+--+-- > usepackage [] amsfonts+amsfonts :: ClassName+amsfonts = "amsfonts"++--++-- | This font is useful for representing sets like+-- R (real numbers) or Z (integers). For instance:+--+-- > "The set of real numbers are represented by " <> mathbb "R" <> "."+--+-- Or in monadic form:+--+-- > "The set of real numbers are represented by " >> mathbb "R" >> "."+--+-- /Note the use of overloaded strings./+mathbb :: LaTeXC l => l -> l+mathbb = liftL $ \l -> TeXComm "mathbb" [FixArg l]
Text/LaTeX/Packages/AMSMath.hs view
@@ -1,904 +1,904 @@- -{-# LANGUAGE OverloadedStrings, TypeFamilies #-} - --- | \AMSMath\ support. Also numeric instances ('Num', 'Fractional' and 'Floating') for 'LaTeX' and 'LaTeXT'. -module Text.LaTeX.Packages.AMSMath - ( -- * AMSMath package - amsmath - -- * 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. - - -- ** Brackets / delimiters - , autoParens - , autoSquareBrackets, autoBraces, autoAngleBrackets - , autoBrackets - - , langle , rangle - , lfloor , rfloor - , lceil , rceil - , dblPipe - -- ** Superscript and subscript - , (^:) , (!:) - -- ** Function symbols - -- | Some symbols are preceded with /t/ to be distinguished from - -- predefined Haskell entities (like 'sin' and 'cos'). - , tsin , arcsin - , tcos , arccos - , ttan , arctan - , cot , arccot - , tsinh , tcosh , ttanh , coth - , sec , csc - , texp - , tlog , ln - , tsqrt - -- ** Sum/Integral symbols - , tsum , sumFromTo - , prod , prodFromTo - , integral , integralFromTo - -- ** Operator symbols - -- *** Arithmetic - , pm , mp - , cdot , times , div_ - , frac - , (*:) , star - , circ , bullet - -- *** Comparison - , (=:) , (/=:) - , (<:) , (<=:) - , (>:) , (>=:) - , ll , gg - , equiv - , propto - -- *** Sets - , in_ , ni , notin - , subset , supset - , cap , cup - , setminus - -- *** Misc operators - , vee , wedge - , oplus , ominus , otimes - , oslash , odot - - -- ** Greek alphabet - -- | Functions of greek alphabet symbols. - -- - -- Uppercase versions are suffixed with @u@. - -- Variants are prefixed with @var@. - -- The function 'pi_' is ended by an underscore symbol to - -- distinguish it from the 'pi' Prelude function. - , alpha , beta , gamma - , gammau , delta , deltau - , epsilon , varepsilon , zeta - , eta , theta , vartheta , thetau - , iota , kappa , lambda - , lambdau , mu , nu - , xi , xiu , pi_ - , varpi , piu , rho - , varrho , sigma , varsigma - , sigmau , tau , upsilon - , upsilonu , phi , varphi - , phiu , chi , psi - , psiu , omega , omegau - -- ** Other symbols - , to , mapsto - , forall , exists - , dagger, ddagger - , infty - -- * Fonts - , mathdefault - , mathbf - , mathrm - , mathcal - , mathsf - , mathtt - , mathit - -- * Matrices - , pmatrix , bmatrix - , b2matrix , vmatrix - , v2matrix - ) where - -import Text.LaTeX.Base -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class - --- External imports -import Data.List -import Data.Ratio -import Data.Matrix - --- | AMSMath package. --- Example: --- --- > usepackage [] amsmath -amsmath :: PackageName -amsmath = "amsmath" - --- | Inline mathematical expressions. -math :: LaTeXC l => l -> l -math = liftL $ TeXMath Dollar - --- | Displayed mathematical expressions, i.e. in a seperate line / block. -mathDisplay :: LaTeXC l => l -> l -mathDisplay = liftL $ TeXMath Square - -------------------------------------------------------- -------- Numeric instances for LaTeX and LaTeXT -------- -------------------------------------------------------- - ------------ LaTeX instances - --- | Careful! Method 'signum' is undefined. Don't use it! --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Num LaTeX where - (+) = between "+" - (-) = between "-" - (*) = (<>) - negate = (TeXEmpty -) - fromInteger = rendertex - abs = autoBrackets "|" "|" - -- Non-defined methods - signum _ = error "Cannot use \"signum\" Num method with a LaTeX value." - --- | Division uses the LaTeX 'frac' command. --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Fractional LaTeX where - (/) = frac - fromRational = rendertex . (fromRational :: Rational -> Double) - --- | Undefined methods: 'asinh', 'atanh' and 'acosh'. --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Floating LaTeX where - pi = pi_ - exp = (texp <>) - sqrt = tsqrt Nothing - log = (tlog <>) - (**) = (^:) - logBase b x = (tlog !: b) <> x - sin = (tsin <>) - tan = (ttan <>) - cos = (tcos <>) - asin = (arcsin <>) - atan = (arctan <>) - acos = (arccos <>) - sinh = (tsinh <>) - tanh = (ttanh <>) - cosh = (tcosh <>) - -- Non-defined methods - asinh = error "Function 'asinh' is not defined in AMSMath!" - atanh = error "Function 'atabh' is not defined in AMSMath!" - acosh = error "Function 'acosh' is not defined in AMSMath!" - ------------ LaTeXT instances - --- | Warning: this instance only exists for the 'Num' instance. --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Eq (LaTeXT m a) where - _ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value." - --- | Warning: this instance only exists for the 'Num' instance. --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance Show (LaTeXT m a) where - show _ = error "Cannot use \"show\" Show method with a LaTeXT value." - --- | Careful! Method 'signum' is undefined. Don't use it! --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance (Monad m, a ~ ()) => Num (LaTeXT m a) where - (+) = liftOp (+) - (-) = liftOp (-) - (*) = (>>) - negate = liftFun negate - fromInteger = fromLaTeX . fromInteger - abs = liftFun abs - -- Non-defined methods - signum _ = error "Cannot use \"signum\" Num method with a LaTeXT value." - --- | Division uses the LaTeX 'frac' command. --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance (Monad m, a ~ ()) => Fractional (LaTeXT m a) where - (/) = liftOp (/) - fromRational = fromLaTeX . fromRational - --- | Undefined methods: 'asinh', 'atanh' and 'acosh'. --- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module. -instance (Monad m, a ~ ()) => Floating (LaTeXT m a) where - pi = pi_ - exp = liftFun exp - sqrt = liftFun sqrt - log = liftFun log - (**) = liftOp (**) - logBase = liftOp logBase - sin = liftFun sin - tan = liftFun tan - cos = liftFun cos - asin = liftFun asin - atan = liftFun atan - acos = liftFun acos - sinh = liftFun sinh - tanh = liftFun tanh - cosh = liftFun cosh - -- Non-defined methods - asinh = error "Function 'asinh' is not defined in AMSMath!" - 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 = commS "left(" <> x <> commS "right)" - --- | Like 'autoParens', but with square brackets. Equivalent to @'autoBrackets'\"[\"\"]\"@. -autoSquareBrackets :: LaTeXC l => l -> l -autoSquareBrackets x = commS "left[" <> x <> commS "right]" - --- | Like 'autoParens', but with curly brackets. -autoBraces :: LaTeXC l => l -> l -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 = 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 - = commS "left" <> braces (fromLaTeX lBrack) <> x <> commS "right" <> braces (fromLaTeX rBrack) - --- | Left angle bracket, 〈. -langle :: LaTeXC l => l -langle = comm0 "langle" - --- | Right angle bracket, 〉. -rangle :: LaTeXC l => l -rangle = comm0 "rangle" - --- | Left floor, ⌊. -lfloor :: LaTeXC l => l -lfloor = comm0 "lfloor" - --- | Right floor, ⌋. -rfloor :: LaTeXC l => l -rfloor = comm0 "rfloor" - --- | Left ceiling, ⌈. -lceil :: LaTeXC l => l -lceil = comm0 "lceil" - --- | Right ceiling, ⌉. -rceil :: LaTeXC l => l -rceil = comm0 "rceil" - --- | Double vertical line, used as delimiter for norms (‖ ... ‖). -dblPipe :: LaTeXC l => l -dblPipe = comm0 "|" - --- | Superscript. -(^:) :: LaTeXC l => l -> l -> l -x ^: y = x <> raw "^" <> braces y - --- | Subscript. -(!:) :: LaTeXC l => l -> l -> l -x !: y = x <> raw "_" <> braces y - ----- Function symbols - --- | Sine function symbol. -tsin :: LaTeXC l => l -tsin = comm0 "sin" - --- | Arcsine function symbol. -arcsin :: LaTeXC l => l -arcsin = comm0 "arcsin" - --- | Cosine function symbol. -tcos :: LaTeXC l => l -tcos = comm0 "cos" - --- | Arccosine function symbol. -arccos :: LaTeXC l => l -arccos = comm0 "arccos" - --- | Tangent function symbol. -ttan :: LaTeXC l => l -ttan = comm0 "tan" - --- | Arctangent function symbol. -arctan :: LaTeXC l => l -arctan = comm0 "arctan" - --- | Cotangent function symbol. -cot :: LaTeXC l => l -cot = comm0 "cot" - --- | Arccotangent function symbol. -arccot :: LaTeXC l => l -arccot = comm0 "arccot" - --- | Hyperbolic sine function symbol. -tsinh :: LaTeXC l => l -tsinh = comm0 "sinh" - --- | Hyperbolic cosine function symbol. -tcosh :: LaTeXC l => l -tcosh = comm0 "cosh" - --- | Hyperbolic tangent function symbol. -ttanh :: LaTeXC l => l -ttanh = comm0 "tanh" - --- | Hyperbolic cotangent function symbol. -coth :: LaTeXC l => l -coth = comm0 "coth" - --- | Secant function symbol. -sec :: LaTeXC l => l -sec = comm0 "sec" - --- | Cosecant function symbol. -csc :: LaTeXC l => l -csc = comm0 "csc" - --- | Exponential function symbol. -texp :: LaTeXC l => l -texp = comm0 "exp" - --- | Logarithm function symbol. -tlog :: LaTeXC l => l -tlog = comm0 "log" - --- | Natural logarithm symbol. -ln :: LaTeXC l => l -ln = comm0 "ln" - --- | Root notation. Use @tsqrt (Just n) x@ for the @n@th root of @x@. --- When 'Nothing' is supplied, the function will output a square root. -tsqrt :: LaTeXC l => Maybe l -> l -> l -tsqrt Nothing = liftL $ \x -> TeXComm "sqrt" [FixArg x] -tsqrt (Just n) = liftL2 (\m x -> TeXComm "sqrt" [OptArg m, FixArg x]) n - ----- Sum/Integral symbols - --- | Sigma sumation symbol. Use 'sumFromTo' instead if you want to --- specify the limits of the sum. -tsum :: LaTeXC l => l -tsum = comm0 "sum" - --- | Sigma sumation symbol with limits. -sumFromTo :: LaTeXC l - => l -- ^ Expression below the sigma. - -> l -- ^ Expression above the sigma. - -> l -sumFromTo x y = commS "sum" !: x ^: y - --- | Pi product symbol. Use 'prodFromTo' if you want to specify the --- limits of the product. -prod :: LaTeXC l => l -prod = comm0 "prod" - --- | Pi product symbol with limits. -prodFromTo :: LaTeXC l - => l -- ^ Expression below the pi. - -> l -- ^ Expression above the pi. - -> l -prodFromTo x y = commS "prod" !: x ^: y - --- | Integral symbol. Use 'integralFromTo' if you want to specify --- the limits of the integral. -integral :: LaTeXC l => l -integral = comm0 "int" - --- | Integral symbol with limits of integration. -integralFromTo :: LaTeXC l - => l -- ^ Lower limit of integration. - -> l -- ^ Upper limit of integration. - -> l -integralFromTo x y = commS "int" !: x ^: y - ----- Operator symbols - --- | Negative form of an operator. -notop :: LaTeXC l => - (l -> l -> l) - -> l -> l -> l -notop op = - \l1 l2 -> - (l1 <> commS "not") `op` l2 - --- | Plus-or-minus operator (±). -pm :: LaTeXC l => l -> l -> l -pm = between $ comm0 "pm" - --- | Minus-or-plus operator (∓). -mp :: LaTeXC l => l -> l -> l -mp = between $ comm0 "mp" - --- | Centered-dot operator (⋅). -cdot :: LaTeXC l => l -> l -> l -cdot = between $ comm0 "cdot" - --- | \"x-cross\" multiplication operator (×). -times :: LaTeXC l => l -> l -> l -times = between $ comm0 "times" - --- | Division operator. -div_ :: LaTeXC l => l -> l -> l -div_ = between $ comm0 "div" - --- | Fraction operator. -frac :: LaTeXC l => l -> l -> l -frac = liftL2 $ \p q -> TeXComm "frac" [FixArg p, FixArg q] - -infixl 7 *: - --- | Asterisk operator (*). --- --- > infixl 7 *: -(*:) :: LaTeXC l => l -> l -> l -(*:) = between $ comm0 "ast" - --- | Star operator (★). -star :: LaTeXC l => l -> l -> l -star = between $ comm0 "star" - --- | Ring operator (∘). -circ :: LaTeXC l => l -> l -> l -circ = between $ comm0 "circ" - --- | Bullet operator (∙). -bullet :: LaTeXC l => l -> l -> l -bullet = between $ comm0 "bullet" - -infixr 4 =: , /=: - --- | Equal. --- --- > infixr 4 =: -(=:) :: LaTeXC l => l -> l -> l -(=:) = between "=" - --- | Not equal (≠). --- --- > infixr 4 /=: -(/=:) :: LaTeXC l => l -> l -> l -(/=:) = notop (=:) - --- | Greater. -(>:) :: LaTeXC l => l -> l -> l -(>:) = between ">" - --- | Greater or equal (≥). -(>=:) :: LaTeXC l => l -> l -> l -(>=:) = between $ comm0 "geq" - --- | Lesser. -(<:) :: LaTeXC l => l -> l -> l -(<:) = between "<" - --- | Lesser or equal (≤). -(<=:) :: LaTeXC l => l -> l -> l -(<=:) = between $ comm0 "leq" - --- | Much less (≪). -ll :: LaTeXC l => l -> l -> l -ll = between $ comm0 "ll" - --- | Much greater (≫). -gg :: LaTeXC l => l -> l -> l -gg = between $ comm0 "gg" - --- | Proportional-to (∝). -propto :: LaTeXC l => l -> l -> l -propto = between $ comm0 "propto" - --- | Identical \/ defined-as \/ equivalent (≡). -equiv :: LaTeXC l => l -> l -> l -equiv = between $ comm0 "equiv" - --- | Element-of (∈). -in_ :: LaTeXC l => l -> l -> l -in_ = between $ comm0 "in" - --- | Mirrored element-of (∋). -ni :: LaTeXC l => l -> l -> l -ni = between $ comm0 "ni" - --- | Not element of (∉). -notin :: LaTeXC l => l -> l -> l -notin = between $ comm0 "notin" - --- | Subset-of (⊂). -subset :: LaTeXC l => l -> l -> l -subset = between $ comm0 "subset" - --- | Superset-of (⊃). -supset :: LaTeXC l => l -> l -> l -supset = between $ comm0 "supset" - --- | Set intersection (∩). -cap :: LaTeXC l => l -> l -> l -cap = between $ comm0 "cap" - --- | Set union (∪). -cup :: LaTeXC l => l -> l -> l -cup = between $ comm0 "cup" - --- | Set minus (∖). -setminus :: LaTeXC l => l -> l -> l -setminus = between $ comm0 "setminus" - --- | Angle pointing downwards (∨). -vee :: LaTeXC l => l -> l -> l -vee = between $ comm0 "vee" - --- | Angle pointing upwards (∧). -wedge :: LaTeXC l => l -> l -> l -wedge = between $ comm0 "wedge" - --- | Circled plus operator (⊕). -oplus :: LaTeXC l => l -> l -> l -oplus = between $ comm0 "oplus" - --- | Circled minus operator (⊖). -ominus :: LaTeXC l => l -> l -> l -ominus = between $ comm0 "ominus" - --- | Circled multiplication cross (⊗). -otimes :: LaTeXC l => l -> l -> l -otimes = between $ comm0 "otimes" - --- | Circled slash (⊘). -oslash :: LaTeXC l => l -> l -> l -oslash = between $ comm0 "oslash" - --- | Circled dot operator (⊙). -odot :: LaTeXC l => l -> l -> l -odot = between $ comm0 "odot" - ----- Greek alphabet - --- | /α/ symbol. -alpha :: LaTeXC l => l -alpha = comm0 "alpha" - --- | /β/ symbol. -beta :: LaTeXC l => l -beta = comm0 "beta" - --- | /γ/ symbol. -gamma :: LaTeXC l => l -gamma = comm0 "gamma" - --- | Γ symbol. -gammau :: LaTeXC l => l -gammau = comm0 "Gamma" - --- | /δ/ symbol. -delta :: LaTeXC l => l -delta = comm0 "delta" - --- | Δ symbol. -deltau :: LaTeXC l => l -deltau = comm0 "Delta" - --- | /ϵ/ symbol. -epsilon :: LaTeXC l => l -epsilon = comm0 "epsilon" - --- | /ε/ symbol. -varepsilon :: LaTeXC l => l -varepsilon = comm0 "varepsilon" - --- | /ζ/ symbol. -zeta :: LaTeXC l => l -zeta = comm0 "zeta" - --- | /η/ symbol. -eta :: LaTeXC l => l -eta = comm0 "eta" - --- | /θ/ symbol. -theta :: LaTeXC l => l -theta = comm0 "theta" - --- | /ϑ/ symbol. -vartheta :: LaTeXC l => l -vartheta = comm0 "vartheta" - --- | Θ symbol. -thetau :: LaTeXC l => l -thetau = comm0 "thetau" - --- | /ι/ symbol. -iota :: LaTeXC l => l -iota = comm0 "iota" - --- | /κ/ symbol. -kappa :: LaTeXC l => l -kappa = comm0 "kappa" - --- | /λ/ symbol. -lambda :: LaTeXC l => l -lambda = comm0 "lambda" - --- | Λ symbol. -lambdau :: LaTeXC l => l -lambdau = comm0 "Lambda" - --- | /μ/ symbol. -mu :: LaTeXC l => l -mu = comm0 "mu" - --- | /ν/ symbol. -nu :: LaTeXC l => l -nu = comm0 "nu" - --- | /ξ/ symbol. -xi :: LaTeXC l => l -xi = comm0 "xi" - --- | Ξ symbol. -xiu :: LaTeXC l => l -xiu = comm0 "Xi" - --- | /π/ symbol. -pi_ :: LaTeXC l => l -pi_ = comm0 "pi" - --- | /ϖ/ symbol. -varpi :: LaTeXC l => l -varpi = comm0 "varpi" - --- | Π symbol. -piu :: LaTeXC l => l -piu = comm0 "Pi" - --- | /ρ/ symbol. -rho :: LaTeXC l => l -rho = comm0 "rho" - --- | /ϱ/ symbol. -varrho :: LaTeXC l => l -varrho = comm0 "varrho" - --- | /σ/ symbol. -sigma :: LaTeXC l => l -sigma = comm0 "sigma" - --- | /ς/ symbol. -varsigma :: LaTeXC l => l -varsigma = comm0 "varsigma" - --- | Σ symbol. -sigmau :: LaTeXC l => l -sigmau = comm0 "Sigma" - --- | /τ/ symbol. -tau :: LaTeXC l => l -tau = comm0 "tau" - --- | /υ/ symbol. -upsilon :: LaTeXC l => l -upsilon = comm0 "upsilon" - --- | Υ symbol. -upsilonu :: LaTeXC l => l -upsilonu = comm0 "Upsilon" - --- | /ϕ/ symbol. -phi :: LaTeXC l => l -phi = comm0 "phi" - --- | /φ/ symbol. -varphi :: LaTeXC l => l -varphi = comm0 "varphi" - --- | Φ symbol. -phiu :: LaTeXC l => l -phiu = comm0 "Phi" - --- | /χ/ symbol. -chi :: LaTeXC l => l -chi = comm0 "chi" - --- | /ψ/ symbol. -psi :: LaTeXC l => l -psi = comm0 "psi" - --- | Ψ symbol. -psiu :: LaTeXC l => l -psiu = comm0 "Psi" - --- | /ω/ symbol. -omega :: LaTeXC l => l -omega = comm0 "omega" - --- | Ω symbol. -omegau :: LaTeXC l => l -omegau = comm0 "Omega" - ----- Other symbols - --- | A right-arrow, →. -to :: LaTeXC l => l -to = comm0 "to" - --- | A right-arrow for function definitions, ↦. -mapsto :: LaTeXC l => l -mapsto = comm0 "mapsto" - --- | /For all/ symbol, ∀. -forall :: LaTeXC l => l -forall = comm0 "forall" - --- | /Exists/ symbol, ∃. -exists :: LaTeXC l => l -exists = comm0 "exists" - --- | Dagger symbol, †. -dagger :: LaTeXC l => l -dagger = comm0 "dagger" - --- | Double dagger symbol, ‡. -ddagger :: LaTeXC l => l -ddagger = comm0 "ddagger" - --- | Infinity symbol. -infty :: LaTeXC l => l -infty = comm0 "infty" - -------------------------------------- ------------- Math Fonts ------------- - --- | Default math symbol font. -mathdefault :: LaTeXC l => l -> l -mathdefault = liftL $ \l -> TeXComm "mathdefault" [FixArg l] - --- | Bold face. -mathbf :: LaTeXC l => l -> l -mathbf = liftL $ \l -> TeXComm "mathbf" [FixArg l] - --- | Roman, i.e. not-italic math. -mathrm :: LaTeXC l => l -> l -mathrm = liftL $ \l -> TeXComm "mathrm" [FixArg l] - --- | Calligraphic math symbols. -mathcal :: LaTeXC l => l -> l -mathcal = liftL $ \l -> TeXComm "mathcal" [FixArg l] - --- | Sans-serif math. -mathsf :: LaTeXC l => l -> l -mathsf = liftL $ \l -> TeXComm "mathsf" [FixArg l] - --- | Typewriter font. -mathtt :: LaTeXC l => l -> l -mathtt = liftL $ \l -> TeXComm "mathtt" [FixArg l] - --- | Italic math. Uses the same glyphs as 'mathdefault', but with spacings --- intended for multi-character symbols rather than juxtaposition of single-character symbols. -mathit :: LaTeXC l => l -> l -mathit = liftL $ \l -> TeXComm "mathit" [FixArg l] - -------------------------------------- -------------- Matrices -------------- - -matrix2tex :: (Texy a, LaTeXC l) => Matrix a -> l -matrix2tex m = mconcat - [ foldr1 (&) [ texy $ m ! (i,j) - | j <- [1 .. ncols m] - ] <> lnbk - | i <- [1 .. nrows m] - ] - -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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l -pmatrix = toMatrix "pmatrix" - --- | 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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l -bmatrix = toMatrix "bmatrix" - --- | 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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l -b2matrix = toMatrix "Bmatrix" - --- | 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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l -vmatrix = toMatrix "vmatrix" - --- | 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 :: (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 ++{-# LANGUAGE OverloadedStrings, TypeFamilies #-}++-- | \AMSMath\ support. Also numeric instances ('Num', 'Fractional' and 'Floating') for 'LaTeX' and 'LaTeXT'.+module Text.LaTeX.Packages.AMSMath+ ( -- * AMSMath package+ amsmath+ -- * 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.+ + -- ** Brackets / delimiters+ , autoParens+ , autoSquareBrackets, autoBraces, autoAngleBrackets+ , autoBrackets+ + , langle , rangle+ , lfloor , rfloor+ , lceil , rceil + , dblPipe+ -- ** Superscript and subscript+ , (^:) , (!:)+ -- ** Function symbols+ -- | Some symbols are preceded with /t/ to be distinguished from+ -- predefined Haskell entities (like 'sin' and 'cos').+ , tsin , arcsin+ , tcos , arccos+ , ttan , arctan+ , cot , arccot+ , tsinh , tcosh , ttanh , coth+ , sec , csc+ , texp+ , tlog , ln+ , tsqrt+ -- ** Sum/Integral symbols+ , tsum , sumFromTo+ , prod , prodFromTo+ , integral , integralFromTo+ -- ** Operator symbols+ -- *** Arithmetic+ , pm , mp+ , cdot , times , div_+ , frac+ , (*:) , star+ , circ , bullet+ -- *** Comparison+ , (=:) , (/=:)+ , (<:) , (<=:)+ , (>:) , (>=:)+ , ll , gg+ , equiv+ , propto+ -- *** Sets+ , in_ , ni , notin+ , subset , supset+ , cap , cup+ , setminus+ -- *** Misc operators+ , vee , wedge+ , oplus , ominus , otimes+ , oslash , odot+ + -- ** Greek alphabet+ -- | Functions of greek alphabet symbols.+ --+ -- Uppercase versions are suffixed with @u@.+ -- Variants are prefixed with @var@.+ -- The function 'pi_' is ended by an underscore symbol to+ -- distinguish it from the 'pi' Prelude function.+ , alpha , beta , gamma+ , gammau , delta , deltau+ , epsilon , varepsilon , zeta+ , eta , theta , vartheta , thetau+ , iota , kappa , lambda+ , lambdau , mu , nu+ , xi , xiu , pi_+ , varpi , piu , rho+ , varrho , sigma , varsigma+ , sigmau , tau , upsilon+ , upsilonu , phi , varphi+ , phiu , chi , psi+ , psiu , omega , omegau+ -- ** Other symbols+ , to , mapsto+ , forall , exists+ , dagger, ddagger+ , infty+ -- * Fonts+ , mathdefault+ , mathbf+ , mathrm+ , mathcal+ , mathsf+ , mathtt+ , mathit+ -- * Matrices+ , pmatrix , bmatrix+ , b2matrix , vmatrix+ , v2matrix+ ) where++import Text.LaTeX.Base+import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class++-- External imports+import Data.List+import Data.Ratio+import Data.Matrix++-- | AMSMath package.+-- Example:+--+-- > usepackage [] amsmath+amsmath :: PackageName+amsmath = "amsmath"++-- | Inline mathematical expressions.+math :: LaTeXC l => l -> l+math = liftL $ TeXMath Dollar++-- | Displayed mathematical expressions, i.e. in a seperate line / block.+mathDisplay :: LaTeXC l => l -> l+mathDisplay = liftL $ TeXMath Square++-------------------------------------------------------+------- Numeric instances for LaTeX and LaTeXT --------+-------------------------------------------------------++----------- LaTeX instances++-- | Careful! Method 'signum' is undefined. Don't use it!+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance Num LaTeX where+ (+) = between "+"+ (-) = between "-"+ (*) = (<>)+ negate = (TeXEmpty -)+ fromInteger = rendertex+ abs = autoBrackets "|" "|"+ -- Non-defined methods+ signum _ = error "Cannot use \"signum\" Num method with a LaTeX value."++-- | Division uses the LaTeX 'frac' command.+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance Fractional LaTeX where+ (/) = frac+ fromRational = rendertex . (fromRational :: Rational -> Double)++-- | Undefined methods: 'asinh', 'atanh' and 'acosh'.+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance Floating LaTeX where+ pi = pi_+ exp = (texp <>)+ sqrt = tsqrt Nothing+ log = (tlog <>)+ (**) = (^:)+ logBase b x = (tlog !: b) <> x+ sin = (tsin <>)+ tan = (ttan <>)+ cos = (tcos <>)+ asin = (arcsin <>)+ atan = (arctan <>)+ acos = (arccos <>)+ sinh = (tsinh <>)+ tanh = (ttanh <>)+ cosh = (tcosh <>)+ -- Non-defined methods+ asinh = error "Function 'asinh' is not defined in AMSMath!"+ atanh = error "Function 'atabh' is not defined in AMSMath!"+ acosh = error "Function 'acosh' is not defined in AMSMath!"++----------- LaTeXT instances++-- | Warning: this instance only exists for the 'Num' instance.+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance Eq (LaTeXT m a) where+ _ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value."++-- | Warning: this instance only exists for the 'Num' instance.+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance Show (LaTeXT m a) where+ show _ = error "Cannot use \"show\" Show method with a LaTeXT value."++-- | Careful! Method 'signum' is undefined. Don't use it!+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance (Monad m, a ~ ()) => Num (LaTeXT m a) where+ (+) = liftOp (+)+ (-) = liftOp (-)+ (*) = (>>)+ negate = liftFun negate+ fromInteger = fromLaTeX . fromInteger+ abs = liftFun abs+ -- Non-defined methods+ signum _ = error "Cannot use \"signum\" Num method with a LaTeXT value."++-- | Division uses the LaTeX 'frac' command.+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance (Monad m, a ~ ()) => Fractional (LaTeXT m a) where+ (/) = liftOp (/)+ fromRational = fromLaTeX . fromRational++-- | Undefined methods: 'asinh', 'atanh' and 'acosh'.+-- This instance is defined in the "Text.LaTeX.Packages.AMSMath" module.+instance (Monad m, a ~ ()) => Floating (LaTeXT m a) where+ pi = pi_+ exp = liftFun exp+ sqrt = liftFun sqrt+ log = liftFun log+ (**) = liftOp (**)+ logBase = liftOp logBase+ sin = liftFun sin+ tan = liftFun tan+ cos = liftFun cos+ asin = liftFun asin+ atan = liftFun atan+ acos = liftFun acos+ sinh = liftFun sinh+ tanh = liftFun tanh+ cosh = liftFun cosh+ -- Non-defined methods+ asinh = error "Function 'asinh' is not defined in AMSMath!"+ 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 = commS "left(" <> x <> commS "right)"++-- | Like 'autoParens', but with square brackets. Equivalent to @'autoBrackets'\"[\"\"]\"@.+autoSquareBrackets :: LaTeXC l => l -> l+autoSquareBrackets x = commS "left[" <> x <> commS "right]"++-- | Like 'autoParens', but with curly brackets.+autoBraces :: LaTeXC l => l -> l+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 = 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+ = commS "left" <> braces (fromLaTeX lBrack) <> x <> commS "right" <> braces (fromLaTeX rBrack)++-- | Left angle bracket, 〈.+langle :: LaTeXC l => l+langle = comm0 "langle"++-- | Right angle bracket, 〉.+rangle :: LaTeXC l => l+rangle = comm0 "rangle"++-- | Left floor, ⌊.+lfloor :: LaTeXC l => l+lfloor = comm0 "lfloor"++-- | Right floor, ⌋.+rfloor :: LaTeXC l => l+rfloor = comm0 "rfloor"++-- | Left ceiling, ⌈.+lceil :: LaTeXC l => l+lceil = comm0 "lceil"++-- | Right ceiling, ⌉.+rceil :: LaTeXC l => l+rceil = comm0 "rceil"++-- | Double vertical line, used as delimiter for norms (‖ ... ‖).+dblPipe :: LaTeXC l => l+dblPipe = comm0 "|"++-- | Superscript.+(^:) :: LaTeXC l => l -> l -> l+x ^: y = x <> raw "^" <> braces y++-- | Subscript.+(!:) :: LaTeXC l => l -> l -> l+x !: y = x <> raw "_" <> braces y++---- Function symbols++-- | Sine function symbol.+tsin :: LaTeXC l => l+tsin = comm0 "sin"++-- | Arcsine function symbol.+arcsin :: LaTeXC l => l+arcsin = comm0 "arcsin"++-- | Cosine function symbol.+tcos :: LaTeXC l => l+tcos = comm0 "cos"++-- | Arccosine function symbol.+arccos :: LaTeXC l => l+arccos = comm0 "arccos"++-- | Tangent function symbol.+ttan :: LaTeXC l => l+ttan = comm0 "tan"++-- | Arctangent function symbol.+arctan :: LaTeXC l => l+arctan = comm0 "arctan"++-- | Cotangent function symbol.+cot :: LaTeXC l => l+cot = comm0 "cot"++-- | Arccotangent function symbol.+arccot :: LaTeXC l => l+arccot = comm0 "arccot"++-- | Hyperbolic sine function symbol.+tsinh :: LaTeXC l => l+tsinh = comm0 "sinh"++-- | Hyperbolic cosine function symbol.+tcosh :: LaTeXC l => l+tcosh = comm0 "cosh"++-- | Hyperbolic tangent function symbol.+ttanh :: LaTeXC l => l+ttanh = comm0 "tanh"++-- | Hyperbolic cotangent function symbol.+coth :: LaTeXC l => l+coth = comm0 "coth"++-- | Secant function symbol.+sec :: LaTeXC l => l+sec = comm0 "sec"++-- | Cosecant function symbol.+csc :: LaTeXC l => l+csc = comm0 "csc"++-- | Exponential function symbol.+texp :: LaTeXC l => l+texp = comm0 "exp"++-- | Logarithm function symbol.+tlog :: LaTeXC l => l+tlog = comm0 "log"++-- | Natural logarithm symbol.+ln :: LaTeXC l => l+ln = comm0 "ln"++-- | Root notation. Use @tsqrt (Just n) x@ for the @n@th root of @x@.+-- When 'Nothing' is supplied, the function will output a square root.+tsqrt :: LaTeXC l => Maybe l -> l -> l+tsqrt Nothing = liftL $ \x -> TeXComm "sqrt" [FixArg x]+tsqrt (Just n) = liftL2 (\m x -> TeXComm "sqrt" [OptArg m, FixArg x]) n++---- Sum/Integral symbols++-- | Sigma sumation symbol. Use 'sumFromTo' instead if you want to+-- specify the limits of the sum.+tsum :: LaTeXC l => l+tsum = comm0 "sum"++-- | Sigma sumation symbol with limits.+sumFromTo :: LaTeXC l+ => l -- ^ Expression below the sigma.+ -> l -- ^ Expression above the sigma.+ -> l+sumFromTo x y = commS "sum" !: x ^: y++-- | Pi product symbol. Use 'prodFromTo' if you want to specify the+-- limits of the product.+prod :: LaTeXC l => l+prod = comm0 "prod"++-- | Pi product symbol with limits.+prodFromTo :: LaTeXC l+ => l -- ^ Expression below the pi.+ -> l -- ^ Expression above the pi.+ -> l+prodFromTo x y = commS "prod" !: x ^: y++-- | Integral symbol. Use 'integralFromTo' if you want to specify+-- the limits of the integral.+integral :: LaTeXC l => l+integral = comm0 "int"++-- | Integral symbol with limits of integration.+integralFromTo :: LaTeXC l+ => l -- ^ Lower limit of integration.+ -> l -- ^ Upper limit of integration.+ -> l+integralFromTo x y = commS "int" !: x ^: y++---- Operator symbols++-- | Negative form of an operator.+notop :: LaTeXC l =>+ (l -> l -> l)+ -> l -> l -> l+notop op =+ \l1 l2 ->+ (l1 <> commS "not") `op` l2++-- | Plus-or-minus operator (±).+pm :: LaTeXC l => l -> l -> l+pm = between $ comm0 "pm"++-- | Minus-or-plus operator (∓).+mp :: LaTeXC l => l -> l -> l+mp = between $ comm0 "mp"++-- | Centered-dot operator (⋅).+cdot :: LaTeXC l => l -> l -> l+cdot = between $ comm0 "cdot"++-- | \"x-cross\" multiplication operator (×).+times :: LaTeXC l => l -> l -> l+times = between $ comm0 "times"++-- | Division operator.+div_ :: LaTeXC l => l -> l -> l+div_ = between $ comm0 "div"++-- | Fraction operator.+frac :: LaTeXC l => l -> l -> l+frac = liftL2 $ \p q -> TeXComm "frac" [FixArg p, FixArg q]++infixl 7 *:++-- | Asterisk operator (*).+--+-- > infixl 7 *:+(*:) :: LaTeXC l => l -> l -> l+(*:) = between $ comm0 "ast"++-- | Star operator (★).+star :: LaTeXC l => l -> l -> l+star = between $ comm0 "star"++-- | Ring operator (∘).+circ :: LaTeXC l => l -> l -> l+circ = between $ comm0 "circ"++-- | Bullet operator (∙).+bullet :: LaTeXC l => l -> l -> l+bullet = between $ comm0 "bullet"++infixr 4 =: , /=:++-- | Equal.+--+-- > infixr 4 =:+(=:) :: LaTeXC l => l -> l -> l+(=:) = between "="++-- | Not equal (≠).+--+-- > infixr 4 /=:+(/=:) :: LaTeXC l => l -> l -> l+(/=:) = notop (=:)++-- | Greater.+(>:) :: LaTeXC l => l -> l -> l+(>:) = between ">"++-- | Greater or equal (≥).+(>=:) :: LaTeXC l => l -> l -> l+(>=:) = between $ comm0 "geq"++-- | Lesser.+(<:) :: LaTeXC l => l -> l -> l+(<:) = between "<"++-- | Lesser or equal (≤).+(<=:) :: LaTeXC l => l -> l -> l+(<=:) = between $ comm0 "leq"++-- | Much less (≪).+ll :: LaTeXC l => l -> l -> l+ll = between $ comm0 "ll"++-- | Much greater (≫).+gg :: LaTeXC l => l -> l -> l+gg = between $ comm0 "gg"++-- | Proportional-to (∝).+propto :: LaTeXC l => l -> l -> l+propto = between $ comm0 "propto"++-- | Identical \/ defined-as \/ equivalent (≡).+equiv :: LaTeXC l => l -> l -> l+equiv = between $ comm0 "equiv"++-- | Element-of (∈).+in_ :: LaTeXC l => l -> l -> l+in_ = between $ comm0 "in"++-- | Mirrored element-of (∋).+ni :: LaTeXC l => l -> l -> l+ni = between $ comm0 "ni"++-- | Not element of (∉).+notin :: LaTeXC l => l -> l -> l+notin = between $ comm0 "notin"++-- | Subset-of (⊂).+subset :: LaTeXC l => l -> l -> l+subset = between $ comm0 "subset"++-- | Superset-of (⊃).+supset :: LaTeXC l => l -> l -> l+supset = between $ comm0 "supset"++-- | Set intersection (∩).+cap :: LaTeXC l => l -> l -> l+cap = between $ comm0 "cap"++-- | Set union (∪).+cup :: LaTeXC l => l -> l -> l+cup = between $ comm0 "cup"++-- | Set minus (∖).+setminus :: LaTeXC l => l -> l -> l+setminus = between $ comm0 "setminus"++-- | Angle pointing downwards (∨).+vee :: LaTeXC l => l -> l -> l+vee = between $ comm0 "vee"++-- | Angle pointing upwards (∧).+wedge :: LaTeXC l => l -> l -> l+wedge = between $ comm0 "wedge"++-- | Circled plus operator (⊕).+oplus :: LaTeXC l => l -> l -> l+oplus = between $ comm0 "oplus"++-- | Circled minus operator (⊖).+ominus :: LaTeXC l => l -> l -> l+ominus = between $ comm0 "ominus"++-- | Circled multiplication cross (⊗).+otimes :: LaTeXC l => l -> l -> l+otimes = between $ comm0 "otimes"++-- | Circled slash (⊘).+oslash :: LaTeXC l => l -> l -> l+oslash = between $ comm0 "oslash"++-- | Circled dot operator (⊙).+odot :: LaTeXC l => l -> l -> l+odot = between $ comm0 "odot"++---- Greek alphabet++-- | /α/ symbol.+alpha :: LaTeXC l => l+alpha = comm0 "alpha"++-- | /β/ symbol.+beta :: LaTeXC l => l+beta = comm0 "beta"++-- | /γ/ symbol.+gamma :: LaTeXC l => l+gamma = comm0 "gamma"++-- | Γ symbol.+gammau :: LaTeXC l => l+gammau = comm0 "Gamma"++-- | /δ/ symbol.+delta :: LaTeXC l => l+delta = comm0 "delta"++-- | Δ symbol.+deltau :: LaTeXC l => l+deltau = comm0 "Delta"++-- | /ϵ/ symbol.+epsilon :: LaTeXC l => l+epsilon = comm0 "epsilon"++-- | /ε/ symbol.+varepsilon :: LaTeXC l => l+varepsilon = comm0 "varepsilon"++-- | /ζ/ symbol.+zeta :: LaTeXC l => l+zeta = comm0 "zeta"++-- | /η/ symbol.+eta :: LaTeXC l => l+eta = comm0 "eta"++-- | /θ/ symbol.+theta :: LaTeXC l => l+theta = comm0 "theta"++-- | /ϑ/ symbol.+vartheta :: LaTeXC l => l+vartheta = comm0 "vartheta"++-- | Θ symbol.+thetau :: LaTeXC l => l+thetau = comm0 "thetau"++-- | /ι/ symbol.+iota :: LaTeXC l => l+iota = comm0 "iota"++-- | /κ/ symbol.+kappa :: LaTeXC l => l+kappa = comm0 "kappa"++-- | /λ/ symbol.+lambda :: LaTeXC l => l+lambda = comm0 "lambda"++-- | Λ symbol.+lambdau :: LaTeXC l => l+lambdau = comm0 "Lambda"++-- | /μ/ symbol.+mu :: LaTeXC l => l+mu = comm0 "mu"++-- | /ν/ symbol.+nu :: LaTeXC l => l+nu = comm0 "nu"++-- | /ξ/ symbol.+xi :: LaTeXC l => l+xi = comm0 "xi"++-- | Ξ symbol.+xiu :: LaTeXC l => l+xiu = comm0 "Xi"++-- | /π/ symbol.+pi_ :: LaTeXC l => l+pi_ = comm0 "pi"++-- | /ϖ/ symbol.+varpi :: LaTeXC l => l+varpi = comm0 "varpi"++-- | Π symbol.+piu :: LaTeXC l => l+piu = comm0 "Pi"++-- | /ρ/ symbol.+rho :: LaTeXC l => l+rho = comm0 "rho"++-- | /ϱ/ symbol.+varrho :: LaTeXC l => l+varrho = comm0 "varrho"++-- | /σ/ symbol.+sigma :: LaTeXC l => l+sigma = comm0 "sigma"++-- | /ς/ symbol.+varsigma :: LaTeXC l => l+varsigma = comm0 "varsigma"++-- | Σ symbol.+sigmau :: LaTeXC l => l+sigmau = comm0 "Sigma"++-- | /τ/ symbol.+tau :: LaTeXC l => l+tau = comm0 "tau"++-- | /υ/ symbol.+upsilon :: LaTeXC l => l+upsilon = comm0 "upsilon"++-- | Υ symbol.+upsilonu :: LaTeXC l => l+upsilonu = comm0 "Upsilon"++-- | /ϕ/ symbol.+phi :: LaTeXC l => l+phi = comm0 "phi"++-- | /φ/ symbol.+varphi :: LaTeXC l => l+varphi = comm0 "varphi"++-- | Φ symbol.+phiu :: LaTeXC l => l+phiu = comm0 "Phi"++-- | /χ/ symbol.+chi :: LaTeXC l => l+chi = comm0 "chi"++-- | /ψ/ symbol.+psi :: LaTeXC l => l+psi = comm0 "psi"++-- | Ψ symbol.+psiu :: LaTeXC l => l+psiu = comm0 "Psi"++-- | /ω/ symbol.+omega :: LaTeXC l => l+omega = comm0 "omega"++-- | Ω symbol.+omegau :: LaTeXC l => l+omegau = comm0 "Omega"++---- Other symbols++-- | A right-arrow, →.+to :: LaTeXC l => l+to = comm0 "to"++-- | A right-arrow for function definitions, ↦.+mapsto :: LaTeXC l => l+mapsto = comm0 "mapsto"++-- | /For all/ symbol, ∀.+forall :: LaTeXC l => l+forall = comm0 "forall"++-- | /Exists/ symbol, ∃.+exists :: LaTeXC l => l+exists = comm0 "exists"++-- | Dagger symbol, †.+dagger :: LaTeXC l => l+dagger = comm0 "dagger"++-- | Double dagger symbol, ‡.+ddagger :: LaTeXC l => l+ddagger = comm0 "ddagger"++-- | Infinity symbol.+infty :: LaTeXC l => l+infty = comm0 "infty"++-------------------------------------+------------ Math Fonts -------------++-- | Default math symbol font.+mathdefault :: LaTeXC l => l -> l+mathdefault = liftL $ \l -> TeXComm "mathdefault" [FixArg l]++-- | Bold face.+mathbf :: LaTeXC l => l -> l+mathbf = liftL $ \l -> TeXComm "mathbf" [FixArg l]++-- | Roman, i.e. not-italic math.+mathrm :: LaTeXC l => l -> l+mathrm = liftL $ \l -> TeXComm "mathrm" [FixArg l]++-- | Calligraphic math symbols.+mathcal :: LaTeXC l => l -> l+mathcal = liftL $ \l -> TeXComm "mathcal" [FixArg l]++-- | Sans-serif math.+mathsf :: LaTeXC l => l -> l+mathsf = liftL $ \l -> TeXComm "mathsf" [FixArg l]++-- | Typewriter font.+mathtt :: LaTeXC l => l -> l+mathtt = liftL $ \l -> TeXComm "mathtt" [FixArg l]++-- | Italic math. Uses the same glyphs as 'mathdefault', but with spacings+-- intended for multi-character symbols rather than juxtaposition of single-character symbols.+mathit :: LaTeXC l => l -> l+mathit = liftL $ \l -> TeXComm "mathit" [FixArg l]++-------------------------------------+------------- Matrices --------------++matrix2tex :: (Texy a, LaTeXC l) => Matrix a -> l+matrix2tex m = mconcat+ [ foldr1 (&) [ texy $ m ! (i,j)+ | j <- [1 .. ncols m]+ ] <> lnbk+ | i <- [1 .. nrows m]+ ]++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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l+pmatrix = toMatrix "pmatrix"++-- | 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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l+bmatrix = toMatrix "bmatrix"++-- | 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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l+b2matrix = toMatrix "Bmatrix"++-- | 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 :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l+vmatrix = toMatrix "vmatrix"++-- | 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 :: (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
@@ -1,71 +1,71 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | Package for theorem environments. -module Text.LaTeX.Packages.AMSThm - ( -- * AMSThm package - amsthm - -- * AMSThm functions - , newtheorem - , theorem - , proof - , qedhere - , TheoremStyle (..) - , theoremstyle - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types - --- | AMSThm package. --- Example: --- --- > usepackage [] amsthm -amsthm :: PackageName -amsthm = "amsthm" - --- | Create a new 'theorem' environment type. --- Arguments are environment name (this will be the argument --- when using the 'theorem' function) and the displayed title. --- --- For example: --- --- > newtheorem "prop" "Proposition" --- --- > theorem "prop" "This is it." -newtheorem :: 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 [] - --- | The 'proof' environment. The first optional argument --- is used to put a custom title to the proof. -proof :: LaTeXC l => Maybe l -> l -> l -proof Nothing = liftL $ TeXEnv "proof" [] -proof (Just n) = liftL2 (\m -> TeXEnv "proof" [OptArg m]) n - --- | Insert the /QED/ symbol. -qedhere :: LaTeXC l => l -qedhere = comm0 "qedhere" - --- | Different styles for 'theorem's. -data TheoremStyle = - Plain - | Definition - | Remark - | CustomThmStyle String - deriving Show - -instance Render TheoremStyle where - render Plain = "plain" - render Definition = "definition" - render Remark = "remark" - render (CustomThmStyle str) = fromString str - --- | Set the theorem style. Call this function in the preamble. -theoremstyle :: LaTeXC l => TheoremStyle -> l -theoremstyle thmsty = fromLaTeX $ TeXComm "theoremstyle" [ FixArg $ TeXRaw $ render thmsty ] ++{-# LANGUAGE OverloadedStrings #-}++-- | Package for theorem environments.+module Text.LaTeX.Packages.AMSThm+ ( -- * AMSThm package+ amsthm+ -- * AMSThm functions+ , newtheorem+ , theorem+ , proof+ , qedhere+ , TheoremStyle (..)+ , theoremstyle+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types++-- | AMSThm package.+-- Example:+--+-- > usepackage [] amsthm+amsthm :: PackageName+amsthm = "amsthm"++-- | Create a new 'theorem' environment type.+-- Arguments are environment name (this will be the argument+-- when using the 'theorem' function) and the displayed title.+--+-- For example:+--+-- > newtheorem "prop" "Proposition"+--+-- > theorem "prop" "This is it."+newtheorem :: 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 []++-- | The 'proof' environment. The first optional argument+-- is used to put a custom title to the proof.+proof :: LaTeXC l => Maybe l -> l -> l+proof Nothing = liftL $ TeXEnv "proof" []+proof (Just n) = liftL2 (\m -> TeXEnv "proof" [OptArg m]) n++-- | Insert the /QED/ symbol.+qedhere :: LaTeXC l => l+qedhere = comm0 "qedhere"++-- | Different styles for 'theorem's.+data TheoremStyle =+ Plain+ | Definition+ | Remark+ | CustomThmStyle String+ deriving Show++instance Render TheoremStyle where+ render Plain = "plain"+ render Definition = "definition"+ render Remark = "remark"+ render (CustomThmStyle str) = fromString str++-- | Set the theorem style. Call this function in the preamble.+theoremstyle :: LaTeXC l => TheoremStyle -> l+theoremstyle thmsty = fromLaTeX $ TeXComm "theoremstyle" [ FixArg $ TeXRaw $ render thmsty ]
Text/LaTeX/Packages/Beamer.hs view
@@ -1,158 +1,158 @@-{-# LANGUAGE OverloadedStrings #-} - --- | Beamer is a LaTeX package for the creation of slides. --- --- Each frame is contained within the 'frame' function. Here is an example: --- --- > {-# LANGUAGE OverloadedStrings #-} --- > --- > import Text.LaTeX --- > import Text.LaTeX.Packages.Beamer --- > --- > mySlides :: Monad m => LaTeXT m () --- > mySlides = do --- > frame $ do --- > frametitle "First frame" --- > "Content of the first frame." --- > frame $ do --- > frametitle "Second frame" --- > "Content of the second frame." --- > pause --- > " And actually a little more." --- --- The 'pause' command in the second frame makes the second part of the text --- to appear one screen later. -module Text.LaTeX.Packages.Beamer - ( -- * Beamer package - beamer - -- * Beamer commands - , frame - , frametitle - , framesubtitle - , alert - , pause - , block - -- ** Overlay Specifications - , OverlaySpec (..) - , beameritem - , uncover - , only - -- ** Themes - , usetheme - , Theme (..) - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types - --- | The 'beamer' document class. Importing a package is not required. Example: --- --- > documentclass [] beamer -beamer :: ClassName -beamer = "beamer" - --- | A presentation is composed of a sequence of frames. Each frame is created with this function. -frame :: LaTeXC l => l -> l -frame = liftL $ TeXEnv "frame" [] - --- | Set the title of the current frame. Use it within a 'frame'. -frametitle :: LaTeXC l => l -> l -frametitle = liftL $ \l -> TeXComm "frametitle" [FixArg l] - --- | Set the subtitle of the current frame. Use it within a 'frame'. -framesubtitle :: LaTeXC l => l -> l -framesubtitle = liftL $ \l -> TeXComm "framesubtitle" [FixArg l] - --- | Highlight in red a piece of text. With the 'OverlaySpec's, you can specify the slides where --- the text will be highlighted. -alert :: LaTeXC l => [OverlaySpec] -> l -> l -alert os = liftL $ \l -> TeXComm "alert" [ MSymArg $ fmap (TeXRaw . render) os, FixArg l] - --- | Introduces a pause in a slide. -pause :: LaTeXC l => l -pause = comm0 "pause" - --- | 'beameritem' works like 'item', but allows you to specify the slides where --- the item will be displayed. -beameritem :: LaTeXC l => [OverlaySpec] -> l -beameritem os = fromLaTeX $ TeXComm "item" [ MSymArg $ fmap (TeXRaw . render) os ] - --- | With 'uncover', show a piece of text only in the slides you want. -uncover :: LaTeXC l => [OverlaySpec] -> l -> l -uncover os = liftL $ \l -> TeXComm "uncover" [ MSymArg $ fmap (TeXRaw . render) os , FixArg l ] - --- TODO: What is the difference between 'uncover' and 'only'?? - --- | Similar to 'uncover'. -only :: LaTeXC l => [OverlaySpec] -> l -> l -only os = liftL $ \l -> TeXComm "only" [ MSymArg $ fmap (TeXRaw . render) os , FixArg l ] - --- | Specifications for beamer functions. -data OverlaySpec = - OneSlide Int - | FromSlide Int - | ToSlide Int - | FromToSlide Int Int - deriving Show - -instance Render OverlaySpec where - render (OneSlide n) = render n - render (FromSlide n) = render n <> "-" - render (ToSlide n) = "-" <> render n - render (FromToSlide n m) = render n <> "-" <> render m - --- | A 'block' will be displayed surrounding a text. -block :: LaTeXC l => - l -- ^ Title for the block - -> l -- ^ Content of the block - -> l -- ^ Result -block = liftL2 $ \tit -> TeXEnv "block" [ FixArg tit ] - --- THEMES -- - --- | A 'Theme' of a presentation. See 'usetheme'. --- A preview of each one is given below. -data Theme = - AnnArbor -- ^ <<docfiles/beamers/previewAnnArbor.png>> - | Antibes -- ^ <<docfiles/beamers/previewAntibes.png>> - | Bergen -- ^ <<docfiles/beamers/previewBergen.png>> - | Berkeley -- ^ <<docfiles/beamers/previewBerkeley.png>> - | Berlin -- ^ <<docfiles/beamers/previewBerlin.png>> - | Boadilla -- ^ <<docfiles/beamers/previewBoadilla.png>> - | CambridgeUS -- ^ <<docfiles/beamers/previewCambridgeUS.png>> - | Copenhagen -- ^ <<docfiles/beamers/previewCopenhagen.png>> - | Darmstadt -- ^ <<docfiles/beamers/previewDarmstadt.png>> - | Dresden -- ^ <<docfiles/beamers/previewDresden.png>> - | Frankfurt -- ^ <<docfiles/beamers/previewFrankfurt.png>> - | Goettingen -- ^ <<docfiles/beamers/previewGoettingen.png>> - | Hannover -- ^ <<docfiles/beamers/previewHannover.png>> - | Ilmenau -- ^ <<docfiles/beamers/previewIlmenau.png>> - | JuanLesPins -- ^ <<docfiles/beamers/previewJuanLesPins.png>> - | Luebeck -- ^ <<docfiles/beamers/previewLuebeck.png>> - | Madrid -- ^ <<docfiles/beamers/previewMadrid.png>> - | Malmoe -- ^ <<docfiles/beamers/previewMalmoe.png>> - | Marburg -- ^ <<docfiles/beamers/previewMarburg.png>> - | Montpellier -- ^ <<docfiles/beamers/previewMontpellier.png>> - | PaloAlto -- ^ <<docfiles/beamers/previewPaloAlto.png>> - | Pittsburgh -- ^ <<docfiles/beamers/previewPittsburgh.png>> - | Rochester -- ^ <<docfiles/beamers/previewRochester.png>> - | Singapore -- ^ <<docfiles/beamers/previewSingapore.png>> - | Szeged -- ^ <<docfiles/beamers/previewSzeged.png>> - | Warsaw -- ^ <<docfiles/beamers/previewWarsaw.png>> - -- - | Boxes - | Default - -- - | CustomTheme String - deriving (Eq,Show) - -instance Render Theme where - render (CustomTheme str) = fromString str - render x = fromString $ show x - --- | Set the 'Theme' employed in your presentation (in the preamble). -usetheme :: LaTeXC l => Theme -> l -usetheme th = fromLaTeX $ TeXComm "usetheme" [ FixArg $ TeXRaw $ render th ] - +{-# LANGUAGE OverloadedStrings #-}++-- | Beamer is a LaTeX package for the creation of slides.+--+-- Each frame is contained within the 'frame' function. Here is an example:+--+-- > {-# LANGUAGE OverloadedStrings #-}+-- >+-- > import Text.LaTeX+-- > import Text.LaTeX.Packages.Beamer+-- >+-- > mySlides :: Monad m => LaTeXT m ()+-- > mySlides = do+-- > frame $ do+-- > frametitle "First frame"+-- > "Content of the first frame."+-- > frame $ do+-- > frametitle "Second frame"+-- > "Content of the second frame." +-- > pause+-- > " And actually a little more."+--+-- The 'pause' command in the second frame makes the second part of the text+-- to appear one screen later.+module Text.LaTeX.Packages.Beamer+ ( -- * Beamer package+ beamer+ -- * Beamer commands+ , frame+ , frametitle+ , framesubtitle+ , alert+ , pause+ , block+ -- ** Overlay Specifications+ , OverlaySpec (..)+ , beameritem+ , uncover+ , only+ -- ** Themes+ , usetheme+ , Theme (..)+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types++-- | The 'beamer' document class. Importing a package is not required. Example:+--+-- > documentclass [] beamer+beamer :: ClassName+beamer = "beamer"++-- | A presentation is composed of a sequence of frames. Each frame is created with this function.+frame :: LaTeXC l => l -> l+frame = liftL $ TeXEnv "frame" []++-- | Set the title of the current frame. Use it within a 'frame'.+frametitle :: LaTeXC l => l -> l+frametitle = liftL $ \l -> TeXComm "frametitle" [FixArg l]++-- | Set the subtitle of the current frame. Use it within a 'frame'.+framesubtitle :: LaTeXC l => l -> l+framesubtitle = liftL $ \l -> TeXComm "framesubtitle" [FixArg l]++-- | Highlight in red a piece of text. With the 'OverlaySpec's, you can specify the slides where+-- the text will be highlighted.+alert :: LaTeXC l => [OverlaySpec] -> l -> l+alert os = liftL $ \l -> TeXComm "alert" [ MSymArg $ fmap (TeXRaw . render) os, FixArg l]++-- | Introduces a pause in a slide.+pause :: LaTeXC l => l+pause = comm0 "pause"++-- | 'beameritem' works like 'item', but allows you to specify the slides where+-- the item will be displayed.+beameritem :: LaTeXC l => [OverlaySpec] -> l+beameritem os = fromLaTeX $ TeXComm "item" [ MSymArg $ fmap (TeXRaw . render) os ]++-- | With 'uncover', show a piece of text only in the slides you want.+uncover :: LaTeXC l => [OverlaySpec] -> l -> l+uncover os = liftL $ \l -> TeXComm "uncover" [ MSymArg $ fmap (TeXRaw . render) os , FixArg l ]++-- TODO: What is the difference between 'uncover' and 'only'??++-- | Similar to 'uncover'.+only :: LaTeXC l => [OverlaySpec] -> l -> l+only os = liftL $ \l -> TeXComm "only" [ MSymArg $ fmap (TeXRaw . render) os , FixArg l ]++-- | Specifications for beamer functions.+data OverlaySpec =+ OneSlide Int+ | FromSlide Int+ | ToSlide Int+ | FromToSlide Int Int+ deriving Show++instance Render OverlaySpec where+ render (OneSlide n) = render n+ render (FromSlide n) = render n <> "-"+ render (ToSlide n) = "-" <> render n+ render (FromToSlide n m) = render n <> "-" <> render m++-- | A 'block' will be displayed surrounding a text.+block :: LaTeXC l =>+ l -- ^ Title for the block+ -> l -- ^ Content of the block+ -> l -- ^ Result+block = liftL2 $ \tit -> TeXEnv "block" [ FixArg tit ]++-- THEMES --++-- | A 'Theme' of a presentation. See 'usetheme'.+-- A preview of each one is given below.+data Theme = + AnnArbor -- ^ <<docfiles/beamers/previewAnnArbor.png>>+ | Antibes -- ^ <<docfiles/beamers/previewAntibes.png>>+ | Bergen -- ^ <<docfiles/beamers/previewBergen.png>>+ | Berkeley -- ^ <<docfiles/beamers/previewBerkeley.png>>+ | Berlin -- ^ <<docfiles/beamers/previewBerlin.png>>+ | Boadilla -- ^ <<docfiles/beamers/previewBoadilla.png>>+ | CambridgeUS -- ^ <<docfiles/beamers/previewCambridgeUS.png>>+ | Copenhagen -- ^ <<docfiles/beamers/previewCopenhagen.png>>+ | Darmstadt -- ^ <<docfiles/beamers/previewDarmstadt.png>>+ | Dresden -- ^ <<docfiles/beamers/previewDresden.png>>+ | Frankfurt -- ^ <<docfiles/beamers/previewFrankfurt.png>>+ | Goettingen -- ^ <<docfiles/beamers/previewGoettingen.png>>+ | Hannover -- ^ <<docfiles/beamers/previewHannover.png>>+ | Ilmenau -- ^ <<docfiles/beamers/previewIlmenau.png>>+ | JuanLesPins -- ^ <<docfiles/beamers/previewJuanLesPins.png>>+ | Luebeck -- ^ <<docfiles/beamers/previewLuebeck.png>>+ | Madrid -- ^ <<docfiles/beamers/previewMadrid.png>>+ | Malmoe -- ^ <<docfiles/beamers/previewMalmoe.png>>+ | Marburg -- ^ <<docfiles/beamers/previewMarburg.png>>+ | Montpellier -- ^ <<docfiles/beamers/previewMontpellier.png>>+ | PaloAlto -- ^ <<docfiles/beamers/previewPaloAlto.png>>+ | Pittsburgh -- ^ <<docfiles/beamers/previewPittsburgh.png>>+ | Rochester -- ^ <<docfiles/beamers/previewRochester.png>>+ | Singapore -- ^ <<docfiles/beamers/previewSingapore.png>>+ | Szeged -- ^ <<docfiles/beamers/previewSzeged.png>>+ | Warsaw -- ^ <<docfiles/beamers/previewWarsaw.png>>+ --+ | Boxes+ | Default+ --+ | CustomTheme String+ deriving (Eq,Show)++instance Render Theme where+ render (CustomTheme str) = fromString str+ render x = fromString $ show x++-- | Set the 'Theme' employed in your presentation (in the preamble).+usetheme :: LaTeXC l => Theme -> l+usetheme th = fromLaTeX $ TeXComm "usetheme" [ FixArg $ TeXRaw $ render th ]+
Text/LaTeX/Packages/Color.hs view
@@ -1,166 +1,166 @@- -{-# 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 - -- * Package options - , monochrome - , dvipsnames - , nodvipsnames - , usenames - -- * Types - , Color (..) - , ColorName (..) - , ColorModel (..) - , ColSpec (..) - -- * Words - -- | RGB255 colors are determined by three parameters of the 'Word8' type. - -- Values of type 'Word8' lie within 0 and 255. - , Word8 - -- * Commands - , pagecolor - , color - , textcolor - , colorbox , fcolorbox - , normalcolor - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types --- -import Data.Text (toLower) -import Data.Word (Word8) - --- | The 'pcolor' package. --- --- > usepackage [] pcolor -pcolor :: PackageName -pcolor = "color" - --- | To convert all colour commands to black and white, --- for previewers that cannot handle colour. -monochrome :: LaTeXC l => l -monochrome = "monochrome" - -dvipsnames :: LaTeXC l => l -dvipsnames = "dvipsnames" - -nodvipsnames :: LaTeXC l => l -nodvipsnames = "nodvipsnames" - -usenames :: LaTeXC l => l -usenames = "usenames" - --- | Color specification. -data ColSpec = - DefColor Color - | ModColor ColorModel - | DvipsColor ColorName - deriving Show - --- | Basic colors. -data Color = - Red - | Green - | Blue - | Yellow - | Cyan - | Magenta - | Black - | White - deriving Show - --- | Specify your own color using one of the different color models. -data ColorModel = - RGB Float Float Float - -- ^ Each parameter determines the proportion of red, green and - -- blue, with a value within the [0,1] interval. - | RGB255 Word8 Word8 Word8 - | GrayM Float - -- ^ Grayscale, from 0 (black) to 1 (white). - | HTML String - | CMYK Float Float Float Float - deriving Show - --- | Other predefined colors. -data ColorName = - Apricot | Aquamarine | Bittersweet - | BlueGreen | BlueViolet | BrickRed - | Brown | BurntOrange | CadetBlue - | CarnationPink | Cerulean | CornflowerBlue - | Dandelion | DarkOrchid | Emerald - | ForestGreen | Fuchsia | Goldenrod - | Gray | GreenYellow | JungleGreen - | Lavender | LimeGreen | Mahogany - | Maroon | Melon | MidnightBlue - | Mulberry | NavyBlue | OliveGreen - | Orange | OrangeRed | Orchid - | Peach | Periwinkle | PineGreen - | Plum | ProcessBlue | Purple - | RawSienna | RedOrange | RedViolet - | Rhodamine | RoyalBlue | RubineRed - | Salmon | SeaGreen | Sepia - | SkyBlue | SpringGreen | Tan - | TealBlue | Thistle | Turquoise - | Violet | VioletRed | WildStrawberry - | YellowGreen | YellowOrange - deriving Show - -instance Render Color where - render = toLower . fromString . show - -instance Render ColorModel where - render (RGB r g b) = mconcat [ "[rgb]{" , renderCommas [r,g,b] , "}" ] - render (RGB255 r g b) = mconcat [ "[RGB]{" , renderCommas [r,g,b] , "}" ] - render (GrayM k) = mconcat [ "[gray]{" , render k , "}"] - render (HTML str) = mconcat [ "[HTML]{" , fromString str , "}" ] - render (CMYK c m y k) = mconcat [ "[cmyk]{" , renderCommas [c,m,y,k] , "}" ] - -instance Render ColorName where - render = fromString . show - -instance Render ColSpec where - render (DefColor c) = mconcat [ "{" , render c , "}" ] - render (ModColor cm) = render cm - render (DvipsColor c) = mconcat [ "{" , render c , "}" ] - --- Commands - --- | Set the background color for the current and following pages. -pagecolor :: LaTeXC l => ColSpec -> l -pagecolor = (commS "pagecolor" <>) . rendertex - --- | Switch to a new text color. -color :: LaTeXC l => ColSpec -> l -color = (commS "color" <>) . rendertex - --- | Set the text of its argument in the given colour. -textcolor :: LaTeXC l => ColSpec -> l -> l -textcolor cs l = commS "textcolor" <> rendertex cs - <> braces l - --- | Put its argument in a box with the given colour as background. -colorbox :: LaTeXC l => ColSpec -> l -> l -colorbox cs l = commS "colorbox" <> rendertex cs - <> braces l - --- | Application of @fcolorbox cs1 cs2 l@ put @l@ in a framed box with --- @cs1@ as frame color and @cs2@ as background color. -fcolorbox :: LaTeXC l => ColSpec -> ColSpec -> l -> l -fcolorbox cs1 cs2 l = - commS "fcolorbox" <> rendertex cs1 - <> rendertex cs2 - <> braces l - --- | Switch to the colour that was active at the end of the preamble. --- Thus, placing a 'color' command in the preamble can change the --- standard colour of the whole document. -normalcolor :: LaTeXC l => l -normalcolor = comm0 "normalcolor" ++{-# 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+ -- * Package options+ , monochrome+ , dvipsnames+ , nodvipsnames+ , usenames+ -- * Types+ , Color (..)+ , ColorName (..)+ , ColorModel (..)+ , ColSpec (..)+ -- * Words+ -- | RGB255 colors are determined by three parameters of the 'Word8' type.+ -- Values of type 'Word8' lie within 0 and 255.+ , Word8+ -- * Commands+ , pagecolor+ , color+ , textcolor+ , colorbox , fcolorbox+ , normalcolor+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types+--+import Data.Text (toLower)+import Data.Word (Word8)++-- | The 'pcolor' package.+--+-- > usepackage [] pcolor+pcolor :: PackageName+pcolor = "color"++-- | To convert all colour commands to black and white,+-- for previewers that cannot handle colour.+monochrome :: LaTeXC l => l+monochrome = "monochrome"++dvipsnames :: LaTeXC l => l+dvipsnames = "dvipsnames"++nodvipsnames :: LaTeXC l => l+nodvipsnames = "nodvipsnames"++usenames :: LaTeXC l => l+usenames = "usenames"++-- | Color specification.+data ColSpec =+ DefColor Color+ | ModColor ColorModel+ | DvipsColor ColorName+ deriving Show++-- | Basic colors.+data Color =+ Red+ | Green+ | Blue+ | Yellow+ | Cyan+ | Magenta+ | Black+ | White+ deriving Show++-- | Specify your own color using one of the different color models.+data ColorModel =+ RGB Float Float Float+ -- ^ Each parameter determines the proportion of red, green and+ -- blue, with a value within the [0,1] interval.+ | RGB255 Word8 Word8 Word8+ | GrayM Float+ -- ^ Grayscale, from 0 (black) to 1 (white).+ | HTML String+ | CMYK Float Float Float Float+ deriving Show++-- | Other predefined colors.+data ColorName =+ Apricot | Aquamarine | Bittersweet+ | BlueGreen | BlueViolet | BrickRed+ | Brown | BurntOrange | CadetBlue+ | CarnationPink | Cerulean | CornflowerBlue+ | Dandelion | DarkOrchid | Emerald+ | ForestGreen | Fuchsia | Goldenrod+ | Gray | GreenYellow | JungleGreen+ | Lavender | LimeGreen | Mahogany+ | Maroon | Melon | MidnightBlue+ | Mulberry | NavyBlue | OliveGreen+ | Orange | OrangeRed | Orchid+ | Peach | Periwinkle | PineGreen+ | Plum | ProcessBlue | Purple+ | RawSienna | RedOrange | RedViolet+ | Rhodamine | RoyalBlue | RubineRed+ | Salmon | SeaGreen | Sepia+ | SkyBlue | SpringGreen | Tan+ | TealBlue | Thistle | Turquoise+ | Violet | VioletRed | WildStrawberry+ | YellowGreen | YellowOrange+ deriving Show++instance Render Color where+ render = toLower . fromString . show++instance Render ColorModel where+ render (RGB r g b) = mconcat [ "[rgb]{" , renderCommas [r,g,b] , "}" ]+ render (RGB255 r g b) = mconcat [ "[RGB]{" , renderCommas [r,g,b] , "}" ]+ render (GrayM k) = mconcat [ "[gray]{" , render k , "}"]+ render (HTML str) = mconcat [ "[HTML]{" , fromString str , "}" ]+ render (CMYK c m y k) = mconcat [ "[cmyk]{" , renderCommas [c,m,y,k] , "}" ]++instance Render ColorName where+ render = fromString . show++instance Render ColSpec where+ render (DefColor c) = mconcat [ "{" , render c , "}" ]+ render (ModColor cm) = render cm+ render (DvipsColor c) = mconcat [ "{" , render c , "}" ]++-- Commands++-- | Set the background color for the current and following pages.+pagecolor :: LaTeXC l => ColSpec -> l+pagecolor = (commS "pagecolor" <>) . rendertex++-- | Switch to a new text color.+color :: LaTeXC l => ColSpec -> l+color = (commS "color" <>) . rendertex++-- | Set the text of its argument in the given colour.+textcolor :: LaTeXC l => ColSpec -> l -> l+textcolor cs l = commS "textcolor" <> rendertex cs+ <> braces l++-- | Put its argument in a box with the given colour as background.+colorbox :: LaTeXC l => ColSpec -> l -> l+colorbox cs l = commS "colorbox" <> rendertex cs+ <> braces l++-- | Application of @fcolorbox cs1 cs2 l@ put @l@ in a framed box with+-- @cs1@ as frame color and @cs2@ as background color.+fcolorbox :: LaTeXC l => ColSpec -> ColSpec -> l -> l+fcolorbox cs1 cs2 l =+ commS "fcolorbox" <> rendertex cs1+ <> rendertex cs2+ <> braces l++-- | Switch to the colour that was active at the end of the preamble.+-- Thus, placing a 'color' command in the preamble can change the+-- standard colour of the whole document.+normalcolor :: LaTeXC l => l+normalcolor = comm0 "normalcolor"
Text/LaTeX/Packages/Graphicx.hs view
@@ -1,108 +1,108 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | This module allows you to use the LaTeX /graphicx/ library in order to --- insert graphics in a document and perform some transformations. --- --- CTAN page for graphicx: <http://ctan.org/pkg/graphicx>. -module Text.LaTeX.Packages.Graphicx - ( -- * Graphicx package - graphicx - -- * Package options - , dvips - , dvipdfm - , pdftex - -- * Including graphics - , IGOption (..) - , includegraphics - -- * Transformations - , rotatebox - , scalebox - , reflectbox - , resizebox - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types --- -import Data.Char (toLower) - --- | The 'graphicx' package. --- --- > usepackage [] graphicx -graphicx :: PackageName -graphicx = "graphicx" - --- Package options - --- | Package option of the 'graphicx' package. -dvips, dvipdfm, pdftex :: LaTeXC l => l -dvips = "dvips" -dvipdfm = "dvipdfm" -pdftex = "pdftex" - --- Including graphics - --- | Include Graphics Option. These options can be passed as arguments to the 'includegraphics' function. -data IGOption = - IGWidth Measure -- ^ Specify the preferred width of the imported image. - | IGHeight Measure -- ^ Specify the preferred height of the imported image. - | KeepAspectRatio Bool -- ^ When 'True', it will scale the image according to both 'IGWidth' and 'IGHeight' - -- , but will not distort the image, so that neither 'IGWidth' nor 'IGHeight' are exceeded. - | IGScale Float -- ^ Scales the image by the desired scale factor. - | IGAngle Int -- ^ Rotate the image by given degrees. - | IGTrim Measure Measure Measure Measure -- ^ This option will crop the imported image. Arguments are from-left - -- , from-bottom, from-right and from-top respectively. - | IGClip Bool -- ^ For the 'IGTrim' option to work, you must set 'IGClip' to 'True'. - | IGPage Int -- ^ If the image file is a pdf file with multiple pages, - -- this parameter allows you to use a different page than the first. - deriving Show - -instance Render IGOption where - render (IGWidth m) = "width=" <> render m - render (IGHeight m) = "height=" <> render m - render (KeepAspectRatio b) = "keepaspectratio=" <> fromString (fmap toLower $ show b) - render (IGScale r) = "scale=" <> render r - render (IGAngle a) = "angle=" <> render a - render (IGTrim l b r t) = "trim=" <> renderChars ' ' [l,b,r,t] - render (IGClip b) = "clip=" <> fromString (fmap toLower $ show b) - render (IGPage p) = "page=" <> render p - --- | Include an image in the document. -includegraphics :: LaTeXC l => - [IGOption] -- ^ Options - -> FilePath -- ^ Image file - -> l -includegraphics opts fp = fromLaTeX $ TeXComm "includegraphics" - [ MOptArg $ fmap rendertex opts , FixArg $ TeXRaw $ fromString fp ] - --- | Rotate the content by the given angle in degrees. -rotatebox :: LaTeXC l => Float -> l -> l -rotatebox a = liftL $ \l -> TeXComm "rotatebox" [FixArg $ rendertex a , FixArg l] - --- | Scale the content by the given factor. If only the horizontal scale is supplied, --- the vertical scaling will be the same. -scalebox :: LaTeXC l => - Float -- ^ Horizontal scale. - -> Maybe Float -- ^ Vertical scale. - -> l - -> l -scalebox h mv = liftL $ \l -> - TeXComm "rotatebox" $ [FixArg $ rendertex h] - ++ maybe [] ((:[]) . OptArg . rendertex) mv - ++ [FixArg l] - --- | Reflect horizontally the content. -reflectbox :: LaTeXC l => l -> l -reflectbox = liftL $ \l -> TeXComm "reflectbox" [FixArg l] - --- | Resize the content to match the given dimensions. -resizebox :: LaTeXC l => - Measure -- ^ Horizontal size. - -> Measure -- ^ Vertical size. - -> l - -> l -resizebox h v = liftL $ \l -> - TeXComm "resizebox" [FixArg $ rendertex h,FixArg $ rendertex v,FixArg l] ++{-# LANGUAGE OverloadedStrings #-}++-- | This module allows you to use the LaTeX /graphicx/ library in order to+-- insert graphics in a document and perform some transformations.+--+-- CTAN page for graphicx: <http://ctan.org/pkg/graphicx>.+module Text.LaTeX.Packages.Graphicx+ ( -- * Graphicx package+ graphicx+ -- * Package options+ , dvips+ , dvipdfm+ , pdftex+ -- * Including graphics+ , IGOption (..)+ , includegraphics+ -- * Transformations+ , rotatebox+ , scalebox+ , reflectbox+ , resizebox+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types+--+import Data.Char (toLower)++-- | The 'graphicx' package.+--+-- > usepackage [] graphicx+graphicx :: PackageName+graphicx = "graphicx"++-- Package options++-- | Package option of the 'graphicx' package.+dvips, dvipdfm, pdftex :: LaTeXC l => l+dvips = "dvips"+dvipdfm = "dvipdfm"+pdftex = "pdftex"++-- Including graphics++-- | Include Graphics Option. These options can be passed as arguments to the 'includegraphics' function.+data IGOption =+ IGWidth Measure -- ^ Specify the preferred width of the imported image.+ | IGHeight Measure -- ^ Specify the preferred height of the imported image.+ | KeepAspectRatio Bool -- ^ When 'True', it will scale the image according to both 'IGWidth' and 'IGHeight'+ -- , but will not distort the image, so that neither 'IGWidth' nor 'IGHeight' are exceeded.+ | IGScale Float -- ^ Scales the image by the desired scale factor.+ | IGAngle Int -- ^ Rotate the image by given degrees.+ | IGTrim Measure Measure Measure Measure -- ^ This option will crop the imported image. Arguments are from-left+ -- , from-bottom, from-right and from-top respectively.+ | IGClip Bool -- ^ For the 'IGTrim' option to work, you must set 'IGClip' to 'True'.+ | IGPage Int -- ^ If the image file is a pdf file with multiple pages,+ -- this parameter allows you to use a different page than the first.+ deriving Show++instance Render IGOption where+ render (IGWidth m) = "width=" <> render m+ render (IGHeight m) = "height=" <> render m+ render (KeepAspectRatio b) = "keepaspectratio=" <> fromString (fmap toLower $ show b)+ render (IGScale r) = "scale=" <> render r+ render (IGAngle a) = "angle=" <> render a+ render (IGTrim l b r t) = "trim=" <> renderChars ' ' [l,b,r,t]+ render (IGClip b) = "clip=" <> fromString (fmap toLower $ show b)+ render (IGPage p) = "page=" <> render p++-- | Include an image in the document.+includegraphics :: LaTeXC l =>+ [IGOption] -- ^ Options+ -> FilePath -- ^ Image file+ -> l+includegraphics opts fp = fromLaTeX $ TeXComm "includegraphics"+ [ MOptArg $ fmap rendertex opts , FixArg $ TeXRaw $ fromString fp ]++-- | Rotate the content by the given angle in degrees.+rotatebox :: LaTeXC l => Float -> l -> l+rotatebox a = liftL $ \l -> TeXComm "rotatebox" [FixArg $ rendertex a , FixArg l]++-- | Scale the content by the given factor. If only the horizontal scale is supplied,+-- the vertical scaling will be the same.+scalebox :: LaTeXC l =>+ Float -- ^ Horizontal scale.+ -> Maybe Float -- ^ Vertical scale.+ -> l+ -> l+scalebox h mv = liftL $ \l ->+ TeXComm "rotatebox" $ [FixArg $ rendertex h]+ ++ maybe [] ((:[]) . OptArg . rendertex) mv+ ++ [FixArg l]++-- | Reflect horizontally the content.+reflectbox :: LaTeXC l => l -> l+reflectbox = liftL $ \l -> TeXComm "reflectbox" [FixArg l]++-- | Resize the content to match the given dimensions.+resizebox :: LaTeXC l =>+ Measure -- ^ Horizontal size.+ -> Measure -- ^ Vertical size.+ -> l+ -> l+resizebox h v = liftL $ \l ->+ TeXComm "resizebox" [FixArg $ rendertex h,FixArg $ rendertex v,FixArg l]
Text/LaTeX/Packages/Hyperref.hs view
@@ -1,80 +1,80 @@- -{-# LANGUAGE OverloadedStrings #-} - -module Text.LaTeX.Packages.Hyperref - ( -- * Hyperref package - hyperref - -- * Hyperref commands - , HRefOption (..) - , URL - , createURL - , href - , url - , nolinkurl - , hyperbaseurl - , hyperimage - , autoref - ) where - -import Text.LaTeX.Base.Syntax -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Render -import Text.LaTeX.Base.Types - --- | The 'hyperref' package. --- --- > usepackage [] hyperref -hyperref :: PackageName -hyperref = "hyperref" - -data HRefOption = - PDFRemoteStartView - | PDFNewWindow - | HRefPage Int - deriving Show - -instance Render HRefOption where - render PDFRemoteStartView = "pdfremotestartview" - render PDFNewWindow = "pdfnewwindow" - render (HRefPage n) = "page=" <> render n - -newtype URL = URL String deriving Show - -instance Render URL where - render (URL str) = fromString str - -createURL :: String -> URL -createURL = URL --- TODO: This function should check that the input --- String is a valid URL. - --- | 'fromString' = 'createURL'. -instance IsString URL where - fromString = createURL - --- | Reference to an 'URL'. -href :: LaTeXC l => [HRefOption] -> URL -> l -> l -href options u = liftL $ \t -> TeXComm "href" [ MOptArg $ fmap rendertex options - , FixArg $ rendertex u - , FixArg t ] - --- | Write an 'URL' hyperlinked. -url :: LaTeXC l => URL -> l -url u = fromLaTeX $ TeXComm "url" [ FixArg $ rendertex u ] - --- | Write an 'URL' without creating a hyperlink. -nolinkurl :: LaTeXC l => URL -> l -nolinkurl u = fromLaTeX $ TeXComm "nolinkurl" [ FixArg $ rendertex u ] - --- | Establish a base 'URL'. -hyperbaseurl :: LaTeXC l => URL -> l -hyperbaseurl u = fromLaTeX $ TeXComm "hyperbaseurl" [ FixArg $ rendertex u ] - --- | @hyperimage imgURL t@: --- The link to the image referenced by the @imgURL@ is inserted, using @t@ as the anchor. -hyperimage :: LaTeXC l => URL -> l -> l -hyperimage u = liftL $ \t -> TeXComm "hyperimage" [ FixArg $ rendertex u , FixArg t ] - --- | This is a replacement for the usual 'ref' command that places a contextual label in front of the reference. -autoref :: LaTeXC l => Label -> l -autoref l = fromLaTeX $ TeXComm "autoref" [ FixArg $ rendertex l ] ++{-# LANGUAGE OverloadedStrings #-}++module Text.LaTeX.Packages.Hyperref+ ( -- * Hyperref package+ hyperref+ -- * Hyperref commands+ , HRefOption (..)+ , URL+ , createURL+ , href+ , url+ , nolinkurl+ , hyperbaseurl+ , hyperimage+ , autoref+ ) where++import Text.LaTeX.Base.Syntax+import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Render+import Text.LaTeX.Base.Types++-- | The 'hyperref' package.+--+-- > usepackage [] hyperref+hyperref :: PackageName+hyperref = "hyperref"++data HRefOption =+ PDFRemoteStartView+ | PDFNewWindow+ | HRefPage Int+ deriving Show++instance Render HRefOption where+ render PDFRemoteStartView = "pdfremotestartview"+ render PDFNewWindow = "pdfnewwindow"+ render (HRefPage n) = "page=" <> render n++newtype URL = URL String deriving Show++instance Render URL where+ render (URL str) = fromString str++createURL :: String -> URL+createURL = URL+-- TODO: This function should check that the input+-- String is a valid URL.++-- | 'fromString' = 'createURL'.+instance IsString URL where+ fromString = createURL++-- | Reference to an 'URL'.+href :: LaTeXC l => [HRefOption] -> URL -> l -> l+href options u = liftL $ \t -> TeXComm "href" [ MOptArg $ fmap rendertex options+ , FixArg $ rendertex u+ , FixArg t ]++-- | Write an 'URL' hyperlinked.+url :: LaTeXC l => URL -> l+url u = fromLaTeX $ TeXComm "url" [ FixArg $ rendertex u ]++-- | Write an 'URL' without creating a hyperlink.+nolinkurl :: LaTeXC l => URL -> l+nolinkurl u = fromLaTeX $ TeXComm "nolinkurl" [ FixArg $ rendertex u ]++-- | Establish a base 'URL'.+hyperbaseurl :: LaTeXC l => URL -> l+hyperbaseurl u = fromLaTeX $ TeXComm "hyperbaseurl" [ FixArg $ rendertex u ]++-- | @hyperimage imgURL t@:+-- The link to the image referenced by the @imgURL@ is inserted, using @t@ as the anchor.+hyperimage :: LaTeXC l => URL -> l -> l+hyperimage u = liftL $ \t -> TeXComm "hyperimage" [ FixArg $ rendertex u , FixArg t ]++-- | This is a replacement for the usual 'ref' command that places a contextual label in front of the reference.+autoref :: LaTeXC l => Label -> l+autoref l = fromLaTeX $ TeXComm "autoref" [ FixArg $ rendertex l ]
Text/LaTeX/Packages/Inputenc.hs view
@@ -1,35 +1,35 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | This package is of vital importance if you use non-ASCII characters in your document. --- For example, if you type the word /Ángela/, the /Á/ character will not appear correctly in the --- output. 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 - -- * Encodings - , utf8 - , latin1 - ) where - -import Text.LaTeX.Base.Class -import Text.LaTeX.Base.Types - --- | Inputenc package. --- Example: --- --- > usepackage [utf8] inputenc -inputenc :: PackageName -inputenc = "inputenc" - --- | UTF-8 encoding. -utf8 :: LaTeXC l => l -utf8 = "utf8" - --- | Latin-1 encoding. -latin1 :: LaTeXC l => l -latin1 = "latin1" ++{-# LANGUAGE OverloadedStrings #-}++-- | This package is of vital importance if you use non-ASCII characters in your document.+-- For example, if you type the word /Ángela/, the /Á/ character will not appear correctly in the+-- output. 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+ -- * Encodings+ , utf8+ , latin1+ ) where++import Text.LaTeX.Base.Class+import Text.LaTeX.Base.Types++-- | Inputenc package.+-- Example:+--+-- > usepackage [utf8] inputenc+inputenc :: PackageName+inputenc = "inputenc"++-- | UTF-8 encoding.+utf8 :: LaTeXC l => l+utf8 = "utf8"++-- | Latin-1 encoding.+latin1 :: LaTeXC l => l+latin1 = "latin1"
Text/LaTeX/Packages/Trees.hs view
@@ -1,28 +1,28 @@- --- | Tree definition with some class instances. -module Text.LaTeX.Packages.Trees ( - -- * Tree - Tree (..) - ) where - -import Data.Monoid -import Data.Foldable -import Data.Traversable -import Control.Applicative - --- | Tree datatype. -data Tree a = - Leaf a -- ^ Leafs are non-empty. - | Node (Maybe a) [Tree a] -- ^ Node values are optional. - -instance Functor Tree where - fmap f (Leaf a) = Leaf $ f a - fmap f (Node ma ts) = Node (fmap f ma) $ fmap (fmap f) ts - -instance Foldable Tree where - foldMap f (Leaf a) = f a - foldMap f (Node ma ts) = foldMap f ma `mappend` mconcat (fmap (foldMap f) ts) - -instance Traversable Tree where - sequenceA (Leaf fa) = Leaf <$> fa - sequenceA (Node mfa ts) = liftA2 Node (sequenceA mfa) $ sequenceA $ fmap sequenceA ts ++-- | Tree definition with some class instances.+module Text.LaTeX.Packages.Trees (+ -- * Tree+ Tree (..)+ ) where++import Data.Monoid+import Data.Foldable+import Data.Traversable+import Control.Applicative++-- | Tree datatype.+data Tree a =+ Leaf a -- ^ Leafs are non-empty.+ | Node (Maybe a) [Tree a] -- ^ Node values are optional.++instance Functor Tree where+ fmap f (Leaf a) = Leaf $ f a+ fmap f (Node ma ts) = Node (fmap f ma) $ fmap (fmap f) ts++instance Foldable Tree where+ foldMap f (Leaf a) = f a+ foldMap f (Node ma ts) = foldMap f ma `mappend` mconcat (fmap (foldMap f) ts)++instance Traversable Tree where+ sequenceA (Leaf fa) = Leaf <$> fa+ sequenceA (Node mfa ts) = liftA2 Node (sequenceA mfa) $ sequenceA $ fmap sequenceA ts
Text/LaTeX/Packages/Trees/Qtree.hs view
@@ -1,48 +1,48 @@- -{-# LANGUAGE OverloadedStrings #-} - --- | Tree interface using the @qtree@ package. --- An example of usage is provided in the /examples/ directory of --- the source distribution. -module Text.LaTeX.Packages.Trees.Qtree ( - -- * Tree re-export - module Text.LaTeX.Packages.Trees - -- * Qtree package - , qtree - -- * Tree to LaTeX rendering - , tree - , rendertree - ) where - -import Text.LaTeX.Base -import Text.LaTeX.Base.Class -import Text.LaTeX.Packages.Trees --- -import Data.List (intersperse) - --- | The 'qtree' package. -qtree :: PackageName -qtree = "qtree" - -tree_ :: LaTeXC l => (a -> l) -> Tree a -> l -tree_ f (Leaf x) = braces $ f x -tree_ f (Node mx ts) = - mconcat [ "[" - , maybe mempty (("." <>) . braces . f) mx - , " " - , mconcat $ intersperse " " $ fmap (tree_ f) ts - , " ]" - ] - --- | Given a function to @LaTeX@ values, you can create a @LaTeX@ tree from a --- Haskell tree. The function specifies how to render the node values. -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) ++{-# LANGUAGE OverloadedStrings #-}++-- | Tree interface using the @qtree@ package.+-- An example of usage is provided in the /examples/ directory of+-- the source distribution.+module Text.LaTeX.Packages.Trees.Qtree (+ -- * Tree re-export+ module Text.LaTeX.Packages.Trees+ -- * Qtree package+ , qtree+ -- * Tree to LaTeX rendering+ , tree+ , rendertree+ ) where++import Text.LaTeX.Base+import Text.LaTeX.Base.Class+import Text.LaTeX.Packages.Trees+--+import Data.List (intersperse)++-- | The 'qtree' package.+qtree :: PackageName+qtree = "qtree"++tree_ :: LaTeXC l => (a -> l) -> Tree a -> l+tree_ f (Leaf x) = braces $ f x+tree_ f (Node mx ts) =+ mconcat [ "["+ , maybe mempty (("." <>) . braces . f) mx+ , " "+ , mconcat $ intersperse " " $ fmap (tree_ f) ts+ , " ]"+ ]++-- | Given a function to @LaTeX@ values, you can create a @LaTeX@ tree from a+-- Haskell tree. The function specifies how to render the node values.+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)
license view
@@ -1,30 +1,30 @@-Copyright (c)2013, Daniel Díaz - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of Daniel Díaz nor the names of other - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Copyright (c)2013, Daniel Díaz++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Daniel Díaz nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ parsertest/example4.tex view
@@ -0,0 +1,8 @@++\documentclass{article}++\begin{document}++Interval: $[0,1)$.++\end{document}
+ parsertest/example5.tex view
@@ -0,0 +1,4 @@+\documentclass{article}+\begin{document}+Let $x \in[0,1)$ be a number.+\end{document}
parsertest/parsertest.hs view
@@ -1,15 +1,15 @@ -import Text.LaTeX import Text.LaTeX.Base.Parser import qualified Data.Text.IO as T+import System.Exit (exitSuccess, exitFailure) testNumbers :: [Int]-testNumbers = [1 .. 3]+testNumbers = [1 .. 5] testFile :: Int -> IO Bool testFile i = do putStr $ "Parsing example " ++ show i ++ "... "- t <- T.readFile $ "example" ++ show i ++ ".tex"+ t <- T.readFile $ "parsertest/example" ++ show i ++ ".tex" case parseLaTeX t of Left err -> do putStrLn "Failed." putStrLn $ "The error was: " ++ show err@@ -22,5 +22,6 @@ bs <- mapM testFile testNumbers let b = and bs putStrLn $ "Parser Test Passed: " ++ show b- if b then return ()- else putStrLn $ "Test result: " ++ show (length $ filter (==True) bs) ++ "/" ++ show (length bs)+ if b then exitSuccess+ else do putStrLn $ "Test result: " ++ show (length $ filter (==True) bs) ++ "/" ++ show (length bs)+ exitFailure
test/Main.hs view
@@ -4,7 +4,6 @@ import Test.Tasty import qualified Test.Tasty.QuickCheck as QC-import Test.QuickCheck instance Eq ParseError where _ == _ = undefined