1 Settings for the listings package with Python
2 =============================================
5 :Contact: milde@users.berlios.de
6 :Revision: $Revision: 5534 $
7 :Date: $Date: 2009-02-24$
8 :Copyright: © 2007, 2009 G. Milde,
9 Released without warranties or conditions of any kind
10 under the terms of the Apache License, Version 2.0
11 http://www.apache.org/licenses/LICENSE-2.0
14 ``--stylesheet=listings-python-options.sty --literal-block-env=lstlisting``
15 options to ``rst2latex.py``.
17 For full documentation see listings.pdf_.
19 Of course, we need to load the listings package itself::
21 \RequirePackage{listings}
23 In a document with lots of lists and listings, separating paragraphs by
24 vertical seems appropriate::
26 \RequirePackage{parskip}
33 % \RequirePackage{mathptmx} % Times
34 \RequirePackage{mathpazo} % Palatino
36 We need a "rich" monospaced font. `txfonts`' typewriter font comes
37 with bold, slanted, and small-caps variants and without the problems of
38 `txfonts`' math fonts::
40 \renewcommand{\ttdefault}{txtt}
48 Highlight literal blocks as Python,
49 add missing keywords::
51 \lstset{language=Python,
52 morekeywords=[1]{yield}
55 % pre-load the language
56 \lstloadlanguages{Python} % comma separated list of languages
65 basicstyle=\ttfamily, % print whole listing in tt
66 % basicstyle=\ttfamily\small, % and, maybe small
67 keywordstyle=\bfseries,
68 % identifierstyle=\slshape, % object names
69 commentstyle=\rmfamily\itshape, % italic comments
70 stringstyle=\slshape, % strings
75 \lstset{showstringspaces=false} % no visible spaces in strings
76 %\lstset{showspaces=true,
78 % tab=\rightarrowfill}
82 %\lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt}
84 Frames around listings::
86 %\lstset{frame=single}
89 Extended characters in listings::
97 (for typesetting with variable width fonts)
99 ``columns=[c|l|r] <alignment>``
100 <alignment> in [fixed, flexible, spaceflexible, or fullflexible]
101 The optional c, l, or r controls the horizontal orientation of smallest
102 output units (keywords, identifiers, etc.).
106 ``basewidth={fixed, flexible}``
107 sets the width of a single character box for fixed and flexible column
108 mode (both to the same value or individually).
110 default: {0.6em,0.45em}
114 \lstset{columns=fullflexible, basewidth={0.5em,0.4em}}
117 ftp://dante.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf