xref: /petsc/doc/developers/documentation.md (revision c3bbc914f9fddcc88f8764d7921fd58e410d04fe)
14bcd95a3SBarry Smith# Developing PETSc Documentation
24bcd95a3SBarry Smith
34bcd95a3SBarry Smith```{toctree}
44bcd95a3SBarry Smith:maxdepth: 2
54bcd95a3SBarry Smith```
64bcd95a3SBarry Smith
74bcd95a3SBarry Smith## General Guidelines
84bcd95a3SBarry Smith
94bcd95a3SBarry Smith- Good documentation should be like a bonsai tree: alive, on display, frequently tended, and as small as possible (adapted from [these best practices](https://github.com/google/styleguide/blob/gh-pages/docguide/best_practices.md)).
104bcd95a3SBarry Smith- Wrong, irrelevant, or confusing documentation is worse than no documentation.
114bcd95a3SBarry Smith
124bcd95a3SBarry Smith(sphinx_documentation)=
134bcd95a3SBarry Smith
144bcd95a3SBarry Smith## Documentation with Sphinx
154bcd95a3SBarry Smith
164bcd95a3SBarry SmithWe use [Sphinx](https://www.sphinx-doc.org/en/master/) to build our web pages and documentation. Most content is written using [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html), a simple markup language.
174bcd95a3SBarry Smith
184bcd95a3SBarry Smith[These slides](https://gitlab.com/psanan/petsc-sphinx-slides) contain an overview of Sphinx and how we use(d) it, as of October 2020.
194bcd95a3SBarry Smith
204bcd95a3SBarry Smith(sec_local_html_docs)=
214bcd95a3SBarry Smith
224bcd95a3SBarry Smith### Building the HTML docs locally
234bcd95a3SBarry Smith
244bcd95a3SBarry SmithWe use a [Python 3 virtual environment](https://docs.python.org/3/tutorial/venv.html) to build the documentation since not all developers can trivially install the needed Python modules directly.
254bcd95a3SBarry Smith
264bcd95a3SBarry Smith```console
274bcd95a3SBarry Smith$ cd $PETSC_DIR
284bcd95a3SBarry Smith$ make docs
294bcd95a3SBarry Smith$ open doc/_build/html/index.html  # in a browser
304bcd95a3SBarry Smith```
314bcd95a3SBarry Smith
324bcd95a3SBarry Smithor
334bcd95a3SBarry Smith
344bcd95a3SBarry Smith```console
354bcd95a3SBarry Smith$ cd $PETSC_DIR/doc
364bcd95a3SBarry Smith$ make sphinxhtml
374bcd95a3SBarry Smith$ open _build/html/index.html
384bcd95a3SBarry Smith```
394bcd95a3SBarry Smith
404bcd95a3SBarry Smith(sec_local_docs_latex)=
414bcd95a3SBarry Smith
424bcd95a3SBarry Smith### Building the manual locally as a PDF via LaTeX
434bcd95a3SBarry Smith
444bcd95a3SBarry Smith:::{admonition} Note
454bcd95a3SBarry SmithBefore following these instructions, you need to have a working
464bcd95a3SBarry Smithlocal LaTeX installation and the ability to install additional packages,
474bcd95a3SBarry Smithif need be, to resolve LaTeX errors.
484bcd95a3SBarry Smith:::
494bcd95a3SBarry Smith
504bcd95a3SBarry SmithSet up your local Python environment (e.g., ref:`as above <sec_local_html_docs>`), then
514bcd95a3SBarry Smith
524bcd95a3SBarry Smith```console
534bcd95a3SBarry Smith$ cd doc
544bcd95a3SBarry Smith$ make sphinxpdf
554bcd95a3SBarry Smith$ open _build/latex/manual.pdf  # in PDF viewer
564bcd95a3SBarry Smith```
574bcd95a3SBarry Smith
584bcd95a3SBarry Smith(sphinx_guidelines)=
594bcd95a3SBarry Smith
604bcd95a3SBarry Smith### Sphinx Documentation Guidelines
614bcd95a3SBarry Smith
624bcd95a3SBarry SmithRefer to Sphinx's [own documentation](https://https://www.sphinx-doc.org) for general information on how to use Sphinx, and note the following additional guidelines.
634bcd95a3SBarry Smith
644bcd95a3SBarry Smith- Use the [literalinclude directive](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-literalinclude) to directly include pieces of source code. Use a path beginning with `/`, relative to the root for the Sphinx docs (where `conf.py` is found).
654bcd95a3SBarry Smith
664bcd95a3SBarry Smith  ```rst
674bcd95a3SBarry Smith  .. literalinclude:: /../src/sys/error/err.c
684bcd95a3SBarry Smith     :start-at: PetscErrorCode PetscError(
694bcd95a3SBarry Smith     :end-at: PetscFunctionReturn(PETSC_SUCCESS)
704bcd95a3SBarry Smith     :append: }
714bcd95a3SBarry Smith  ```
724bcd95a3SBarry Smith
734bcd95a3SBarry Smith  For robustness to changes in the source files, Use `:start-at:` and related options when possible, noting that you can also use (positive) values of `:lines:` relative to this. Use the `:language:` option to appropriately highlight languages other than C.
744bcd95a3SBarry Smith
754bcd95a3SBarry Smith- Any invocable command line statements longer than a few words should be in
764bcd95a3SBarry Smith  `.. code-block::` sections. Double backticks must enclose any such statements not in code-block statements"\`\`". For example `make all` is acceptable but
774bcd95a3SBarry Smith
784bcd95a3SBarry Smith  ```console
794bcd95a3SBarry Smith  $ make PETSC_DIR=/my/path/to/petsc PETSC_ARCH=my-petsc-arch all
804bcd95a3SBarry Smith  ```
814bcd95a3SBarry Smith
824bcd95a3SBarry Smith  should be in a `.. code-block::`.
834bcd95a3SBarry Smith
844bcd95a3SBarry Smith- All code blocks showing command line invocation must use the "console" block
854bcd95a3SBarry Smith  directive. E.g.
864bcd95a3SBarry Smith
874bcd95a3SBarry Smith  ```rst
884bcd95a3SBarry Smith  .. code-block:: console
894bcd95a3SBarry Smith
904bcd95a3SBarry Smith     $ cd $PETSC_DIR/src/snes/interface
914bcd95a3SBarry Smith     $ ./someprog
924bcd95a3SBarry Smith     output1
934bcd95a3SBarry Smith     output2
944bcd95a3SBarry Smith  ```
954bcd95a3SBarry Smith
964bcd95a3SBarry Smith  The only exception to this is when displaying raw output, i.e., with no preceding
974bcd95a3SBarry Smith  commands. Then one may use just the "::" directive to improve visibility, e.g.,
984bcd95a3SBarry Smith
994bcd95a3SBarry Smith  ```rst
1004bcd95a3SBarry Smith  ::
1014bcd95a3SBarry Smith
1024bcd95a3SBarry Smith     output1
1034bcd95a3SBarry Smith     output2
1044bcd95a3SBarry Smith  ```
1054bcd95a3SBarry Smith
1064bcd95a3SBarry Smith- Any code blocks that show command line invocations must be preceded by `$`, e.g.
1074bcd95a3SBarry Smith
1084bcd95a3SBarry Smith  ```rst
1094bcd95a3SBarry Smith  .. code-block:: console
1104bcd95a3SBarry Smith
1114bcd95a3SBarry Smith     $ ./configure --some-args
1124bcd95a3SBarry Smith     $ make libs
1134bcd95a3SBarry Smith     $ make ./ex1
1144bcd95a3SBarry Smith     $ ./ex1 --some-args
1154bcd95a3SBarry Smith  ```
1164bcd95a3SBarry Smith
1174bcd95a3SBarry Smith- Environment variables such as `$PETSC_DIR` or `$PATH` must be preceded by
1184bcd95a3SBarry Smith  `$` and be enclosed in double backticks, e.g.
1194bcd95a3SBarry Smith
1204bcd95a3SBarry Smith  ```rst
1214bcd95a3SBarry Smith  Set ``$PETSC_DIR`` and ``$PETSC_ARCH``
1224bcd95a3SBarry Smith  ```
1234bcd95a3SBarry Smith
1244bcd95a3SBarry Smith- For internal links, use explicit labels, e.g
1254bcd95a3SBarry Smith
1264bcd95a3SBarry Smith  ```rst
1274bcd95a3SBarry Smith  .. _sec_short_name:
1284bcd95a3SBarry Smith
1294bcd95a3SBarry Smith  Section name
1304bcd95a3SBarry Smith  ============
1314bcd95a3SBarry Smith  ```
1324bcd95a3SBarry Smith
1334bcd95a3SBarry Smith  and elsewhere (in any document),
1344bcd95a3SBarry Smith
1354bcd95a3SBarry Smith  ```rst
1364bcd95a3SBarry Smith  See :ref:`link text <sec_short_name>`
1374bcd95a3SBarry Smith  ```
1384bcd95a3SBarry Smith
1394bcd95a3SBarry Smith- For internal links in the manual with targets outside the manual, always provide alt text
1404bcd95a3SBarry Smith  so that the text will be properly formatted in the {ref}`standalone PDF manual <sec_local_docs_latex>`, e.g.
1414bcd95a3SBarry Smith
1424bcd95a3SBarry Smith  > ```rst
1434bcd95a3SBarry Smith  > PETSc has :doc:`mailing lists </community/mailing>`.
1444bcd95a3SBarry Smith  > ```
1454bcd95a3SBarry Smith
1464bcd95a3SBarry Smith- We use the [sphinxcontrib-bibtex extension](https://sphinxcontrib-bibtex.readthedocs.io/en/latest/)
1474bcd95a3SBarry Smith  to include citations from BibTeX files.
1484bcd95a3SBarry Smith  You must include `.. bibliography::` blocks at the bottom of a page, including citations ([example](https://gitlab.com/petsc/petsc/-/raw/main/doc/manual/ksp.rst)).
1494bcd95a3SBarry Smith  To cite the same reference on more than one page, use [this workaround](https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#key-prefixing) on one of them ([example](https://gitlab.com/petsc/petsc/-/raw/main/doc/developers/articles.rst)) [^bibtex-footnote].
1504bcd95a3SBarry Smith
1514bcd95a3SBarry Smith- See special instructions on {any}`docs_images`.
1524bcd95a3SBarry Smith
1534bcd95a3SBarry Smith- Prefer formatting styles that are easy to modify and maintain. In particular, the use of [list-table](https://docutils.sourceforge.io/docs/ref/rst/directives.html#list-table) is recommended.
1544bcd95a3SBarry Smith
1554bcd95a3SBarry Smith- When using external links with inline URLs, prefer to use [anonymous hyperlink references](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#anonymous-hyperlinks) with two trailing underscores, e.g.
1564bcd95a3SBarry Smith
1574bcd95a3SBarry Smith  ```rst
1584bcd95a3SBarry Smith  `link text <https://external.org>`__
1594bcd95a3SBarry Smith  ```
1604bcd95a3SBarry Smith
1614bcd95a3SBarry Smith- To pluralize something with inline markup, e.g. `DM`s, escape the trailing character to avoid `WARNING: Inline literal start-string without end-string`.
1624bcd95a3SBarry Smith
1634bcd95a3SBarry Smith  ```rst
1644bcd95a3SBarry Smith  ``DM``\s
1654bcd95a3SBarry Smith  ```
1664bcd95a3SBarry Smith
1674bcd95a3SBarry Smith- Use restraint in adding new Sphinx extensions, in particular, those which aren't
1684bcd95a3SBarry Smith  widely used and well-supported, or those with hidden system dependencies.
1694bcd95a3SBarry Smith
1704bcd95a3SBarry Smith(petsc_repositories)=
1714bcd95a3SBarry Smith
1724bcd95a3SBarry Smith## Other PETSc repositories
1734bcd95a3SBarry Smith
174*c3bbc914SBarry SmithIn addition to the [PETSc repository](https://gitlab.com/petsc/petsc), there are three other PETSc repositories which contain large data
175*c3bbc914SBarry Smithfiles that are unnecessary for most PETSc usages and thus are not stored in the main repository.
176*c3bbc914SBarry Smith
177*c3bbc914SBarry Smith- [Images](https://gitlab.com/petsc/images) contains images that are used in the PETSc documentation or have other uses. See {any}`docs_images`
178*c3bbc914SBarry Smith  for details on its use.
179*c3bbc914SBarry Smith- [Annual-Meetings](https://gitlab.com/petsc/annual-meetings) contains various documents from the {any}`meetings`. See {any}`docs_meetings`.
180*c3bbc914SBarry Smith- [Datafiles](https://gitlab.com/petsc/datafiles) contains large matrices, meshes, and various other data files that
181*c3bbc914SBarry Smith  are used in the {any}`PETSc CI<test_harness_data>`.
182*c3bbc914SBarry Smith
183*c3bbc914SBarry SmithOther repositories containing software PETSc uses are located at [GitLab](https://gitlab.com/petsc/)
184*c3bbc914SBarry Smithand [BitBucket](https://bitbucket.org/petsc/workspace/repositories). The BitBucket location is used for historical reasons,
185*c3bbc914SBarry Smiththere are many links on the web to these locations thus the repositories have not been migrated to GitLab.
1864bcd95a3SBarry Smith
1874bcd95a3SBarry Smith(docs_images)=
1884bcd95a3SBarry Smith
1894bcd95a3SBarry Smith## Images
1904bcd95a3SBarry Smith
1914bcd95a3SBarry SmithPETSc's documentation is tightly coupled to the source code and tests and
1924bcd95a3SBarry Smithis tracked in the primary PETSc Git repository. However, image files are
193*c3bbc914SBarry Smithtoo large to track directly this way (especially because they persist in the integration branches' histories). Thus we do not put images
194*c3bbc914SBarry Smithinto the PETSc git repository.
1954bcd95a3SBarry Smith
196*c3bbc914SBarry SmithTherefore, we store image files in a separate Git repository, [Images](https://gitlab.com/petsc/petsc). This repository is automatically cloned
197*c3bbc914SBarry Smith(if not already available) and updated  when building the documentation. It can also be cloned by running
1984bcd95a3SBarry Smith`make images` in the `doc/` directory.
1994bcd95a3SBarry SmithAny new images required must be added to the currently-used branch of this repository.
2004bcd95a3SBarry Smith
2014bcd95a3SBarry Smith### Image Guidelines
2024bcd95a3SBarry Smith
2034bcd95a3SBarry Smith- Whenever possible, use SVG files. SVG is a web-friendly vector format and will be automatically converted to PDF using `rsvg-convert` [^svg-footnote]
2044bcd95a3SBarry Smith- Avoid large files and large numbers of images.
2054bcd95a3SBarry Smith- Do not add movies or other non-image files.
2064bcd95a3SBarry Smith
2074bcd95a3SBarry Smith### Adding new images
2084bcd95a3SBarry Smith
2094bcd95a3SBarry Smith- Decide where in `doc/images` a new image should go. Use the structure of the `doc/` tree as a guide.
2104bcd95a3SBarry Smith- Create a Merge Request to the currently-used branch of the upstream images repository, adding this image [^maintainer-fast-image-footnote].
211*c3bbc914SBarry Smith- Once this Merge Request is merged, you may make a MR on the main PETSc Git repository relying on the new image(s).
2124bcd95a3SBarry Smith
2134bcd95a3SBarry SmithIt may be helpful to place working copies of the new image(s) in your local `doc/images`
2144bcd95a3SBarry Smithwhile iterating on documentation; don't forget to update the upstream images repository.
2154bcd95a3SBarry Smith
2164bcd95a3SBarry Smith### Removing, renaming, moving, or updating images
2174bcd95a3SBarry Smith
2184bcd95a3SBarry SmithDo not directly move, rename, or update images in the images repository.
2194bcd95a3SBarry SmithSimply add a logically-numbered new version of the image.
2204bcd95a3SBarry Smith
2214bcd95a3SBarry SmithIf an image is not used in *any* {any}`integration branch <sec_integration_branches>` (`main` or `release`),
2224bcd95a3SBarry Smithadd it to the top-level list of files to delete in the images repository.
2234bcd95a3SBarry Smith
2244bcd95a3SBarry Smith(docs_images_cleanup)=
2254bcd95a3SBarry Smith
2264bcd95a3SBarry Smith### Cleaning up the images repository (maintainers only)
2274bcd95a3SBarry Smith
2284bcd95a3SBarry SmithIf the size of the image repository grows too large,
2294bcd95a3SBarry Smith
2304bcd95a3SBarry Smith- Create a new branch `main-X`, where `X` increments the current value
2314bcd95a3SBarry Smith- Create a new commit deleting all files in the to-delete list and clearing the list
2324bcd95a3SBarry Smith- Reset the new `main-X` to a single commit with this new, cleaned-up state
2334bcd95a3SBarry Smith- Set `main-X` as the "default" branch on GitLab.
2344bcd95a3SBarry Smith- Update both `release` and `main` in the primary PETSc repository to clone this new branch
2354bcd95a3SBarry Smith
236*c3bbc914SBarry Smith(docs_meetings)=
237*c3bbc914SBarry Smith
238*c3bbc914SBarry Smith## Annual meetings website
239*c3bbc914SBarry Smith
240*c3bbc914SBarry SmithLike {any}`docs_images` the material (slides, etc.) for the PETSc annual meetings is too large to store in the primary PETSc Git repository.
241*c3bbc914SBarry SmithIt is stored in [Annual-Meetings](https://gitlab.com/petsc/annual-meetings) repository and linked from {any}`meetings`.
242*c3bbc914SBarry Smith
243*c3bbc914SBarry SmithThe files are all in the public directory of the repository so that the `.gitlab-ci.yml` file for the repository
244*c3bbc914SBarry Smithautomatically displays all the files at https://petsc.gitlab.io/annual-meetings. Thus, all one needs to do is add files into
245*c3bbc914SBarry Smith[Annual-Meetings](https://gitlab.com/petsc/annual-meetings) and provide appropriate links within that repository or from {any}`meetings`
246*c3bbc914SBarry Smithin the primary PETSc Git repository.
247*c3bbc914SBarry Smith
248*c3bbc914SBarry Smith
2494bcd95a3SBarry Smith(manpages_c2html_build)=
2504bcd95a3SBarry Smith
2514bcd95a3SBarry Smith## Building Manual Pages and C2HTML Files
2524bcd95a3SBarry Smith
2534bcd95a3SBarry SmithThe manual pages and C2HTML-generated file as built in a process described below using the documentation tools listed below, which are
2544bcd95a3SBarry Smithautomatically downloaded and installed if needed while building the PETSc documentation./
2554bcd95a3SBarry Smith
2564bcd95a3SBarry Smith- [Sowing](https://bitbucket.org/petsc/pkg-sowing): Developed by Bill Gropp, this produces the PETSc manual pages; see the [Sowing documentation](http://wgropp.cs.illinois.edu/projects/software/sowing/doctext/doctext.htm) and {ref}`manual_page_format`.
2574bcd95a3SBarry Smith- [C2html](https://gitlab.com/petsc/pkg-c2html): This generates the HTML versions of all the source code.
2584bcd95a3SBarry Smith
2594bcd95a3SBarry SmithSowing and C2html are build tools that do not use the compilers specified to PETSc's `configure`, as they
2604bcd95a3SBarry Smithneed to work in cross-compilation environments. Thus, they default to using `gcc`, `g++`, and `flex` from
2614bcd95a3SBarry Smiththe user's environment (or `configure` options like `--download-sowing-cxx`). Microsoft Windows users must install `gcc`
2624bcd95a3SBarry Smithetc., from Cygwin in order to be able to build the documentation.
2634bcd95a3SBarry Smith
2644bcd95a3SBarry Smith```{rubric} Footnotes
2654bcd95a3SBarry Smith```
2664bcd95a3SBarry Smith
2674bcd95a3SBarry Smith[^bibtex-footnote]: The extensions's [development branch](https://github.com/mcmtroffaes/sphinxcontrib-bibtex) [supports our use case better](https://github.com/mcmtroffaes/sphinxcontrib-bibtex/pull/185) (`:footcite:`), which can be investigated if a release is ever made. This stuff is now in the main repository but does not work as advertised from .md files.
2684bcd95a3SBarry Smith
2694bcd95a3SBarry Smith[^svg-footnote]: `rsvg-convert` is installable with your package manager, e.g., `librsvg2-bin` on Debian/Ubuntu systems).
2704bcd95a3SBarry Smith
2714bcd95a3SBarry Smith[^maintainer-fast-image-footnote]: Maintainers may directly push commits.
272