Personal tools

HaTeX

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m
(Added HaTeX User's Guide)
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== About HaTeX ==
 
== About HaTeX ==
   
HaTeX is a package wich lets you to write LaTeX code from Haskell.
+
HaTeX consists in a set of combinators which allow you to build LaTeX code, following the LaTeX syntax in a type-safe manner.
   
Here a link to the package in Hackage: http://hackage.haskell.org/package/HaTeX
+
This allows you to build programs which generates LaTeX code automatically for any purpose you can figure out.
   
== How to use HaTeX ==
+
* HaTeX homepage: http://dhelta.net/hprojects/HaTeX.
   
If you know how to use LaTeX, you will easily understand how to use HaTeX.
+
* HaTeX in Hackage: http://hackage.haskell.org/package/HaTeX.
Otherwise, you will need to read well the documentation.
 
   
A first step may be to know the LaTeX file structure.
+
* [[HaTeX User's Guide]] (HaskellWiki version).
   
== LaTeX file structure ==
+
[[Category:Packages]]
 
A LaTeX file has two parts:
 
 
- A header where you define general settings (document class, page style, use of extern packages, ...) of your document.
 
 
- The document's content.
 
 
== A simple example ==
 
 
We're going to write an example, the best for understanding.
 
 
* Function <code>documentclass</code> is used for determining if our document is an <code>article</code>, a <code>book</code>, a <code>report</code>, etc.
 
 
* Function <code>author</code> is used for specify document's authory.
 
 
* Function <code>title</code> for document's title.
 
 
Then, with this three functions, we will define a header in the <code>LaTeX</code> monad.
 
<code>LaTeX</code> is a writer monad that concatenates the text generated by the programmer.
 
Usually, the text is generated simply writing it, or by functions.
 
<haskell>
 
example = do documentclass [] article
 
author "Daniel Diaz"
 
title "Example"
 
</haskell>
 
The first argument of <code>documentclass</code> is used for change certain settings of the class.
 
For example, you can set the document's main font size to 12pt, writing:
 
<haskell>
 
documentclass [pt 12] article
 
</haskell>
 
Or set paper size to A4:
 
<haskell>
 
documentclass [pt 12,a4paper] article
 
</haskell>
 
Now, I will write a content:
 
<haskell>
 
hello = "Hello, world!"
 
</haskell>
 
To insert the content into the document, we have the function <code>document</code>. Completing our first example:
 
<haskell>
 
example = do documentclass [] article
 
author "Daniel Diaz"
 
title "Example"
 
document hello
 
</haskell>
 
At first glance, it seems that <code>author</code>, <code>title</code> or <code>document</code> receive a <code>String</code> as argument.
 
Really, they require a <code>LaTeX</code> argument. <code>LaTeX</code> is the type that represents texts in HaTeX.
 
So, I recommend to use Overloaded Strings
 
(See [http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/type-class-extensions.html#overloaded-strings]).
 
 
== Enriching your text ==
 
 
There are numerous functions to enrich your document.
 
One feature is change your font format. For example, in:
 
<haskell>
 
texttt "Hello!"
 
</haskell>
 
<code>texttt</code> sets as monospaced font his content. Or composing:
 
<haskell>
 
texttt $ textbf "Hello!"
 
</haskell>
 
<code>textbf</code> sets as bold font the monospaced font of <code>"Hello!"</code>.
 
 
If you only want <code>"ll"</code> with bold format:
 
<haskell>
 
texttt $ do "He"
 
textbf "ll"
 
"o!"
 
</haskell>
 
Applying the function to only part of the text, we achieve modify just that part.
 
 
== Performing IO computations ==
 
 
To includes an <code>IO</code> computation in <code>LaTeX</code> monad, use <code>iolx</code>.
 
<haskell>
 
gtime = do t <- iolx getClockTime
 
...
 
</haskell>
 
Some <code>IO</code> computations are predefined in Text.LaTeX.IO.
 
 
== HaTeX Support ==
 
 
You can report any bug or suggestion at:
 
 
[email protected]
 

Revision as of 17:16, 28 April 2012

About HaTeX

HaTeX consists in a set of combinators which allow you to build LaTeX code, following the LaTeX syntax in a type-safe manner.

This allows you to build programs which generates LaTeX code automatically for any purpose you can figure out.