4 \title{Documenting Python
}
10 % Now override the stuff that includes author information;
11 % Guido did *not* write this one!
13 \author{Fred L. Drake, Jr.
}
16 Email:
\email{fdrake@acm.org
}
26 The Python language has a substantial body of
27 documentation, much of it contributed by various authors. The markup
28 used for the Python documentation is based on
\LaTeX{} and requires a
29 significant set of macros written specifically for documenting Python.
30 This
document describes the macros introduced to support Python
31 documentation and how they should be used to support a wide range of
34 This
document describes the
document classes and special markup used
35 in the Python documentation. Authors may use this guide, in
36 conjunction with the template files provided with the
37 distribution, to create or maintain whole documents or sections.
43 \section{Introduction
\label{intro
}}
45 Python's documentation has long been considered to be good for a
46 free programming language. There are a number of reasons for this,
47 the most important being the early commitment of Python's creator,
48 Guido van Rossum, to providing documentation on the language and its
49 libraries, and the continuing involvement of the user community in
50 providing assistance for creating and maintaining documentation.
52 The involvement of the community takes many forms, from authoring to
53 bug reports to just plain complaining when the documentation could
54 be more complete or easier to use. All of these forms of input from
55 the community have proved useful during the time I've been involved
56 in maintaining the documentation.
58 This
document is aimed at authors and potential authors of
59 documentation for Python. More specifically, it is for people
60 contributing to the standard documentation and developing additional
61 documents using the same tools as the standard documents. This
62 guide will be less useful for authors using the Python documentation
63 tools for topics other than Python, and less useful still for
64 authors not using the tools at all.
66 The material in this guide is intended to assist authors using the
67 Python documentation tools. It includes information on the source
68 distribution of the standard documentation, a discussion of the
69 document types, reference material on the markup defined in the
70 document classes, a list of the external tools needed for processing
71 documents, and reference material on the tools provided with the
72 documentation resources. At the end, there is also a section
73 discussing future directions for the Python documentation and where
74 to turn for more information.
76 \section{Directory Structure
\label{directories
}}
78 The source distribution for the standard Python documentation
79 contains a large number of directories. While third-party documents
80 do not need to be placed into this structure or need to be placed
81 within a similar structure, it can be helpful to know where to look
82 for examples and tools when developing new documents using the
83 Python documentation tools. This section describes this directory
86 The documentation sources are usually placed within the Python
87 source distribution as the top-level directory
\file{Doc/
}, but
88 are not dependent on the Python source distribution in any way.
90 The
\file{Doc/
} directory contains a few files and several
91 subdirectories. The files are mostly self-explanatory, including a
92 \file{README
} and a
\file{Makefile
}. The directories fall into
96 \term{Document Sources
}
97 The
\LaTeX{} sources for each
document are placed in a
98 separate directory. These directories are given short
99 names which vaguely indicate the
document in each:
101 \begin{tableii
}{p
{.75in
}|p
{3in
}}{filenq
}{Directory
}{Document Title
}
103 {\citetitle[../api/api.html
]{The Python/C API
}}
105 {\citetitle[../dist/dist.html
]{Distributing Python Modules
}}
107 {\citetitle[../doc/doc.html
]{Documenting Python
}}
109 {\citetitle[../ext/ext.html
]{Extending and Embedding the Python Interpreter
}}
111 {\citetitle[../inst/inst.html
]{Installing Python Modules
}}
113 {\citetitle[../lib/lib.html
]{Python Library Reference
}}
115 {\citetitle[../mac/mac.html
]{Macintosh Module Reference
}}
117 {\citetitle[../ref/ref.html
]{Python Reference Manual
}}
119 {\citetitle[../tut/tut.html
]{Python Tutorial
}}
122 \term{Format-Specific Output
}
123 Most output formats have a directory which contains a
124 \file{Makefile
} which controls the generation of that format
125 and provides storage for the formatted documents. The only
126 variations within this category are the Portable Document
127 Format (PDF) and PostScript versions are placed in the
128 directories
\file{paper-a4/
} and
\file{paper-letter/
} (this
129 causes all the temporary files created by
\LaTeX{} to be kept
130 in the same place for each paper size, where they can be more
133 \begin{tableii
}{p
{.75in
}|p
{3in
}}{filenq
}{Directory
}{Output Formats
}
134 \lineii{html/
}{HTML output
}
135 \lineii{info/
}{GNU info output
}
136 \lineii{isilo/
}{\ulink{iSilo
}{http://www.isilo.com/
}
137 documents (for Palm OS devices)
}
138 \lineii{paper-a4/
}{PDF and PostScript, A4 paper
}
139 \lineii{paper-letter/
}{PDF and PostScript, US-Letter paper
}
142 \term{Supplemental Files
}
143 Some additional directories are used to store supplemental
144 files used for the various processes. Directories are
145 included for the shared
\LaTeX{} document classes, the
146 \LaTeX2HTML support, template files for various
document
147 components, and the scripts used to perform various steps in
148 the formatting processes.
150 \begin{tableii
}{p
{.75in
}|p
{3in
}}{filenq
}{Directory
}{Contents
}
151 \lineii{perl/
}{Support for
\LaTeX2HTML processing
}
152 \lineii{templates/
}{Example files for source documents
}
153 \lineii{texinputs/
}{Style implementation for
\LaTeX}
154 \lineii{tools/
}{Custom processing scripts
}
160 \section{Style Guide
\label{style-guide
}}
162 The Python documentation should follow the
\citetitle
163 [http://developer.apple.com/techpubs/macos8/pdf/apple_styleguide00.pdf
]
164 {Apple Publications Style Guide
} wherever possible. This particular
165 style guide was selected mostly because it seems reasonable and is
166 easy to get online. (Printed copies are available; see the Apple's
167 \citetitle[http://developer.apple.com/techpubs/faq.html
]{Developer
168 Documentation FAQ
} for more information.)
170 Topics which are not covered in the Apple's style guide will be
171 discussed in this
document if necessary.
173 Many special names are used in the Python documentation, including
174 the names of operating systems, programming languages, standards
175 bodies, and the like. Many of these were assigned
\LaTeX{} macros
176 at some point in the distant past, and these macros lived on long
177 past their usefulness. In the current markup, most of these entities
178 are not assigned any special markup, but the preferred spellings are
179 given here to aid authors in maintaining the consistency of
180 presentation in the Python documentation.
182 Other terms and words deserve special mention as well; these conventions
183 should be used to ensure consistency throughout the documentation:
187 For ``central processing unit.'' Many style guides say this
188 should be spelled out on the first use (and if you must use it,
189 do so!). For the Python documentation, this abbreviation should
190 be avoided since there's no reasonable way to predict which occurance
191 will be the first seen by the reader. It is better to use the
192 word ``processor'' instead.
195 The name assigned to a particular group of standards. This is
196 always uppercase. Use the macro
\macro{POSIX
} to represent this
200 The name of our favorite programming language is always
204 The name of a character set and matching encoding. This is
205 always written capitalized.
208 The name of the operating system developed at AT\&T Bell Labs
209 in the early
1970s. Use the macro
\macro{UNIX
} to use this name.
213 \section{\LaTeX{} Primer
\label{latex-primer
}}
215 This section is a brief introduction to
\LaTeX{} concepts and
216 syntax, to provide authors enough information to author documents
217 productively without having to become ``
\TeX{}nicians.''
219 Perhaps the most important concept to keep in mind while marking up
220 Python documentation is that while
\TeX{} is unstructured,
\LaTeX{} was
221 designed as a layer on top of
\TeX{} which specifically supports
222 structured markup. The Python-specific markup is intended to extend
223 the structure provided by standard
\LaTeX{} document classes to
224 support additional information specific to Python.
226 \LaTeX{} documents contain two parts: the preamble and the body.
227 The preamble is used to specify certain metadata about the
document
228 itself, such as the title, the list of authors, the date, and the
229 \emph{class
} the
document belongs to. Additional information used
230 to control index generation and the use of bibliographic databases
231 can also be placed in the preamble. For most authors, the preamble
232 can be most easily created by copying it from an existing
document
233 and modifying a few key pieces of information.
235 The
\dfn{class
} of a
document is used to place a
document within a
236 broad category of documents and set some fundamental formatting
237 properties. For Python documentation, two classes are used: the
238 \code{manual
} class and the
\code{howto
} class. These classes also
239 define the additional markup used to
document Python concepts and
240 structures. Specific information about these classes is provided in
241 section
\ref{classes
}, ``Document Classes,'' below. The first thing
242 in the preamble is the declaration of the
document's class.
244 After the class declaration, a number of
\emph{macros
} are used to
245 provide further information about the
document and setup any
246 additional markup that is needed. No output is generated from the
247 preamble; it is an error to include free text in the preamble
248 because it would cause output.
250 The
document body follows the preamble. This contains all the
251 printed components of the
document marked up structurally. Generic
252 \LaTeX{} structures include hierarchical sections, numbered and
253 bulleted lists, and special structures for the
document abstract and
256 \subsection{Syntax
\label{latex-syntax
}}
258 There are some things that an author of Python documentation needs
259 to know about
\LaTeX{} syntax.
261 A
\dfn{comment
} is started by the ``percent'' character
262 (
\character{\%
}) and continues through the end of the line and all
263 leading whitespace on the following line. This is a little
264 different from any programming language I know of, so an example
268 This is text.
% comment
269 This is more text.
% another comment
273 The first non-comment character following the first comment is the
274 letter
\character{T
} on the second line; the leading whitespace on
275 that line is consumed as part of the first comment. This means
276 that there is no space between the first and second sentences, so
277 the period and letter
\character{T
} will be directly adjacent in
278 the typeset
document.
280 Note also that though the first non-comment character after the
281 second comment is the letter
\character{S
}, there is whitespace
282 preceding the comment, so the two sentences are separated as
285 A
\dfn{group
} is an enclosure for a collection of text and
286 commands which encloses the formatting context and constrains the
287 scope of any changes to that context made by commands within the
288 group. Groups can be nested hierarchically. The formatting
289 context includes the font and the definition of additional macros
290 (or overrides of macros defined in outer groups). Syntactically,
291 groups are enclosed in braces:
297 An alternate syntax for a group using brackets,
\code{[...
]}, is
298 used by macros and environment constructors which take optional
299 parameters; brackets do not normally hold syntactic significance.
300 A degenerate group, containing only one atomic bit of content,
301 does not need to have an explicit group, unless it is required to
302 avoid ambiguity. Since Python tends toward the explicit, groups
303 are also made explicit in the documentation markup.
305 Groups are used only sparingly in the Python documentation, except
306 for their use in marking parameters to macros and environments.
308 A
\dfn{macro
} is usually a simple construct which is identified by
309 name and can take some number of parameters. In normal
\LaTeX{}
310 usage, one of these can be optional. The markup is introduced
311 using the backslash character (
\character{\e}), and the name is
312 given by alphabetic characters (no digits, hyphens, or
313 underscores). Required parameters should be marked as a group,
314 and optional parameters should be marked using the alternate
317 For example, a macro named ``foo'' which takes a single parameter
318 would appear like this:
324 A macro which takes an optional parameter would be typed like this
325 when the optional paramter is given:
331 If both optional and required parameters are to be required, it
335 \name[optional
]{required
}
338 A macro name may be followed by a space or newline; a space
339 between the macro name and any parameters will be consumed, but
340 this usage is not practiced in the Python documentation. Such a
341 space is still consumed if there are no parameters to the macro,
342 in which case inserting an empty group (
\code{\
{\
}}) or explicit
343 word space (
\samp{\e\
}) immediately after the macro name helps to
344 avoid running the expansion of the macro into the following text.
345 Macros which take no parameters but which should not be followed
346 by a word space do not need special treatment if the following
347 character in the
document source if not a name character (such as
350 Each line of this example shows an appropriate way to write text
351 which includes a macro which takes no parameters:
354 This
\UNIX{} is followed by a space.
355 This
\UNIX\ is also followed by a space.
356 \UNIX, followed by a comma, needs no additional markup.
359 An
\dfn{environment
} is a larger construct than a macro, and can
360 be used for things with more content than would conveniently fit
361 in a macro parameter. They are primarily used when formatting
362 parameters need to be changed before and after a large chunk of
363 content, but the content itself needs to be highly flexible. Code
364 samples are presented using an environment, and descriptions of
365 functions, methods, and classes are also marked using environments.
367 Since the content of an environment is free-form and can consist
368 of several paragraphs, they are actually marked using a pair of
369 macros:
\macro{begin
} and
\macro{end
}. These macros both take the
370 name of the environment as a parameter. An example is the
371 environment used to mark the abstract of a
document:
375 This is the text of the abstract. It concisely explains what
376 information is found in the
document.
378 It can consist of multiple paragraphs.
382 An environment can also have required and optional parameters of
383 its own. These follow the parameter of the
\macro{begin
} macro.
384 This example shows an environment which takes a single required
388 \begin{datadesc
}{controlnames
}
389 A
33-element string array that contains the
\ASCII{} mnemonics for
390 the thirty-two
\ASCII{} control characters from
0 (NUL) to
0x1f
391 (US), in order, plus the mnemonic
\samp{SP
} for the space character.
395 There are a number of less-used marks in
\LaTeX{} which are used
396 to enter characters which are not found in
\ASCII{} or which a
397 considered special, or
\emph{active
} in
\TeX{} or
\LaTeX. Given
398 that these are often used adjacent to other characters, the markup
399 required to produce the proper character may need to be followed
400 by a space or an empty group, or the markup can be enclosed in a
401 group. Some which are found in Python documentation are:
403 \begin{tableii
}{c|l
}{textrm
}{Character
}{Markup
}
404 \lineii{\textasciicircum}{\code{\e textasciicircum
}}
405 \lineii{\textasciitilde}{\code{\e textasciitilde
}}
406 \lineii{\textgreater}{\code{\e textgreater
}}
407 \lineii{\textless}{\code{\e textless
}}
408 \lineii{\c c
}{\code{\e c c
}}
409 \lineii{\"o
}{\code{\e"o
}}
410 \lineii{\o}{\code{\e o
}}
414 \subsection{Hierarchical Structure
\label{latex-structure
}}
416 \LaTeX{} expects documents to be arranged in a conventional,
417 hierarchical way, with chapters, sections, sub-sections,
418 appendixes, and the like. These are marked using macros rather
419 than environments, probably because the end of a section can be
420 safely inferred when a section of equal or higher level starts.
422 There are six ``levels'' of sectioning in the
document classes
423 used for Python documentation, and the deepest two
424 levels
\footnote{The deepest levels have the highest numbers in the
425 table.
} are not used. The levels are:
427 \begin{tableiii
}{c|l|c
}{textrm
}{Level
}{Macro Name
}{Notes
}
428 \lineiii{1}{\macro{chapter
}}{(
1)
}
429 \lineiii{2}{\macro{section
}}{}
430 \lineiii{3}{\macro{subsection
}}{}
431 \lineiii{4}{\macro{subsubsection
}}{}
432 \lineiii{5}{\macro{paragraph
}}{(
2)
}
433 \lineiii{6}{\macro{subparagraph
}}{}
441 Only used for the
\code{manual
} documents, as described in
442 section
\ref{classes
}, ``Document Classes.''
444 Not the same as a paragraph of text; nobody seems to use this.
448 \section{Document Classes
\label{classes
}}
450 Two
\LaTeX{} document classes are defined specifically for use with
451 the Python documentation. The
\code{manual
} class is for large
452 documents which are sectioned into chapters, and the
\code{howto
}
453 class is for smaller documents.
455 The
\code{manual
} documents are larger and are used for most of the
456 standard documents. This
document class is based on the standard
457 \LaTeX{} \code{report} class and is formatted very much like a long
458 technical
report. The
\citetitle[../ref/ref.html
]{Python Reference
459 Manual
} is a good example of a
\code{manual
} document, and the
460 \citetitle[../lib/lib.html
]{Python Library Reference
} is a large
463 The
\code{howto
} documents are shorter, and don't have the large
464 structure of the
\code{manual
} documents. This class is based on
465 the standard
\LaTeX{} \code{article
} class and is formatted somewhat
466 like the Linux Documentation Project's ``HOWTO'' series as done
467 originally using the LinuxDoc software. The original intent for the
468 document class was that it serve a similar role as the LDP's HOWTO
469 series, but the applicability of the class turns out to be somewhat
470 broader. This class is used for ``how-to'' documents (this
471 document is an example) and for shorter reference manuals for small,
472 fairly cohesive module libraries. Examples of the later use include
473 \citetitle[http://starship.python.net/crew/fdrake/manuals/krb5py/krb5py.html
]{Using
474 Kerberos from Python
}, which contains reference material for an
475 extension package. These documents are roughly equivalent to a
476 single chapter from a larger work.
479 \section{Special Markup Constructs
\label{special-constructs
}}
481 The Python
document classes define a lot of new environments and
482 macros. This section contains the reference material for these
485 \subsection{Markup for the Preamble
\label{preamble-info
}}
487 \begin{macrodesc
}{release
}{\p{ver
}}
488 Set the version number for the software described in the
492 \begin{macrodesc
}{setshortversion
}{\p{sver
}}
493 Specify the ``short'' version number of the documented software
497 \subsection{Meta-information Markup
\label{meta-info
}}
499 \begin{macrodesc
}{sectionauthor
}{\p{author
}\p{email
}}
500 Identifies the author of the current section.
\var{author
}
501 should be the author's name such that it can be used for
502 presentation (though it isn't), and
\var{email
} should be the
503 author's email address. The domain name portion of
504 the address should be lower case.
506 No presentation is generated from this markup, but it is used to
507 help keep track of contributions.
510 \subsection{Information Units
\label{info-units
}}
512 XXX Explain terminology, or come up with something more ``lay.''
514 There are a number of environments used to describe specific
515 features provided by modules. Each environment requires
516 parameters needed to provide basic information about what is being
517 described, and the environment content should be the description.
518 Most of these environments make entries in the general index (if
519 one is being produced for the
document); if no index entry is
520 desired, non-indexing variants are available for many of these
521 environments. The environments have names of the form
522 \code{\var{feature
}desc
}, and the non-indexing variants are named
523 \code{\var{feature
}descni
}. The available variants are explicitly
524 included in the list below.
526 For each of these environments, the first parameter,
\var{name
},
527 provides the name by which the feature is accessed.
529 Environments which describe features of objects within a module,
530 such as object methods or data attributes, allow an optional
531 \var{type name
} parameter. When the feature is an attribute of
532 class instances,
\var{type name
} only needs to be given if the
533 class was not the most recently described class in the module; the
534 \var{name
} value from the most recent
\env{classdesc
} is implied.
535 For features of built-in or extension types, the
\var{type name
}
536 value should always be provided. Another special case includes
537 methods and members of general ``protocols,'' such as the
538 formatter and writer protocols described for the
539 \module{formatter
} module: these may be documented without any
540 specific implementation classes, and will always require the
541 \var{type name
} parameter to be provided.
543 \begin{envdesc
}{cfuncdesc
}{\p{type
}\p{name
}\p{args
}}
544 Environment used to described a C function. The
\var{type
}
545 should be specified as a
\keyword{typedef
} name,
\code{struct
546 \var{tag
}}, or the name of a primitive type. If it is a pointer
547 type, the trailing asterisk should not be preceded by a space.
548 \var{name
} should be the name of the function (or function-like
549 pre-processor macro), and
\var{args
} should give the types and
550 names of the parameters. The names need to be given so they may
551 be used in the description.
554 \begin{envdesc
}{cmemberdesc
}{\p{container
}\p{type
}\p{name
}}
555 Description for a structure member.
\var{container
} should be
556 the
\keyword{typedef
} name, if there is one, otherwise if should
557 be
\samp{struct
\var{tag
}}. The type of the member should given
558 as
\var{type
}, and the name should be given as
\var{name
}. The
559 text of the description should include the range of values
560 allowed, how the value should be interpreted, and whether the
561 value can be changed. References to structure members in text
562 should use the
\macro{member
} macro.
565 \begin{envdesc
}{csimplemacrodesc
}{\p{name
}}
566 Documentation for a ``simple'' macro. Simple macros are macros
567 which are used for code expansion, but which do not take
568 arguments so cannot be described as functions. This is not to
569 be used for simple constant definitions. Examples of it's use
570 in the Python documentation include
571 \csimplemacro{PyObject_HEAD
} and
572 \csimplemacro{Py_BEGIN_ALLOW_THREADS
}.
575 \begin{envdesc
}{ctypedesc
}{\op{tag
}\p{name
}}
576 Environment used to described a C type. The
\var{name
}
577 parameter should be the
\keyword{typedef
} name. If the type is
578 defined as a
\keyword{struct
} without a
\keyword{typedef
},
579 \var{name
} should have the form
\code{struct
\var{tag
}}.
580 \var{name
} will be added to the index unless
\var{tag
} is
581 provided, in which case
\var{tag
} will be used instead.
582 \var{tag
} should not be used for a
\keyword{typedef
} name.
585 \begin{envdesc
}{cvardesc
}{\p{type
}\p{name
}}
586 Description of a global C variable.
\var{type
} should be the
587 \keyword{typedef
} name,
\code{struct
\var{tag
}}, or the name of
588 a primitive type. If variable has a pointer type, the trailing
589 asterisk should
\emph{not
} be preceded by a space.
592 \begin{envdesc
}{datadesc
}{\p{name
}}
593 This environment is used to
document global data in a module,
594 including both variables and values used as ``defined
595 constants.'' Class and object attributes are not documented
596 using this environment.
598 \begin{envdesc
}{datadescni
}{\p{name
}}
599 Like
\env{datadesc
}, but without creating any index entries.
602 \begin{envdesc
}{excclassdesc
}{\p{name
}\p{constructor parameters
}}
603 Descibe an exception defined by a class.
\var{constructor
604 parameters
} should not include the
\var{self
} parameter or
605 the parentheses used in the call syntax. To describe an
606 exception class without describing the parameters to its
607 constructor, use the
\env{excdesc
} environment.
610 \begin{envdesc
}{excdesc
}{\p{name
}}
611 Describe an exception. This may be either a string exception or
612 a class exception. In the case of class exceptions, the
613 constructor parameters are not described; use
\env{excclassdesc
}
614 to describe an exception class and its constructor.
617 \begin{envdesc
}{funcdesc
}{\p{name
}\p{parameters
}}
618 Describe a module-level function.
\var{parameters
} should
619 not include the parentheses used in the call syntax. Object
620 methods are not documented using this environment. Bound object
621 methods placed in the module namespace as part of the public
622 interface of the module are documented using this, as they are
623 equivalent to normal functions for most purposes.
625 The description should include information about the parameters
626 required and how they are used (especially whether mutable
627 objects passed as parameters are modified), side effects, and
628 possible exceptions. A small example may be provided.
630 \begin{envdesc
}{funcdescni
}{\p{name
}\p{parameters
}}
631 Like
\env{funcdesc
}, but without creating any index entries.
634 \begin{envdesc
}{classdesc
}{\p{name
}\p{constructor parameters
}}
635 Describe a class and its constructor.
\var{constructor
636 parameters
} should not include the
\var{self
} parameter or
637 the parentheses used in the call syntax.
640 \begin{envdesc
}{classdesc*
}{\p{name
}}
641 Describe a class without describing the constructor. This can
642 be used to describe classes that are merely containers for
643 attributes or which should never be instantiated or subclassed
647 \begin{envdesc
}{memberdesc
}{\op{type name
}\p{name
}}
648 Describe an object data attribute. The description should
649 include information about the type of the data to be expected
650 and whether it may be changed directly.
652 \begin{envdesc
}{memberdescni
}{\op{type name
}\p{name
}}
653 Like
\env{memberdesc
}, but without creating any index entries.
656 \begin{envdesc
}{methoddesc
}{\op{type name
}\p{name
}\p{parameters
}}
657 Describe an object method.
\var{parameters
} should not include
658 the
\var{self
} parameter or the parentheses used in the call
659 syntax. The description should include similar information to
660 that described for
\env{funcdesc
}.
662 \begin{envdesc
}{methoddescni
}{\op{type name
}\p{name
}\p{parameters
}}
663 Like
\env{methoddesc
}, but without creating any index entries.
667 \subsection{Showing Code Examples
\label{showing-examples
}}
669 Examples of Python source code or interactive sessions are
670 represented as
\env{verbatim
} environments. This environment
671 is a standard part of
\LaTeX{}. It is important to only use
672 spaces for indentation in code examples since
\TeX{} drops tabs
673 instead of converting them to spaces.
675 Representing an interactive session requires including the prompts
676 and output along with the Python code. No special markup is
677 required for interactive sessions. After the last line of input
678 or output presented, there should not be an ``unused'' primary
679 prompt; this is an example of what
\emph{not
} to do:
687 Within the
\env{verbatim
} environment, characters special to
688 \LaTeX{} do not need to be specially marked in any way. The entire
689 example will be presented in a monospaced font; no attempt at
690 ``pretty-printing'' is made, as the environment must work for
691 non-Python code and non-code displays. There should be no blank
692 lines at the top or bottom of any
\env{verbatim
} display.
694 Longer displays of verbatim text may be included by storing the
695 example text in an external file containing only plain text. The
696 file may be included using the standard
\macro{verbatiminput
}
697 macro; this macro takes a single argument naming the file
698 containing the text. For example, to include the Python source
699 file
\file{example.py
}, use:
702 \verbatiminput{example.py
}
705 Use of
\macro{verbatiminput
} allows easier use of special editing
706 modes for the included file. The file should be placed in the
707 same directory as the
\LaTeX{} files for the
document.
709 The Python Documentation Special Interest Group has discussed a
710 number of approaches to creating pretty-printed code displays and
711 interactive sessions; see the Doc-SIG area on the Python Web site
712 for more information on this topic.
715 \subsection{Inline Markup
\label{inline-markup
}}
717 The macros described in this section are used to mark just about
718 anything interesting in the
document text. They may be used in
719 headings (though anything involving hyperlinks should be avoided
720 there) as well as in the body text.
722 \begin{macrodesc
}{bfcode
}{\p{text
}}
723 Like
\macro{code
}, but also makes the font bold-face.
726 \begin{macrodesc
}{cdata
}{\p{name
}}
727 The name of a C-language variable.
730 \begin{macrodesc
}{cfunction
}{\p{name
}}
731 The name of a C-language function.
\var{name
} should include the
732 function name and the trailing parentheses.
735 \begin{macrodesc
}{character
}{\p{char
}}
736 A character when discussing the character rather than a one-byte
737 string value. The character will be typeset as with
\macro{samp
}.
740 \begin{macrodesc
}{citetitle
}{\op{url
}\p{title
}}
741 A title for a referenced publication. If
\var{url
} is specified,
742 the title will be made into a hyperlink when formatted as HTML.
745 \begin{macrodesc
}{class
}{\p{name
}}
746 A class name; a dotted name may be used.
749 \begin{macrodesc
}{code
}{\p{text
}}
750 A short code fragment or literal constant value. Typically, it
751 should not include any spaces since no quotation marks are
755 \begin{macrodesc
}{constant
}{\p{name
}}
756 The name of a ``defined'' constant. This may be a C-language
757 \code{\#define
} or a Python variable that is not intended to be
761 \begin{macrodesc
}{csimplemacro
}{\p{name
}}
762 The name of a ``simple'' macro. Simple macros are macros
763 which are used for code expansion, but which do not take
764 arguments so cannot be described as functions. This is not to
765 be used for simple constant definitions. Examples of it's use
766 in the Python documentation include
767 \csimplemacro{PyObject_HEAD
} and
768 \csimplemacro{Py_BEGIN_ALLOW_THREADS
}.
771 \begin{macrodesc
}{ctype
}{\p{name
}}
772 The name of a C
\keyword{typedef
} or structure. For structures
773 defined without a
\keyword{typedef
}, use
\code{\e ctype\
{struct
774 struct_tag\
}} to make it clear that the
\keyword{struct
} is
778 \begin{macrodesc
}{deprecated
}{\p{version
}\p{what to do
}}
779 Declare whatever is being described as being deprecated starting
780 with release
\var{version
}. The text given as
\var{what to do
}
781 should recommend something to use instead. It should be
782 complete sentences. The entire deprecation notice will be
783 presented as a separate paragraph; it should either preceed or
784 succeed the description of the deprecated feature.
787 \begin{macrodesc
}{dfn
}{\p{term
}}
788 Mark the defining instance of
\var{term
} in the text. (No index
789 entries are generated.)
792 \begin{macrodesc
}{e
}{}
793 Produces a backslash. This is convenient in
\macro{code
} and
794 similar macros, and is only defined there. To create a
795 backslash in ordinary text (such as the contents of the
796 \macro{file
} macro), use the standard
\macro{textbackslash
} macro.
799 \begin{macrodesc
}{email
}{\p{address
}}
800 An email address. Note that this is
\emph{not
} hyperlinked in
801 any of the possible output formats. The domain name portion of
802 the address should be lower case.
805 \begin{macrodesc
}{emph
}{\p{text
}}
806 Emphasized text; this will be presented in an italic font.
809 \begin{macrodesc
}{envvar
}{\p{name
}}
810 An environment variable. Index entries are generated.
813 \begin{macrodesc
}{exception
}{\p{name
}}
814 The name of an exception. A dotted name may be used.
817 \begin{macrodesc
}{file
}{\p{file or dir
}}
818 The name of a file or directory. In the PDF and PostScript
819 outputs, single quotes and a font change are used to indicate
820 the file name, but no quotes are used in the HTML output.
821 \warning{The
\macro{file
} macro cannot be used in the
822 content of a section title due to processing limitations.
}
825 \begin{macrodesc
}{filenq
}{\p{file or dir
}}
826 Like
\macro{file
}, but single quotes are never used. This can
827 be used in conjunction with tables if a column will only contain
828 file or directory names.
829 \warning{The
\macro{filenq
} macro cannot be used in the
830 content of a section title due to processing limitations.
}
833 \begin{macrodesc
}{function
}{\p{name
}}
834 The name of a Python function; dotted names may be used.
837 \begin{macrodesc
}{infinity
}{}
838 The symbol for mathematical infinity:
\infinity. Some Web
839 browsers are not able to render the HTML representation of this
840 symbol properly, but support is growing.
843 \begin{macrodesc
}{kbd
}{\p{key sequence
}}
844 Mark a sequence of keystrokes. What form
\var{key sequence
}
845 takes may depend on platform- or application-specific
846 conventions. When there are no relevant conventions, the names
847 of modifier keys should be spelled out, to improve accessibility
848 for new users and non-native speakers. For example, an
849 \program{xemacs
} key sequence may be marked like
850 \code{\e kbd\
{C-x C-f\
}}, but without reference to a specific
851 application or platform, the same sequence should be marked as
852 \code{\e kbd\
{Control-x Control-f\
}}.
855 \begin{macrodesc
}{keyword
}{\p{name
}}
856 The name of a keyword in a programming language.
859 \begin{macrodesc
}{mailheader
}{\p{name
}}
860 The name of an
\rfc{822}-style mail header. This markup does
861 not imply that the header is being used in an email message, but
862 can be used to refer to any header of the same ``style.'' This
863 is also used for headers defined by the various MIME
864 specifications. The header name should be entered in the same
865 way it would normally be found in practice, with the
866 camel-casing conventions being preferred where there is more
867 than one common usage. The colon which follows the name of the
868 header should not be included.
869 For example:
\code{\e mailheader\
{Content-Type\
}}.
872 \begin{macrodesc
}{makevar
}{\p{name
}}
873 The name of a
\program{make
} variable.
876 \begin{macrodesc
}{manpage
}{\p{name
}\p{section
}}
877 A reference to a
\UNIX{} manual page.
880 \begin{macrodesc
}{member
}{\p{name
}}
881 The name of a data attribute of an object.
884 \begin{macrodesc
}{method
}{\p{name
}}
885 The name of a method of an object.
\var{name
} should include the
886 method name and the trailing parentheses. A dotted name may be
890 \begin{macrodesc
}{mimetype
}{\p{name
}}
891 The name of a MIME type, or a component of a MIME type (the
892 major or minor portion, taken alone).
895 \begin{macrodesc
}{module
}{\p{name
}}
896 The name of a module; a dotted name may be used. This should
897 also be used for package names.
900 \begin{macrodesc
}{newsgroup
}{\p{name
}}
901 The name of a Usenet newsgroup.
904 \begin{macrodesc
}{note
}{\p{text
}}
905 An especially important bit of information about an API that a
906 user should be aware of when using whatever bit of API the
907 note pertains to. This should be the last thing in the
908 paragraph as the end of the note is not visually marked in
909 any way. The content of
\var{text
} should be written in
910 complete sentences and include all appropriate punctuation.
913 \begin{macrodesc
}{pep
}{\p{number
}}
914 A reference to a Python Enhancement Proposal. This generates
915 appropriate index entries. The text
\samp{PEP
\var{number
}} is
916 generated; in the HTML output, this text is a hyperlink to an
917 online copy of the specified PEP.
920 \begin{macrodesc
}{plusminus
}{}
921 The symbol for indicating a value that may take a positive or
922 negative value of a specified magnitude, typically represented
923 by a plus sign placed over a minus sign. For example:
924 \code{\e plusminus
3\%
{}}.
927 \begin{macrodesc
}{program
}{\p{name
}}
928 The name of an executable program. This may differ from the
929 file name for the executable for some platforms. In particular,
930 the
\file{.exe
} (or other) extension should be omitted for
934 \begin{macrodesc
}{programopt
}{\p{option
}}
935 A command-line option to an executable program. Use this only
936 for ``short'' options, and include the leading hyphen.
939 \begin{macrodesc
}{longprogramopt
}{\p{option
}}
940 A long command-line option to an executable program. This
941 should only be used for long option names which will be prefixed
942 by two hyphens; the hyphens should not be provided as part of
946 \begin{macrodesc
}{refmodule
}{\op{key
}\p{name
}}
947 Like
\macro{module
}, but create a hyperlink to the documentation
948 for the named module. Note that the corresponding
949 \macro{declaremodule
} must be in the same
document. If the
950 \macro{declaremodule
} defines a module key different from the
951 module name, it must also be provided as
\var{key
} to the
952 \macro{refmodule
} macro.
955 \begin{macrodesc
}{regexp
}{\p{string
}}
956 Mark a regular expression.
959 \begin{macrodesc
}{rfc
}{\p{number
}}
960 A reference to an Internet Request for Comments. This generates
961 appropriate index entries. The text
\samp{RFC
\var{number
}} is
962 generated; in the HTML output, this text is a hyperlink to an
963 online copy of the specified RFC.
966 \begin{macrodesc
}{samp
}{\p{text
}}
967 A short code sample, but possibly longer than would be given
968 using
\macro{code
}. Since quotation marks are added, spaces are
972 \begin{macrodesc
}{shortversion
}{}
973 The ``short'' version number of the documented software, as
974 specified using the
\macro{setshortversion
} macro in the
975 preamble. For Python, the short version number for a release is
976 the first three characters of the
\code{sys.version
} value. For
977 example, versions
2.0b1 and
2.0.1 both have a short version of
978 2.0. This may not apply for all packages; if
979 \macro{setshortversion
} is not used, this produces an empty
980 expansion. See also the
\macro{version
} macro.
983 \begin{macrodesc
}{strong
}{\p{text
}}
984 Strongly emphasized text; this will be presented using a bold
988 \begin{macrodesc
}{ulink
}{\p{text
}\p{url
}}
989 A hypertext link with a target specified by a URL, but for which
990 the link text should not be the title of the resource. For
991 resources being referenced by name, use the
\macro{citetitle
}
992 macro. Not all formatted versions support arbitrary hypertext
993 links. Note that many characters are special to
\LaTeX{} and
994 this macro does not always do the right thing. In particular,
995 the tilde character (
\character{\~
}) is mis-handled; encoding it
996 as a hex-sequence does work, use
\samp{\%
7e
} in place of the
1000 \begin{macrodesc
}{url
}{\p{url
}}
1001 A URL (or URN). The URL will be presented as text. In the HTML
1002 and PDF formatted versions, the URL will also be a hyperlink.
1003 This can be used when referring to external resources without
1004 specific titles; references to resources which have titles
1005 should be marked using the
\macro{citetitle
} macro. See the
1006 comments about special characters in the description of the
1007 \macro{ulink
} macro for special considerations.
1010 \begin{macrodesc
}{var
}{\p{name
}}
1011 The name of a variable or formal parameter in running text.
1014 \begin{macrodesc
}{version
}{}
1015 The version number of the described software, as specified using
1016 \macro{release
} in the preamble. See also the
1017 \macro{shortversion
} macro.
1020 \begin{macrodesc
}{versionadded
}{\op{explanation
}\p{version
}}
1021 The version of Python which added the described feature to the
1022 library or C API.
\var{explanation
} should be a
\emph{brief
}
1023 explanation of the change consisting of a capitalized sentence
1024 fragment; a period will be appended by the formatting process.
1025 This is typically added to the end of the first paragraph of the
1026 description before any availability notes. The location should
1027 be selected so the explanation makes sense and may vary as
1031 \begin{macrodesc
}{versionchanged
}{\op{explanation
}\p{version
}}
1032 The version of Python in which the named feature was changed in
1033 some way (new parameters, changed side effects, etc.).
1034 \var{explanation
} should be a
\emph{brief
} explanation of the
1035 change consisting of a capitalized sentence fragment; a
1036 period will be appended by the formatting process.
1037 This is typically added to the end of the first paragraph of the
1038 description before any availability notes and after
1039 \macro{versionadded
}. The location should be selected so the
1040 explanation makes sense and may vary as needed.
1043 \begin{macrodesc
}{warning
}{\p{text
}}
1044 An important bit of information about an API that a user should
1045 be very aware of when using whatever bit of API the warning
1046 pertains to. This should be the last thing in the paragraph as
1047 the end of the warning is not visually marked in any way. The
1048 content of
\var{text
} should be written in complete sentences
1049 and include all appropriate punctuation. This differs from
1050 \macro{note
} in that it is recommended over
\macro{note
} for
1051 information regarding security.
1055 \subsection{Miscellaneous Text Markup
\label{misc-text-markup
}}
1057 In addition to the inline markup, some additional ``block'' markup
1058 is defined to make it easier to bring attention to various bits of
1059 text. The markup described here serves this purpose, and is
1060 intended to be used when marking one or more paragraphs or other
1061 block constructs (such as
\env{verbatim
} environments).
1063 \begin{envdesc
}{notice
}{\op{type
}}
1064 Label some paragraphs as being worthy of additional attention from
1065 the reader. What sort of attention is warrented can be indicated
1066 by specifying the
\var{type
} of the notice. The only values
1067 defined for
\var{type
} are
\code{note
} and
\code{warning
}; these
1068 are equivalent in intent to the inline markup of the same name.
1069 If
\var{type
} is omitted,
\code{note
} is used. Additional values
1070 may be defined in the future.
1074 \subsection{Module-specific Markup
\label{module-markup
}}
1076 The markup described in this section is used to provide information
1077 about a module being documented. A typical use of this markup
1078 appears at the top of the section used to
document a module. A
1079 typical example might look like this:
1082 \section{\module{spam
} ---
1083 Access to the SPAM facility
}
1085 \declaremodule{extension
}{spam
}
1087 \modulesynopsis{Access to the SPAM facility of
\UNIX.
}
1088 \moduleauthor{Jane Doe
}{jane.doe@frobnitz.org
}
1091 Python packages
\index{packages
} --- collections of modules that can
1092 be described as a unit --- are documented using the same markup as
1093 modules. The name for a module in a package should be typed in
1094 ``fully qualified'' form (it should include the package name).
1095 For example, a module ``foo'' in package ``bar'' should be marked as
1096 \code{\e module\
{bar.foo\
}}, and the beginning of the reference
1097 section would appear as:
1100 \section{\module{bar.foo
} ---
1101 Module from the
\module{bar
} package
}
1103 \declaremodule{extension
}{bar.foo
}
1104 \modulesynopsis{Nifty module from the
\module{bar
} package.
}
1105 \moduleauthor{Jane Doe
}{jane.doe@frobnitz.org
}
1108 Note that the name of a package is also marked using
1111 \begin{macrodesc
}{declaremodule
}{\op{key
}\p{type
}\p{name
}}
1112 Requires two parameters: module type (
\samp{standard
},
1113 \samp{builtin
},
\samp{extension
}, or
\samp{}), and the module
1114 name. An optional parameter should be given as the basis for the
1115 module's ``key'' used for linking to or referencing the section.
1116 The ``key'' should only be given if the module's name contains any
1117 underscores, and should be the name with the underscores stripped.
1118 Note that the
\var{type
} parameter must be one of the values
1119 listed above or an error will be printed. For modules which are
1120 contained in packages, the fully-qualified name should be given as
1121 \var{name
} parameter. This should be the first thing after the
1122 \macro{section
} used to introduce the module.
1125 \begin{macrodesc
}{platform
}{\p{specifier
}}
1126 Specifies the portability of the module.
\var{specifier
} is a
1127 comma-separated list of keys that specify what platforms the
1128 module is available on. The keys are short identifiers;
1129 examples that are in use include
\samp{IRIX
},
\samp{Mac
},
1130 \samp{Windows
}, and
\samp{Unix
}. It is important to use a key
1131 which has already been used when applicable. This is used to
1132 provide annotations in the Module Index and the HTML and GNU info
1136 \begin{macrodesc
}{modulesynopsis
}{\p{text
}}
1137 The
\var{text
} is a short, ``one line'' description of the
1138 module that can be used as part of the chapter introduction.
1139 This is must be placed after
\macro{declaremodule
}.
1140 The synopsis is used in building the contents of the table
1141 inserted as the
\macro{localmoduletable
}. No text is
1142 produced at the point of the markup.
1145 \begin{macrodesc
}{moduleauthor
}{\p{name
}\p{email
}}
1146 This macro is used to encode information about who authored a
1147 module. This is currently not used to generate output, but can be
1148 used to help determine the origin of the module.
1152 \subsection{Library-level Markup
\label{library-markup
}}
1154 This markup is used when describing a selection of modules. For
1155 example, the
\citetitle[../mac/mac.html
]{Macintosh Library
1156 Modules
} document uses this to help provide an overview of the
1157 modules in the collection, and many chapters in the
1158 \citetitle[../lib/lib.html
]{Python Library Reference
} use it for
1161 \begin{macrodesc
}{localmoduletable
}{}
1162 If a
\file{.syn
} file exists for the current
1163 chapter (or for the entire
document in
\code{howto
} documents), a
1164 \env{synopsistable
} is created with the contents loaded from the
1169 \subsection{Table Markup
\label{table-markup
}}
1171 There are three general-purpose table environments defined which
1172 should be used whenever possible. These environments are defined
1173 to provide tables of specific widths and some convenience for
1174 formatting. These environments are not meant to be general
1175 replacements for the standard
\LaTeX{} table environments, but can
1176 be used for an advantage when the documents are processed using
1177 the tools for Python documentation processing. In particular, the
1178 generated HTML looks good! There is also an advantage for the
1179 eventual conversion of the documentation to XML (see section
1180 \ref{futures
}, ``Future Directions'').
1182 Each environment is named
\env{table
\var{cols
}}, where
\var{cols
}
1183 is the number of columns in the table specified in lower-case
1184 Roman numerals. Within each of these environments, an additional
1185 macro,
\macro{line
\var{cols
}}, is defined, where
\var{cols
}
1186 matches the
\var{cols
} value of the corresponding table
1187 environment. These are supported for
\var{cols
} values of
1188 \code{ii
},
\code{iii
}, and
\code{iv
}. These environments are all
1189 built on top of the
\env{tabular
} environment. Variants based on
1190 the
\env{longtable
} environment are also provided.
1192 Note that all tables in the standard Python documentation use
1193 vertical lines between columns, and this must be specified in the
1194 markup for each table. A general border around the outside of the
1195 table is not used, but would be the responsibility of the
1196 processor; the
document markup should not include an exterior
1199 The
\env{longtable
}-based variants of the table environments are
1200 formatted with extra space before and after, so should only be
1201 used on tables which are long enough that splitting over multiple
1202 pages is reasonable; tables with fewer than twenty rows should
1203 never by marked using the long flavors of the table environments.
1204 The header row is repeated across the top of each part of the
1207 \begin{envdesc
}{tableii
}{\p{colspec
}\p{col1font
}\p{heading1
}\p{heading2
}}
1208 Create a two-column table using the
\LaTeX{} column specifier
1209 \var{colspec
}. The column specifier should indicate vertical
1210 bars between columns as appropriate for the specific table, but
1211 should not specify vertical bars on the outside of the table
1212 (that is considered a stylesheet issue). The
\var{col1font
}
1213 parameter is used as a stylistic treatment of the first column
1214 of the table: the first column is presented as
1215 \code{\e\var{col1font
}\
{column1\
}}. To avoid treating the first
1216 column specially,
\var{col1font
} may be
\samp{textrm
}. The
1217 column headings are taken from the values
\var{heading1
} and
1221 \begin{envdesc
}{longtableii
}{\unspecified}
1222 Like
\env{tableii
}, but produces a table which may be broken
1223 across page boundaries. The parameters are the same as for
1227 \begin{macrodesc
}{lineii
}{\p{column1
}\p{column2
}}
1228 Create a single table row within a
\env{tableii
} or
1229 \env{longtableii
} environment.
1230 The text for the first column will be generated by applying the
1231 macro named by the
\var{col1font
} value when the
\env{tableii
}
1235 \begin{envdesc
}{tableiii
}{\p{colspec
}\p{col1font
}\p{heading1
}\p{heading2
}\p{heading3
}}
1236 Like the
\env{tableii
} environment, but with a third column.
1237 The heading for the third column is given by
\var{heading3
}.
1240 \begin{envdesc
}{longtableiii
}{\unspecified}
1241 Like
\env{tableiii
}, but produces a table which may be broken
1242 across page boundaries. The parameters are the same as for
1246 \begin{macrodesc
}{lineiii
}{\p{column1
}\p{column2
}\p{column3
}}
1247 Like the
\macro{lineii
} macro, but with a third column. The
1248 text for the third column is given by
\var{column3
}.
1251 \begin{envdesc
}{tableiv
}{\p{colspec
}\p{col1font
}\p{heading1
}\p{heading2
}\p{heading3
}\p{heading4
}}
1252 Like the
\env{tableiii
} environment, but with a fourth column.
1253 The heading for the fourth column is given by
\var{heading4
}.
1256 \begin{envdesc
}{longtableiv
}{\unspecified}
1257 Like
\env{tableiv
}, but produces a table which may be broken
1258 across page boundaries. The parameters are the same as for
1262 \begin{macrodesc
}{lineiv
}{\p{column1
}\p{column2
}\p{column3
}\p{column4
}}
1263 Like the
\macro{lineiii
} macro, but with a fourth column. The
1264 text for the fourth column is given by
\var{column4
}.
1267 \begin{envdesc
}{tablev
}{\p{colspec
}\p{col1font
}\p{heading1
}\p{heading2
}\p{heading3
}\p{heading4
}\p{heading5
}}
1268 Like the
\env{tableiv
} environment, but with a fifth column.
1269 The heading for the fifth column is given by
\var{heading5
}.
1272 \begin{envdesc
}{longtablev
}{\unspecified}
1273 Like
\env{tablev
}, but produces a table which may be broken
1274 across page boundaries. The parameters are the same as for
1278 \begin{macrodesc
}{linev
}{\p{column1
}\p{column2
}\p{column3
}\p{column4
}\p{column5
}}
1279 Like the
\macro{lineiv
} macro, but with a fifth column. The
1280 text for the fifth column is given by
\var{column5
}.
1284 An additional table-like environment is
\env{synopsistable
}. The
1285 table generated by this environment contains two columns, and each
1286 row is defined by an alternate definition of
1287 \macro{modulesynopsis
}. This environment is not normally used by
1288 authors, but is created by the
\macro{localmoduletable
} macro.
1290 Here is a small example of a table given in the documentation for
1291 the
\module{warnings
} module; markup inside the table cells is
1292 minimal so the markup for the table itself is readily discernable.
1293 Here is the markup for the table:
1296 \begin{tableii
}{l|l
}{exception
}{Class
}{Description
}
1298 {This is the base class of all warning category classes. It
1299 is a subclass of
\exception{Exception
}.
}
1300 \lineii{UserWarning
}
1301 {The default category for
\function{warn()
}.
}
1302 \lineii{DeprecationWarning
}
1303 {Base category for warnings about deprecated features.
}
1304 \lineii{SyntaxWarning
}
1305 {Base category for warnings about dubious syntactic
1307 \lineii{RuntimeWarning
}
1308 {Base category for warnings about dubious runtime features.
}
1309 \lineii{FutureWarning
}
1310 {Base category for warnings about constructs that will change
1311 semantically in the future.
}
1315 Here is the resulting table:
1317 \begin{tableii
}{l|l
}{exception
}{Class
}{Description
}
1319 {This is the base class of all warning category classes. It
1320 is a subclass of
\exception{Exception
}.
}
1321 \lineii{UserWarning
}
1322 {The default category for
\function{warn()
}.
}
1323 \lineii{DeprecationWarning
}
1324 {Base category for warnings about deprecated features.
}
1325 \lineii{SyntaxWarning
}
1326 {Base category for warnings about dubious syntactic
1328 \lineii{RuntimeWarning
}
1329 {Base category for warnings about dubious runtime features.
}
1332 Note that the class names are implicitly marked using the
1333 \macro{exception
} macro, since that is given as the
\var{col1font
}
1334 value for the
\env{tableii
} environment. To create a table using
1335 different markup for the first column, use
\code{textrm
} for the
1336 \var{col1font
} value and mark each entry individually.
1338 To add a horizontal line between vertical sections of a table, use
1339 the standard
\macro{hline
} macro between the rows which should be
1343 \begin{tableii
}{l|l
}{constant
}{Language
}{Audience
}
1344 \lineii{APL
}{Masochists.
}
1345 \lineii{BASIC
}{First-time programmers on PC hardware.
}
1346 \lineii{C
}{\UNIX{} \&\ Linux kernel developers.
}
1348 \lineii{Python
}{Everyone!
}
1352 Note that not all presentation formats are capable of displaying a
1353 horizontal rule in this position. This is how the table looks in
1354 the format you're reading now:
1356 \begin{tableii
}{l|l
}{constant
}{Language
}{Audience
}
1357 \lineii{APL
}{Masochists.
}
1358 \lineii{C
}{\UNIX{} \&\ Linux kernel developers.
}
1359 \lineii{JavaScript
}{Web developers.
}
1361 \lineii{Python
}{Everyone!
}
1365 \subsection{Reference List Markup
\label{references
}}
1367 Many sections include a list of references to module documentation
1368 or external documents. These lists are created using the
1369 \env{seealso
} or
\env{seealso*
} environments. These environments
1370 define some additional macros to support creating reference
1371 entries in a reasonable manner.
1373 The
\env{seealso
} environment is typically placed in a section
1374 just before any sub-sections. This is done to ensure that
1375 reference links related to the section are not hidden in a
1376 subsection in the hypertext renditions of the documentation. For
1377 the HTML output, it is shown as a ``side bar,'' boxed off from the
1378 main flow of the text. The
\env{seealso*
} environment is
1379 different in that it should be used when a list of references is
1380 being presented as part of the primary content; it is not
1381 specially set off from the text.
1383 \begin{envdesc
}{seealso
}{}
1384 This environment creates a ``See also:'' heading and defines the
1385 markup used to describe individual references.
1388 \begin{envdesc
}{seealso*
}{}
1389 This environment is used to create a list of references which
1390 form part of the main content. It is not given a special
1391 header and is not set off from the main flow of the text. It
1392 provides the same additional markup used to describe individual
1396 For each of the following macros,
\var{why
} should be one or more
1397 complete sentences, starting with a capital letter (unless it
1398 starts with an identifier, which should not be modified), and
1399 ending with the apropriate punctuation.
1401 These macros are only defined within the content of the
1402 \env{seealso
} and
\env{seealso*
} environments.
1404 \begin{macrodesc
}{seemodule
}{\op{key
}\p{name
}\p{why
}}
1405 Refer to another module.
\var{why
} should be a brief
1406 explanation of why the reference may be interesting. The module
1407 name is given in
\var{name
}, with the link key given in
1408 \var{key
} if necessary. In the HTML and PDF conversions, the
1409 module name will be a hyperlink to the referred-to module.
1410 \note{The module must be documented in the same
1411 document (the corresponding
\macro{declaremodule
} is required).
}
1414 \begin{macrodesc
}{seepep
}{\p{number
}\p{title
}\p{why
}}
1415 Refer to an Python Enhancement Proposal (PEP).
\var{number
}
1416 should be the official number assigned by the PEP Editor,
1417 \var{title
} should be the human-readable title of the PEP as
1418 found in the official copy of the
document, and
\var{why
} should
1419 explain what's interesting about the PEP. This should be used
1420 to refer the reader to PEPs which specify interfaces or language
1421 features relevant to the material in the annotated section of the
1425 \begin{macrodesc
}{seerfc
}{\p{number
}\p{title
}\p{why
}}
1426 Refer to an IETF Request for Comments (RFC). Otherwise very
1427 similar to
\macro{seepep
}. This should be used
1428 to refer the reader to PEPs which specify protocols or data
1429 formats relevant to the material in the annotated section of the
1433 \begin{macrodesc
}{seetext
}{\p{text
}}
1434 Add arbitrary text
\var{text
} to the ``See also:'' list. This
1435 can be used to refer to off-line materials or on-line materials
1436 using the
\macro{url
} macro. This should consist of one or more
1440 \begin{macrodesc
}{seetitle
}{\op{url
}\p{title
}\p{why
}}
1441 Add a reference to an external
document named
\var{title
}. If
1442 \var{url
} is given, the title is made a hyperlink in the HTML
1443 version of the documentation, and displayed below the title in
1444 the typeset versions of the documentation.
1447 \begin{macrodesc
}{seeurl
}{\p{url
}\p{why
}}
1448 References to specific on-line resources should be given using
1449 the
\macro{seeurl
} macro if they don't have a meaningful title.
1450 Online documents which have identifiable titles should be
1451 referenced using the
\macro{seetitle
} macro, using the optional
1452 parameter to that macro to provide the URL.
1456 \subsection{Index-generating Markup
\label{indexing
}}
1458 Effective index generation for technical documents can be very
1459 difficult, especially for someone familiar with the topic but not
1460 the creation of indexes. Much of the difficulty arises in the
1461 area of terminology: including the terms an expert would use for a
1462 concept is not sufficient. Coming up with the terms that a novice
1463 would look up is fairly difficult for an author who, typically, is
1464 an expert in the area she is writing on.
1466 The truly difficult aspects of index generation are not areas with
1467 which the documentation tools can help. However, ease
1468 of producing the index once content decisions are made is within
1469 the scope of the tools. Markup is provided which the processing
1470 software is able to use to generate a variety of kinds of index
1471 entry with minimal effort. Additionally, many of the environments
1472 described in section
\ref{info-units
}, ``Information Units,'' will
1473 generate appropriate entries into the general and module indexes.
1475 The following macro can be used to control the generation of index
1476 data, and should be used in the
document preamble:
1478 \begin{macrodesc
}{makemodindex
}{}
1479 This should be used in the
document preamble if a ``Module
1480 Index'' is desired for a
document containing reference material
1481 on many modules. This causes a data file
1482 \code{lib
\var{jobname
}.idx
} to be created from the
1483 \macro{declaremodule
} macros. This file can be processed by the
1484 \program{makeindex
} program to generate a file which can be
1485 \macro{input
} into the
document at the desired location of the
1489 There are a number of macros that are useful for adding index
1490 entries for particular concepts, many of which are specific to
1491 programming languages or even Python.
1493 \begin{macrodesc
}{bifuncindex
}{\p{name
}}
1494 Add an index entry referring to a built-in function named
1495 \var{name
}; parentheses should not be included after
1499 \begin{macrodesc
}{exindex
}{\p{exception
}}
1500 Add a reference to an exception named
\var{exception
}. The
1501 exception may be either string- or class-based.
1504 \begin{macrodesc
}{kwindex
}{\p{keyword
}}
1505 Add a reference to a language keyword (not a keyword parameter
1506 in a function or method call).
1509 \begin{macrodesc
}{obindex
}{\p{object type
}}
1510 Add an index entry for a built-in object type.
1513 \begin{macrodesc
}{opindex
}{\p{operator
}}
1514 Add a reference to an operator, such as
\samp{+
}.
1517 \begin{macrodesc
}{refmodindex
}{\op{key
}\p{module
}}
1518 Add an index entry for module
\var{module
}; if
\var{module
}
1519 contains an underscore, the optional parameter
\var{key
} should
1520 be provided as the same string with underscores removed. An
1521 index entry ``
\var{module
} (module)'' will be generated. This
1522 is intended for use with non-standard modules implemented in
1526 \begin{macrodesc
}{refexmodindex
}{\op{key
}\p{module
}}
1527 As for
\macro{refmodindex
}, but the index entry will be
1528 ``
\var{module
} (extension module).'' This is intended for use
1529 with non-standard modules not implemented in Python.
1532 \begin{macrodesc
}{refbimodindex
}{\op{key
}\p{module
}}
1533 As for
\macro{refmodindex
}, but the index entry will be
1534 ``
\var{module
} (built-in module).'' This is intended for use
1535 with standard modules not implemented in Python.
1538 \begin{macrodesc
}{refstmodindex
}{\op{key
}\p{module
}}
1539 As for
\macro{refmodindex
}, but the index entry will be
1540 ``
\var{module
} (standard module).'' This is intended for use
1541 with standard modules implemented in Python.
1544 \begin{macrodesc
}{stindex
}{\p{statement
}}
1545 Add an index entry for a statement type, such as
\keyword{print
}
1546 or
\keyword{try
}/
\keyword{finally
}.
1548 XXX Need better examples of difference from
\macro{kwindex
}.
1552 Additional macros are provided which are useful for conveniently
1553 creating general index entries which should appear at many places
1554 in the index by rotating a list of words. These are simple macros
1555 that simply use
\macro{index
} to build some number of index
1556 entries. Index entries build using these macros contain both
1557 primary and secondary text.
1559 \begin{macrodesc
}{indexii
}{\p{word1
}\p{word2
}}
1560 Build two index entries. This is exactly equivalent to using
1561 \code{\e index\
{\var{word1
}!
\var{word2
}\
}} and
1562 \code{\e index\
{\var{word2
}!
\var{word1
}\
}}.
1565 \begin{macrodesc
}{indexiii
}{\p{word1
}\p{word2
}\p{word3
}}
1566 Build three index entries. This is exactly equivalent to using
1567 \code{\e index\
{\var{word1
}!
\var{word2
} \var{word3
}\
}},
1568 \code{\e index\
{\var{word2
}!
\var{word3
},
\var{word1
}\
}}, and
1569 \code{\e index\
{\var{word3
}!
\var{word1
} \var{word2
}\
}}.
1572 \begin{macrodesc
}{indexiv
}{\p{word1
}\p{word2
}\p{word3
}\p{word4
}}
1573 Build four index entries. This is exactly equivalent to using
1574 \code{\e index\
{\var{word1
}!
\var{word2
} \var{word3
} \var{word4
}\
}},
1575 \code{\e index\
{\var{word2
}!
\var{word3
} \var{word4
},
\var{word1
}\
}},
1576 \code{\e index\
{\var{word3
}!
\var{word4
},
\var{word1
} \var{word2
}\
}},
1578 \code{\e index\
{\var{word4
}!
\var{word1
} \var{word2
} \var{word3
}\
}}.
1581 \subsection{Grammar Production Displays
\label{grammar-displays
}}
1583 Special markup is available for displaying the productions of a
1584 formal grammar. The markup is simple and does not attempt to
1585 model all aspects of BNF (or any derived forms), but provides
1586 enough to allow context-free grammars to be displayed in a way
1587 that causes uses of a symbol to be rendered as hyperlinks to the
1588 definition of the symbol. There is one environment and a pair of
1591 \begin{envdesc
}{productionlist
}{\op{language
}}
1592 This environment is used to enclose a group of productions. The
1593 two macros are only defined within this environment. If a
1594 document descibes more than one language, the optional parameter
1595 \var{language
} should be used to distinguish productions between
1596 languages. The value of the parameter should be a short name
1597 that can be used as part of a filename; colons or other
1598 characters that can't be used in filename across platforms
1602 \begin{macrodesc
}{production
}{\p{name
}\p{definition
}}
1603 A production rule in the grammar. The rule defines the symbol
1604 \var{name
} to be
\var{definition
}.
\var{name
} should not
1605 contain any markup, and the use of hyphens in a
document which
1606 supports more than one grammar is undefined.
\var{definition
}
1607 may contain
\macro{token
} macros and any additional content
1608 needed to describe the grammatical model of
\var{symbol
}. Only
1609 one
\macro{production
} may be used to define a symbol ---
1610 multiple definitions are not allowed.
1613 \begin{macrodesc
}{token
}{\p{name
}}
1614 The name of a symbol defined by a
\macro{production
} macro, used
1615 in the
\var{definition
} of a symbol. Where possible, this will
1616 be rendered as a hyperlink to the definition of the symbol
1620 Note that the entire grammar does not need to be defined in a
1621 single
\env{productionlist
} environment; any number of
1622 groupings may be used to describe the grammar. Every use of the
1623 \macro{token
} must correspond to a
\macro{production
}.
1625 The following is an example taken from the
1626 \citetitle[../ref/identifiers.html
]{Python Reference Manual
}:
1629 \begin{productionlist
}
1630 \production{identifier
}
1631 {(
\token{letter
}|"_") (
\token{letter
} |
\token{digit
} | "_")*
}
1633 {\token{lowercase
} |
\token{uppercase
}}
1634 \production{lowercase
}
1636 \production{uppercase
}
1640 \end{productionlist
}
1644 \subsection{Graphical Interface Components
\label{gui-markup
}}
1646 The components of graphical interfaces will be assigned markup, but
1647 most of the specifics have not been determined.
1649 \begin{macrodesc
}{menuselection
}{\p{menupath
}}
1650 Menu selections should be marked using a combination of
1651 \macro{menuselection
} and
\macro{sub
}. This macro is used to mark
1652 a complete sequence of menu selections, including selecting
1653 submenus and choosing a specific operation, or any subsequence of
1654 such a sequence. The names of individual selections should be
1655 separated by occurances of
\macro{sub
}.
1657 For example, to mark the selection ``
\menuselection{Start
\sub
1658 Programs
}'', use this markup:
1661 \menuselection{Start
\sub Programs
}
1664 When including a selection that includes some trailing indicator,
1665 such as the ellipsis some operating systems use to indicate that
1666 the command opens a dialog, the indicator should be omitted from
1670 \begin{macrodesc
}{sub
}{}
1671 Separator for menu selections that include multiple levels. This
1672 macro is only defined within the context of the
1673 \macro{menuselection
} macro.
1677 \section{Processing Tools
\label{tools
}}
1679 \subsection{External Tools
\label{tools-external
}}
1681 Many tools are needed to be able to process the Python
1682 documentation if all supported formats are required. This
1683 section lists the tools used and when each is required. Consult
1684 the
\file{Doc/README
} file to see if there are specific version
1685 requirements for any of these.
1688 \item[\program{dvips}]
1689 This program is a typical part of
\TeX{} installations. It is
1690 used to generate PostScript from the ``device independent''
1691 \file{.dvi
} files. It is needed for the conversion to
1694 \item[\program{emacs
}]
1695 Emacs is the kitchen sink of programmers' editors, and a damn
1696 fine kitchen sink it is. It also comes with some of the
1697 processing needed to support the proper menu structures for
1698 Texinfo documents when an info conversion is desired. This is
1699 needed for the info conversion. Using
\program{xemacs
}
1700 instead of FSF
\program{emacs
} may lead to instability in the
1701 conversion, but that's because nobody seems to maintain the
1702 Emacs Texinfo code in a portable manner.
1704 \item[\program{latex
}]
1705 \LaTeX{} is a large and extensible macro package by Leslie
1706 Lamport, based on
\TeX, a world-class typesetter by Donald
1707 Knuth. It is used for the conversion to PostScript, and is
1708 needed for the HTML conversion as well (
\LaTeX2HTML requires
1709 one of the intermediate files it creates).
1711 \item[\program{latex2html
}]
1712 Probably the longest Perl script anyone ever attempted to
1713 maintain. This converts
\LaTeX{} documents to HTML documents,
1714 and does a pretty reasonable job. It is required for the
1715 conversions to HTML and GNU info.
1717 \item[\program{lynx
}]
1718 This is a text-mode Web browser which includes an
1719 HTML-to-plain text conversion. This is used to convert
1720 \code{howto
} documents to text.
1722 \item[\program{make
}]
1723 Just about any version should work for the standard documents,
1724 but GNU
\program{make
} is required for the experimental
1725 processes in
\file{Doc/tools/sgmlconv/
}, at least while
1726 they're experimental. This is not required for running the
1727 \program{mkhowto
} script.
1729 \item[\program{makeindex
}]
1730 This is a standard program for converting
\LaTeX{} index data
1731 to a formatted index; it should be included with all
\LaTeX{}
1732 installations. It is needed for the PDF and PostScript
1735 \item[\program{makeinfo
}]
1736 GNU
\program{makeinfo
} is used to convert Texinfo documents to
1737 GNU info files. Since Texinfo is used as an intermediate
1738 format in the info conversion, this program is needed in that
1741 \item[\program{pdflatex
}]
1742 pdf
\TeX{} is a relatively new variant of
\TeX, and is used to
1743 generate the PDF version of the manuals. It is typically
1744 installed as part of most of the large
\TeX{} distributions.
1745 \program{pdflatex
} is pdf
\TeX{} using the
\LaTeX{} format.
1747 \item[\program{perl
}]
1748 Perl is required for
\LaTeX2HTML{} and one of the scripts used
1749 to post-process
\LaTeX2HTML output, as well as the
1750 HTML-to-Texinfo conversion. This is required for
1751 the HTML and GNU info conversions.
1753 \item[\program{python
}]
1754 Python is used for many of the scripts in the
1755 \file{Doc/tools/
} directory; it is required for all
1756 conversions. This shouldn't be a problem if you're interested
1757 in writing documentation for Python!
1761 \subsection{Internal Tools
\label{tools-internal
}}
1763 This section describes the various scripts that are used to
1764 implement various stages of
document processing or to orchestrate
1765 entire build sequences. Most of these tools are only useful
1766 in the context of building the standard documentation, but some
1770 \item[\program{mkhowto
}]
1771 This is the primary script used to format third-party
1772 documents. It contains all the logic needed to ``get it
1773 right.'' The proper way to use this script is to make a
1774 symbolic link to it or run it in place; the actual script file
1775 must be stored as part of the documentation source tree,
1776 though it may be used to format documents outside the
1777 tree. Use
\program{mkhowto
} \longprogramopt{help
}
1779 command line options.
1781 \program{mkhowto
} can be used for both
\code{howto
} and
1782 \code{manual
} class documents. It is usually a good idea to
1783 always use the latest version of this tool rather than a
1784 version from an older source release of Python.
1790 \subsection{Working on Cygwin
\label{cygwin
}}
1792 Installing the required tools under Cygwin under Cygwin can be a
1793 little tedious, if only because many packages are more difficult
1794 to install under Cygwin.
1796 Using the Cygwin installer, make sure your Cygwin installation
1797 includes Perl, Python, and the
\TeX{} packages. Perl and Python
1798 are located under
\menuselection{Interpreters
} in the installer
1799 The
\TeX{} packages are located in the
\menuselection{Text
}
1800 section; installing the tetex-beta, texmf, texmf-base, and
1801 texmf-extra ensures that all the required packages are available.
1802 (There may be a more minimal set, but I've not spent time trying
1803 to minimize the installation.)
1805 The netpbm package is used by
\LaTeX2HTML, and
\emph{must
} be
1806 installed before
\LaTeX2HTML can be successfully installed, even
1807 though they will never be used for most Python documentation.
1808 References to download locations are located in the
\ulink{netpbm
1809 README
}{http://netpbm.sourceforge.net/README
}. Install according
1810 to the instructions.
1812 \LaTeX2HTML can be installed from the source archive, but only
1813 after munging one of the files in the distribution. Edit the file
1814 \file{L2hos.pm
} in the top level of the unpacked distribution;
1815 near the bottom of the file, change the text
1816 \code{\$
\textasciicircum{}O
} with the text
\code{'unix'
}. Proceed
1817 using this command to build and install the software:
1820 % configure && make install
1823 You should now be able to build at least the HTML, PDF, and
1824 PostScript versions of the formatted documentation.
1827 \section{Future Directions
\label{futures
}}
1829 The history of the Python documentation is full of changes, most of
1830 which have been fairly small and evolutionary. There has been a
1831 great deal of discussion about making large changes in the markup
1832 languages and tools used to process the documentation. This section
1833 deals with the nature of the changes and what appears to be the most
1834 likely path of future development.
1836 \subsection{Structured Documentation
\label{structured
}}
1838 Most of the small changes to the
\LaTeX{} markup have been made
1839 with an eye to divorcing the markup from the presentation, making
1840 both a bit more maintainable. Over the course of
1998, a large
1841 number of changes were made with exactly this in mind; previously,
1842 changes had been made but in a less systematic manner and with
1843 more concern for not needing to update the existing content. The
1844 result has been a highly structured and semantically loaded markup
1845 language implemented in
\LaTeX. With almost no basic
\TeX{} or
1846 \LaTeX{} markup in use, however, the markup syntax is about the
1847 only evidence of
\LaTeX{} in the actual
document sources.
1849 One side effect of this is that while we've been able to use
1850 standard ``engines'' for manipulating the documents, such as
1851 \LaTeX{} and
\LaTeX2HTML, most of the actual transformations have
1852 been created specifically for Python. The
\LaTeX{} document
1853 classes and
\LaTeX2HTML support are both complete implementations
1854 of the specific markup designed for these documents.
1856 Combining highly customized markup with the somewhat esoteric
1857 systems used to process the documents leads us to ask some
1858 questions: Can we do this more easily? and, Can we do this
1859 better? After a great deal of discussion with the community, we
1860 have determined that actively pursuing modern structured
1861 documentation systems is worth some investment of time.
1863 There appear to be two real contenders in this arena: the Standard
1864 General Markup Language (SGML), and the Extensible Markup Language
1865 (XML). Both of these standards have advantages and disadvantages,
1866 and many advantages are shared.
1868 SGML offers advantages which may appeal most to authors,
1869 especially those using ordinary text editors. There are also
1870 additional abilities to define content models. A number of
1871 high-quality tools with demonstrated maturity are available, but
1872 most are not free; for those which are, portability issues remain
1875 The advantages of XML include the availability of a large number
1876 of evolving tools. Unfortunately, many of the associated
1877 standards are still evolving, and the tools will have to follow
1878 along. This means that developing a robust tool set that uses
1879 more than the basic XML
1.0 recommendation is not possible in the
1880 short term. The promised availability of a wide variety of
1881 high-quality tools which support some of the most important
1882 related standards is not immediate. Many tools are likely to be
1883 free, and the portability issues of those which are, are not
1884 expected to be significant.
1886 It turns out that converting to an XML or SGML system holds
1887 promise for translators as well; how much can be done to ease the
1888 burden on translators remains to be seen, and may have some impact
1889 on the schema and specific technologies used.
1891 XXX Eventual migration to XML.
1893 The documentation will be moved to XML in the future, and tools
1894 are being written which will convert the documentation from the
1895 current format to something close to a finished version, to the
1896 extent that the desired information is already present in the
1897 documentation. Some XSLT stylesheets have been started for
1898 presenting a preliminary XML version as HTML, but the results are
1901 The timeframe for the conversion is not clear since there doesn't
1902 seem to be much time available to work on this, but the appearant
1903 benefits are growing more substantial at a moderately rapid pace.
1906 \subsection{Discussion Forums
\label{discussion
}}
1908 Discussion of the future of the Python documentation and related
1909 topics takes place in the Documentation Special Interest Group, or
1910 ``Doc-SIG.'' Information on the group, including mailing list
1911 archives and subscription information, is available at
1912 \url{http://www.python.org/sigs/doc-sig/
}. The SIG is open to all
1915 Comments and bug reports on the standard documents should be sent
1916 to
\email{python-docs@python.org
}. This may include comments
1917 about formatting, content, grammatical and spelling errors, or
1918 this
document. You can also send comments on this
document
1919 directly to the author at
\email{fdrake@acm.org
}.