blob: 1a0117d64e31ea135b7df11625958eb6b43922fd [file] [log] [blame]
Guido van Rossum51bbdfb1995-03-01 14:07:08 +00001% Template for a library manual section.
2% PLEASE REMOVE THE COMMENTS AFTER USING THE TEMPLATE
Fred Drake2a9bda92001-06-06 16:02:47 +00003%
4% Complete documentation on the extended LaTeX markup used for Python
5% documentation is available in ``Documenting Python'', which is part
6% of the standard documentation for Python. It may be found online
7% at:
8%
9% http://www.python.org/doc/current/doc/doc.html
Guido van Rossum6a11eb41992-06-03 17:59:07 +000010
Fred Drake0618f5e1998-08-11 17:43:45 +000011% ==== 0. ====
12% Copy this file to <mydir>/lib<mymodule>.tex, and edit that file
13% according to the instructions below.
14
Guido van Rossum6a11eb41992-06-03 17:59:07 +000015
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000016% ==== 1. ====
Fred Drake295da241998-08-10 19:42:37 +000017% The section prologue. Give the section a title and provide some
18% meta-information. References to the module should use
19% \refbimodindex, \refstmodindex, \refexmodindex or \refmodindex, as
20% appropriate.
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000021
Fred Drake295da241998-08-10 19:42:37 +000022\section{\module{spam} ---
Fred Drake2a9bda92001-06-06 16:02:47 +000023 Short description, for section title and table of contents}
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000024
Fred Drake295da241998-08-10 19:42:37 +000025% Choose one of these to specify the module module name. If there's
26% an underscore in the name, use
27% \declaremodule[modname]{...}{mod_name} instead.
28%
29\declaremodule{builtin}{spam} % standard library, in C
30\declaremodule{standard}{spam} % standard library, in Python
31\declaremodule{extension}{spam} % not standard, in C
32\declaremodule{}{spam} % not standard, in Python
Fred Drake07bcd991998-04-03 21:25:16 +000033
Fred Drake46a94381999-03-02 16:24:22 +000034% Portability statement: Uncomment and fill in the parameter to specify the
35% availability of the module. The parameter can be Unix, IRIX, SunOS, Mac,
36% Windows, or lots of other stuff. When ``Mac'' is specified, the availability
37% statement will say ``Macintosh'' and the Module Index may say ``Mac''.
38% Please use a name that has already been used whenever applicable. If this
39% is omitted, no availability statement is produced or implied.
40%
Fred Drake2a9bda92001-06-06 16:02:47 +000041% \platform{Unix}
Fred Drake46a94381999-03-02 16:24:22 +000042
Fred Drake2a9bda92001-06-06 16:02:47 +000043% These apply to all modules, and may be given more than once:
Fred Drake07bcd991998-04-03 21:25:16 +000044
Fred Drake295da241998-08-10 19:42:37 +000045\moduleauthor{name}{email} % Author of the module code;
46 % omit if not known.
Fred Drake5eecd7b1998-12-22 18:15:04 +000047\sectionauthor{name}{email} % Author of the documentation,
48 % even if not a module section.
Guido van Rossum6a11eb41992-06-03 17:59:07 +000049
Fred Drakeb91e9341998-07-23 17:59:49 +000050
Fred Drake295da241998-08-10 19:42:37 +000051% Leave at least one blank line after this, to simplify ad-hoc tools
52% that are sometimes used to massage these files.
Fred Drakeb91e9341998-07-23 17:59:49 +000053\modulesynopsis{This is a one-line descrition, for the chapter header.}
54
Guido van Rossum6a11eb41992-06-03 17:59:07 +000055
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000056% ==== 2. ====
57% Give a short overview of what the module does.
58% If it is platform specific, mention this.
59% Mention other important restrictions or general operating principles.
60% For example:
61
Fred Draked10d0fa1998-02-24 21:43:05 +000062The \module{spam} module defines operations for handling cans of Spam.
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000063It knows the four generally available Spam varieties and understands
64both can sizes.
65
Fred Drake4b3f0311996-12-13 22:04:31 +000066Because spamification requires \UNIX{} process management, the module
67is only available on genuine \UNIX{} systems.
Guido van Rossum6a11eb41992-06-03 17:59:07 +000068
69
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000070% ==== 3. ====
71% List the public functions defined by the module. Begin with a
72% standard phrase. You may also list the exceptions and other data
73% items defined in the module, insofar as they are important for the
74% user.
75
Fred Draked10d0fa1998-02-24 21:43:05 +000076The \module{spam} module defines the following functions:
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000077
78% ---- 3.1. ----
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000079% For each function, use a ``funcdesc'' block. This has exactly two
80% parameters (each parameters is contained in a set of curly braces):
81% the first parameter is the function name (this automatically
82% generates an index entry); the second parameter is the function's
83% argument list. If there are no arguments, use an empty pair of
84% curly braces. If there is more than one argument, separate the
85% arguments with backslash-comma. Optional parts of the parameter
86% list are contained in \optional{...} (this generates a set of square
87% brackets around its parameter). Arguments are automatically set in
88% italics in the parameter list. Each argument should be mentioned at
89% least once in the description; each usage (even inside \code{...})
90% should be enclosed in \var{...}.
91
Fred Drake07bcd991998-04-03 21:25:16 +000092\begin{funcdesc}{open}{filename\optional{, mode\optional{, buffersize}}}
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000093Open the file \var{filename} as a can of Spam. The optional
Fred Drakee1a85f52000-07-06 16:12:47 +000094\var{mode} and \var{buffersize} arguments specify the read/write mode
Guido van Rossum51bbdfb1995-03-01 14:07:08 +000095(\code{'r'} (default) or \code{'w'}) and the buffer size (default:
96system dependent).
97\end{funcdesc}
98
Fred Drake07bcd991998-04-03 21:25:16 +000099% ---- 3.2. ----
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000100% Data items are described using a ``datadesc'' block. This has only
101% one parameter: the item's name.
102
103\begin{datadesc}{cansize}
104The default can size, in ounces. Legal values are 7 and 12. The
105default varies per supermarket. This variable should not be changed
Fred Draked10d0fa1998-02-24 21:43:05 +0000106once the \function{open()} function has been called.
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000107\end{datadesc}
108
Fred Drake07bcd991998-04-03 21:25:16 +0000109% --- 3.3. ---
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000110% Exceptions are described using a ``excdesc'' block. This has only
Fred Drakee1a85f52000-07-06 16:12:47 +0000111% one parameter: the exception name. Exceptions defined as classes in
112% the source code should be documented using this environment, but
113% constructor parameters must be ommitted.
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000114
115\begin{excdesc}{error}
116Exception raised when an operation fails for a Spam specific reason.
117The exception argument is a string describing the reason of the
118failure.
119\end{excdesc}
120
Fred Drake07bcd991998-04-03 21:25:16 +0000121% ---- 3.4. ----
122% Other standard environments:
123%
124% classdesc - Python classes; same arguments are funcdesc
125% methoddesc - methods, like funcdesc but has an optional parameter
126% to give the type name: \begin{methoddesc}[mytype]{name}{args}
127% By default, the type name will be the name of the
128% last class defined using classdesc. The type name
129% is required if the type is implemented in C (because
130% there's no classdesc) or if the class isn't directly
131% documented (if it's private).
132% memberdesc - data members, like datadesc, but with an optional
133% type name like methoddesc.
Guido van Rossum6a11eb41992-06-03 17:59:07 +0000134
135
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000136% ==== 4. ====
137% Now is probably a good time for a complete example. (Alternatively,
138% an example giving the flavor of the module may be given before the
139% detailed list of functions.)
Guido van Rossum6a11eb41992-06-03 17:59:07 +0000140
Fred Drakee1a85f52000-07-06 16:12:47 +0000141\subsection{Example \label{spam-example}}
Skip Montanaro8968a822000-07-06 13:43:37 +0000142
143The following example demonstrates how to open a can of spam using the
144\module{spam} module.
Guido van Rossum6a11eb41992-06-03 17:59:07 +0000145
Fred Drake19479911998-02-13 06:58:54 +0000146\begin{verbatim}
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000147>>> import spam
148>>> can = spam.open('/etc/passwd')
149>>> can.empty()
150>>> can.close()
Fred Drake19479911998-02-13 06:58:54 +0000151\end{verbatim}
Fred Drake07bcd991998-04-03 21:25:16 +0000152% Note that there is no trailing ">>> " prompt shown.
153
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000154% ==== 5. ====
155% If your module defines new object types (for a built-in module) or
156% classes (for a module written in Python), you should list the
157% methods and instance variables (if any) of each type or class in a
Fred Drake07bcd991998-04-03 21:25:16 +0000158% separate subsection.
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000159
Guido van Rossum470be141995-03-17 16:07:09 +0000160\subsection{Spam Objects}
Fred Drake07bcd991998-04-03 21:25:16 +0000161\label{spam-objects}
162% This label is generally useful for referencing this section, but is
163% also used to give a filename when generating HTML.
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000164
Fred Drake07bcd991998-04-03 21:25:16 +0000165Spam objects, as returned by \function{open()} above, have the
166following methods:
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000167
Fred Drake07bcd991998-04-03 21:25:16 +0000168\begin{methoddesc}[spam]{empty}{}
Guido van Rossum51bbdfb1995-03-01 14:07:08 +0000169Empty the can into the trash.
Fred Drake07bcd991998-04-03 21:25:16 +0000170\end{methoddesc}