|
1 | 1 | .. redirect-from:: /devel/documenting_mpl |
2 | 2 |
|
3 | | -.. _documenting-matplotlib: |
4 | 3 |
|
5 | | -=================== |
6 | | -Write documentation |
7 | | -=================== |
8 | | - |
9 | | -Getting started |
10 | | -=============== |
11 | | - |
12 | | -General file structure |
13 | | ----------------------- |
14 | | - |
15 | | -All documentation is built from the :file:`doc/`. The :file:`doc/` |
16 | | -directory contains configuration files for Sphinx and reStructuredText |
17 | | -(ReST_; ``.rst``) files that are rendered to documentation pages. |
18 | | - |
19 | | -Documentation is created in three ways. First, API documentation |
20 | | -(:file:`doc/api`) is created by Sphinx_ from |
21 | | -the docstrings of the classes in the Matplotlib library. Except for |
22 | | -:file:`doc/api/api_changes/`, ``.rst`` files in :file:`doc/api` are created |
23 | | -when the documentation is built. See :ref:`writing-docstrings` below. |
24 | | - |
25 | | -Second, our example pages, tutorials, and some of the narrative documentation |
26 | | -are created by `Sphinx Gallery`_. Sphinx Gallery converts example Python files |
27 | | -to ``*.rst`` files with the result of Matplotlib plot calls as embedded images. |
28 | | -See :ref:`writing-examples-and-tutorials` below. |
29 | | - |
30 | | -Third, Matplotlib has narrative docs written in ReST_ in subdirectories of |
31 | | -:file:`doc/users/`. If you would like to add new documentation that is suited |
32 | | -to an ``.rst`` file rather than a gallery or tutorial example, choose an |
33 | | -appropriate subdirectory to put it in, and add the file to the table of |
34 | | -contents of :file:`index.rst` of the subdirectory. See |
35 | | -:ref:`writing-rest-pages` below. |
36 | | - |
37 | | -.. note:: |
38 | | - |
39 | | - Don't directly edit the ``.rst`` files in :file:`doc/plot_types`, |
40 | | - :file:`doc/gallery`, :file:`doc/tutorials`, and :file:`doc/api` |
41 | | - (excepting :file:`doc/api/api_changes/`). Sphinx_ regenerates |
42 | | - files in these directories when building documentation. |
43 | | - |
44 | | -Set up the build |
45 | | ----------------- |
46 | | - |
47 | | -The documentation for Matplotlib is generated from reStructuredText (ReST_) |
48 | | -using the Sphinx_ documentation generation tool. |
49 | | - |
50 | | -To build the documentation you will need to |
51 | | -:ref:`set up Matplotlib for development <installing_for_devs>`. Note in |
52 | | -particular the :ref:`additional dependencies <doc-dependencies>` required to |
53 | | -build the documentation. |
54 | | - |
55 | | -.. _build_docs: |
56 | | - |
57 | | -Build the docs |
58 | | --------------- |
59 | | - |
60 | | -The documentation sources are found in the :file:`doc/` directory. |
61 | | -The configuration file for Sphinx is :file:`doc/conf.py`. It controls which |
62 | | -directories Sphinx parses, how the docs are built, and how the extensions are |
63 | | -used. To build the documentation in html format, cd into :file:`doc/` and run: |
64 | | - |
65 | | -.. code-block:: sh |
66 | | -
|
67 | | - make html |
68 | | -
|
69 | | -.. note:: |
| 4 | +.. _document-format: |
70 | 5 |
|
71 | | - Since the documentation is very large, the first build may take 10-20 minutes, |
72 | | - depending on your machine. Subsequent builds will be faster. |
73 | | - |
74 | | -Other useful invocations include |
75 | | - |
76 | | -.. code-block:: sh |
77 | | -
|
78 | | - # Build the html documentation, but skip generation of the gallery images to |
79 | | - # save time. |
80 | | - make html-noplot |
81 | | -
|
82 | | - # Build the html documentation, but skip specific subdirectories. If a gallery |
83 | | - # directory is skipped, the gallery images are not generated. The first |
84 | | - # time this is run, it creates ``.mpl_skip_subdirs.yaml`` which can be edited |
85 | | - # to add or remove subdirectories |
86 | | - make html-skip-subdirs |
87 | | -
|
88 | | - # Delete built files. May help if you get errors about missing paths or |
89 | | - # broken links. |
90 | | - make clean |
91 | | -
|
92 | | - # Build pdf docs. |
93 | | - make latexpdf |
94 | | -
|
95 | | -The ``SPHINXOPTS`` variable is set to ``-W --keep-going`` by default to build |
96 | | -the complete docs but exit with exit status 1 if there are warnings. To unset |
97 | | -it, use |
98 | | - |
99 | | -.. code-block:: sh |
100 | | -
|
101 | | - make SPHINXOPTS= html |
102 | | -
|
103 | | -You can use the ``O`` variable to set additional options: |
104 | | - |
105 | | -* ``make O=-j4 html`` runs a parallel build with 4 processes. |
106 | | -* ``make O=-Dplot_formats=png:100 html`` saves figures in low resolution. |
107 | | - |
108 | | -Multiple options can be combined, e.g. ``make O='-j4 -Dplot_formats=png:100' |
109 | | -html``. |
110 | | - |
111 | | -On Windows, set the options as environment variables, e.g.: |
112 | | - |
113 | | -.. code-block:: bat |
114 | | -
|
115 | | - set SPHINXOPTS= & set O=-j4 -Dplot_formats=png:100 & make html |
116 | | -
|
117 | | -Show locally built docs |
118 | | ------------------------ |
119 | | - |
120 | | -The built docs are available in the folder :file:`build/html`. A shortcut |
121 | | -for opening them in your default browser is: |
122 | | - |
123 | | -.. code-block:: sh |
124 | | -
|
125 | | - make show |
| 6 | +******************* |
| 7 | +Write documentation |
| 8 | +******************* |
126 | 9 |
|
127 | 10 | .. _writing-rest-pages: |
128 | 11 |
|
@@ -1183,11 +1066,12 @@ style or topbar should be made there to propagate across all subprojects. |
1183 | 1066 |
|
1184 | 1067 | .. TODO: Add section about uploading docs |
1185 | 1068 |
|
| 1069 | +
|
1186 | 1070 | .. _ReST: https://docutils.sourceforge.io/rst.html |
1187 | 1071 | .. _Sphinx: http://www.sphinx-doc.org |
| 1072 | +.. _`Sphinx Gallery`: https://sphinx-gallery.readthedocs.io/en/latest/ |
1188 | 1073 | .. _documentation: https://www.sphinx-doc.org/en/master/contents.html |
1189 | 1074 | .. _index: http://www.sphinx-doc.org/markup/para.html#index-generating-markup |
1190 | | -.. _`Sphinx Gallery`: https://sphinx-gallery.readthedocs.io/en/latest/ |
1191 | 1075 | .. _references: https://www.sphinx-doc.org/en/stable/usage/restructuredtext/roles.html |
1192 | 1076 | .. _`numpydoc docstring guide`: https://numpydoc.readthedocs.io/en/latest/format.html |
1193 | 1077 | .. _`Manually passing files`: https://sphinx-gallery.github.io/stable/configuration.html#manually-passing-files |
0 commit comments