packages feed

HaTeX 3.13.0.1 → 3.13.1.0

raw patch · 10 files changed

+155/−17 lines, 10 filesbinary-addedPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.LaTeX.Base.Commands: matrixTabular :: (LaTeXC l, Texy a) => [l] -> Matrix a -> l

Files

+ CHANGELOG.md view
@@ -0,0 +1,7 @@++# 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.+* Some documentation improvements.+* Added this CHANGELOG!
Examples/parser.hs view
@@ -8,7 +8,7 @@  main :: IO () main = case parseLaTeX example of-  Left err -> putStrLn err+  Left err -> print err   Right l  -> do     putStrLn "Printing LaTeX AST..."     print l
+ Examples/tables.hs view
@@ -0,0 +1,38 @@++{-# LANGUAGE OverloadedStrings #-}++import Text.LaTeX+import Text.LaTeX.Packages.Inputenc+import Data.Matrix++main :: IO ()+main = execLaTeXT tables >>= renderFile "tables.tex"++tables :: Monad m => LaTeXT m ()+tables = thePreamble >> document theBody++thePreamble :: Monad m => LaTeXT m ()+thePreamble = do+  documentclass [] article+  usepackage [utf8] inputenc+  author "Daniel Díaz"+  title "Examples of Tables"++theBody :: Monad m => LaTeXT m ()+theBody = do+  maketitle+  -- Table from a simple matrix+  center $ matrixTabular (fmap textbf ["x","y","z"]) $+    fromList 3 3 [ (1 :: Int)..]+  -- Table from a matrix calculated in-place+  center $ matrixTabular (fmap textbf ["Number","Square root"]) $+    matrix 9 2 $ \(i,j) -> if j == 1 then I i else R $ sqrt $ fromIntegral i++-- Creating custom instances of Texy to display elements+-- within a table.++data Number = R Double | I Int++instance Texy Number where+  texy (R x) = texy x+  texy (I i) = texy i
HaTeX.cabal view
@@ -1,5 +1,5 @@ Name: HaTeX
-Version: 3.13.0.1
+Version: 3.13.1.0
 Author: Daniel Díaz
 Category: Text, LaTeX
 Build-type: Simple
@@ -9,23 +9,37 @@ Bug-reports: https://github.com/Daniel-Diaz/HaTeX/issues
 homepage: http://daniel-diaz.github.io/projects/hatex
 Synopsis: The Haskell LaTeX library.
-Description: This library provides a bridge between LaTeX and Haskell, implementing the LaTeX /syntax/
-             in Haskell.
+Description: This library implements the LaTeX syntax and provides some useful abstractions.
              .
              Some of the things you can do with HaTeX are:
              .
-             Write LaTeX documents with all the advantages you already have in Haskell (recursion,
-             type system, high order functions, ...), create a LaTeX backend for your own program,
-             parse a LaTeX file and obtain its Abstract Syntax Tree (AST), pretty-print Haskell
-             values in LaTeX, generate TikZ scripts easily, ...
+             * Write LaTeX documents with all the advantages you already have in Haskell: recursion,
+               type system, high order functions, ...
              .
+             * Create a LaTeX backend for your own program.
+             .
+             * Parse a LaTeX file and obtain its Abstract Syntax Tree (AST).
+             .
+             * Pretty-print Haskell values in LaTeX.
+             .
+             * Generate TikZ scripts (images!) easily.
+             .
              Browse the @examples@ directory in the source distribution to see some simple examples.
-             It would be good to get you started. The HaTeX User's Guide is available at
+             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)
+             and an IRC channel (@#hatex@). If you just want to read a short introduction, read
+             the "Text.LaTeX" module.
+             .
+             If you prefer to write in LaTeX and all you want is to /program/ some parts of the document,
+             or if you already have the LaTeX document written and you just want to add some automatically
+             generated LaTeX code somewhere, check haskintex: <http://daniel-diaz.github.io/projects/haskintex>.
+             It allows you to embed Haskell in LaTeX. It also makes you easy to use HaTeX within a LaTeX document.
 Cabal-version: >= 1.10
 Extra-source-files:
   ReleaseNotes
   README.md
+  CHANGELOG.md
   -- Examples
   Examples/*.hs
   -- Tests
@@ -36,6 +50,8 @@   docfiles/tikz/*.png
   -- Beamer
   docfiles/beamers/*.png
+  -- Others
+  docfiles/others/*.png
 
 Source-repository head
   type: git
Text/LaTeX/Base/Commands.hs view
@@ -1,6 +1,10 @@+ {-# LANGUAGE OverloadedStrings #-} --- | LaTeX standard commands and environments.+-- | This module is the /Prelude/ of LaTeX functions.+--   It includes commands, environments, and some other+--   useful abstractions, that don't require you to+--   import additional LaTeX packages. module Text.LaTeX.Base.Commands  ( -- * Basic functions    raw , between , comment , (%:)@@ -189,6 +193,8 @@  , hline  , cline  , multicolumn+   -- *** Special tables+ , matrixTabular    -- ** Others  , footnote  , protect@@ -208,13 +214,15 @@ import Text.LaTeX.Base.Class import Text.LaTeX.Base.Render import Text.LaTeX.Base.Types+import Text.LaTeX.Base.Texy import Data.Version-import Data.List (find, intercalate)+import Data.List (find, intercalate,intersperse)+import Data.Matrix (Matrix,nrows,ncols,(!)) -- import Paths_HaTeX  -- | Insert a raw piece of 'Text'.--- This functions doesn't care about @LaTeX@ reserved characters,+-- This functions doesn't escape @LaTeX@ reserved characters, -- it insert the text just as it is received. -- -- /Warning:/ This function is /unsafe/, in the sense that it does@@ -296,6 +304,7 @@ part :: LaTeXC l => l -> l part = comm1 "part" +-- | Start a new chapter with the given title. chapter :: LaTeXC l => l -> l chapter = comm1 "chapter" @@ -320,7 +329,7 @@ subparagraph = comm1 "subparagraph"  -- | Create the table of contents, automatically generated--- from your 'section's, 'subsection's, and other related stuff.+-- from your 'section's, 'subsection's, and related functions. tableofcontents :: LaTeXC l => l tableofcontents = comm0 "tableofcontents" @@ -861,6 +870,69 @@   , FixArg . TeXRaw $ renderAppend c   , FixArg l   ]++-----------------------------------------+-- Special Tables (Tabulars)++-- | If you are able to arrange some data in matrix form, you+--   might want to use this function to quickly generate a+--   tabular with your data. Each element of the matrix is+--   rendered using the 'Texy' instance of its type. If you+--   want a custom instance for an already instantiated type,+--   wrap that type using @newtype@, and then create your own+--   instance. Since every element of a matrix must be of the+--   same type, for mixed tables you might want to create an+--   union type. For example, if your data matrix contains+--   'Int's and 'Double's:+--+-- > data Number = R Double | I Int+-- >+-- > instance Texy Number where+-- >   texy (R x) = texy x+-- >   texy (I x) = texy x+--+--   Now you can have a matrix of type @Matrix Number@ and use it+--   to render your mixed data in a LaTeX table.+--+--   The function 'matrixTabular' does not give you many options,+--   so it is not as flexible as generating the table by yourself,+--   but it uses a reasonable standard style.+--+--   A very simple example:+--+-- > matrixTabular (fmap textbf ["x","y","z"]) $+-- >   fromList 3 3 [ (1 :: Int)..]+--+--   This code generates the following table:+--+--   <<docfiles/others/table.png>>+--+--   For more examples see the file @Examples/tables.hs@, included+--   in the source distribution.+--+--   For more info about how to generate and manipulate matrices,+--   see "Data.Matrix".+--+matrixTabular :: (LaTeXC l, Texy a)+              => [l] -- ^ (Non-empty) List of column titles+              -> Matrix a -- ^ Matrix of data+              -> l -- ^ Data organized in a tabular environment+matrixTabular ts m =+  let spec = VerticalLine : (intersperse VerticalLine $ replicate (ncols m) CenterColumn) ++ [VerticalLine]+  in  tabular Nothing spec $ mconcat+        [ hline+        , foldl1 (&) ts+        , lnbk+        , hline+        , mconcat $ fmap (+            \i -> mconcat [ foldl1 (&) $ fmap (\j -> texy (m ! (i,j))) [1 .. ncols m]+                          , lnbk+                          , hline+                            ] ) [1 .. nrows m]+          ]++-----------------------------------------+-----------------------------------------  -- | @cline i j@ writes a partial horizontal line beginning in column @i@ and ending in column @j@. cline :: LaTeXC l => Int -> Int -> l
Text/LaTeX/Base/Syntax.hs view
@@ -96,6 +96,9 @@  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"),
Text/LaTeX/Base/Texy.hs view
@@ -8,7 +8,6 @@ import Text.LaTeX.Base.Syntax import Text.LaTeX.Base.Class import Text.LaTeX.Base.Render-import Text.LaTeX.Base.Commands -- import Numeric import Data.Fixed@@ -23,7 +22,7 @@  texy = fromLaTeX  instance Texy Text where- texy = raw . protectText+ texy = fromLaTeX . TeXRaw . protectText  instance Texy Int where  texy = rendertex
Text/LaTeX/Base/Writer.hs view
@@ -174,7 +174,6 @@  tell $ f l
  return p
 
-
 -- | Lift an operator over 'LaTeX' values to an operator
 --   acting over the state of two 'LaTeXT' computations.
 --
@@ -192,6 +191,7 @@ -- | Just like 'rendertex', but with 'LaTeXT' output.
 --
 -- > rendertexM = textell . rendertex
+--
 rendertexM :: (Render a, Monad m) => a -> LaTeXT m ()
 rendertexM = textell . rendertex
 
@@ -200,6 +200,9 @@ 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 = (>>)
+
+ docfiles/others/table.png view

binary file changed (absent → 7033 bytes)

test/Main.hs view
@@ -16,7 +16,7 @@          \l -> (mempty <> l) == (l <> mempty)             && (mempty <> l) == (l :: LaTeX)     , QC.testProperty "LaTeX mappend" $-         \l1 l2 l3 -> render (l1 <> (l2 <> l3)) == render ((l1 <> l2) <> (l3 :: LaTeX))+         \l1 l2 l3 -> l1 <> (l2 <> l3) == (l1 <> l2) <> (l3 :: LaTeX)     ]   , testGroup "Parser"     [ QC.testProperty "render . parse = id" $