Debian Codegraph @

doc/tutorial/first-steps.rst

raw
1 First steps to document your project using Sphinx
2 =================================================
3
4 Building your HTML documentation
5 --------------------------------
6
7 The ``index.rst`` file that ``sphinx-quickstart`` created has some content
8 already, and it gets rendered as the front page of your HTML documentation. It
9 is written in reStructuredText, a powerful markup language.
10
11 Modify the file as follows:
12
13 .. code-block:: rst
14 :caption: docs/source/index.rst
15
16 Welcome to Lumache's documentation!
17 ===================================
18
19 **Lumache** (/lu'make/) is a Python library for cooks and food lovers that
20 creates recipes mixing random ingredients. It pulls data from the `Open Food
21 Facts database <https://world.openfoodfacts.org/>`_ and offers a *simple* and
22 *intuitive* API.
23
24 .. note::
25
26 This project is under active development.
27
28 This showcases several features of the reStructuredText syntax, including:
29
30 - a **section header** using ``===`` for the underline,
31 - two examples of :ref:`rst-inline-markup`: ``**strong emphasis**`` (typically
32 bold) and ``*emphasis*`` (typically italics),
33 - an **inline external link**,
34 - and a ``note`` **admonition** (one of the available :ref:`directives
35 <rst-directives>`)
36
37 Now to render it with the new content, you can use the ``sphinx-build`` command
38 as before, or leverage the convenience script as follows:
39
40 .. code-block:: console
41
42 (.venv) $ cd docs
43 (.venv) $ make html
44
45 After running this command, you will see that ``index.html`` reflects the new
46 changes!
47
48 Building your documentation in other formats
49 --------------------------------------------
50
51 Sphinx supports a variety of formats apart from HTML, including PDF, EPUB,
52 :ref:`and more <builders>`. For example, to build your documentation
53 in EPUB format, run this command from the ``docs`` directory:
54
55 .. code-block:: console
56
57 (.venv) $ make epub
58
59 After that, you will see the files corresponding to the e-book under
60 ``docs/build/epub/``. You can either open ``Lumache.epub`` with an
61 EPUB-compatible e-book viewer, like `Calibre <https://calibre-ebook.com/>`_,
62 or preview ``index.xhtml`` on a web browser.
63
64 .. note::
65
66 To quickly display a complete list of possible output formats, plus some
67 extra useful commands, you can run :code:`make help`.
68
69 Each output format has some specific configuration options that you can tune,
70 :ref:`including EPUB <epub-options>`. For instance, the default value of
71 :confval:`epub_show_urls` is ``inline``, which means that, by default, URLs are
72 shown right after the corresponding link, in parentheses. You can change that
73 behavior by adding the following code at the end of your ``conf.py``:
74
75 .. code-block:: python
76 :caption: docs/source/conf.py
77
78 # EPUB options
79 epub_show_urls = 'footnote'
80
81 With this configuration value, and after running ``make epub`` again, you will
82 notice that URLs appear now as footnotes, which avoids cluttering the text.
83 Sweet! Read on to explore :doc:`other ways to customize
84 Sphinx </tutorial/more-sphinx-customization>`.
85
86 .. note::
87
88 Generating a PDF using Sphinx can be done running ``make latexpdf``,
89 provided that the system has a working LaTeX installation,
90 as explained in the documentation of :class:`sphinx.builders.latex.LaTeXBuilder`.
91 Although this is perfectly feasible, such installations are often big,
92 and in general LaTeX requires careful configuration in some cases,
93 so PDF generation is out of scope for this tutorial.