Creating a LaTeX table to display results
This recipe will create a table in LaTeX programmatically to facilitate document creation. We can create a PDF out of the LaTeX code and share it as we please.
Getting Ready
Install HaTeX
, the Haskell LaTeX library, from cabal:
$ cabal install LaTeX
How to do it…
Create a file named Main.hs
and follow these steps:
- Import the libraries as follows:
{-# LANGUAGE OverloadedStrings #-} import Text.LaTeX import Text.LaTeX.Base.Class import Text.LaTeX.Base.Syntax import qualified Data.Map as M
- Save a LaTeX file with our specifications as follows:
main :: IO () main = execLaTeXT myDoc >>= renderFile "output.tex"
- Define the document, which is split up into a preamble and a body, as follows:
myDoc :: Monad m => LaTeXT_ m myDoc = do thePreamble document theBody
- The preamble contains author data, title, and formatting options, among other things, as presented in the following code:
thePreamble :: Monad m => LaTeXT_ m thePreamble = do...