Skip to content

Commit 59ff085

Browse files
committed
DOC: Improve docs on writing documentation
1 parent fee65f1 commit 59ff085

1 file changed

Lines changed: 49 additions & 55 deletions

File tree

doc/devel/document.rst

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ for opening them in your default browser is:
154154
155155
.. _writing-rest-pages:
156156

157-
Write ReST pages
158-
================
157+
reStructuredText pages
158+
======================
159159

160160
Most documentation is either in the docstrings of individual
161161
classes and methods, in explicit ``.rst`` files, or in examples and tutorials.
@@ -243,11 +243,15 @@ nor the ````literal```` role:
243243
Do not describe ``argument`` like this.
244244
245245
246-
Write mathematical expressions
247-
------------------------------
246+
Mathematical expressions
247+
------------------------
248+
Use sphinx's built in math support:
249+
250+
- **Inline math:** Use the ``:math:``
251+
`role <https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#math>`__
252+
- **Math blocks:** Use the ``.. math::``
253+
`directive <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#math>`__
248254

249-
In most cases, you will likely want to use one of `Sphinx's builtin Math
250-
extensions <https://www.sphinx-doc.org/en/master/usage/extensions/math.html>`__.
251255
In rare cases we want the rendering of the mathematical text in the
252256
documentation html to exactly match with the rendering of the mathematical
253257
expression in the Matplotlib figure. In these cases, you can use the
@@ -257,17 +261,17 @@ expression in the Matplotlib figure. In these cases, you can use the
257261

258262
.. _internal-section-refs:
259263

260-
Refer to other documents and sections
261-
-------------------------------------
264+
Cross-references
265+
----------------
262266

263267
Sphinx_ supports internal references_:
264268

265-
========== =============== ===========================================
266-
Role Links target Representation in rendered HTML
267-
========== =============== ===========================================
268-
|doc-dir|_ document link to a page
269-
|ref-dir|_ reference label link to an anchor associated with a heading
270-
========== =============== ===========================================
269+
========== ================================== ===========================================
270+
Role Links target Representation in rendered HTML
271+
========== ================================== ===========================================
272+
|doc-dir|_ :ref:`document <cross-ref-doc>` link to a page
273+
|ref-dir|_ :ref:`section <cross-ref-section>` link to an anchor associated with a heading
274+
========== ================================== ===========================================
271275

272276
.. The following is a hack to have a link with literal formatting
273277
See https://stackoverflow.com/a/4836544
@@ -277,63 +281,53 @@ Role Links target Representation in rendered HTML
277281
.. |ref-dir| replace:: ``:ref:``
278282
.. _ref-dir: https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-ref
279283

280-
Examples:
284+
.. _cross-ref-doc:
281285

282-
.. code-block:: rst
286+
Document cross-references
287+
^^^^^^^^^^^^^^^^^^^^^^^^^
283288

284-
See the :doc:`/install/index`
289+
To cross-link to another page, use the ``:doc:`` role. We generally prefer
290+
absolute paths, starting with ``/`` as the :file:`doc` root directory.
285291

286-
See the tutorial :ref:`quick_start`
292+
Example:
287293

288-
See the example :doc:`/gallery/lines_bars_and_markers/simple_plot`
294+
.. code-block:: rst
295+
296+
See the :doc:`/install/index`
289297
290298
will render as:
291299

292300
See the :doc:`/install/index`
293301

294-
See the tutorial :ref:`quick_start`
302+
.. _cross-ref-section:
295303

296-
See the example :doc:`/gallery/lines_bars_and_markers/simple_plot`
304+
Section cross-references
305+
^^^^^^^^^^^^^^^^^^^^^^^^
297306

298-
Sections can also be given reference labels. For instance from the
299-
:doc:`/install/index` link:
307+
Use hyphen-separated, descriptive names for reference labels.
308+
Do not encode the documentation hierarchy in the label as that may change;
309+
e.g. do not prefix all *User guide* labels with ``user-``.
300310

301-
.. code-block:: rst
302-
303-
.. _clean-install:
304-
305-
How to completely remove Matplotlib
306-
===================================
307-
308-
Occasionally, problems with Matplotlib can be solved with a clean...
309-
310-
and refer to it using the standard reference syntax:
311+
To cross-link a specific section, add a reference label ``.. _[label]:``
312+
before the section
311313

312314
.. code-block:: rst
313315
314-
See :ref:`clean-install`
316+
.. _pr-author-guidelines:
315317
316-
will give the following link: :ref:`clean-install`
318+
Summary for pull request authors
319+
================================
317320
318-
To maximize internal consistency in section labeling and references,
319-
use hyphen separated, descriptive labels for section references.
320-
Keep in mind that contents may be reorganized later, so
321-
avoid top level names in references like ``user`` or ``devel``
322-
or ``faq`` unless necessary, because for example the FAQ "what is a
323-
backend?" could later become part of the users guide, so the label:
321+
and then link to with ``:ref:`[label]\```
324322

325323
.. code-block:: rst
326324
327-
.. _what-is-a-backend:
328-
329-
is better than:
325+
See the :ref:`pr-author-guidelines`
330326
331-
.. code-block:: rst
327+
This with render as:
332328

333-
.. _faq-backend:
329+
See the :ref:`pr-author-guidelines`
334330

335-
In addition, since underscores are widely used by Sphinx itself, use
336-
hyphens to separate words.
337331

338332
.. _referring-to-other-code:
339333

@@ -461,8 +455,8 @@ For clarity, do not use relative links.
461455

462456
.. _writing-docstrings:
463457

464-
Write API documentation
465-
=======================
458+
API documentation
459+
=================
466460

467461
The API reference documentation describes the library interfaces, e.g. inputs, outputs,
468462
and expected behavior. Most of the API documentation is written in docstrings. These are
@@ -957,8 +951,8 @@ Example:
957951

958952
.. _writing-examples-and-tutorials:
959953

960-
Write examples and tutorials
961-
============================
954+
Examples and tutorials
955+
======================
962956

963957
Examples and tutorials are Python scripts that are run by `Sphinx Gallery`_.
964958
Sphinx Gallery finds ``*.py`` files in source directories and runs the files to
@@ -1226,10 +1220,10 @@ Format
12261220
:code: The code should be about 5-10 lines with minimal customization. Plots in
12271221
this gallery use the ``_mpl-gallery`` stylesheet for a uniform aesthetic.
12281222

1229-
Analytics
1230-
==========
1223+
Website analytics
1224+
=================
12311225

1232-
Documentation page analytics are available at
1226+
Analytics of our hosted documentation https://matplotlib.org is available at
12331227
https://views.scientific-python.org/matplotlib.org.
12341228

12351229

0 commit comments

Comments
 (0)