The listings environment has support for ML syntax highlighting.
To enable it, simply \lstset{language=ML}. Here is an example of it in action:
\documentclass[a4paper, oneside, final]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{listings} % Perform code highlighting
\lstset{language=ML} % Select language
\begin{document}
\begin{lstlisting}
fun fact 0 = 1
| fact n = n * fact (n-1);
val test_fact_00 = fact 0 = 1;
val test_fact_01 = fact 1 = 1;
val test_fact_02 = fact 4 = 12;
\end{lstlisting}
\end{document}
If you don't like how it looks, fret not, for you can configure listings quite a bit. If you just need a quick example of such a configuration, here is the one I use:
\lstset{
language=ML,
keywordstyle=\bfseries\ttfamily\color[rgb]{0,0,1},
identifierstyle=\ttfamily,
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\ttfamily\color[rgb]{0.627,0.126,0.941},
showstringspaces=false,
basicstyle=\footnotesize,
%numberstyle=\footnotesize,
%numbers=left,
%stepnumber=1,
numbersep=10pt,
tabsize=2,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
breakatwhitespace=false,
aboveskip={1.5\baselineskip},
columns=fixed,
upquote=true,
extendedchars=true,
% frame=single,
% backgroundcolor=\color{lbcolor},
}
Simply put it in your preamble and it should do its thing. If you're confused about what any of the options do, take a look at the listings manual, or on Wikibooks.
answered
26 Dec '11, 23:22
Sebastian Pa... ♦♦
865●3●11●33
accept rate:
41%