Skip to content

Instantly share code, notes, and snippets.

@spockz
Created September 27, 2011 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spockz/1245990 to your computer and use it in GitHub Desktop.
Save spockz/1245990 to your computer and use it in GitHub Desktop.
%% ----------------------------------------------------------------------------
%% required packages
%% ----------------------------------------------------------------------------
\RequirePackage{calc}
\RequirePackage{graphicx}
\RequirePackage{tikz}
\RequirePackage{hyperref} %% should be included last
%% ----------------------------------------------------------------------------
%% options
%% ----------------------------------------------------------------------------
\newif\iflang@dutch
\lang@dutchfalse
\newif\ifsection@pages
\section@pagestrue
\newif\ifhelvet
\helvetfalse
\DeclareOptionBeamer{dutch}{\lang@dutchtrue}
\DeclareOptionBeamer{english}{\lang@dutchfalse}
\DeclareOptionBeamer{sectionpages}{\section@pagestrue}
\DeclareOptionBeamer{nosectionpages}{\section@pagesfalse}
\DeclareOptionBeamer{helvet}{\helvettrue}
\ProcessOptionsBeamer
%% ----------------------------------------------------------------------------
%% colors
%% ----------------------------------------------------------------------------
% Official CS colors
\definecolor{uuxsilver}{rgb} {0.5,0.5,0.5}
\definecolor{uuxorange}{cmyk}{0,0.25,0.9,0}
\definecolor{uuxgreen} {cmyk}{1,0,0.75,0}
\definecolor{uuxred} {cmyk}{0.2,1,0.9,0.1}
% Corporate colors
\definecolor{uuyyellow}{cmyk}{0,0.115,0.94,0.15}
\definecolor{uuyred} {cmyk}{0,0.91,0.76,0.06}
% Extra corporate colors
\definecolor{uuyorange}{cmyk}{0,0.3,0.9,0}
\definecolor{uuyred} {cmyk}{0.2,1,0.9,0.1}
\definecolor{uuygreen} {cmyk}{0.9,0.15,0.7,0}
\definecolor{uuyblue} {cmyk}{0.9,0.55,0,0}
\definecolor{uuypurple}{cmyk}{0.7,1,0.2,0.05}
%
%% ----------------------------------------------------------------------------
%% outer theme
%% ----------------------------------------------------------------------------
% dimensions: 128mm * 96mm
\setbeamercolor{background canvas}{fg=black,bg=uuxsilver!20!white}
\setbeamercolor{structure}{fg=uuxred}
\newcommand{\backgroundpicture}{uueduc}
\newcommand{\includebackgroundpicture}{%
\if!\backgroundpicture!
\relax
\else
\includegraphics[width=12.8cm]{\backgroundpicture}%
\fi}
\newcommand{\frontmatter}{%
\setbeamertemplate{background}{%
\begin{tikzpicture}{0mm}{0mm}%
\clip (0,0) rectangle (12.8,9.6);%
\fill [uuxorange] (0,0) rectangle (12.8,9.6);%
\fill [uuxsilver] (45,10.5) circle (43.75cm);%
\fill [uuxred] (12.8,-23) circle (32.3cm);%
\begin{scope}%
\clip (12.8,-23) circle (32.3cm);%
\clip (45,10.5) circle (43.75cm);%
\fill [uuxsilver!10!white] (45,10.5) circle (43.75cm);%
\draw [opacity=0.2] (6.9,4.8) node%
{\includebackgroundpicture};%
\end{scope}%
\draw (2.9,7.2) node {\includegraphics[height=1.1cm]{uulogo}};%
\draw (9.8,7.35) node {\parbox[b]{5cm}{\scriptsize\cs@logo}};%
\end{tikzpicture}}%
\setbeamertemplate{navigation symbols}{}}
\newcommand{\mainmatter}{%
\setbeamertemplate{background}{%
\begin{tikzpicture}{0mm}{0mm}%
\clip (0,0) rectangle (12.8,9.6);%
\fill [uuxsilver!50!white] (0,0) rectangle (12.8,9.6);%
\draw [opacity=0.2] (-3.0,4.8) node%
{\includebackgroundpicture};%
\fill [uuxsilver!10!white] (30,6.5) circle (28.9cm);%
\draw (2.8,0.6) node {\includegraphics[height=0.8cm]{uulogo}};%
\draw (10.3,0.7) node {\parbox[b]{4cm}{\tiny\cs@logo}};%
\draw (0.5,0.25) node {\tiny\insertframenumber};%
\end{tikzpicture}}%
\setbeamertemplate{navigation symbols}{%
\insertslidenavigationsymbol%
\insertframenavigationsymbol%
\insertsubsectionnavigationsymbol%
\insertsectionnavigationsymbol%
\insertdocnavigationsymbol%
\insertbackfindforwardnavigationsymbol%
\hspace{0.35cm}}}
\mainmatter
\setbeamersize{text margin left=2cm}
\setbeamersize{text margin right=.5cm}
\newcommand{\cs@englishlogo}{%
\raggedleft %
\sffamily%
\textcolor{uuxred}{\textbf{[}}%%
Faculty of \textbf{Science}\\%
\textcolor{uuxred}{\textbf{Information and Computing Sciences}}%%
\textcolor{uuxred}{\textbf{]}}}%
\newcommand{\cs@dutchlogo}{%
\raggedleft%
\sffamily%
\textcolor{uuxred}{\textbf{[}}%%
Faculteit \textbf{B\`etawetenschappen}\\%
\textcolor{uuxred}{\textbf{Informatica}}%
\textcolor{uuxred}{\textbf{]}}}%
\newcommand{\cs@logo}{%
\renewcommand{\sfdefault}{cmss}
\iflang@dutch\cs@dutchlogo\else\cs@englishlogo\fi}%
\setbeamertemplate{head}{}
\setbeamertemplate{foot}{}
\setbeamertemplate{navigation symbols}{}
\ifhelvet
\renewcommand{\sfdefault}{phv}
\else
\renewcommand{\sfdefault}{cmss}
\fi
\renewcommand{\ttdefault}{cmtt}
\renewcommand{\emph}[1]{\textcolor{uuxred}{#1}}
\usefonttheme[onlymath]{serif}
%% ----------------------------------------------------------------------------
%% inner theme
\setlength{\parskip}{0.25cm}
\setbeamerfont{title}{series=\bfseries,size=\Large}
\setbeamertemplate{title page}{%
\vspace{2.5cm}%
\begin{center}%
{\usebeamerfont{title}\textcolor{uuxred}{\inserttitle}}%
\ifx\insertsubtitle\@empty%
\else%
\par{\usebeamerfont{subtitle}\textcolor{uuxred}{\insertsubtitle}}%
\fi%
\par\large\insertauthor%
\par\footnotesize\insertinstitute%
\par\small\insertdate%
\vfill%
\end{center}}
\newcommand{\section@number}{}%
\setbeamercolor{frametitle}{fg=uuxred}
\setbeamerfont{frametitle}{series=\bfseries}
\setbeamertemplate{frametitle}{%
\vspace{0.25cm}%
\hspace{-1.5cm}%
\usebeamerfont{frametitle}\usebeamercolor{frametitle}\insertframetitle%
\normalfont\normalsize\hfill\section@number}
\newcommand{\section@page}{%
\hspace{-1cm}%
\parbox{11.3cm}{%
\begin{center}%
\usebeamerfont{frametitle}%
\usebeamercolor[fg]{frametitle}%
\thesection.\ \,\insertsection%
\end{center}}}
\newcommand{\section@pagestar}{%
\hspace{-1cm}%
\parbox{11.3cm}{%
\begin{center}%
\usebeamerfont{frametitle}%
\usebeamercolor[fg]{frametitle}%
\insertsection%
\end{center}}}
\newcommand{\sectionheader}{\S\thesection}
\ifsection@pages
\AtBeginSection%
[\begin{frame}%
\section@pagestar%
\end{frame}%
\let\section@number\relax]%
{\begin{frame}%
\section@page%
\end{frame}%
\let\section@number\sectionheader}
\newcommand{\subsection@page}{%
\hspace{-1cm}%
\parbox{11.3cm}{%
\begin{center}%
\usebeamerfont{frametitle}%
\usebeamercolor[fg]{frametitle}%
\thesection.\thesubsection\ \,\insertsubsection%
\end{center}}}
\newcommand{\subsection@pagestar}{%
\hspace{-1cm}%
\parbox{11.3cm}{%
\begin{center}%
\usebeamerfont{frametitle}%
\usebeamercolor[fg]{frametitle}%
\insertsubsection%
\end{center}}}
\AtBeginSubsection%
[\begin{frame}%
\subsection@pagestar%
\end{frame}%
\renewcommand{\section@number}{}]
{\begin{frame}%
\subsection@page%
\end{frame}%
\renewcommand{\section@number}{\S\thesection.\thesubsection}}
\fi
\begin{code}
Your Haskell code,
make sure that the code and \begin{code} start
at column 0
\end{code}
%options ghci
\documentclass[]{beamer}
\usetheme{uucs}
\usepackage{xcolor, minted, verbatim}
\usemintedstyle{tango}
%include polycode.fmt
%if False
\begin{code}
{-# LANGUAGE UnicodeSyntax #-}
\end{code}
foo :: Int
foo = 4
%endif
\definecolor{syntax}{RGB}{0, 0, 0}
\definecolor{datatype}{RGB}{196, 6, 11}
\definecolor{class}{RGB}{168,37,39}
\definecolor{fieldname}{RGB}{0,0,162}
\definecolor{prelude}{RGB}{64,80,117}
\definecolor{numeral}{RGB}{0,0,205}
\definecolor{infixoperator}{RGB}{19, 19, 168}
\definecolor{constructor}{RGB}{196, 6, 11}
\definecolor{keyword}{RGB}{4, 58, 252}
\definecolor{special1}{RGB}{159,138,0}
\definecolor{string}{RGB}{3, 106, 7}
\definecolor{char} {RGB}{3, 106, 7}
\newcommand{\lhsCHsyntax}[1]{\color{syntax}{{#1}}}
\newcommand{\lhsCHfunction}[1]{\color{infixoperator}{{#1}}}
\newcommand{\lhsCHinfixoperator}[1]{\color{infixoperator}{{#1}}}
\newcommand{\lhsCHprelude}[1]{\color{prelude}{\mathbf{#1}}}
\newcommand{\lhsCHkeyword}[1]{\color{keyword}{\textbf{#1}}}
\newcommand{\lhsCHconstructor}[1]{\color{constructor}{\textbf{#1}}}
\newcommand{\lhsCHtype}[1]{\color{datatype}{{#1}}}
\newcommand{\lhsCHclass}[1]{\color{class}{{#1}}}
\title{Literate Haskell Programming}
\subtitle{with colour}
\date{October 28th}
\author{Alessandro Vermeulen}
%format code_ = code
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Why literate programming?}
\begin{itemize}
\item Easily document your code
\item Easily generate readable PDF documents with Haskell
\begin{itemize}
\item Check for type-errors with ghci, run your documents
\item Automatically evaluate expressions
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Requirements}
\begin{itemize}
\item A working \LaTeX\ environment
\item GHC(i)
\item \textbf{lhs2TeX}\\
For converting the literate haskell files
\item \textbf{optionally lhs2TeX-hl}\\
To colour your haskell source!
\end{itemize}
\end{frame}
\begin{frame}{Requirements - \LaTeX}
\begin{block}{Windows}
\url{http://miktex.org/}
\end{block}
\begin{block}{OS X}
\url{http://www.tug.org/mactex/2011/}
\end{block}
\begin{block}{Other}
See your own package manager
\end{block}
\end{frame}
\begin{frame}[fragile]{lhs2TeX and lhs2TeX-hl}
Install lhs2TeX and lhs2TeX-hl from hackage
\begin{minted}{sh}
?> cabal install lhs2TeX
?> cabal install lhs2TeX-hl
\end{minted}
\end{frame}
\begin{frame}[fragile]{Wrapping your document}
Just use the following include somewhere in the preamble of your document.
\begin{verbatim}
%include polycode.fmt
\end{verbatim}
\end{frame}
\begin{frame}[fragile]{Code}
\begin{block}{Code}
The code between these code blocks is automatically read by GHC(i) and
treated as code.
{\small\inputminted{latex}{code.snip}}
\end{block}
\end{frame}
\begin{frame}[fragile]{Specs}
\begin{block}{Specs}
Sometimes you want to typeset Haskell, but you don't want GHC(i) to
interpret it as code. Then you use spec:
{\small\inputminted{latex}{spec.snip}}
\end{block}
\end{frame}
\begin{frame}[fragile]{Building the document}
\begin{minted}{bash}
lhs2TeX -o file.tex file.lhs
pdflatex file.tex
\end{minted}
\end{frame}
\begin{frame}[fragile]{TMS}
This code is nice, but still looks a bit messy.
\begin{code}
tms :: [Int]
tms = map t [0..]
where t 0 = 0
t n | even n = t (n `div` 2)
| otherwise = 1 - t ((n-1) `div` 2)
\end{code}
\begin{verbatim}
tms :: [Int]
tms = map t [0..]
where t 0 = 0
t n | even n = t (n `div` 2)
| otherwise = 1 - t ((n-1) `div` 2)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]{TMS - again}
\begin{block}{Solution}
Layout the code with extra spaces. Each token that is in the same column and
is preceeded by two spaces or more will get aligned in the same column.
\end{block}
\begin{spec}
tms :: [Int]
tms = map t [0..]
where t 0 = 0
t n | even n = t (n `div` 2)
| otherwise = 1 - t ((n-1) `div` 2)
\end{spec}
\begin{verbatim}
tms :: [Int]
tms = map t [0..]
where t 0 = 0
t n | even n = t (n `div` 2)
| otherwise = 1 - t ((n-1) `div` 2)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]{Eval}
Evaluate an expression:
\begin{spec}
take 10 tms
\end{spec}
\begin{block}{Evaluation}
\begin{verbatim}
\eval{take 10 tms}
\end{verbatim}
Result: \eval{take 10 tms}
\end{block}
\end{frame}
\begin{frame}{Running GHC(i)}
You can just open the literate file as if it were a normal Haskell file.
\end{frame}
\begin{frame}[fragile]{Adding colour}
\begin{block}{Command}
Run this command additionally.
\begin{minted}{bash}
lhs2TeX-hl -o file.fmt file.lhs
\end{minted}
\end{block}
\begin{block}{Experimental}
This tool is still experimental so please report bugs to:
\url{https://github.com/spockz/lhs2texhl}
\end{block}
\end{frame}
\begin{frame}[fragile]{Including the format file}
Include the generated format file
\begin{verbatim}
%include file.fmt
\end{verbatim}
\end{frame}
\begin{frame}[fragile]{Latex colour definitions}
\begin{minted}[fontsize=\footnotesize]{latex}
\definecolor{syntax}{RGB}{0, 0, 0}
\definecolor{datatype}{RGB}{196, 6, 11}
\definecolor{class}{RGB}{168,37,39}
\definecolor{fieldname}{RGB}{0,0,162}
\definecolor{prelude}{RGB}{64,80,117}
\definecolor{numeral}{RGB}{0,0,205}
\definecolor{infixoperator}{RGB}{19, 19, 168}
\definecolor{constructor}{RGB}{196, 6, 11}
\definecolor{keyword}{RGB}{4, 58, 252}
\definecolor{special1}{RGB}{159,138,0}
\definecolor{string}{RGB}{3, 106, 7}
\definecolor{char} {RGB}{3, 106, 7}
\end{minted}
\end{frame}
\begin{frame}[fragile]{Latex colour definitions}
\begin{minted}[fontsize=\footnotesize]{latex}
\newcommand{\lhsCHsyntax}[1]{\color{syntax}{{#1}}}
\newcommand{\lhsCHfunction}[1]{\color{infixoperator}{{#1}}}
\newcommand{\lhsCHinfixoperator}[1]{\color{infixoperator}{{#1}}}
\newcommand{\lhsCHprelude}[1]{\color{prelude}{\mathbf{#1}}}
\newcommand{\lhsCHkeyword}[1]{\color{keyword}{\textbf{#1}}}
\newcommand{\lhsCHconstructor}[1]{\color{constructor}{\textbf{#1}}}
\newcommand{\lhsCHtype}[1]{\color{datatype}{{#1}}}
\newcommand{\lhsCHclass}[1]{\color{class}{{#1}}}
\end{minted}
\end{frame}
\begin{frame}[fragile]{Constants}
\begin{verbatim}
%subst char a = "{\color{char}\text{\tt ''" a "''}}"
%subst string a = "{\color{string}\text{\tt \char34 " a "\char34}}"
%subst numeral a = "{\color{numeral}{ " a " }}"
\end{verbatim}
\end{frame}
%include presentation.fmt
%subst char a = "{\color{char}\text{\tt ''" a "''}}"
%subst string a = "{\color{string}\text{\tt \char34 " a "\char34}}"
%subst numeral a = "{\color{numeral}{ " a " }}"
\begin{frame}[fragile]{TMS with colour}
\begin{spec}
tms :: [Int]
tms = map t [0..]
where t 0 = 0
t n | even n = t (n `div` 2)
| otherwise = 1 - t ((n-1) `div` 2)
tms_test = take 500 tms
main = print "Hello World"
\end{spec}
\end{frame}
\begin{frame}{Themes}
Create your own themes by changing the colour definitions from the above slide.
\end{frame}
\begin{frame}{Source and More}
\begin{block}{Source}
You can find the source of this presentation at:
\url{https://gist.github.com/1245990}
The command used to generate this pdf:
\begin{verbatim}
lhs2TeX-hl -o presentation.fmt presentation.lhs \
&& lhs2TeX -o presentation.tex presentation.lhs \
&& pdflatex --shell-escape presentation.tex
\end{verbatim}
\end{block}
\begin{block}{More information}
For more information on lhs2TeX you can visit:
\url{http://people.cs.uu.nl/andres/lhs2tex/}
\end{block}
\end{frame}
\end{document}
\begin{spec}
Here you can write down Haskell
\end{spec}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment