HaTeX- The Haskell LaTeX library.

Safe HaskellSafe




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.



class (Monoid l, IsString l) => LaTeXC l where Source

This is the class of LaTeX code generators. It has Monoid and IsString as superclasses.


liftListL :: ([LaTeX] -> LaTeX) -> [l] -> l Source

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.


LaTeXC LaTeX Source

This instance just sets liftListL = id.

(Monad m, (~) * a ()) => LaTeXC (LaTeXT m a) Source 

class Monoid a where

The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:

  • mappend mempty x = x
  • mappend x mempty = x
  • mappend x (mappend y z) = mappend (mappend x y) z
  • mconcat = foldr mappend mempty

The method names refer to the monoid of lists under concatenation, but there are many other instances.

Some types can be viewed as a monoid in more than one way, e.g. both addition and multiplication on numbers. In such cases we often define newtypes and make those instances of Monoid, e.g. Sum and Product.

Minimal complete definition

mempty, mappend


mempty :: a

Identity of mappend

mappend :: a -> a -> a

An associative operation

mconcat :: [a] -> a

Fold a list using the monoid. For most types, the default definition for mconcat will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.


Monoid Ordering 
Monoid () 
Monoid All 
Monoid Any 
Monoid ByteString 
Monoid ByteString 
Monoid Builder 
Monoid IntSet 
Monoid Doc 
Monoid LaTeX

Method mappend is strict in both arguments (except in the case when the first argument is TeXEmpty).

Monoid TeXCheck 
Monoid [a] 
Ord a => Monoid (Max a) 
Ord a => Monoid (Min a) 
Monoid a => Monoid (Dual a) 
Monoid (Endo a) 
Num a => Monoid (Sum a) 
Num a => Monoid (Product a) 
Monoid (First a) 
Monoid (Last a) 
Monoid a => Monoid (Maybe a)

Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S." Since there is no "Semigroup" typeclass providing just mappend, we use Monoid instead.

Ord a => Monoid (Max a) 
Ord a => Monoid (Min a) 
Monoid (IntMap a) 
Ord a => Monoid (Set a) 
Monoid (Seq a) 
Monoid (Vector a) 
(Ord a, Bounded a) => Monoid (Min a) 
(Ord a, Bounded a) => Monoid (Max a) 
Monoid m => Monoid (WrappedMonoid m) 
Semigroup a => Monoid (Option a) 
(Hashable a, Eq a) => Monoid (HashSet a) 
Monoid (Doc e) 
Monoid b => Monoid (a -> b) 
(Monoid a, Monoid b) => Monoid (a, b) 
Monoid a => Monoid (Const a b) 
Monoid (Proxy k s) 
Ord k => Monoid (Map k v) 
(Eq k, Hashable k) => Monoid (HashMap k v) 
(Monad m, (~) * a ()) => Monoid (LaTeXT m a) 
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) 
Alternative f => Monoid (Alt * f a) 
Monoid a => Monoid (Tagged k s a) 
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) 
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) 


From LaTeX

fromLaTeX :: LaTeXC l => LaTeX -> l Source

Map a LaTeX value to its equivalent in any LaTeXC instance.


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 :: LaTeXC l => (LaTeX -> LaTeX) -> l -> l Source

Lift a inner function of LaTeX values into any LaTeXC instance.

liftL2 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX) -> l -> l -> l Source

Variant of liftL with a two arguments function.

liftL3 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l Source

Variant of liftL with a three arguments function.


comm0 :: LaTeXC l => String -> l Source

A simple (without arguments) and handy command generator using the name of the command.

comm0 str = fromLaTeX $ TeXComm str []

comm1 :: LaTeXC l => String -> l -> l Source

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]

commS :: LaTeXC l => String -> l Source

Like comm0 but using TeXCommS, i.e. no "{}" will be inserted to protect the command's end.

commS = fromLaTeX . TeXCommS

braces :: LaTeXC l => l -> l Source

A lifted version of the TeXBraces constructor.

braces = liftL TeXBraces