Literate highlighter preprocessor for lhs2tex http://spockz.github.com/lhs2texhl/

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

MIT licensed and maintained by Alessandro Vermeulen
Literate HS to TeX Highlighter Helper

Hi there,

welcome to the lhs2TeX-hl readme. lhs2TeX-hl is a tool for generating
formatting rules used by lhs2TeX. This tool is to be used in combination with

It aims to detect the `kind' of an identifier either by it's use or it's
declaration. Trying to detect both local declarations and usages.

Alessandro Vermeulen


* Make sure you have cabal installed and run

cabal install lhs2TeX-hl

* Or download the latest release from:
and install in the standard way.

* Or visit the github page:

Using lhs2TeX-hl is very simple. Just pass it your Haskell source file and it
will automatically generating formatting directives for you. Including but not
limited to formatting directives for data constructors and functions. Currently
`functions' that are strictly constants are not highlighted as functions.

lhs2TeX-hl -o <filename>.fmt <filename>.lhs

For more details see:

lhs2TeX-hl --help

Currently this is the only way to work with the tool.

In your .lhs file include the generated formatting files, like this:

%include polycode.fmt
%include <filename>.fmt

After this you'll need to provide the following LaTeX commands yourself:

* \lhsCHsyntax
* \lhsCHkeyword
* \lhsCHprelude
* \lhsCHtype
* \lhsCHconstructor
* \lhsCHfunction
* \lhsCHinfixoperator
* \lhsCHclass

Check out the ./examples directory and the examples section for example themes.

This tool only generates formatting directives for identifiers (including
operators) for you. If you want to change the formatting of characters,
strings or literal numbers add the following directives:

%subst char a = "{\color{char}\text{\tt ''" a "''}}"
%subst string a = "{\color{string}\text{\tt \char34 " a "\char34}}"
%subst numeral a = "{\color{numeral}{ " a " }}"

For other available substitutions consult the lhs2TeX manual.

Automatic markup
For your convenience there are some automatic rewrites being done.

* If a identifier names in a sequence of digits, the digits will be
typeset in subscript.
* If you have trailing underscores they will be omitted in the typesetting. This
is so you can do something like in <<Automatic_underscore_removal, Automatic
removal of trailing underscores>>.
And have Foo highlighted as a type constructor, and Foo_ highlighted as
`Foo' in a data constructor colour.

* If there are underscores in the middle of your identifier, everything after
the underscores will be typeset in subscript as in
<<Automatic_subscript_generation, Automatic subscript generation>>.

.Automatic removal of trailing underscores
data Foo = Foo_ a;

.Automatic subscript generation
foo_1 = undefined
-- Is transformed into
foo₁ = undefined


[source, latex]
% use package color
\definecolor{syntax}{RGB}{0, 0, 0}
\definecolor{datatype}{RGB}{196, 6, 11}
\definecolor{infixoperator}{RGB}{19, 19, 168}
\definecolor{constructor}{RGB}{196, 6, 11}
\definecolor{keyword}{RGB}{4, 58, 252}
\definecolor{string}{RGB}{3, 106, 7}
\definecolor{char} {RGB}{3, 106, 7}


%subst char a = "\color{char}\text{\tt ''" a "''}"
%subst string a = "\color{string}\text{\tt \char34 " a "\char34}"
%subst numeral a = "\color{numeral}{ " a " }"


* Infix operators may not work that great, or normal functions that are used
`infix`. Sometimes you might get an `ambiguous infix operator' error.
* AGDA isn't supported yet unfortunately.
* Errors aren't that informative. :)

* Added support for recursively traversing includes of .lhs files
* The program now doesn't fail completely when haskell-src-exts fails to parse
a file. An error is reported and the program continues. :) A fmt file is
still generated.
* Removed a faulty command from the list.
* Added a new url.
* Cleaned up some code. (Probably introduced other ugly code)
* Removed trace statement
* Fixed ambiguous import error on GHC 7.2
* You can now ask for a list of commands to import.
* Fixed build error + cabal things
* Removed the MissingH dependency.
* Added the file Language.Markup
* Added automatic rewrite rules, see section `Automatic markup'.
* And classes are now also written to the output file, somewhere I was
sleeping during all this. :)
* Fixed a regression, detection of language pragmas was apparently broken and
now they aren't anymore.
* Hopefully the ``ambiguous infix operator'' error shouldn't occur that often
* Removed the AGDA dependency for until it actually works.
* Classes are now detected.

comments powered byDisqus