[Haskell-cafe] LaTeX question: interpreter examples
Joachim Breitner
mail at joachim-breitner.de
Fri Aug 28 08:51:58 UTC 2015
Hi,
Am Freitag, den 28.08.2015, 00:19 -0800 schrieb Christopher Howard:
> Hi. I'm doing a lot of Literate Haskell lately, with proofs and
> commentary in each module. I'm not very familiar with LaTeX, but I'm
> learning. (I'm using lhs2tex and texi2pdf.) However, in my
> commentary,
> I occasionally have blocks of example interpreter interaction, and
> I'm
> not sure what to do with it. Is there a certain command enclosure
> that
> would be appropriate? Ideally, it would treat the text like
> monospace,
> and also preserve line breaks. Example text would be:
>
> *GCD> extEuclidean 546 2022
> (6,100,-27)
> *GCD> 546 * 100 + 2022 * (-27) == 6
> True
>
> But this does not come out looking similar in the final output.
I have a hack used for
http://www.joachim-breitner.de/publications/haskell_bytes_portland_2014-06-13.pdf
where in interpreter sessions, everything is in mono-spaced fonts but the line following a >.
This is the relevant LaTeX code:
\usepackage{listings}
\definecolor{light-gray}{gray}{0.95}
\lstdefinestyle{basic}{
,columns=flexible
,basewidth={.365em}
,keepspaces=True
,belowskip=0pt
,backgroundcolor=\color{light-gray}
,frame=single
,xleftmargin=1em
,xrightmargin=1em
,basicstyle=\small\sffamily
,stringstyle=\itshape
}
\lstdefinestyle{shell}{
,style=basic
,basicstyle=\footnotesize\ttfamily
}
\lstdefinestyle{haskell}{
style=basic
,language=Haskell
,literate=
{ö}{{\"o}}1
{ä}{{\"a}}1
{ü}{{\"u}}1
,texcl=true
,showstringspaces=false
,keywords={module,where,open,import,using,renaming,to,data,let,in,with,deriving}
}
\newcommand{\mylabel}[1]{\raisebox{2em}[0pt][0pt]{\makebox[0pt][l]{\makebox[\linewidth][r]{\color{gray}{\sffamily #1}\hspace{1em}}}}\ignorespaces}
\lstnewenvironment{haskell}{\pagebreak[3]\lstset{style=haskell}}{\mylabel{Haskell}\pagebreak[2]}
%\lstnewenvironment{ghci}{\lstset{style=haskell}}{\mylabel{GHCi}\pagebreak[2]}
\lstnewenvironment{shell}{\lstset{style=shell}}{\mylabel{Shell}\pagebreak[2]}
\begingroup
\gdef\savedgt{>}%
\catcode`\>=\active%
\catcode`\^^M=\active%
\gdef\foo{%
\catcode`\>=\active%
\catcode`^^M=\active%
\def > ##1^^M{\savedgt{} \li!##1!\par}%
\def ^^M{\par}%
}%
\endgroup
\newlength{\mylength}
\newenvironment{ghci}{
\par
\setlength{\mylength}{\linewidth}
\addtolength{\mylength}{-2em}
\addtolength{\mylength}{-\fboxrule}
\addtolength{\mylength}{-\fboxrule}
\strut\hspace{1em}\hspace{-\fboxsep}\begin{adjustbox}{minipage={\mylength},valign=b,margin*=\fboxsep,bgcolor=light-gray,frame}%
\begingroup
\small\ttfamily%
\foo
}{
\endgroup
\end{adjustbox}%\par
\adjustbox{lap=-\width}{\color{gray}{\sffamily GHCi}\hspace{\fboxsep}\hspace{\fboxrule}}
\par
}
\newcommand{\inputhaskell}[1]{\lstinputlisting[style=haskell]{#1}\mylabel{Haskell}}
\newcommand{\li}{\lstinline[style=haskell]}
Greetings,
Joachim
--
Joachim “nomeata” Breitner
mail at joachim-breitner.de • http://www.joachim-breitner.de/
Jabber: nomeata at joachim-breitner.de • GPG-Key: 0xF0FBF51F
Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150828/bf15415b/attachment.sig>
More information about the Haskell-Cafe
mailing list