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