|
| 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 | +
|
| 77 | + # EPUB options |
| 78 | + epub_show_urls = 'footnote' |
| 79 | +
|
| 80 | +With this configuration value, and after running ``make epub`` again, you will |
| 81 | +notice that URLs appear now as footnotes, which avoids cluttering the text. |
| 82 | +Sweet! |
| 83 | + |
| 84 | +.. note:: |
| 85 | + |
| 86 | + Generating a PDF using Sphinx can be done running ``make latexpdf``, |
| 87 | + provided that the system has a working LaTeX installation, |
| 88 | + as explained in the documentation of :class:`sphinx.builders.latex.LaTeXBuilder`. |
| 89 | + Although this is perfectly feasible, such installations are often big, |
| 90 | + and in general LaTeX requires careful configuration in some cases, |
| 91 | + so PDF generation is out of scope for this tutorial. |
0 commit comments