reST cheat sheet¶
See also
This document is by no means an exhaustive guide to Sphinx and reStructuredText (reST). Additional resources:
reStructuredText primer (a lot of stuff in this document is taken from here)
super useful page (or https://github.com/marczz/rest-sphinx-memo/blob/master/source/ReST.rst)
Our documentation is a collection of several Sphinx projects (ADF, AMS, Band, Tutorials,…). All the projects import global_conf.py
from the local conf.py
.
External links¶
Important
For cross-links between different SCM documentation projects, see Inter-project links.
This `Search engine <https://duckduckgo.com>`__
creates an external link like this: Search engine
This `<https://duckduckgo.com>`__
creates an external link like this: https://duckduckgo.com
Internal links¶
For internal links standard reST labels are used. The are two ways of doing this:
If you place a label directly before a section title, you can reference to it with
:ref:`label-name`
. For example... _label-name: Section to cross-reference -------------------------- This is the text of the section. It refers to the section itself, see :ref:`label-name`.
Labels that aren’t placed before a section title can still be referenced, but you must give the link an explicit title, using this syntax
.. _label-name: Some random text, see :ref:`link title <label-name>`.
Inter-project links¶
Option 1: intersphinx to refer to labels¶
If you use intersphinx then you can refer to labels in other docs, just as for Internal links.
See for example how this works in the Workflows conf.py:
# -*- coding: utf-8 -*-
from global_conf import *
project, htmlhelp_basename, latex_documents = set_project_specific_var("Workflows")
html_logo = None
extensions += ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", "sphinx_copybutton"]
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
add_module_names = False
autodoc_default_options = {"members": True, "private-members": True, "special-members": True}
autodoc_member_order = "bysource"
autodoc_typehints = "none"
intersphinx_mapping = {
"AMS": ("../AMS/", "../build/AMS/objects.inv"),
"MLPotential": ("../MLPotential/", "../build/MLPotential/objects.inv"),
"Tutorials": ("../Tutorials/", "../build/Tutorials/objects.inv"),
"params": ("../params/", "../build/params/objects.inv"),
}
intersphinx_disabled_reftypes = ["*"]
Note the extension sphinx.ext.intersphinx
and the intersphinx_mapping
dictionary, which specifies the AMS objects.inv file which contains all labels and
the corresponding targets. This makes it possible to refer the labels defined in the AMS docs
from inside the Workflows docs. For example, :external+AMS:ref:`chemtrayzer2`
.
For this to work, 'AMS'
needs to be specified before 'Workflows'
in the
targets
list in build_doc.sh. If this is not the case, (for example to
create a link from AMS to Workflows), you must follow Option 2: external
links with relative paths below.
Option 2: external links with relative paths¶
For links from one documentation project to another one (e.g. links from the AMS manual to the Tutorials or vice versa) use external links with relative paths. To make a link from page_A (in project_A) to page_B (in project_B) you should use the relative path from page_A to page_B.
For example, to make a link from this page to a page in the Tutorials:
Link to a page in the Tutorials: `AMS Tutorial <../Tutorials/AMS/ZN-PES-Scan_TST.html>`__
Do not use an absolute link starting with www.SCM.com/doc
for inter-project links.
Citations / References¶
For citations we use footnotes.
Example:
Cite a paper here [#ref1]_ and another one here [#ref2]_.
.. Then, at the bottom of the page:
.. [#ref1] \G. te Velde, F.M. Bickelhaupt, E.J. Baerends, C. Fonseca Guerra, S.J.A. van Gisbergen, J.G. Snijders, T. Ziegler, *Chemistry with ADF*, `Journal of Computational Chemistry 22, 931 (2001) <https://doi.org/10.1002/jcc.1056>`__
.. [#ref2] \E. J. Baerends and P. Ros, *Evaluation of the LCAO Hartree-Fock-Slater method: Applications to transition-metal complexes*, `International Journal of Quantum Chemistry 14, S12, 169 (1978) <https://doi.org/10.1002/qua.560140814>`__
Result: Cite a paper here 1 and another one here 2.
Note
In the example above, the \
before G. te Velde
at the beginning of the line is to prevent sphinx from interpreting G.
that as an enumerated list!
Equations¶
For equation we use MathJax. The syntax is essentially the same as for latex equations.
Example:
The current :math:`I(V)` can be computed using the following equation:
.. math::
I(V) = \frac{2e}{h} \int_{-\infty}^\infty T(E,V) f(E) dE
Result:
The current \(I(V)\) can be computed using the following equation:
Images¶
For images we use the figure
directive. Simple usage:
.. figure:: Images/NEGF.png
Example (with some options):
.. figure:: Images/NEGF.png
:width: 80%
:align: center
Optionally, you can put your caption here.
Result:
File download¶
Example:
Download the file :download:`link-title <downloads/file.txt>`
Result: Download the file link-title
Videos¶
This is how you can embed videos:
.. raw:: html
<center>
<video controls src="../_downloads/burning_isooctane.mp4"></video>
</center>
You can download the movie :download:`here </downloads/burning_isooctane.mp4>`.
You must include a have a download link to the video file, otherwise the video will not be copied over when the documentation is built. (also, note that there is an underscore in the video controls link)
Index¶
Before section titles you generally want to use many index directives with plausible alternative names.
Example:
.. index:: Excitations
.. index:: TDDFT
.. index:: UV/Vis
.. index:: Other reasonable names people might search for...
Excitations with TDDFT
----------------------
Tables¶
For tables I advise using csv-table
(they are much easier to maintain than grid tables
and Simple tables
). See also http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#tables. Example:
Example:
.. csv-table:: Optional title
:header: "Animal", "Furry", "Pettability [a.u.]"
"Cat", "Yes", 9
"Dog", "Yes", 9
"Naked mole rat", "No", 5
Result:
Animal |
Furry |
Pettability [a.u.] |
---|---|---|
Cat |
Yes |
9.5 |
Dog |
Yes |
9.8 |
Naked mole rat |
No |
2.7 |
Code and input snippets¶
For snippets of code or run-scripts use the code-block
directive.
Example:
Some python code:
.. code-block:: python
:emphasize-lines: 3,4
def some_function():
interesting = False
print 'This line is highlighted.'
print 'This one as well...'
print '...but not this one.'
Some ADF input block example:
.. code-block:: none
Excitations
Lowest 5
FullKernel
OnlySing
End
Result:
Some python code:
def some_function():
interesting = False
print 'This line is highlighted.'
print 'This one as well...'
print '...but not this one.'
Some ADF input block example:
Excitations
Lowest 5
FullKernel
OnlySing
End
- 1
G. te Velde, F.M. Bickelhaupt, E.J. Baerends, C. Fonseca Guerra, S.J.A. van Gisbergen, J.G. Snijders, T. Ziegler, Chemistry with ADF, Journal of Computational Chemistry 22, 931 (2001)
- 2
E. J. Baerends and P. Ros, Evaluation of the LCAO Hartree-Fock-Slater method: Applications to transition-metal complexes, International Journal of Quantum Chemistry 14, S12, 169 (1978)