Formatting

For general guidance see the reStructuredText Primer and other online resources.

Details are provided below for MyriadRF conventions.

Sections

Every Sphinx document has multiple sections or heading levels. Section headers are created by underlining (and optionally overlining) the section title with a punctuation character, at least as long as the text.

Levels are not assigned to specific characters and instead the structure is determined from their succession. However, for the sake of consistency across projects they should be used in this order:

  • # for title – with overline, for parts

  • * for subtitle – with overline, for chapters

  • =, for sections

  • -, for subsections

  • ^, for subsubsections

  • ", for paragraphs

This follows the Python community best practice.

Levels give structure to the document, which is used in navigation and in the display in all output formats.

Regular documents start with a title heading underlined by #. Subtitles are optional. Headings are then marked with = and - etc.

Images

For consistency images should always be included using the figure directive, rather than the simpler image directive.

Images should be stored in the docs/images directory of the relevant project, and not be distributed across multiple directories or referenced in other projects. This ensures that they are easy to find and maintain.

Images are then referenced using an absolute path, e.g. /images/myimage.png.

Tables

There are four different ways to create tables in reStructuredText, but for consistency and ease of maintenance, the list-table directive should be used. The only exception to this is where a table is generated from a CSV file, in which case the csv-table directive should be used.

Warning

While grid and simple tables may be quicker to write, they are more difficult to maintain and update, and are not as visually clear in the source files. Therefore they should not be used!

Some earlier projects may contain examples of the other table formats, but these should not be used for new documentation. Where possible, existing tables in older documentation should be converted to the list-table format when they are updated for other reasons.

Numbering

The current policy is that:

  1. Sections are not numbered;

  2. Figures and tables are numbered, but not prefixed with the section number;

  3. Numbering is unique to the document, but not unique across the project or globally.

A Sphinx project may contain multiple documents, such as an Introduction, User Guide and Hardware Reference. In such cases numbering will be restarted for each document, so as to make it easier to maintain and update them independently. However, within each document, numbering will be unique, so that there are no duplicate figure or table numbers.

Subscript and Superscript

Subscript and superscript characters can be generated using the :sub: and :sup: roles. For example:

Upper limit 10\ :sup:`6`. See note\ :sub:`2`.

Gives:

Upper limit 106. See note2.

Note

Interpreted text needs to be surrounded by whitespace or punctuation, which means that if we don’t want a gap, e.g. between 10 and 6, or between note and 2, we need to escape the whitespace with a backslash.

Non-ASCII Characters

Non-ASCII characters can be inserted by using substitutions. For example, the right arrow (→) is inserted by entering |rarr|.

Substitutions are defined in two places:

  1. At the project level

Substitutions for use anywhere within the current Sphinx project only are configured via the file docs/substitutions.conf. For example, to be able to insert a cat emoji using |cat|, we would add the following line:

.. |cat| unicode:: U+1F408

Where possible a standard name should be used, such as the HTML entity name or Unicode character name.

  1. Globally for all Sphinx projects

Where a substitution is likely to be used in multiple Sphinx projects, it can be defined via the assets/sphinx/substitutions.conf file in the static-assets repository. This uses the same format as the project-level substitutions.conf file and as with this, it is appended to every document.

Note

In general it is preferable to update the global substitutions, so as to avoid duplication and inconsistencies between projects.

Equations (LaTeX)

For inline math use this format:

Here is an equation: :math:`a^2 + b^2 = c^2`.

Which results in:

Here is an equation: \(a^2 + b^2 = c^2\).

Alternatively, for a block with multiple equations, which should be separated by a line:

.. math::

   (a + b)^2 = a^2 + 2ab + b^2

   (a - b)^2 = a^2 - 2ab + b^2

Which gives:

\[ \begin{align}\begin{aligned}(a + b)^2 = a^2 + 2ab + b^2\\(a - b)^2 = a^2 - 2ab + b^2\end{aligned}\end{align} \]

For further details see the Sphinx math directive.