Personal tools

HaTeX

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m (Text.LaTeX.IO module has been removed)
(About HaTeX)
 
(3 intermediate revisions by one user 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.
   
HaTeX page: http://ddiaz.asofilak.es/packages/HaTeX
+
This allows you to build programs which generates LaTeX code automatically for any purpose you can figure out.
   
Here a link to the package in Hackage: http://hackage.haskell.org/package/HaTeX
+
* HaTeX in Hackage: http://hackage.haskell.org/package/HaTeX.
   
== How to use HaTeX ==
+
* HaTeX in GitHub: https://github.com/Daniel-Diaz/HaTeX.
   
If you know how to use LaTeX, you will easily understand how to use HaTeX.
+
* [[HaTeX User's Guide]] (HaskellWiki version).
Otherwise, you will need to read well the documentation.
 
 
A first step may be to know the LaTeX file structure.
 
 
== LaTeX file structure ==
 
 
A LaTeX file has two parts:
 
 
- A ''preamble'' 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 preamble 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 $ do maketitle
 
hello
 
</haskell>
 
''Note: <code>maketitle</code> doesn't work in some document classes.''
 
 
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 monadic computations ==
 
 
All computations in HaTeX take place in the <code>LaTeXT</code> monadic transformer.
 
To includes a monadic computation, use <code>mlx</code>.
 
 
<haskell>
 
gtime = do t <- mlx getClockTime
 
...
 
</haskell>
 
 
== Adding sections ==
 
 
Commands to adding sections are included in Text.LaTeX.Commands. Examples are <code>section</code> or <code>paragraph</code>.
 
 
If you want sections without number, use <code>section_</code>. This also avoid showing the section into the table of contents.
 
 
If you want title of section to be different in the context than in the table of contents, use <code>sectiontab</code>.
 
 
== HaTeX Support ==
 
 
You can report any bug or suggestion at:
 
 
[email protected]
 
   
 
[[Category:Packages]]
 
[[Category:Packages]]

Latest revision as of 18:56, 6 January 2013

[edit] 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.