|
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 the docs |
56 | | --------------- |
57 | | - |
58 | | -The documentation sources are found in the :file:`doc/` directory. |
59 | | -The configuration file for Sphinx is :file:`doc/conf.py`. It controls which |
60 | | -directories Sphinx parses, how the docs are built, and how the extensions are |
61 | | -used. To build the documentation in html format, cd into :file:`doc/` and run: |
62 | | - |
63 | | -.. code-block:: sh |
64 | | -
|
65 | | - make html |
66 | | -
|
67 | | -.. note:: |
68 | | - |
69 | | - Since the documentation is very large, the first build may take 10-20 minutes, |
70 | | - depending on your machine. Subsequent builds will be faster. |
| 4 | +.. _document-format: |
71 | 5 |
|
72 | | -Other useful invocations include |
73 | | - |
74 | | -.. code-block:: sh |
75 | | -
|
76 | | - # Build the html documentation, but skip generation of the gallery images to |
77 | | - # save time. |
78 | | - make html-noplot |
79 | | -
|
80 | | - # Build the html documentation, but skip specific subdirectories. If a gallery |
81 | | - # directory is skipped, the gallery images are not generated. The first |
82 | | - # time this is run, it creates ``.mpl_skip_subdirs.yaml`` which can be edited |
83 | | - # to add or remove subdirectories |
84 | | - make html-skip-subdirs |
85 | | -
|
86 | | - # Delete built files. May help if you get errors about missing paths or |
87 | | - # broken links. |
88 | | - make clean |
89 | | -
|
90 | | - # Build pdf docs. |
91 | | - make latexpdf |
92 | | -
|
93 | | -The ``SPHINXOPTS`` variable is set to ``-W --keep-going`` by default to build |
94 | | -the complete docs but exit with exit status 1 if there are warnings. To unset |
95 | | -it, use |
96 | | - |
97 | | -.. code-block:: sh |
98 | | -
|
99 | | - make SPHINXOPTS= html |
100 | | -
|
101 | | -You can use the ``O`` variable to set additional options: |
102 | | - |
103 | | -* ``make O=-j4 html`` runs a parallel build with 4 processes. |
104 | | -* ``make O=-Dplot_formats=png:100 html`` saves figures in low resolution. |
105 | | - |
106 | | -Multiple options can be combined, e.g. ``make O='-j4 -Dplot_formats=png:100' |
107 | | -html``. |
108 | | - |
109 | | -On Windows, set the options as environment variables, e.g.: |
110 | | - |
111 | | -.. code-block:: bat |
112 | | -
|
113 | | - set SPHINXOPTS= & set O=-j4 -Dplot_formats=png:100 & make html |
114 | | -
|
115 | | -Show locally built docs |
116 | | ------------------------ |
117 | | - |
118 | | -The built docs are available in the folder :file:`build/html`. A shortcut |
119 | | -for opening them in your default browser is: |
120 | | - |
121 | | -.. code-block:: sh |
122 | | -
|
123 | | - make show |
| 6 | +******************* |
| 7 | +Write documentation |
| 8 | +******************* |
124 | 9 |
|
125 | 10 | .. _writing-rest-pages: |
126 | 11 |
|
@@ -1174,11 +1059,12 @@ style or topbar should be made there to propagate across all subprojects. |
1174 | 1059 |
|
1175 | 1060 | .. TODO: Add section about uploading docs |
1176 | 1061 |
|
| 1062 | +
|
1177 | 1063 | .. _ReST: https://docutils.sourceforge.io/rst.html |
1178 | 1064 | .. _Sphinx: http://www.sphinx-doc.org |
| 1065 | +.. _`Sphinx Gallery`: https://sphinx-gallery.readthedocs.io/en/latest/ |
1179 | 1066 | .. _documentation: https://www.sphinx-doc.org/en/master/contents.html |
1180 | 1067 | .. _index: http://www.sphinx-doc.org/markup/para.html#index-generating-markup |
1181 | | -.. _`Sphinx Gallery`: https://sphinx-gallery.readthedocs.io/en/latest/ |
1182 | 1068 | .. _references: https://www.sphinx-doc.org/en/stable/usage/restructuredtext/roles.html |
1183 | 1069 | .. _`numpydoc docstring guide`: https://numpydoc.readthedocs.io/en/latest/format.html |
1184 | 1070 | .. _`Manually passing files`: https://sphinx-gallery.github.io/stable/configuration.html#manually-passing-files |
0 commit comments