Skip to content

Instantly share code, notes, and snippets.

@ulysses4ever
Last active June 23, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulysses4ever/c2374d35326b8644e27d0018b12d8ae3 to your computer and use it in GitHub Desktop.
Save ulysses4ever/c2374d35326b8644e27d0018b12d8ae3 to your computer and use it in GitHub Desktop.
Typeset Haskell code in LaTeX: an example of colorful lhs2TeX
% Build main.pdf:
% lhs2TeX main.lhs -o main.tex
% pdflatex main.tex
\documentclass{article}
%%%%%%%%%%%%%% Color-related things %%%%%%%%%%%%%%
\usepackage[dvipsnames]{xcolor}
%include polycode.fmt
%subst keyword a = "\textcolor{BlueViolet}{\textbf{" a "}}"
\newcommand{\id}[1]{\textsf{\textsl{#1}}}
\renewcommand{\Varid}[1]{\textcolor{Sepia}{\id{#1}}}
\renewcommand{\Conid}[1]{\textcolor{OliveGreen}{\id{#1}}}
%%%%%%%%%%%% End of Color-related things %%%%%%%%%%%%
% It might make sence to add pretty formating of individual things
% like "forall", cf.
% https://github.com/goldfirere/thesis/blob/master/tex/rae.fmt
\begin{document}
\begin{code}
module ColorsInLhs2TeX where
newtype Foo = MkFoo Int
plusFoo :: Foo -> Foo -> Int
plusFoo (MkFoo n) (MkFoo m) = n + m
\end{code}
\end{document}
@ulysses4ever
Copy link
Author

ulysses4ever commented Jun 23, 2018

Result:
screenshot from 2018-06-23 13-28-08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment