blob: 4f1fcae9e75b3a99fb57e3a80597a256f7b61992 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001.. highlightlang:: rest
2
3Additional Markup Constructs
4============================
5
6Sphinx adds a lot of new directives and interpreted text roles to standard reST
7markup. This section contains the reference material for these facilities.
8Documentation for "standard" reST constructs is not included here, though
9they are used in the Python documentation.
10
Georg Brandlbce1f5f2008-11-08 11:48:20 +000011.. note::
Georg Brandl8ec7f652007-08-15 14:28:01 +000012
Georg Brandlbce1f5f2008-11-08 11:48:20 +000013 This is just an overview of Sphinx' extended markup capabilities; full
14 coverage can be found in `its own documentation
15 <http://sphinx.pocoo.org/contents.html>`_.
Georg Brandl8ec7f652007-08-15 14:28:01 +000016
17
18Meta-information markup
19-----------------------
20
21.. describe:: sectionauthor
22
23 Identifies the author of the current section. The argument should include
24 the author's name such that it can be used for presentation (though it isn't)
25 and email address. The domain name portion of the address should be lower
26 case. Example::
27
28 .. sectionauthor:: Guido van Rossum <guido@python.org>
29
30 Currently, this markup isn't reflected in the output in any way, but it helps
31 keep track of contributions.
32
33
34Module-specific markup
35----------------------
36
37The markup described in this section is used to provide information about a
38module being documented. Each module should be documented in its own file.
39Normally this markup appears after the title heading of that file; a typical
40file might start like this::
41
42 :mod:`parrot` -- Dead parrot access
43 ===================================
44
45 .. module:: parrot
46 :platform: Unix, Windows
47 :synopsis: Analyze and reanimate dead parrots.
48 .. moduleauthor:: Eric Cleese <eric@python.invalid>
49 .. moduleauthor:: John Idle <john@python.invalid>
50
51As you can see, the module-specific markup consists of two directives, the
52``module`` directive and the ``moduleauthor`` directive.
53
54.. describe:: module
55
56 This directive marks the beginning of the description of a module (or package
57 submodule, in which case the name should be fully qualified, including the
58 package name).
59
60 The ``platform`` option, if present, is a comma-separated list of the
61 platforms on which the module is available (if it is available on all
62 platforms, the option should be omitted). The keys are short identifiers;
63 examples that are in use include "IRIX", "Mac", "Windows", and "Unix". It is
64 important to use a key which has already been used when applicable.
65
66 The ``synopsis`` option should consist of one sentence describing the
67 module's purpose -- it is currently only used in the Global Module Index.
68
Georg Brandl7f758c42007-08-15 18:41:25 +000069 The ``deprecated`` option can be given (with no value) to mark a module as
70 deprecated; it will be designated as such in various locations then.
71
Georg Brandl8ec7f652007-08-15 14:28:01 +000072.. describe:: moduleauthor
73
74 The ``moduleauthor`` directive, which can appear multiple times, names the
75 authors of the module code, just like ``sectionauthor`` names the author(s)
76 of a piece of documentation. It too does not result in any output currently.
77
Georg Brandl8ec7f652007-08-15 14:28:01 +000078.. note::
79
80 It is important to make the section title of a module-describing file
81 meaningful since that value will be inserted in the table-of-contents trees
82 in overview files.
83
84
85Information units
86-----------------
87
88There are a number of directives used to describe specific features provided by
89modules. Each directive requires one or more signatures to provide basic
90information about what is being described, and the content should be the
91description. The basic version makes entries in the general index; if no index
92entry is desired, you can give the directive option flag ``:noindex:``. The
93following example shows all of the features of this directive type::
94
95 .. function:: spam(eggs)
96 ham(eggs)
97 :noindex:
98
99 Spam or ham the foo.
100
Éric Araujo3322a252011-06-04 18:35:04 +0200101The signatures of object methods or data attributes should not include the
102class name, but be nested in a class directive. The generated files will
103reflect this nesting, and the target identifiers (for HTML output) will use
104both the class and method name, to enable consistent cross-references. If you
105describe methods belonging to an abstract protocol such as context managers,
106use a class directive with a (pseudo-)type name too to make the
Georg Brandl8ec7f652007-08-15 14:28:01 +0000107index entries more informative.
108
109The directives are:
110
111.. describe:: cfunction
112
113 Describes a C function. The signature should be given as in C, e.g.::
114
115 .. cfunction:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
116
117 This is also used to describe function-like preprocessor macros. The names
118 of the arguments should be given so they may be used in the description.
119
120 Note that you don't have to backslash-escape asterisks in the signature,
121 as it is not parsed by the reST inliner.
122
123.. describe:: cmember
124
125 Describes a C struct member. Example signature::
126
127 .. cmember:: PyObject* PyTypeObject.tp_bases
128
129 The text of the description should include the range of values allowed, how
130 the value should be interpreted, and whether the value can be changed.
131 References to structure members in text should use the ``member`` role.
132
133.. describe:: cmacro
134
135 Describes a "simple" C macro. Simple macros are macros which are used
136 for code expansion, but which do not take arguments so cannot be described as
137 functions. This is not to be used for simple constant definitions. Examples
138 of its use in the Python documentation include :cmacro:`PyObject_HEAD` and
139 :cmacro:`Py_BEGIN_ALLOW_THREADS`.
140
141.. describe:: ctype
142
143 Describes a C type. The signature should just be the type name.
144
145.. describe:: cvar
146
147 Describes a global C variable. The signature should include the type, such
148 as::
149
150 .. cvar:: PyObject* PyClass_Type
151
152.. describe:: data
153
154 Describes global data in a module, including both variables and values used
155 as "defined constants." Class and object attributes are not documented
Éric Araujo46c09da2011-04-16 23:47:53 +0200156 using this directive.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000157
158.. describe:: exception
159
160 Describes an exception class. The signature can, but need not include
161 parentheses with constructor arguments.
162
163.. describe:: function
164
165 Describes a module-level function. The signature should include the
166 parameters, enclosing optional parameters in brackets. Default values can be
167 given if it enhances clarity. For example::
168
Éric Araujo46c09da2011-04-16 23:47:53 +0200169 .. function:: repeat([repeat=3[, number=1000000]])
Georg Brandl8ec7f652007-08-15 14:28:01 +0000170
171 Object methods are not documented using this directive. Bound object methods
172 placed in the module namespace as part of the public interface of the module
173 are documented using this, as they are equivalent to normal functions for
174 most purposes.
175
176 The description should include information about the parameters required and
177 how they are used (especially whether mutable objects passed as parameters
178 are modified), side effects, and possible exceptions. A small example may be
179 provided.
180
181.. describe:: class
182
183 Describes a class. The signature can include parentheses with parameters
184 which will be shown as the constructor arguments.
185
186.. describe:: attribute
187
188 Describes an object data attribute. The description should include
189 information about the type of the data to be expected and whether it may be
Éric Araujo46c09da2011-04-16 23:47:53 +0200190 changed directly. This directive should be nested in a class directive,
191 like in this example::
192
193 .. class:: Spam
194
195 Description of the class.
196
197 .. data:: ham
198
199 Description of the attribute.
200
201 If is also possible to document an attribute outside of a class directive,
202 for example if the documentation for different attributes and methods is
203 split in multiple sections. The class name should then be included
204 explicitly::
205
206 .. data:: Spam.eggs
Georg Brandl8ec7f652007-08-15 14:28:01 +0000207
208.. describe:: method
209
210 Describes an object method. The parameters should not include the ``self``
211 parameter. The description should include similar information to that
Éric Araujo2a53d332011-05-01 02:15:03 +0200212 described for ``function``. This directive should be nested in a class
213 directive, like in the example above.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000214
215.. describe:: opcode
216
Georg Brandl63fa1682007-10-21 10:24:20 +0000217 Describes a Python :term:`bytecode` instruction.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000218
Georg Brandldd197e952007-10-20 13:36:24 +0000219.. describe:: cmdoption
220
Georg Brandl8891e232010-08-01 21:23:50 +0000221 Describes a Python command line option or switch. Option argument names
222 should be enclosed in angle brackets. Example::
Georg Brandldd197e952007-10-20 13:36:24 +0000223
224 .. cmdoption:: -m <module>
225
226 Run a module as a script.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000227
Georg Brandla147bf92007-10-20 17:51:39 +0000228.. describe:: envvar
229
230 Describes an environment variable that Python uses or defines.
231
232
Georg Brandl8ec7f652007-08-15 14:28:01 +0000233There is also a generic version of these directives:
234
235.. describe:: describe
236
237 This directive produces the same formatting as the specific ones explained
238 above but does not create index entries or cross-referencing targets. It is
239 used, for example, to describe the directives in this document. Example::
240
241 .. describe:: opcode
242
243 Describes a Python bytecode instruction.
244
245
246Showing code examples
247---------------------
248
249Examples of Python source code or interactive sessions are represented using
250standard reST literal blocks. They are started by a ``::`` at the end of the
251preceding paragraph and delimited by indentation.
252
253Representing an interactive session requires including the prompts and output
254along with the Python code. No special markup is required for interactive
255sessions. After the last line of input or output presented, there should not be
256an "unused" primary prompt; this is an example of what *not* to do::
257
258 >>> 1 + 1
259 2
260 >>>
261
262Syntax highlighting is handled in a smart way:
263
264* There is a "highlighting language" for each source file. Per default,
265 this is ``'python'`` as the majority of files will have to highlight Python
266 snippets.
267
268* Within Python highlighting mode, interactive sessions are recognized
269 automatically and highlighted appropriately.
270
271* The highlighting language can be changed using the ``highlightlang``
272 directive, used as follows::
273
274 .. highlightlang:: c
275
276 This language is used until the next ``highlightlang`` directive is
277 encountered.
278
Georg Brandlbce1f5f2008-11-08 11:48:20 +0000279* The values normally used for the highlighting language are:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000280
281 * ``python`` (the default)
282 * ``c``
283 * ``rest``
284 * ``none`` (no highlighting)
285
286* If highlighting with the current language fails, the block is not highlighted
287 in any way.
288
289Longer displays of verbatim text may be included by storing the example text in
290an external file containing only plain text. The file may be included using the
291``literalinclude`` directive. [1]_ For example, to include the Python source file
292:file:`example.py`, use::
293
294 .. literalinclude:: example.py
295
296The file name is relative to the current file's path. Documentation-specific
297include files should be placed in the ``Doc/includes`` subdirectory.
298
299
300Inline markup
301-------------
302
303As said before, Sphinx uses interpreted text roles to insert semantic markup in
304documents.
305
Georg Brandl40e84152009-01-22 18:29:28 +0000306Names of local variables, such as function/method arguments, are an exception,
307they should be marked simply with ``*var*``.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000308
309For all other roles, you have to write ``:rolename:`content```.
310
Georg Brandl0c2430b2009-01-26 21:29:38 +0000311There are some additional facilities that make cross-referencing roles more
312versatile:
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000313
Georg Brandl0c2430b2009-01-26 21:29:38 +0000314* You may supply an explicit title and reference target, like in reST direct
315 hyperlinks: ``:role:`title <target>``` will refer to *target*, but the link
316 text will be *title*.
317
318* If you prefix the content with ``!``, no reference/hyperlink will be created.
319
320* For the Python object roles, if you prefix the content with ``~``, the link
321 text will only be the last component of the target. For example,
322 ``:meth:`~Queue.Queue.get``` will refer to ``Queue.Queue.get`` but only
323 display ``get`` as the link text.
324
325 In HTML output, the link's ``title`` attribute (that is e.g. shown as a
326 tool-tip on mouse-hover) will always be the full target name.
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000327
Georg Brandl8ec7f652007-08-15 14:28:01 +0000328The following roles refer to objects in modules and are possibly hyperlinked if
329a matching identifier is found:
330
331.. describe:: mod
332
333 The name of a module; a dotted name may be used. This should also be used for
334 package names.
335
336.. describe:: func
337
338 The name of a Python function; dotted names may be used. The role text
Georg Brandlc7bef372008-04-19 17:00:14 +0000339 should not include trailing parentheses to enhance readability. The
340 parentheses are stripped when searching for identifiers.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000341
342.. describe:: data
343
Georg Brandl40e84152009-01-22 18:29:28 +0000344 The name of a module-level variable or constant.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000345
346.. describe:: const
347
348 The name of a "defined" constant. This may be a C-language ``#define``
349 or a Python variable that is not intended to be changed.
350
351.. describe:: class
352
353 A class name; a dotted name may be used.
354
355.. describe:: meth
356
357 The name of a method of an object. The role text should include the type
Georg Brandlc7bef372008-04-19 17:00:14 +0000358 name and the method name. A dotted name may be used.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000359
360.. describe:: attr
361
362 The name of a data attribute of an object.
363
364.. describe:: exc
365
366 The name of an exception. A dotted name may be used.
367
368The name enclosed in this markup can include a module name and/or a class name.
369For example, ``:func:`filter``` could refer to a function named ``filter`` in
370the current module, or the built-in function of that name. In contrast,
371``:func:`foo.filter``` clearly refers to the ``filter`` function in the ``foo``
372module.
373
Georg Brandl7f758c42007-08-15 18:41:25 +0000374Normally, names in these roles are searched first without any further
375qualification, then with the current module name prepended, then with the
376current module and class name (if any) prepended. If you prefix the name with a
377dot, this order is reversed. For example, in the documentation of the
378:mod:`codecs` module, ``:func:`open``` always refers to the built-in function,
379while ``:func:`.open``` refers to :func:`codecs.open`.
380
Georg Brandl8ec7f652007-08-15 14:28:01 +0000381A similar heuristic is used to determine whether the name is an attribute of
382the currently documented class.
383
384The following roles create cross-references to C-language constructs if they
385are defined in the API documentation:
386
387.. describe:: cdata
388
389 The name of a C-language variable.
390
391.. describe:: cfunc
392
393 The name of a C-language function. Should include trailing parentheses.
394
395.. describe:: cmacro
396
397 The name of a "simple" C macro, as defined above.
398
399.. describe:: ctype
400
401 The name of a C-language type.
402
403
404The following role does possibly create a cross-reference, but does not refer
405to objects:
406
407.. describe:: token
408
409 The name of a grammar token (used in the reference manual to create links
410 between production displays).
411
Georg Brandl437e6a32007-08-17 06:27:11 +0000412
413The following role creates a cross-reference to the term in the glossary:
414
415.. describe:: term
416
417 Reference to a term in the glossary. The glossary is created using the
418 ``glossary`` directive containing a definition list with terms and
419 definitions. It does not have to be in the same file as the ``term``
420 markup, in fact, by default the Python docs have one global glossary
421 in the ``glossary.rst`` file.
422
423 If you use a term that's not explained in a glossary, you'll get a warning
424 during build.
425
Georg Brandl8ec7f652007-08-15 14:28:01 +0000426---------
427
428The following roles don't do anything special except formatting the text
429in a different style:
430
431.. describe:: command
432
433 The name of an OS-level command, such as ``rm``.
434
435.. describe:: dfn
436
437 Mark the defining instance of a term in the text. (No index entries are
438 generated.)
439
440.. describe:: envvar
441
442 An environment variable. Index entries are generated.
443
444.. describe:: file
445
446 The name of a file or directory. Within the contents, you can use curly
447 braces to indicate a "variable" part, for example::
448
449 ... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
450
451 In the built documentation, the ``x`` will be displayed differently to
452 indicate that it is to be replaced by the Python minor version.
453
454.. describe:: guilabel
455
456 Labels presented as part of an interactive user interface should be marked
457 using ``guilabel``. This includes labels from text-based interfaces such as
458 those created using :mod:`curses` or other text-based libraries. Any label
459 used in the interface should be marked with this role, including button
460 labels, window titles, field names, menu and menu selection names, and even
461 values in selection lists.
462
463.. describe:: kbd
464
465 Mark a sequence of keystrokes. What form the key sequence takes may depend
466 on platform- or application-specific conventions. When there are no relevant
467 conventions, the names of modifier keys should be spelled out, to improve
468 accessibility for new users and non-native speakers. For example, an
469 *xemacs* key sequence may be marked like ``:kbd:`C-x C-f```, but without
470 reference to a specific application or platform, the same sequence should be
471 marked as ``:kbd:`Control-x Control-f```.
472
473.. describe:: keyword
474
Georg Brandlb19be572007-12-29 10:57:00 +0000475 The name of a keyword in Python.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000476
477.. describe:: mailheader
478
479 The name of an RFC 822-style mail header. This markup does not imply that
480 the header is being used in an email message, but can be used to refer to any
481 header of the same "style." This is also used for headers defined by the
482 various MIME specifications. The header name should be entered in the same
483 way it would normally be found in practice, with the camel-casing conventions
484 being preferred where there is more than one common usage. For example:
485 ``:mailheader:`Content-Type```.
486
487.. describe:: makevar
488
489 The name of a :command:`make` variable.
490
491.. describe:: manpage
492
493 A reference to a Unix manual page including the section,
494 e.g. ``:manpage:`ls(1)```.
495
496.. describe:: menuselection
497
498 Menu selections should be marked using the ``menuselection`` role. This is
499 used to mark a complete sequence of menu selections, including selecting
500 submenus and choosing a specific operation, or any subsequence of such a
501 sequence. The names of individual selections should be separated by
502 ``-->``.
503
504 For example, to mark the selection "Start > Programs", use this markup::
505
506 :menuselection:`Start --> Programs`
507
508 When including a selection that includes some trailing indicator, such as the
509 ellipsis some operating systems use to indicate that the command opens a
510 dialog, the indicator should be omitted from the selection name.
511
512.. describe:: mimetype
513
514 The name of a MIME type, or a component of a MIME type (the major or minor
515 portion, taken alone).
516
517.. describe:: newsgroup
518
519 The name of a Usenet newsgroup.
520
521.. describe:: option
522
Georg Brandlb917af82010-08-01 21:33:42 +0000523 A command-line option of Python. The leading hyphen(s) must be included.
524 If a matching ``cmdoption`` directive exists, it is linked to. For options
525 of other programs or scripts, use simple ````code```` markup.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000526
527.. describe:: program
528
529 The name of an executable program. This may differ from the file name for
530 the executable for some platforms. In particular, the ``.exe`` (or other)
531 extension should be omitted for Windows programs.
532
533.. describe:: regexp
534
535 A regular expression. Quotes should not be included.
536
537.. describe:: samp
538
539 A piece of literal text, such as code. Within the contents, you can use
540 curly braces to indicate a "variable" part, as in ``:file:``.
541
542 If you don't need the "variable part" indication, use the standard
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000543 ````code```` instead.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000544
Georg Brandl8ec7f652007-08-15 14:28:01 +0000545
546The following roles generate external links:
547
548.. describe:: pep
549
550 A reference to a Python Enhancement Proposal. This generates appropriate
551 index entries. The text "PEP *number*\ " is generated; in the HTML output,
552 this text is a hyperlink to an online copy of the specified PEP.
553
554.. describe:: rfc
555
556 A reference to an Internet Request for Comments. This generates appropriate
557 index entries. The text "RFC *number*\ " is generated; in the HTML output,
558 this text is a hyperlink to an online copy of the specified RFC.
559
560
561Note that there are no special roles for including hyperlinks as you can use
562the standard reST markup for that purpose.
563
564
565.. _doc-ref-role:
566
567Cross-linking markup
568--------------------
569
570To support cross-referencing to arbitrary sections in the documentation, the
571standard reST labels are "abused" a bit: Every label must precede a section
572title; and every label name must be unique throughout the entire documentation
573source.
574
575You can then reference to these sections using the ``:ref:`label-name``` role.
576
577Example::
578
579 .. _my-reference-label:
580
581 Section to cross-reference
582 --------------------------
583
584 This is the text of the section.
585
586 It refers to the section itself, see :ref:`my-reference-label`.
587
588The ``:ref:`` invocation is replaced with the section title.
589
590
591Paragraph-level markup
592----------------------
593
594These directives create short paragraphs and can be used inside information
595units as well as normal text:
596
597.. describe:: note
598
599 An especially important bit of information about an API that a user should be
600 aware of when using whatever bit of API the note pertains to. The content of
601 the directive should be written in complete sentences and include all
602 appropriate punctuation.
603
604 Example::
605
606 .. note::
607
608 This function is not suitable for sending spam e-mails.
609
610.. describe:: warning
611
Georg Brandl16a57f62009-04-27 15:29:09 +0000612 An important bit of information about an API that a user should be aware of
613 when using whatever bit of API the warning pertains to. The content of the
614 directive should be written in complete sentences and include all appropriate
Benjamin Peterson6fedc522009-09-17 03:27:33 +0000615 punctuation. In the interest of not scaring users away from pages filled
616 with warnings, this directive should only be chosen over ``note`` for
617 information regarding the possibility of crashes, data loss, or security
618 implications.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000619
620.. describe:: versionadded
621
622 This directive documents the version of Python which added the described
623 feature to the library or C API. When this applies to an entire module, it
624 should be placed at the top of the module section before any prose.
625
626 The first argument must be given and is the version in question; you can add
627 a second argument consisting of a *brief* explanation of the change.
628
629 Example::
630
631 .. versionadded:: 2.5
Georg Brandle92818f2009-01-03 20:47:01 +0000632 The *spam* parameter.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000633
634 Note that there must be no blank line between the directive head and the
635 explanation; this is to make these blocks visually continuous in the markup.
636
637.. describe:: versionchanged
638
639 Similar to ``versionadded``, but describes when and what changed in the named
640 feature in some way (new parameters, changed side effects, etc.).
641
642--------------
643
Georg Brandld0329122009-10-22 11:28:06 +0000644.. describe:: impl-detail
645
646 This directive is used to mark CPython-specific information. Use either with
647 a block content or a single sentence as an argument, i.e. either ::
648
649 .. impl-detail::
650
651 This describes some implementation detail.
652
653 More explanation.
654
655 or ::
656
657 .. impl-detail:: This shortly mentions an implementation detail.
658
659 "\ **CPython implementation detail:**\ " is automatically prepended to the
660 content.
661
Georg Brandl8ec7f652007-08-15 14:28:01 +0000662.. describe:: seealso
663
664 Many sections include a list of references to module documentation or
665 external documents. These lists are created using the ``seealso`` directive.
666
667 The ``seealso`` directive is typically placed in a section just before any
668 sub-sections. For the HTML output, it is shown boxed off from the main flow
669 of the text.
670
671 The content of the ``seealso`` directive should be a reST definition list.
672 Example::
673
674 .. seealso::
675
676 Module :mod:`zipfile`
677 Documentation of the :mod:`zipfile` standard module.
678
679 `GNU tar manual, Basic Tar Format <http://link>`_
680 Documentation for tar archive files, including GNU tar extensions.
681
682.. describe:: rubric
683
684 This directive creates a paragraph heading that is not used to create a
685 table of contents node. It is currently used for the "Footnotes" caption.
686
687.. describe:: centered
688
689 This directive creates a centered boldfaced paragraph. Use it as follows::
690
691 .. centered::
692
693 Paragraph contents.
694
695
696Table-of-contents markup
697------------------------
698
699Since reST does not have facilities to interconnect several documents, or split
700documents into multiple output files, Sphinx uses a custom directive to add
701relations between the single files the documentation is made of, as well as
702tables of contents. The ``toctree`` directive is the central element.
703
704.. describe:: toctree
705
706 This directive inserts a "TOC tree" at the current location, using the
707 individual TOCs (including "sub-TOC trees") of the files given in the
708 directive body. A numeric ``maxdepth`` option may be given to indicate the
709 depth of the tree; by default, all levels are included.
710
711 Consider this example (taken from the library reference index)::
712
713 .. toctree::
714 :maxdepth: 2
715
Georg Brandlfd3eff62010-06-12 09:45:01 +0000716 intro
717 strings
718 datatypes
719 numeric
Georg Brandl8ec7f652007-08-15 14:28:01 +0000720 (many more files listed here)
721
722 This accomplishes two things:
723
724 * Tables of contents from all those files are inserted, with a maximum depth
725 of two, that means one nested heading. ``toctree`` directives in those
726 files are also taken into account.
Georg Brandlfd3eff62010-06-12 09:45:01 +0000727 * Sphinx knows that the relative order of the files ``intro``,
728 ``strings`` and so forth, and it knows that they are children of the
Georg Brandl8ec7f652007-08-15 14:28:01 +0000729 shown file, the library index. From this information it generates "next
730 chapter", "previous chapter" and "parent chapter" links.
731
732 In the end, all files included in the build process must occur in one
733 ``toctree`` directive; Sphinx will emit a warning if it finds a file that is
734 not included, because that means that this file will not be reachable through
735 standard navigation.
736
737 The special file ``contents.rst`` at the root of the source directory is the
738 "root" of the TOC tree hierarchy; from it the "Contents" page is generated.
739
740
741Index-generating markup
742-----------------------
743
744Sphinx automatically creates index entries from all information units (like
745functions, classes or attributes) like discussed before.
746
747However, there is also an explicit directive available, to make the index more
748comprehensive and enable index entries in documents where information is not
749mainly contained in information units, such as the language reference.
750
751The directive is ``index`` and contains one or more index entries. Each entry
752consists of a type and a value, separated by a colon.
753
754For example::
755
756 .. index::
Georg Brandl3acd6d52007-08-31 08:47:51 +0000757 single: execution; context
Georg Brandl8ec7f652007-08-15 14:28:01 +0000758 module: __main__
759 module: sys
760 triple: module; search; path
761
762This directive contains five entries, which will be converted to entries in the
763generated index which link to the exact location of the index statement (or, in
764case of offline media, the corresponding page number).
765
766The possible entry types are:
767
768single
769 Creates a single index entry. Can be made a subentry by separating the
Georg Brandl3acd6d52007-08-31 08:47:51 +0000770 subentry text with a semicolon (this notation is also used below to describe
771 what entries are created).
Georg Brandl8ec7f652007-08-15 14:28:01 +0000772pair
773 ``pair: loop; statement`` is a shortcut that creates two index entries,
Georg Brandl3acd6d52007-08-31 08:47:51 +0000774 namely ``loop; statement`` and ``statement; loop``.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000775triple
776 Likewise, ``triple: module; search; path`` is a shortcut that creates three
Georg Brandl3acd6d52007-08-31 08:47:51 +0000777 index entries, which are ``module; search path``, ``search; path, module`` and
778 ``path; module search``.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000779module, keyword, operator, object, exception, statement, builtin
780 These all create two index entries. For example, ``module: hashlib`` creates
Georg Brandl3acd6d52007-08-31 08:47:51 +0000781 the entries ``module; hashlib`` and ``hashlib; module``.
Georg Brandl9856e052007-08-31 06:59:27 +0000782
783For index directives containing only "single" entries, there is a shorthand
784notation::
785
786 .. index:: BNF, grammar, syntax, notation
787
788This creates four index entries.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000789
790
791Grammar production displays
792---------------------------
793
794Special markup is available for displaying the productions of a formal grammar.
795The markup is simple and does not attempt to model all aspects of BNF (or any
796derived forms), but provides enough to allow context-free grammars to be
797displayed in a way that causes uses of a symbol to be rendered as hyperlinks to
798the definition of the symbol. There is this directive:
799
800.. describe:: productionlist
801
802 This directive is used to enclose a group of productions. Each production is
803 given on a single line and consists of a name, separated by a colon from the
804 following definition. If the definition spans multiple lines, each
805 continuation line must begin with a colon placed at the same column as in the
806 first line.
807
808 Blank lines are not allowed within ``productionlist`` directive arguments.
809
810 The definition can contain token names which are marked as interpreted text
Georg Brandle92818f2009-01-03 20:47:01 +0000811 (e.g. ``unaryneg ::= "-" `integer```) -- this generates cross-references
Georg Brandl8ec7f652007-08-15 14:28:01 +0000812 to the productions of these tokens.
813
814 Note that no further reST parsing is done in the production, so that you
815 don't have to escape ``*`` or ``|`` characters.
816
817
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000818.. XXX describe optional first parameter
Georg Brandl8ec7f652007-08-15 14:28:01 +0000819
820The following is an example taken from the Python Reference Manual::
821
822 .. productionlist::
823 try_stmt: try1_stmt | try2_stmt
824 try1_stmt: "try" ":" `suite`
825 : ("except" [`expression` ["," `target`]] ":" `suite`)+
826 : ["else" ":" `suite`]
827 : ["finally" ":" `suite`]
828 try2_stmt: "try" ":" `suite`
829 : "finally" ":" `suite`
830
831
832Substitutions
833-------------
834
835The documentation system provides three substitutions that are defined by default.
Georg Brandl0d2fa3a2008-11-08 12:52:25 +0000836They are set in the build configuration file :file:`conf.py`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000837
838.. describe:: |release|
839
840 Replaced by the Python release the documentation refers to. This is the full
841 version string including alpha/beta/release candidate tags, e.g. ``2.5.2b3``.
842
843.. describe:: |version|
844
845 Replaced by the Python version the documentation refers to. This consists
846 only of the major and minor version parts, e.g. ``2.5``, even for version
847 2.5.1.
848
849.. describe:: |today|
850
851 Replaced by either today's date, or the date set in the build configuration
852 file. Normally has the format ``April 14, 2007``.
853
854
855.. rubric:: Footnotes
856
857.. [1] There is a standard ``.. include`` directive, but it raises errors if the
858 file is not found. This one only emits a warning.