Showing code¶
The complete sphinx documentation about this topic is here.
To insert inline code use double backticks, like this.
code-block¶
If more space is needed, use the code-block directive:
$ wget https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz
[...]
$ wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz
[...]
$ ls
hBN-2D.tar.gz hBN.tar.gz
Code can also be highlighted specifying the language, for example
import numpy as np
import matplotlib.pyplot as plt
but this does not always work, so it’s better to use code-block:: none (which does not highlight code).
One useful option is :emphasize-lines:, which can be used to highlight specific lines in the code block:
1[...]
2rim_cut # [R] Coulomb potential
3gw0 # [R] GW approximation
4el_el_corr # [R] Electron-Electron Correlation
5HF_and_locXC # [R] Hartree-Fock
6em1d # [R][X] Dynamically Screened Interaction
7NLogCPUs=0 # [PARALLEL] Live-timing CPU`s (0 for all)
8RandQpts=1000000 # [RIM] Number of random q-points in the BZ
9CUTGeo= "slab z" # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere/ws/slab X/Y/Z/XY..
10RandGvec= 5 Ry # [RIM] Coulomb interaction RS components
11NGsBlkXm= 1 Ry # [Xm] Response block size
12[...]
If you want to highlight specific characters or keywords, remember that
nested markup is not possible in rST
and for code-block this applies also to MarkDown syntax. A possible workaround
is provided by the raw directive (inspect the source of this file to see the syntax):
% QpntsRXd
1 | 1 | # [Xd] Transferred momenta
%
ETStpsXd=1001 # [Xd] Total Energy steps
literalinclude¶
Finally, there is also the literalinclude directive that takes the code from an external file:
A file containing
dummy text
to show
the literalinclude directive
Attention
Remember that every file in docs/source is read by sphinx.
When using literalinclude add the path of the files used by this
directive to exclude_patterns in conf.py, otherwise you can
get errors due to sphinx-build trying to process spurious instructions
contained in those files.