GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.sphinx-doc.org — Getting started — Sphinx documentation Getting started¶Sphinx is a documentation generator or a tool that translates a set of plain text source files into various output formats, automatically producing cross-references, indices, etc. That is, if you have a directory containing a bunch of reStructuredText or Markdown documents, Sphinx can generate a series of HTML files, a PDF file (via LaTeX), man pages and much more. Sphinx focuses on documentation, in particular handwritten documentation, however, Sphinx can also be used to generate blogs, homepages and even books. Much of Sphinx’s power comes from the richness of its default plain-text markup format, reStructuredText, along with its significant extensibility capabilities. The goal of this document is to give you a quick taste of what Sphinx is and how you might use it. When you’re done here, you can check out the installation guide followed by the intro to the default markup format used by Sphinx, reStructuredText. For a great “introduction” to writing docs in general – the whys and hows, see also Write the docs, written by Eric Holscher. Setting up the documentation sources¶The root directory of a Sphinx collection of plain-text document sources is
called the source directory. This directory also contains the Sphinx
configuration file Sphinx comes with a script called sphinx-quickstart that sets up a
source directory and creates a default $ sphinx-quickstart
Defining document structure¶Let’s assume you’ve run sphinx-quickstart. It created a source
directory with reStructuredText directives
Arguments are given directly after the double colon following the directive’s name. Each directive decides whether it can have arguments, and how many. Options are given after the arguments, in form of a “field list”. The
Content follows the options or arguments after a blank line. Each directive decides whether to allow content, and what to do with it. A common gotcha with directives is that the first line of the content must be indented to the same level as the options are. The .. toctree:: :maxdepth: 2 You add documents listing them in the content of the directive: .. toctree:: :maxdepth: 2 usage/installation usage/quickstart ... This is exactly how the See also Read more about the toctree directive. You can now create the files you listed in the Adding content¶In Sphinx source files, you can use most features of standard
reStructuredText. There are also several features added by Sphinx.
For example, you can add cross-file references in a portable way (which works
for all output types) using the For an example, if you are viewing the HTML version, you can look at the source for this document – use the “Show Source” link in the sidebar. See also reStructuredText for a more in-depth introduction to reStructuredText, including markup added by Sphinx. Running the build¶Now that you have added some files and content, let’s make a first build of the docs. A build is started with the sphinx-build program: $ sphinx-build -M html sourcedir outputdir where sourcedir is the source directory, and outputdir is the
directory in which you want to place the built documentation.
The See also Refer to the sphinx-build man page for all options that sphinx-build supports. You can also build a live version of the documentation that you can preview in the browser. It will detect changes and reload the page any time you make edits. To do so, use sphinx-autobuild to run the following command: $ sphinx-autobuild source-dir output-dir However, sphinx-quickstart script creates a $ make html This will build HTML docs in the build directory you chose. Execute make without an argument to see which targets are available. How do I generate PDF documents?
Documenting objects¶One of Sphinx’s main objectives is easy documentation of objects (in a very general sense) in any domain. A domain is a collection of object types that belong together, complete with markup to create and reference descriptions of these objects. The most prominent domain is the Python domain. For example, to document
Python’s built-in function .. py:function:: enumerate(sequence[, start=0]) Return an iterator that yields tuples of an index and an item of the *sequence*. (And so on.) This is rendered like this:
The argument of the directive is the signature of the object you describe, the content is the documentation for it. Multiple signatures can be given, each in its own line. The Python domain also happens to be the default domain, so you don’t need to prefix the markup with the domain name. .. function:: enumerate(sequence[, start=0]) ... does the same job if you keep the default setting for the default domain. There are several more directives for documenting other types of Python
objects, for example The :py:func:`enumerate` function can be used for ... And here is the proof: A link to Again, the Each domain will have special rules for how the signatures can look like, and make the formatted output look pretty, or add specific features like links to parameter types, e.g. in the C/C++ domains. See also Domains for all the available domains and their directives/roles. Basic configuration¶Earlier we mentioned that the The config values that you probably want to change are already put into the
Keep in mind that the file uses Python syntax for strings, numbers, lists and so on. The file is saved in UTF-8 by default, as indicated by the encoding declaration in the first line. See also Configuration for documentation of all available config values. Autodoc¶When documenting Python code, it is common to put a lot of documentation in the source files, in documentation strings. Sphinx supports the inclusion of docstrings from your modules with an extension (an extension is a Python module that provides additional features for Sphinx projects) called autodoc. See also
Intersphinx¶Many Sphinx documents including the Python documentation are published on
the Internet. When you want to make links to such documents from your
documentation, you can do it with In order to use intersphinx, you need to activate it in For example, to link to intersphinx_mapping = {'python': ('https://docs.python.org/3', None)} And now, you can write a cross-reference like See also
More topics to be covered¶
Footnotes |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |