Saturday, February 2, 2008

Phil's TexPertise

I've published Phil's response here so it's searchable for future reference. I couldn't publish it as a comment as blogger rejected something in the text below as a comment but strangely seems to accept it as a post.

Dom --- Have you thought of using either fancyvrb.sty or listings.sty ? fancyvrb is simpler but listings is very customizable. Rather than using the alltt package and embedding lots of LaTeX formatting you define a code environment that does what you want --- I choose the name ``code'' so that you can run your LaTeX as a Haskell literate script. Here's three ways of defining a code environment

(1) Using fancybox

\usepackage{fancybox}

\newenvironment{code}%
{\VerbatimEnvironment
\NMATcodesize%
\begin{Verbatim}}%
{\end{Verbatim}}


(2) Using fancyvrb

\usepackage{fancyvrb}

\DefineVerbatimEnvironment%
{code}{Verbatim}
{fontsize=\NMATcodesize}

% Typical usage
% \begin{code}[numbers=left,frame=lines,framesep=3mm,
% label={[Beginning of code]End of code}]
%
%
%
% \end{code}


(3) Using listings

\usepackage{listings}

\lstnewenvironment{code}[1][]
{\lstset{language=haskell,numbers=left,numberstyle=\tiny,float,#1}}
{}

The above example is from page 41 of the listings manual --- there is already a Haskell driver in the set of languages that listings comes with --- I couldn't see an ASN.1 language definition but it would be easier to define one than doing all the LaTeX embedding. I need to use listings to typeset my JavaScript notes.

Let me know if this helps.

Phil

1 comment:

cinimod said...

Phil Molyneux wrote:
> > Dom --- Have you thought of using either fancyvrb.sty or listings.sty ?

I've gone down the listings.sty route.

> > Let me know if this helps.

It certainly does. Thanks very much. See the attached. I think the
layout looks a bit ugly compared to what lhs2TeX gives but it will do to
get the content sorted out.

Dom.