"pre-commit" hook to trim trailing whitespace.
[pylit.git] / doc / examples / listings-python-options.sty.txt
blobbe508d817b6f64b2f55066c5768e73e5baf1d5c5
1 Settings for the listings package with Python
2 =============================================
4 :Author:    Günter Milde
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
13 To use this pass the
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}
28 Font settings
29 ~~~~~~~~~~~~~
31 Textfont::
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}
42 Default language
43 ~~~~~~~~~~~~~~~~
46   %\lstset{language={}}
48 Highlight literal blocks as Python,
49 add missing keywords::
51   \lstset{language=Python,
52           morekeywords=[1]{yield}
53   }
55   % pre-load the language
56   \lstloadlanguages{Python} %  comma separated list of languages
59 Style
60 ~~~~~
62 Typeface settings::
64   \lstset{
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
71   }
73 Visible whitespace::
75   \lstset{showstringspaces=false}  % no visible spaces in strings
76   %\lstset{showspaces=true,
77   %        showtabs=true,
78   %        tab=\rightarrowfill}
80 Line numbers::
82   %\lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt}
84 Frames around listings::
86   %\lstset{frame=single}
89 Extended characters in listings::
91   %extendedchars=true
92   %extendedchars=false
94 Column alignment
95 ~~~~~~~~~~~~~~~~
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.).
104   default: [c]fixed
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}}
116 .. _listings.pdf:
117    ftp://dante.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf