See the title.

This question is marked "community wiki".

asked 23 Dec '11, 17:53

Martin%20Dybdal's gravatar image

Martin Dybdal ♦♦
1.1k123282
accept rate: 69%

edited 19 Jan '12, 13:01


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.

link

answered 26 Dec '11, 23:22

Sebastian%20Paaske%20T%C3%B8rholm's gravatar image

Sebastian Pa... ♦♦
86531133
accept rate: 41%

edited 26 Dec '11, 23:35

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×122
×12

Asked: 23 Dec '11, 17:53

Seen: 1,454 times

Last updated: 19 Jan '12, 13:01

powered by OSQA