Typesetting Haskell in LaTeX for research

I find myself writing a conference paper that will feature a couple Haskell snippets.

Short of re-doing everything in Literate Haskell or pulling in pandoc, what’s a good reference for nice-looking lstlistings (LaTeX package for typesetting code) defaults ?

4 Likes

A good way to find examples is to search GitHub repositories using a query like the following:

https://github.com/search?l=TeX&q=haskell&s=stars&type=Repositories

When using listings, it is pretty common practice to configure settings for each specific paper, adding/removing keywords and setting options to make the code in that paper look as desired. You can check the source definition for the Haskell “driver” (based on Haskell98) in the lstdrvrs.pdf documentation to better understand the defaults.

Searching for recent examples, I found the following, which uses lstset:

https://github.com/snowleopard/united/blob/master/paper/main.tex

Here is another example, which uses lstdefinestyle:

https://github.com/liuxinyu95/AlgoXY/blob/algoxy/prelude.sty

Note that the minted package is a popular alternative to listings that uses Pygments for syntax highlighting. You might want to consider it, particularly if you want more sophisticated syntax highlighting than listings can provide.

1 Like

Use lhs2tex. The most beautiful typeset Haskell you will see. It’s with the conversion to literate Haskell. Check out my cheat sheet (cheatsheet.codeslower.com) and thesis (mil.codeslower.com) to see what it can do.

Good luck!

2 Likes

Thanks! Unfortunately the cheatsheet link doesn’t work though.

Oops, misspelled. Here you go http://cheatsheet.codeslower.com/

1 Like