File: listings.tex

package info (click to toggle)
hevea 2.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,824 kB
  • sloc: ml: 19,525; sh: 505; makefile: 311; ansic: 132
file content (90 lines) | stat: -rw-r--r-- 1,844 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
\documentclass{article}
\usepackage{listings}
\usepackage{color}

\title{Listings}
\author{}

\newstyle{.clisting}{border-left:solid green 2px;white-space:pre;padding-left:4px;font-family:monospace}
\newstyle{.camllisting}{border:double red 10px;white-space:pre;padding:4px;
  font-family:monospace;border-radius:300px;padding-left:60px}

\begin{document}

\maketitle

\lstdefinestyle{colors}{keywordstyle={\bf\color{blue}}, commentstyle={\em\color{magenta}}}

\lstnewenvironment{clisting}
  {\setenvclass{lstlisting}{clisting}\lstset{language=C, style=colors}}
  {}

\lstnewenvironment{camllisting}
  {\setenvclass{lstlisting}{camllisting}\lstset{language=caml, style=colors}}
  {}

C code, with a green left border :

\begin{clisting}
/* Compute, guess what! */
int fact(int n) {
  int r = 1 ;
  for ( ; n > 0 ; n--) {
    r *= n ;
  }
  return r ;
}
\end{clisting}

OCaml code, with a double red round border (ugly!):

\begin{camllisting}
(* Hello there *)
module MyList (E : sig type t end) : sig
  type t
  val nil : t
  val cons : E.t -> t -> t
end
  = 
struct
  type t = E.t list
  let nil = []
  let cons x xs = x :: xs
end
\end{camllisting}

Listing in a listing, no style :

\lstset{style=colors}

\begin{lstlisting}
\documentclass{article}
\usepackage{listings}
\usepackage{color}

\title{Listings}
\author{}

\newstyle{.clisting}{border-left:solid green 2px;white-space:pre;padding-left:4px;font-family:monospace}
\newstyle{.camllisting}{border:ridge red 10px;white-space:pre;padding:4px;
  font-family:monospace;border-radius:300px;padding-left:60px}

\begin{document}

\begin{camllisting}
(* Hello there *)
module MyList (E : sig type t end) : sig
  type t
  val nil : t
  val cons : E.t -> t -> t
end
  = 
struct
  type t = E.t list
  let nil = []
  let cons x xs = x :: xs
end
\end{camllisting}
\end{lstlisting}

\end{document}