% Demo of latex-highlight.
% To regenerate the highlighting in this document, do:
%   latex-highlight latex-highlight-demo.tex
\documentclass{article}
\usepackage{alltt}
\usepackage{color} % Some other classes pull this in anyway.

% Colour definitions.
% I would recommend using a less dramatic highlighting scheme for actual
% documents. ;)
\definecolor{Red}{rgb}{0.6,0.0,0.0}
\definecolor{Green}{rgb}{0.0,0.6,0.0}
\definecolor{Blue}{rgb}{0.0,0.0,0.6}
\definecolor{Purple}{rgb}{0.6,0.0,0.6}
\definecolor{Brown}{rgb}{0.5,0.5,0.0}
\def\function#1{{\color{Red}#1}}
\def\channel#1{\emph{#1}}
\def\keyword#1{{\color{Green}#1}}
\def\operator#1{{\color{Purple}#1}}
\def\highlight#1{{\color{Brown}#1}}
\def\stringconst#1{{\color{Blue}#1}}
\def\numconst#1{{\color{Blue}#1}}

\def\preservethis#1{#1}

\title{Demo of latex-highlight}

\begin{document}
\maketitle

\section{occam}

\begin{alltt}
\keyword{PROC} integrate (\keyword{CHAN} \keyword{OF} \keyword{INT} \channel{in}, \channel{out})
  \keyword{INT} \function{total}:
  \keyword{SEQ}
    \function{total} \operator{:=} \numconst{0}
    \keyword{WHILE} \keyword{TRUE}
      \keyword{INT} n:
      \keyword{SEQ}
        \channel{in} \operator{?} n
        \function{total} \operator{:=} \function{total} \operator{+} n
        \channel{out} \operator{!} \function{total}
:
\end{alltt} % occam function: total channel: in out
% The line above means that the standard definitions for "occam" should
% be used, and also "total" should be wrapped with "\function" and "in"
% and "out" with "\channel".

\section{C}

\begin{alltt}
\keyword{void} integrate\_u6 (Process *me,
  Channel *in\_u2, Channel *out\_u3) \{
    \keyword{int} total\_u4;
    total\_u4 \operator{=} \numconst{0};
    \keyword{while} (\keyword{true}) \{
        \keyword{int} n\_u5;
        ChanInInt (in\_u2, &n\_u5);
        total\_u4 \operator{=} occam\_add\_int (total\_u4,
          n\_u5, \stringconst{"demo.occ:\numconst{13}:\numconst{18}"});
        ChanOutInt (out\_u3, total\_u4);
    \}
\}
\end{alltt} % C

\section{Haskell}

\begin{alltt}
\function{cStyleNames} \operator{=} everywhere (mkT \function{doName})
  \keyword{where}
    \function{doName} \operator{::} Name \operator{->} Name
    \function{doName} (Name s) =
      Name [\keyword{if} c \operator{==} \stringconst{'.'} \keyword{then} \stringconst{'\_'} \keyword{else} c
            | c \operator{<-} s]
\end{alltt} % Haskell function: cStyleNames doName

\section{Non-highlighted example}

\begin{alltt}
do not process this one -- \preservethis{foo}.
\end{alltt}

\end{document}

