Repository navigation
Description
Description of the desired feature
The GMT documentation is built by Sphinx with the theme sphinx_rtd_theme and a few sphinx extensions.
Currently, the source codes of the theme sphinx_rtd_theme and the extensions are included in the GMT repository (https://github.com/GenericMappingTools/gmt/tree/master/doc/rst/themes/rtd and https://github.com/GenericMappingTools/gmt/tree/master/doc/rst/_extensions). With the theme and extensions included, anyone can build the GMT documentation without installing extra dependencies, except sphinx.
Recently, I find some sphinx extensions which may be useful in the GMT documentation:
sphinx-copybutton: add a little “copy” button to the right of code blocks so that readers can easily copy the codessphinx-panels: provide some useful directives. For example, thepanelsdirective can be used to design a better landing page.
| Current (a waste of space) | Expected (better) |
|---|---|
![]() |
![]() |
the dropdown directive (see the screenshot below) can be used to add examples to show the usage of specific options, without making the manpage too long (the examples are collapsed by default).

We already have a solution to add inline examples, but the code is difficult to read and maintain. For example, we have an example for plot -L option, and the raw codes are crazy:

Another similar extension is sphinx-togglebutton.
Hopefully, you all agree that these extensions can help improve the readability of the GMT documentation.
However, these extensions (and most other sphinx extensions) usually have several source code files (in Python or CSS), and it's difficult to include them in the GMT repository (it's possible but a little difficult to maintain). I think the best way is to install them before building documentation, e.g.:
pip install sphinx-copybutton sphinx-panels sphinx-togglebutton
but it means that anyone who wants to build the documentation must install the python packages by themselves. It would be a little difficult for non-python users, but perhaps still acceptable for GMT developers?
Edit: we decided to include these extensions in the GMT repository.


Activity
[-]Use more sphinx extensions in the documentations[/-][+]Use more sphinx extensions in the documentation[/+]PaulWessel commentedon Feb 4, 2021
This looks very promising for both the panels directive and the togglebutton. To add simple, working examples for many options will be quite a bit of work, of course. I wonder if it may be a small step in the right direction to at least have a link from such options to an example that we already have, to at least demonstrate how a particular option is used in a command. Would the toglebutton open up access to a command that users can copy/paste into terminal to run? Should there be a figure as well? Maybe we need a template for this first, so that they all are very similar, e.g.,example code, figure result, link to more reading?
maxrjones commentedon Mar 7, 2021
@seisman, I am interested in trying out the dropdown directive for the figures in cookbook/features.rst. Would this overlap with anything you are working on/plan to work on?
seisman commentedon Mar 7, 2021
No, feel free to try it. Good to have a PR using the
dropdowndirective to compare with the PR #4926 which used a new extension.maxrjones commentedon Mar 9, 2021
What do you think of the autosectionlabel extension? It seems like it could be really helpful for the cookbook.
seisman commentedon Mar 10, 2021
It looks useful.
maxrjones commentedon Mar 10, 2021
Nevermind. It leads to hundreds of duplicate label warnings, so won't work easily for the GMT docs.
seisman commentedon Mar 10, 2021
Did you try
autosectionlabel_prefix_document?