^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. _sphinxdoc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) Introduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) The Linux kernel uses `Sphinx`_ to generate pretty documentation from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) `reStructuredText`_ files under ``Documentation``. To build the documentation in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) HTML or PDF formats, use ``make htmldocs`` or ``make pdfdocs``. The generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) documentation is placed in ``Documentation/output``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) .. _Sphinx: http://www.sphinx-doc.org/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) .. _reStructuredText: http://docutils.sourceforge.net/rst.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) The reStructuredText files may contain directives to include structured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) documentation comments, or kernel-doc comments, from source files. Usually these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) are used to describe the functions and types and design of the code. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) kernel-doc comments have some special structure and formatting, but beyond that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) they are also treated as reStructuredText.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) Finally, there are thousands of plain text documentation files scattered around
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ``Documentation``. Some of these will likely be converted to reStructuredText
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) over time, but the bulk of them will remain in plain text.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .. _sphinx_install:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) Sphinx Install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) The ReST markups currently used by the Documentation/ files are meant to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) built with ``Sphinx`` version 1.3 or higher.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) There's a script that checks for the Sphinx requirements. Please see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) :ref:`sphinx-pre-install` for further details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) Most distributions are shipped with Sphinx, but its toolchain is fragile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) and it is not uncommon that upgrading it or some other Python packages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) on your machine would cause the documentation build to break.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) A way to avoid that is to use a different version than the one shipped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) with your distributions. In order to do so, it is recommended to install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) Sphinx inside a virtual environment, using ``virtualenv-3``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) or ``virtualenv``, depending on how your distribution packaged Python 3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #) Sphinx versions below 1.5 don't work properly with Python's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) docutils version 0.13.1 or higher. So, if you're willing to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) those versions, you should run ``pip install 'docutils==0.12'``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #) It is recommended to use the RTD theme for html output. Depending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) on the Sphinx version, it should be installed in separate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) with ``pip install sphinx_rtd_theme``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #) Some ReST pages contain math expressions. Due to the way Sphinx work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) those expressions are written using LaTeX notation. It needs texlive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) installed with amdfonts and amsmath in order to evaluate them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) In summary, if you want to install Sphinx version 1.7.9, you should do::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) $ virtualenv sphinx_1.7.9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) $ . sphinx_1.7.9/bin/activate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) (sphinx_1.7.9) $ pip install -r Documentation/sphinx/requirements.txt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) After running ``. sphinx_1.7.9/bin/activate``, the prompt will change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) in order to indicate that you're using the new environment. If you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) open a new shell, you need to rerun this command to enter again at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) the virtual environment before building the documentation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) Image output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) The kernel documentation build system contains an extension that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) handles images on both GraphViz and SVG formats (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) :ref:`sphinx_kfigure`).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) For it to work, you need to install both GraphViz and ImageMagick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) packages. If those packages are not installed, the build system will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) still build the documentation, but won't include any images at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) PDF and LaTeX builds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) --------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) Such builds are currently supported only with Sphinx versions 1.4 and higher.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) For PDF and LaTeX output, you'll also need ``XeLaTeX`` version 3.14159265.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) Depending on the distribution, you may also need to install a series of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ``texlive`` packages that provide the minimal set of functionalities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) required for ``XeLaTeX`` to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .. _sphinx-pre-install:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) Checking for Sphinx dependencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) --------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) There's a script that automatically check for Sphinx dependencies. If it can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) recognize your distribution, it will also give a hint about the install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) command line options for your distro::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) $ ./scripts/sphinx-pre-install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) Checking if the needed tools for Fedora release 26 (Twenty Six) are available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) Warning: better to also install "texlive-luatex85".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) You should run:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) sudo dnf install -y texlive-luatex85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /usr/bin/virtualenv sphinx_1.7.9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) . sphinx_1.7.9/bin/activate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) pip install -r Documentation/sphinx/requirements.txt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) Can't build as 1 mandatory dependency is missing at ./scripts/sphinx-pre-install line 468.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) By default, it checks all the requirements for both html and PDF, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) the requirements for images, math expressions and LaTeX build, and assumes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) that a virtual Python environment will be used. The ones needed for html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) builds are assumed to be mandatory; the others to be optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) It supports two optional parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ``--no-pdf``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) Disable checks for PDF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ``--no-virtualenv``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) Use OS packaging for Sphinx instead of Python virtual environment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) Sphinx Build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) The usual way to generate the documentation is to run ``make htmldocs`` or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ``make pdfdocs``. There are also other formats available, see the documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) section of ``make help``. The generated documentation is placed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) format-specific subdirectories under ``Documentation/output``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) To generate documentation, Sphinx (``sphinx-build``) must obviously be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) installed. For prettier HTML output, the Read the Docs Sphinx theme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) (``sphinx_rtd_theme``) is used if available. For PDF output you'll also need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ``XeLaTeX`` and ``convert(1)`` from ImageMagick (https://www.imagemagick.org).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) All of these are widely available and packaged in distributions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) To pass extra options to Sphinx, you can use the ``SPHINXOPTS`` make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) variable. For example, use ``make SPHINXOPTS=-v htmldocs`` to get more verbose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) To remove the generated documentation, run ``make cleandocs``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) Writing Documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) =====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) Adding new documentation can be as simple as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 1. Add a new ``.rst`` file somewhere under ``Documentation``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 2. Refer to it from the Sphinx main `TOC tree`_ in ``Documentation/index.rst``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .. _TOC tree: http://www.sphinx-doc.org/en/stable/markup/toctree.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) This is usually good enough for simple documentation (like the one you're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) reading right now), but for larger documents it may be advisable to create a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) subdirectory (or use an existing one). For example, the graphics subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) documentation is under ``Documentation/gpu``, split to several ``.rst`` files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) and has a separate ``index.rst`` (with a ``toctree`` of its own) referenced from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) the main index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) See the documentation for `Sphinx`_ and `reStructuredText`_ on what you can do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) with them. In particular, the Sphinx `reStructuredText Primer`_ is a good place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) to get started with reStructuredText. There are also some `Sphinx specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) markup constructs`_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .. _reStructuredText Primer: http://www.sphinx-doc.org/en/stable/rest.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .. _Sphinx specific markup constructs: http://www.sphinx-doc.org/en/stable/markup/index.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) Specific guidelines for the kernel documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) Here are some specific guidelines for the kernel documentation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Please don't go overboard with reStructuredText markup. Keep it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) simple. For the most part the documentation should be plain text with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) just enough consistency in formatting that it can be converted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) other formats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * Please keep the formatting changes minimal when converting existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) documentation to reStructuredText.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Also update the content, not just the formatting, when converting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) documentation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Please stick to this order of heading adornments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 1. ``=`` with overline for document title::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) Document title
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 2. ``=`` for chapters::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) Chapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 3. ``-`` for sections::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 4. ``~`` for subsections::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) Subsection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) Although RST doesn't mandate a specific order ("Rather than imposing a fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) number and order of section title adornment styles, the order enforced will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) the order as encountered."), having the higher levels the same overall makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) it easier to follow the documents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * For inserting fixed width text blocks (for code examples, use case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) examples, etc.), use ``::`` for anything that doesn't really benefit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) from syntax highlighting, especially short snippets. Use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ``.. code-block:: <language>`` for longer code blocks that benefit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) from highlighting. For a short snippet of code embedded in the text, use \`\`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) the C domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) The **Sphinx C Domain** (name c) is suited for documentation of C API. E.g. a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) function prototype:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .. code-block:: rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .. c:function:: int ioctl( int fd, int request )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) The C domain of the kernel-doc has some additional features. E.g. you can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) *rename* the reference name of a function with a common name like ``open`` or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ``ioctl``:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .. code-block:: rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .. c:function:: int ioctl( int fd, int request )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) :name: VIDIOC_LOG_STATUS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) The func-name (e.g. ioctl) remains in the output but the ref-name changed from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ``ioctl`` to ``VIDIOC_LOG_STATUS``. The index entry for this function is also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) changed to ``VIDIOC_LOG_STATUS``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) Please note that there is no need to use ``c:func:`` to generate cross
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) references to function documentation. Due to some Sphinx extension magic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) the documentation build system will automatically turn a reference to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ``function()`` into a cross reference if an index entry for the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) function name exists. If you see ``c:func:`` use in a kernel document,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) please feel free to remove it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) list tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) We recommend the use of *list table* formats. The *list table* formats are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) double-stage lists. Compared to the ASCII-art they might not be as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) comfortable for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) readers of the text files. Their advantage is that they are easy to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) create or modify and that the diff of a modification is much more meaningful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) because it is limited to the modified content.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) The ``flat-table`` is a double-stage list similar to the ``list-table`` with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) some additional features:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * column-span: with the role ``cspan`` a cell can be extended through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) additional columns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * row-span: with the role ``rspan`` a cell can be extended through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) additional rows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * auto span rightmost cell of a table row over the missing cells on the right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) side of that table-row. With Option ``:fill-cells:`` this behavior can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) changed from *auto span* to *auto fill*, which automatically inserts (empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) cells instead of spanning the last cell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) options:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * ``:header-rows:`` [int] count of header rows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * ``:stub-columns:`` [int] count of stub columns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * ``:widths:`` [[int] [int] ... ] widths of columns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * ``:fill-cells:`` instead of auto-spanning missing cells, insert missing cells
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) roles:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * ``:cspan:`` [int] additional columns (*morecols*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * ``:rspan:`` [int] additional rows (*morerows*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) The example below shows how to use this markup. The first level of the staged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) list is the *table-row*. In the *table-row* there is only one markup allowed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) the list of the cells in this *table-row*. Exceptions are *comments* ( ``..`` )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) and *targets* (e.g. a ref to ``:ref:`last row <last row>``` / :ref:`last row
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) <last row>`).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .. code-block:: rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .. flat-table:: table title
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) :widths: 2 1 1 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * - head col 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) - head col 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) - head col 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) - head col 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * - column 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) - field 1.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) - field 1.2 with autospan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * - column 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) - field 2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) - :rspan:`1` :cspan:`1` field 2.2 - 3.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * .. _`last row`:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) - column 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) Rendered as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .. flat-table:: table title
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) :widths: 2 1 1 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * - head col 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) - head col 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) - head col 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) - head col 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * - column 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) - field 1.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) - field 1.2 with autospan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * - column 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) - field 2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) - :rspan:`1` :cspan:`1` field 2.2 - 3.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * .. _`last row`:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) - column 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) Cross-referencing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) -----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) Cross-referencing from one documentation page to another can be done by passing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) the path to the file starting from the Documentation folder.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) For example, to cross-reference to this page (the .rst extension is optional)::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) See Documentation/doc-guide/sphinx.rst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) If you want to use a relative path, you need to use Sphinx's ``doc`` directive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) For example, referencing this page from the same directory would be done as::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) See :doc:`sphinx`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) For information on cross-referencing to kernel-doc functions or types, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) Documentation/doc-guide/kernel-doc.rst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) .. _sphinx_kfigure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) Figures & Images
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) If you want to add an image, you should use the ``kernel-figure`` and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ``kernel-image`` directives. E.g. to insert a figure with a scalable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) image format use SVG (:ref:`svg_image_example`)::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .. kernel-figure:: svg_image.svg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) :alt: simple SVG image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) SVG image example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .. _svg_image_example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) .. kernel-figure:: svg_image.svg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) :alt: simple SVG image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) SVG image example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) The kernel figure (and image) directive support **DOT** formated files, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * DOT: http://graphviz.org/pdf/dotguide.pdf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * Graphviz: http://www.graphviz.org/content/dot-language
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) A simple example (:ref:`hello_dot_file`)::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .. kernel-figure:: hello.dot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) :alt: hello world
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) DOT's hello world example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .. _hello_dot_file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .. kernel-figure:: hello.dot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) :alt: hello world
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) DOT's hello world example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) Embed *render* markups (or languages) like Graphviz's **DOT** is provided by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ``kernel-render`` directives.::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .. kernel-render:: DOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) :alt: foobar digraph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) :caption: Embedded **DOT** (Graphviz) code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) digraph foo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) "bar" -> "baz";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) How this will be rendered depends on the installed tools. If Graphviz is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) installed, you will see an vector image. If not the raw markup is inserted as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) *literal-block* (:ref:`hello_dot_render`).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .. _hello_dot_render:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .. kernel-render:: DOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) :alt: foobar digraph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) :caption: Embedded **DOT** (Graphviz) code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) digraph foo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) "bar" -> "baz";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) The *render* directive has all the options known from the *figure* directive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) plus option ``caption``. If ``caption`` has a value, a *figure* node is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) inserted. If not, a *image* node is inserted. A ``caption`` is also needed, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) you want to refer it (:ref:`hello_svg_render`).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) Embedded **SVG**::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .. kernel-render:: SVG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) :caption: Embedded **SVG** markup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) :alt: so-nw-arrow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) <?xml version="1.0" encoding="UTF-8"?>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) <svg xmlns="http://www.w3.org/2000/svg" version="1.1" ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) </svg>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) .. _hello_svg_render:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) .. kernel-render:: SVG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) :caption: Embedded **SVG** markup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) :alt: so-nw-arrow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) <?xml version="1.0" encoding="UTF-8"?>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) <svg xmlns="http://www.w3.org/2000/svg"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) version="1.1" baseProfile="full" width="70px" height="40px" viewBox="0 0 700 400">
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) <line x1="180" y1="370" x2="500" y2="50" stroke="black" stroke-width="15px"/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) <polygon points="585 0 525 25 585 50" transform="rotate(135 525 25)"/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) </svg>