This Guide to lhs2TeX shows an example of customization of the poly style in 4.2 which is pretty much exactly what I want, but it does not actually show the way to achieve this. I am quite new LaTeX and don't really get how to do this without manually wrapping a new font directive around each code block in the file generated by lhs2Tex.

  • Please add a minimal working example (MWE). Feb 5, 2019 at 3:41
  • I have not used it as I do not have a need for Haskell or a working lhs2TeX however looking at the out of date manuals and dependencies I suggest you read all the manuals (with appropriate pinches of salt) you will need a stable working Latex that you are familiar with, Then in the package manager add both LazyList and PolyStyle DO NOT manually install either as both of those packages should be controlled by either MiKTeX or TexLive. IS there a reason to go down this tabular/tabbing-like environments route do you have vast amounts of complex Haskell output or would it be easier to hand build?
    – user170109
    Feb 5, 2019 at 5:25
  • @KJO Hand building would be tedious for about 10 pages of Haskell code. I also really like the style they used in the example, but I can't really find anything about achieving that in the Documentation.
    – tolUene
    Feb 8, 2019 at 1:14

1 Answer 1


You can insert arbitrary LaTeX commands in your preamble after %include polycode.fmt, including font commands.

The polycode.fmt file does set up a few commands that change the font to a specific family, so it is necessary to override them with \renewcommand.

This example sets up the output to use unicode-math, and selects TeX Gyre Pagella (a Palatino clone) as the main font.

\usepackage[paperwidth = 10cm]{geometry} % Appropriate width for a MWE on TeX.SX.
%include polycode.fmt

\defaultfontfeatures{ Scale = MatchUppercase }
\setmainfont{TeX Gyre Pagella}[Ligatures = {Common, TeX}, Scale = 1.0]
\setsansfont{URW Classico}
\setmathfont{TeX Gyre Pagella Math}


zip                        ::  [a] -> [b] -> [(a,b)]
zip                        =   zipWith  (\a b -> (a,b))

zipWith                    ::  (a->b->c) -> 
                               [a]->[b] ->
zipWith z  (a:as)  (b:bs)  =   z a b : zipWith z as bs
zipWith _  _       _       =   []

partition                  ::  (a -> Bool) -> [a] ->
partition p xs             =   foldr select ([],[]) xs
  where select x (ts,fs)    |  p x        =  (x:ts,fs)
                            |  otherwise  =  (ts,x:fs)

Pagella listing sample

  • +1 am deleting my poor first attempt, since on digging deeper I feel LyX is currently not as well suited as the "traditional route" and may simply add an extra layer of complexity.
    – user170109
    Feb 8, 2019 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.