summaryrefslogtreecommitdiffstats
path: root/doc/usage/restructuredtext/domains.rst
blob: 729e651f79906d5355132cfec41e7652acdbda42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
.. highlight:: rst

=======
Domains
=======

.. versionadded:: 1.0

Originally, Sphinx was conceived for a single project, the documentation of the
Python language.  Shortly afterwards, it was made available for everyone as a
documentation tool, but the documentation of Python modules remained deeply
built in -- the most fundamental directives, like ``function``, were designed
for Python objects.  Since Sphinx has become somewhat popular, interest
developed in using it for many different purposes: C/C++ projects, JavaScript,
or even reStructuredText markup (like in this documentation).

While this was always possible, it is now much easier to easily support
documentation of projects using different programming languages or even ones
not supported by the main Sphinx distribution, by providing a **domain** for
every such purpose.

A domain is a collection of markup (reStructuredText :term:`directive`\ s and
:term:`role`\ s) to describe and link to :term:`object`\ s belonging together,
e.g. elements of a programming language.  Directive and role names in a domain
have names like ``domain:name``, e.g. ``py:function``.  Domains can also
provide custom indices (like the Python Module Index).

Having domains means that there are no naming problems when one set of
documentation wants to refer to e.g. C++ and Python classes.  It also means
that extensions that support the documentation of whole new languages are much
easier to write.

This section describes what the domains that are included with Sphinx provide.
The domain API is documented as well, in the section :ref:`domain-api`.


.. _basic-domain-markup:

Basic Markup
------------

Most domains provide a number of :dfn:`object description directives`, used to
describe specific objects provided by modules.  Each directive requires one or
more signatures to provide basic information about what is being described, and
the content should be the description.

A domain will typically keep an internal index of all entities to aid
cross-referencing.
Typically it will also add entries in the shown general index.
If you want to suppress the addition of an entry in the shown index, you can
give the directive option flag ``:no-index-entry:``.
If you want to exclude the object description from the table of contents, you
can give the directive option flag ``:no-contents-entry:``.
If you want to typeset an object description, without even making it available
for cross-referencing, you can give the directive option flag ``:no-index:``
(which implies ``:no-index-entry:``).
If you do not want to typeset anything, you can give the directive option flag
``:no-typesetting:``.  This can for example be used to create only a target and
index entry for later reference.
Though, note that not every directive in every domain may support these
options.

.. versionadded:: 3.2
   The directive option ``noindexentry`` in the Python, C, C++, and Javascript
   domains.

.. versionadded:: 5.2.3
   The directive option ``:nocontentsentry:`` in the Python, C, C++, Javascript,
   and reStructuredText domains.

.. versionadded:: 7.2
   The directive option ``no-typesetting`` in the Python, C, C++, Javascript,
   and reStructuredText domains.

.. versionchanged:: 7.2

   *  The directive option ``:noindex:`` was renamed
      to ``:no-index:``.
   *  The directive option ``:noindexentry:`` was renamed
      to ``:no-index-entry:``.
   *  The directive option ``:nocontentsentry:`` was renamed
      to ``:no-contents-entry:``.

   The previous names are retained as aliases,
   but will be deprecated and removed
   in a future version of Sphinx.

An example using a Python domain directive::

   .. py:function:: spam(eggs)
                    ham(eggs)

      Spam or ham the foo.

This describes the two Python functions ``spam`` and ``ham``.  (Note that when
signatures become too long, you can break them if you add a backslash to lines
that are continued in the next line.  Example::

   .. py:function:: filterwarnings(action, message='', category=Warning, \
                                   module='', lineno=0, append=False)
      :no-index:

(This example also shows how to use the ``:no-index:`` flag.)

The domains also provide roles that link back to these object descriptions.
For example, to link to one of the functions described in the example above,
you could say ::

   The function :py:func:`spam` does a similar thing.

As you can see, both directive and role names contain the domain name and the
directive name.

The directive option ``:no-typesetting:`` can be used to create a target
(and index entry) which can later be referenced
by the roles provided by the domain.
This is particularly useful for literate programming:

.. code-block:: rst

   .. py:function:: spam(eggs)
      :no-typesetting:

   .. code::

      def spam(eggs):
          pass

   The function :py:func:`spam` does nothing.

.. rubric:: Default Domain

For documentation describing objects from solely one domain, authors will not
have to state again its name at each directive, role, etc... after
having specified a default. This can be done either via the config
value :confval:`primary_domain` or via this directive:

.. rst:directive:: .. default-domain:: name

   Select a new default domain.  While the :confval:`primary_domain` selects a
   global default, this only has an effect within the same file.

If no other default is selected, the Python domain (named ``py``) is the
default one, mostly for compatibility with documentation written for older
versions of Sphinx.

Directives and roles that belong to the default domain can be mentioned without
giving the domain name, i.e. ::

   .. function:: pyfunc()

      Describes a Python function.

   Reference to :func:`pyfunc`.

Cross-referencing syntax
~~~~~~~~~~~~~~~~~~~~~~~~

For cross-reference roles provided by domains, the same facilities exist as for
general cross-references.  See :ref:`xref-syntax`.

In short:

* You may supply an explicit title and reference target: ``:role:`title
  <target>``` will refer to *target*, but the link text will be *title*.

* If you prefix the content with ``!``, no reference/hyperlink will be created.

* If you prefix the content with ``~``, the link text will only be the last
  component of the target.  For example, ``:py:meth:`~Queue.Queue.get``` will
  refer to ``Queue.Queue.get`` but only display ``get`` as the link text.

.. _python-domain:

The Python Domain
-----------------

The Python domain (name **py**) provides the following directives for module
declarations:

.. rst:directive:: .. py:module:: name

   This directive marks the beginning of the description of a module (or package
   submodule, in which case the name should be fully qualified, including the
   package name).  A description of the module such as the docstring can be
   placed in the body of the directive.

   This directive will also cause an entry in the global module index.

   .. versionchanged:: 5.2

      Module directives support body content.

   .. rubric:: options

   .. rst:directive:option:: platform: platforms
      :type: comma separated list

      Indicate platforms which the module is available (if it is available on
      all platforms, the option should be omitted).  The keys are short
      identifiers; examples that are in use include "IRIX", "Mac", "Windows"
      and "Unix".  It is important to use a key which has already been used when
      applicable.

   .. rst:directive:option:: synopsis: purpose
      :type: text

      Consist of one sentence describing the module's purpose -- it is currently
      only used in the Global Module Index.

   .. rst:directive:option:: deprecated
      :type: no argument

      Mark a module as deprecated; it will be designated as such in various
      locations then.



.. rst:directive:: .. py:currentmodule:: name

   This directive tells Sphinx that the classes, functions etc. documented from
   here are in the given module (like :rst:dir:`py:module`), but it will not
   create index entries, an entry in the Global Module Index, or a link target
   for :rst:role:`py:mod`.  This is helpful in situations where documentation
   for things in a module is spread over multiple files or sections -- one
   location has the :rst:dir:`py:module` directive, the others only
   :rst:dir:`py:currentmodule`.

The following directives are provided for module and class contents:

.. rst:directive:: .. py:function:: name(parameters)
                   .. py:function:: name[type parameters](parameters)

   Describes a module-level function.
   The signature should include the parameters,
   together with optional type parameters,
   as given in the Python function definition, see :ref:`signatures`.
   For example::

      .. py:function:: Timer.repeat(repeat=3, number=1_000_000)
      .. py:function:: add[T](a: T, b: T) -> T

   For methods you should use :rst:dir:`py:method`.

   The description normally includes information about the parameters required
   and how they are used (especially whether mutable objects passed as
   parameters are modified), side effects, and possible exceptions.

   This information can (in any ``py`` directive) optionally be given in a
   structured form, see :ref:`info-field-lists`.

   .. rubric:: options

   .. rst:directive:option:: async
      :type: no value

      Indicate the function is an async function.

      .. versionadded:: 2.1

   .. rst:directive:option:: canonical
      :type: full qualified name including module name

      Describe the location where the object is defined if the object is
      imported from other modules

      .. versionadded:: 4.0

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the function's arguments will be emitted on a single logical
      line, overriding :confval:`python_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

   .. rst:directive:option:: single-line-type-parameter-list
      :type: no value

      Ensure that the function's type parameters are emitted on a single
      logical line, overriding :confval:`python_maximum_signature_line_length`
      and :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1


.. rst:directive:: .. py:data:: name

   Describes global data in a module, including both variables and values used
   as "defined constants."  Class and object attributes are not documented
   using this environment.

   .. rubric:: options

   .. rst:directive:option:: type: type of the variable
      :type: text

      .. versionadded:: 2.4

   .. rst:directive:option:: value: initial value of the variable
      :type: text

      .. versionadded:: 2.4

   .. rst:directive:option:: canonical
      :type: full qualified name including module name

      Describe the location where the object is defined if the object is
      imported from other modules

      .. versionadded:: 4.0

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

.. rst:directive:: .. py:exception:: name
                   .. py:exception:: name(parameters)
                   .. py:exception:: name[type parmeters](parameters)

   Describes an exception class.
   The signature can, but need not include parentheses with constructor arguments,
   or may optionally include type parameters (see :pep:`695`).

   .. rubric:: options

   .. rst:directive:option:: final
      :type: no value

      Indicate the class is a final class.

      .. versionadded:: 3.1

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      See :rst:dir:`py:class:single-line-parameter-list`.

      .. versionadded:: 7.1

   .. rst:directive:option:: single-line-type-parameter-list
      :type: no value

      See :rst:dir:`py:class:single-line-type-parameter-list`.

      .. versionadded:: 7.1

.. rst:directive:: .. py:class:: name
                   .. py:class:: name(parameters)
                   .. py:class:: name[type parmeters](parameters)

   Describes a class.
   The signature can optionally include type parameters (see :pep:`695`)
   or parentheses with parameters which will be shown as the constructor arguments.
   See also :ref:`signatures`.

   Methods and attributes belonging to the class should be placed in this
   directive's body.  If they are placed outside, the supplied name should
   contain the class name so that cross-references still work.  Example::

      .. py:class:: Foo

         .. py:method:: quux()

      -- or --

      .. py:class:: Bar

      .. py:method:: Bar.quux()

   The first way is the preferred one.

   .. rubric:: options

   .. rst:directive:option:: canonical
      :type: full qualified name including module name

      Describe the location where the object is defined if the object is
      imported from other modules

      .. versionadded:: 4.0

   .. rst:directive:option:: final
      :type: no value

      Indicate the class is a final class.

      .. versionadded:: 3.1

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the class constructor's arguments will be emitted on a single
      logical line, overriding :confval:`python_maximum_signature_line_length`
      and :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

   .. rst:directive:option:: single-line-type-parameter-list
      :type: no value

      Ensure that the class type parameters are emitted on a single logical
      line, overriding :confval:`python_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

.. rst:directive:: .. py:attribute:: name

   Describes an object data attribute.  The description should include
   information about the type of the data to be expected and whether it may be
   changed directly.

   .. rubric:: options

   .. rst:directive:option:: type: type of the attribute
      :type: text

      .. versionadded:: 2.4

   .. rst:directive:option:: value: initial value of the attribute
      :type: text

      .. versionadded:: 2.4

   .. rst:directive:option:: canonical
      :type: full qualified name including module name

      Describe the location where the object is defined if the object is
      imported from other modules

      .. versionadded:: 4.0

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

.. rst:directive:: .. py:property:: name

   Describes an object property.

   .. versionadded:: 4.0

   .. rubric:: options

   .. rst:directive:option:: abstractmethod
      :type: no value

      Indicate the property is abstract.

   .. rst:directive:option:: classmethod
      :type: no value

      Indicate the property is a classmethod.

      .. versionaddedd: 4.2

   .. rst:directive:option:: type: type of the property
      :type: text

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

.. rst:directive:: .. py:method:: name(parameters)
                   .. py:method:: name[type parameters](parameters)

   Describes an object method.  The parameters should not include the ``self``
   parameter.  The description should include similar information to that
   described for ``function``.  See also :ref:`signatures` and
   :ref:`info-field-lists`.

   .. rubric:: options

   .. rst:directive:option:: abstractmethod
      :type: no value

      Indicate the method is an abstract method.

      .. versionadded:: 2.1

   .. rst:directive:option:: async
      :type: no value

      Indicate the method is an async method.

      .. versionadded:: 2.1

   .. rst:directive:option:: canonical
      :type: full qualified name including module name

      Describe the location where the object is defined if the object is
      imported from other modules

      .. versionadded:: 4.0

   .. rst:directive:option:: classmethod
      :type: no value

      Indicate the method is a class method.

      .. versionadded:: 2.1

   .. rst:directive:option:: final
      :type: no value

      Indicate the class is a final method.

      .. versionadded:: 3.1

   .. rst::directive:option:: module
      :type: text

      Describe the location where the object is defined.  The default value is
      the module specified by :rst:dir:`py:currentmodule`.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the method's arguments will be emitted on a single logical
      line, overriding :confval:`python_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

   .. rst:directive:option:: single-line-type-parameter-list
      :type: no value

      Ensure that the method's type parameters are emitted on a single logical
      line, overriding :confval:`python_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.2

   .. rst:directive:option:: staticmethod
      :type: no value

      Indicate the method is a static method.

      .. versionadded:: 2.1


.. rst:directive:: .. py:staticmethod:: name(parameters)
                   .. py:staticmethod:: name[type parameters](parameters)

   Like :rst:dir:`py:method`, but indicates that the method is a static method.

   .. versionadded:: 0.4

.. rst:directive:: .. py:classmethod:: name(parameters)
                   .. py:classmethod:: name[type parameters](parameters)

   Like :rst:dir:`py:method`, but indicates that the method is a class method.

   .. versionadded:: 0.6

.. rst:directive:: .. py:decorator:: name
                   .. py:decorator:: name(parameters)
                   .. py:decorator:: name[type parameters](parameters)

   Describes a decorator function.  The signature should represent the usage as
   a decorator.  For example, given the functions

   .. code-block:: python

      def removename(func):
          func.__name__ = ''
          return func

      def setnewname(name):
          def decorator(func):
              func.__name__ = name
              return func
          return decorator

   the descriptions should look like this::

      .. py:decorator:: removename

         Remove name of the decorated function.

      .. py:decorator:: setnewname(name)

         Set name of the decorated function to *name*.

   (as opposed to ``.. py:decorator:: removename(func)``.)

   There is no ``py:deco`` role to link to a decorator that is marked up with
   this directive; rather, use the :rst:role:`py:func` role.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the decorator's arguments will be emitted on a single logical
      line, overriding :confval:`python_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

   .. rst:directive:option:: single-line-type-parameter-list
      :type: no value

      Ensure that the decorator's type parameters are emitted on a single
      logical line, overriding :confval:`python_maximum_signature_line_length`
      and :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.2

.. rst:directive:: .. py:decoratormethod:: name
                   .. py:decoratormethod:: name(signature)
                   .. py:decoratormethod:: name[type parameters](signature)

   Same as :rst:dir:`py:decorator`, but for decorators that are methods.

   Refer to a decorator method using the :rst:role:`py:meth` role.

.. _signatures:

Python Signatures
~~~~~~~~~~~~~~~~~

Signatures of functions, methods and class constructors can be given like they
would be written in Python.

Default values for optional arguments can be given (but if they contain commas,
they will confuse the signature parser).  Python 3-style argument annotations
can also be given as well as return type annotations::

   .. py:function:: compile(source : string, filename, symbol='file') -> ast object

For functions with optional parameters that don't have default values
(typically functions implemented in C extension modules without keyword
argument support), you can use brackets to specify the optional parts:

.. py:function:: compile(source[, filename[, symbol]])
   :no-index:

It is customary to put the opening bracket before the comma.

Python 3.12 introduced *type parameters*, which are type variables
declared directly  within the class or function definition:

.. code:: python

   class AnimalList[AnimalT](list[AnimalT]):
      ...

   def add[T](a: T, b: T) -> T:
      return a + b

The corresponding reStructuredText documentation would be:

.. code:: rst

   .. py:class:: AnimalList[AnimalT]

   .. py:function:: add[T](a: T, b: T) -> T

See :pep:`695` and :pep:`696` for details and the full specification.

.. _info-field-lists:

Info field lists
~~~~~~~~~~~~~~~~

.. versionadded:: 0.4
.. versionchanged:: 3.0

   meta fields are added.

Inside Python object description directives, reST field lists with these fields
are recognized and formatted nicely:

* ``param``, ``parameter``, ``arg``, ``argument``, ``key``, ``keyword``:
  Description of a parameter.
* ``type``: Type of a parameter.  Creates a link if possible.
* ``raises``, ``raise``, ``except``, ``exception``: That (and when) a specific
  exception is raised.
* ``var``, ``ivar``, ``cvar``: Description of a variable.
* ``vartype``: Type of a variable.  Creates a link if possible.
* ``returns``, ``return``: Description of the return value.
* ``rtype``: Return type.  Creates a link if possible.
* ``meta``: Add metadata to description of the python object.  The metadata will
  not be shown on output document.  For example, ``:meta private:`` indicates
  the python object is private member.  It is used in
  :py:mod:`sphinx.ext.autodoc` for filtering members.

.. note::

   In current release, all ``var``, ``ivar`` and ``cvar`` are represented as
   "Variable".  There is no difference at all.

The field names must consist of one of these keywords and an argument (except
for ``returns`` and ``rtype``, which do not need an argument).  This is best
explained by an example::

   .. py:function:: send_message(sender, recipient, message_body, [priority=1])

      Send a message to a recipient

      :param str sender: The person sending the message
      :param str recipient: The recipient of the message
      :param str message_body: The body of the message
      :param priority: The priority of the message, can be a number 1-5
      :type priority: integer or None
      :return: the message id
      :rtype: int
      :raises ValueError: if the message_body exceeds 160 characters
      :raises TypeError: if the message_body is not a basestring

This will render like this:

.. py:function:: send_message(sender, recipient, message_body, [priority=1])
   :no-index:

   Send a message to a recipient

   :param str sender: The person sending the message
   :param str recipient: The recipient of the message
   :param str message_body: The body of the message
   :param priority: The priority of the message, can be a number 1-5
   :type priority: int or None
   :return: the message id
   :rtype: int
   :raises ValueError: if the message_body exceeds 160 characters
   :raises TypeError: if the message_body is not a basestring

It is also possible to combine parameter type and description, if the type is a
single word, like this::

   :param int priority: The priority of the message, can be a number 1-5

.. versionadded:: 1.5

Container types such as lists and dictionaries can be linked automatically
using the following syntax::

   :type priorities: list(int)
   :type priorities: list[int]
   :type mapping: dict(str, int)
   :type mapping: dict[str, int]
   :type point: tuple(float, float)
   :type point: tuple[float, float]

Multiple types in a type field will be linked automatically if separated by the
word "or"::

   :type an_arg: int or None
   :vartype a_var: str or int
   :rtype: float or str

.. _python-roles:

Cross-referencing Python objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following roles refer to objects in modules and are possibly hyperlinked if
a matching identifier is found:

.. rst:role:: py:mod

   Reference a module; a dotted name may be used.  This should also be used for
   package names.

.. rst:role:: py:func

   Reference a Python function; dotted names may be used.  The role text needs
   not include trailing parentheses to enhance readability; they will be added
   automatically by Sphinx if the :confval:`add_function_parentheses` config
   value is ``True`` (the default).

.. rst:role:: py:data

   Reference a module-level variable.

.. rst:role:: py:const

   Reference a "defined" constant.  This may be a Python variable that is not
   intended to be changed.

.. rst:role:: py:class

   Reference a class; a dotted name may be used.

.. rst:role:: py:meth

   Reference a method of an object.  The role text can include the type name
   and the method name; if it occurs within the description of a type, the type
   name can be omitted.  A dotted name may be used.

.. rst:role:: py:attr

   Reference a data attribute of an object.

   .. note:: The role is also able to refer to property.

.. rst:role:: py:exc

   Reference an exception.  A dotted name may be used.

.. rst:role:: py:obj

   Reference an object of unspecified type.  Useful e.g. as the
   :confval:`default_role`.

   .. versionadded:: 0.4

The name enclosed in this markup can include a module name and/or a class name.
For example, ``:py:func:`filter``` could refer to a function named ``filter``
in the current module, or the built-in function of that name.  In contrast,
``:py:func:`foo.filter``` clearly refers to the ``filter`` function in the
``foo`` module.

Normally, names in these roles are searched first without any further
qualification, then with the current module name prepended, then with the
current module and class name (if any) prepended.  If you prefix the name with
a dot, this order is reversed.  For example, in the documentation of Python's
:mod:`codecs` module, ``:py:func:`open``` always refers to the built-in
function, while ``:py:func:`.open``` refers to :func:`codecs.open`.

A similar heuristic is used to determine whether the name is an attribute of
the currently documented class.

Also, if the name is prefixed with a dot, and no exact match is found, the
target is taken as a suffix and all object names with that suffix are searched.
For example, ``:py:meth:`.TarFile.close``` references the
``tarfile.TarFile.close()`` function, even if the current module is not
``tarfile``.  Since this can get ambiguous, if there is more than one possible
match, you will get a warning from Sphinx.

Note that you can combine the ``~`` and ``.`` prefixes:
``:py:meth:`~.TarFile.close``` will reference the ``tarfile.TarFile.close()``
method, but the visible link caption will only be ``close()``.


.. _c-domain:

The C Domain
------------

The C domain (name **c**) is suited for documentation of C API.

.. rst:directive:: .. c:member:: declaration
                   .. c:var:: declaration

   Describes a C struct member or variable. Example signature::

      .. c:member:: PyObject *PyTypeObject.tp_bases

   The difference between the two directives is only cosmetic.

.. rst:directive:: .. c:function:: function prototype

   Describes a C function. The signature should be given as in C, e.g.::

      .. c:function:: PyObject *PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)

   Note that you don't have to backslash-escape asterisks in the signature, as
   it is not parsed by the reST inliner.

   In the description of a function you can use the following info fields
   (see also :ref:`info-field-lists`).

   * ``param``, ``parameter``, ``arg``, ``argument``,
     Description of a parameter.
   * ``type``: Type of a parameter,
     written as if passed to the :rst:role:`c:expr` role.
   * ``returns``, ``return``: Description of the return value.
   * ``rtype``: Return type,
     written as if passed to the :rst:role:`c:expr` role.
   * ``retval``, ``retvals``: An alternative to ``returns`` for describing
     the result of the function.

   .. versionadded:: 4.3
      The ``retval`` field type.

   For example::

      .. c:function:: PyObject *PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)

         :param type: description of the first parameter.
         :param nitems: description of the second parameter.
         :returns: a result.
         :retval NULL: under some conditions.
         :retval NULL: under some other conditions as well.

   which renders as

   .. c:function:: PyObject *PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)

      ..
         ** for some editors (e.g., vim) to stop bold-highlighting the source

      :param type: description of the first parameter.
      :param nitems: description of the second parameter.
      :returns: a result.
      :retval NULL: under some conditions.
      :retval NULL: under some other conditions as well.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the function's parameters will be emitted on a single logical
      line, overriding :confval:`c_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1


.. rst:directive:: .. c:macro:: name
                   .. c:macro:: name(arg list)

   Describes a C macro, i.e., a C-language ``#define``, without the replacement
   text.

   In the description of a macro you can use the same info fields as for the
   :rst:dir:`c:function` directive.

   .. versionadded:: 3.0
      The function style variant.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the macro's parameters will be emitted on a single logical
      line, overriding :confval:`c_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

.. rst:directive:: .. c:struct:: name

   Describes a C struct.

   .. versionadded:: 3.0

.. rst:directive:: .. c:union:: name

   Describes a C union.

   .. versionadded:: 3.0

.. rst:directive:: .. c:enum:: name

   Describes a C enum.

   .. versionadded:: 3.0

.. rst:directive:: .. c:enumerator:: name

   Describes a C enumerator.

   .. versionadded:: 3.0

.. rst:directive:: .. c:type:: typedef-like declaration
                   .. c:type:: name

   Describes a C type, either as a typedef, or the alias for an unspecified
   type.

.. _c-roles:

Cross-referencing C constructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following roles create cross-references to C-language constructs if they
are defined in the documentation:

.. rst:role:: c:member
              c:data
              c:var
              c:func
              c:macro
              c:struct
              c:union
              c:enum
              c:enumerator
              c:type

   Reference a C declaration, as defined above.
   Note that :rst:role:`c:member`, :rst:role:`c:data`, and
   :rst:role:`c:var` are equivalent.

   .. versionadded:: 3.0
      The var, struct, union, enum, and enumerator roles.


Anonymous Entities
~~~~~~~~~~~~~~~~~~

C supports anonymous structs, enums, and unions.
For the sake of documentation they must be given some name that starts with
``@``, e.g., ``@42`` or ``@data``.
These names can also be used in cross-references,
though nested symbols will be found even when omitted.
The ``@...`` name will always be rendered as **[anonymous]** (possibly as a
link).

Example::

   .. c:struct:: Data

      .. c:union:: @data

         .. c:var:: int a

         .. c:var:: double b

   Explicit ref: :c:var:`Data.@data.a`. Short-hand ref: :c:var:`Data.a`.

This will be rendered as:

.. c:struct:: Data
   :no-contents-entry:
   :no-index-entry:

   .. c:union:: @data
      :no-contents-entry:
      :no-index-entry:

      .. c:var:: int a
         :no-contents-entry:
         :no-index-entry:

      .. c:var:: double b
         :no-contents-entry:
         :no-index-entry:

Explicit ref: :c:var:`Data.@data.a`. Short-hand ref: :c:var:`Data.a`.

.. versionadded:: 3.0


Aliasing Declarations
~~~~~~~~~~~~~~~~~~~~~

.. c:namespace-push:: @alias

Sometimes it may be helpful list declarations elsewhere than their main
documentation, e.g., when creating a synopsis of an interface.
The following directive can be used for this purpose.

.. rst:directive:: .. c:alias:: name

   Insert one or more alias declarations. Each entity can be specified
   as they can in the :rst:role:`c:any` role.

   For example::

       .. c:var:: int data
       .. c:function:: int f(double k)

       .. c:alias:: data
                    f

   becomes

   .. c:var:: int data
   .. c:function:: int f(double k)

   .. c:alias:: data
                f

   .. versionadded:: 3.2


   .. rubric:: Options

   .. rst:directive:option:: maxdepth: int

      Insert nested declarations as well, up to the total depth given.
      Use 0 for infinite depth and 1 for just the mentioned declaration.
      Defaults to 1.

      .. versionadded:: 3.3

   .. rst:directive:option:: noroot

      Skip the mentioned declarations and only render nested declarations.
      Requires ``maxdepth`` either 0 or at least 2.

      .. versionadded:: 3.5


.. c:namespace-pop::


Inline Expressions and Types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. rst:role:: c:expr
              c:texpr

   Insert a C expression or type either as inline code (``cpp:expr``)
   or inline text (``cpp:texpr``). For example::

      .. c:var:: int a = 42

      .. c:function:: int f(int i)

      An expression: :c:expr:`a * f(a)` (or as text: :c:texpr:`a * f(a)`).

      A type: :c:expr:`const Data*`
      (or as text :c:texpr:`const Data*`).

   will be rendered as follows:

   .. c:var:: int a = 42
      :no-contents-entry:
      :no-index-entry:

   .. c:function:: int f(int i)
      :no-contents-entry:
      :no-index-entry:

   An expression: :c:expr:`a * f(a)` (or as text: :c:texpr:`a * f(a)`).

   A type: :c:expr:`const Data*`
   (or as text :c:texpr:`const Data*`).

   .. versionadded:: 3.0


Namespacing
~~~~~~~~~~~

.. versionadded:: 3.1

The C language it self does not support namespacing, but it can sometimes be
useful to emulate it in documentation, e.g., to show alternate declarations.
The feature may also be used to document members of structs/unions/enums
separate from their parent declaration.

The current scope can be changed using three namespace directives.  They manage
a stack declarations where ``c:namespace`` resets the stack and changes a given
scope.

The ``c:namespace-push`` directive changes the scope to a given inner scope
of the current one.

The ``c:namespace-pop`` directive undoes the most recent
``c:namespace-push`` directive.

.. rst:directive:: .. c:namespace:: scope specification

   Changes the current scope for the subsequent objects to the given scope, and
   resets the namespace directive stack. Note that nested scopes can be
   specified by separating with a dot, e.g.::

      .. c:namespace:: Namespace1.Namespace2.SomeStruct.AnInnerStruct

   All subsequent objects will be defined as if their name were declared with
   the scope prepended. The subsequent cross-references will be searched for
   starting in the current scope.

   Using ``NULL`` or ``0`` as the scope will change to global scope.

.. rst:directive:: .. c:namespace-push:: scope specification

   Change the scope relatively to the current scope. For example, after::

      .. c:namespace:: A.B

      .. c:namespace-push:: C.D

   the current scope will be ``A.B.C.D``.

.. rst:directive:: .. c:namespace-pop::

   Undo the previous ``c:namespace-push`` directive (*not* just pop a scope).
   For example, after::

      .. c:namespace:: A.B

      .. c:namespace-push:: C.D

      .. c:namespace-pop::

   the current scope will be ``A.B`` (*not* ``A.B.C``).

   If no previous ``c:namespace-push`` directive has been used, but only a
   ``c:namespace`` directive, then the current scope will be reset to global
   scope.  That is, ``.. c:namespace:: A.B`` is equivalent to::

      .. c:namespace:: NULL

      .. c:namespace-push:: A.B

Configuration Variables
~~~~~~~~~~~~~~~~~~~~~~~

See :ref:`c-config`.


.. _cpp-domain:

The C++ Domain
--------------

The C++ domain (name **cpp**) supports documenting C++ projects.

Directives for Declaring Entities
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following directives are available. All declarations can start with a
visibility statement (``public``, ``private`` or ``protected``).

.. rst:directive:: .. cpp:class:: class specifier
                   .. cpp:struct:: class specifier

   Describe a class/struct, possibly with specification of inheritance, e.g.,::

      .. cpp:class:: MyClass : public MyBase, MyOtherBase

   The difference between :rst:dir:`cpp:class` and :rst:dir:`cpp:struct` is
   only cosmetic: the prefix rendered in the output, and the specifier shown
   in the index.

   The class can be directly declared inside a nested scope, e.g.,::

      .. cpp:class:: OuterScope::MyClass : public MyBase, MyOtherBase

   A class template can be declared::

      .. cpp:class:: template<typename T, std::size_t N> std::array

   or with a line break::

      .. cpp:class:: template<typename T, std::size_t N> \
                     std::array

   Full and partial template specialisations can be declared::

      .. cpp:class:: template<> \
                     std::array<bool, 256>

      .. cpp:class:: template<typename T> \
                     std::array<T, 42>

   .. versionadded:: 2.0
      The :rst:dir:`cpp:struct` directive.

.. rst:directive:: .. cpp:function:: (member) function prototype

   Describe a function or member function, e.g.,::

      .. cpp:function:: bool myMethod(int arg1, std::string arg2)

         A function with parameters and types.

      .. cpp:function:: bool myMethod(int, double)

         A function with unnamed parameters.

      .. cpp:function:: const T &MyClass::operator[](std::size_t i) const

         An overload for the indexing operator.

      .. cpp:function:: operator bool() const

         A casting operator.

      .. cpp:function:: constexpr void foo(std::string &bar[2]) noexcept

         A constexpr function.

      .. cpp:function:: MyClass::MyClass(const MyClass&) = default

         A copy constructor with default implementation.

   Function templates can also be described::

      .. cpp:function:: template<typename U> \
                        void print(U &&u)

   and function template specialisations::

      .. cpp:function:: template<> \
                        void print(int i)

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the function's parameters will be emitted on a single logical
      line, overriding :confval:`cpp_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

.. rst:directive:: .. cpp:member:: (member) variable declaration
                   .. cpp:var:: (member) variable declaration

   Describe a variable or member variable, e.g.,::

      .. cpp:member:: std::string MyClass::myMember

      .. cpp:var:: std::string MyClass::myOtherMember[N][M]

      .. cpp:member:: int a = 42

   Variable templates can also be described::

      .. cpp:member:: template<class T> \
                      constexpr T pi = T(3.1415926535897932385)

.. rst:directive:: .. cpp:type:: typedef declaration
                   .. cpp:type:: name
                   .. cpp:type:: type alias declaration

   Describe a type as in a typedef declaration, a type alias declaration, or
   simply the name of a type with unspecified type, e.g.,::

      .. cpp:type:: std::vector<int> MyList

         A typedef-like declaration of a type.

      .. cpp:type:: MyContainer::const_iterator

         Declaration of a type alias with unspecified type.

      .. cpp:type:: MyType = std::unordered_map<int, std::string>

         Declaration of a type alias.

   A type alias can also be templated::

      .. cpp:type:: template<typename T> \
                    MyContainer = std::vector<T>

   The example are rendered as follows.

   .. cpp:type:: std::vector<int> MyList
      :no-contents-entry:
      :no-index-entry:

      A typedef-like declaration of a type.

   .. cpp:type:: MyContainer::const_iterator
      :no-contents-entry:
      :no-index-entry:

      Declaration of a type alias with unspecified type.

   .. cpp:type:: MyType = std::unordered_map<int, std::string>
      :no-contents-entry:
      :no-index-entry:

      Declaration of a type alias.

   .. cpp:type:: template<typename T> \
                 MyContainer = std::vector<T>
      :no-contents-entry:
      :no-index-entry:

.. rst:directive:: .. cpp:enum:: unscoped enum declaration
                   .. cpp:enum-struct:: scoped enum declaration
                   .. cpp:enum-class:: scoped enum declaration

   Describe a (scoped) enum, possibly with the underlying type specified.  Any
   enumerators declared inside an unscoped enum will be declared both in the
   enum scope and in the parent scope.  Examples::

      .. cpp:enum:: MyEnum

         An unscoped enum.

      .. cpp:enum:: MySpecificEnum : long

         An unscoped enum with specified underlying type.

      .. cpp:enum-class:: MyScopedEnum

         A scoped enum.

      .. cpp:enum-struct:: protected MyScopedVisibilityEnum : std::underlying_type<MySpecificEnum>::type

         A scoped enum with non-default visibility, and with a specified
         underlying type.

.. rst:directive:: .. cpp:enumerator:: name
                   .. cpp:enumerator:: name = constant

   Describe an enumerator, optionally with its value defined, e.g.,::

      .. cpp:enumerator:: MyEnum::myEnumerator

      .. cpp:enumerator:: MyEnum::myOtherEnumerator = 42

.. rst:directive:: .. cpp:union:: name

   Describe a union.

   .. versionadded:: 1.8

.. rst:directive:: .. cpp:concept:: template-parameter-list name

   .. warning:: The support for concepts is experimental. It is based on the
      current draft standard and the Concepts Technical Specification.
      The features may change as they evolve.

   Describe a concept. It must have exactly 1 template parameter list. The name
   may be a nested name. Example::

      .. cpp:concept:: template<typename It> std::Iterator

         Proxy to an element of a notional sequence that can be compared,
         indirected, or incremented.

         **Notation**

         .. cpp:var:: It r

            An lvalue.

         **Valid Expressions**

         - :cpp:expr:`*r`, when :cpp:expr:`r` is dereferenceable.
         - :cpp:expr:`++r`, with return type :cpp:expr:`It&`, when
           :cpp:expr:`r` is incrementable.

   This will render as follows:

   .. cpp:concept:: template<typename It> std::Iterator

      Proxy to an element of a notional sequence that can be compared,
      indirected, or incremented.

      **Notation**

      .. cpp:var:: It r

         An lvalue.

      **Valid Expressions**

      - :cpp:expr:`*r`, when :cpp:expr:`r` is dereferenceable.
      - :cpp:expr:`++r`, with return type :cpp:expr:`It&`, when :cpp:expr:`r`
        is incrementable.

   .. versionadded:: 1.5


Options
^^^^^^^

Some directives support options:

- ``:no-index-entry:`` and ``:no-contents-entry:``, see :ref:`basic-domain-markup`.
- ``:tparam-line-spec:``, for templated declarations.
  If specified, each template parameter will be rendered on a separate line.

  .. versionadded:: 1.6

Anonymous Entities
~~~~~~~~~~~~~~~~~~

C++ supports anonymous namespaces, classes, enums, and unions.
For the sake of documentation they must be given some name that starts with
``@``, e.g., ``@42`` or ``@data``.
These names can also be used in cross-references and (type) expressions,
though nested symbols will be found even when omitted.
The ``@...`` name will always be rendered as **[anonymous]** (possibly as a
link).

Example::

   .. cpp:class:: Data

      .. cpp:union:: @data

         .. cpp:var:: int a

         .. cpp:var:: double b

   Explicit ref: :cpp:var:`Data::@data::a`. Short-hand ref: :cpp:var:`Data::a`.

This will be rendered as:

.. cpp:class:: Data
   :no-contents-entry:
   :no-index-entry:

   .. cpp:union:: @data
      :no-contents-entry:
      :no-index-entry:

      .. cpp:var:: int a
         :no-contents-entry:
         :no-index-entry:

      .. cpp:var:: double b
         :no-contents-entry:
         :no-index-entry:

Explicit ref: :cpp:var:`Data::@data::a`. Short-hand ref: :cpp:var:`Data::a`.

.. versionadded:: 1.8


Aliasing Declarations
~~~~~~~~~~~~~~~~~~~~~

Sometimes it may be helpful list declarations elsewhere than their main
documentation, e.g., when creating a synopsis of a class interface.
The following directive can be used for this purpose.

.. rst:directive:: .. cpp:alias:: name or function signature

   Insert one or more alias declarations. Each entity can be specified
   as they can in the :rst:role:`cpp:any` role.
   If the name of a function is given (as opposed to the complete signature),
   then all overloads of the function will be listed.

   For example::

       .. cpp:alias:: Data::a
                      overload_example::C::f

   becomes

   .. cpp:alias:: Data::a
                  overload_example::C::f

   whereas::

       .. cpp:alias:: void overload_example::C::f(double d) const
                      void overload_example::C::f(double d)

   becomes

   .. cpp:alias:: void overload_example::C::f(double d) const
                  void overload_example::C::f(double d)

   .. versionadded:: 2.0


   .. rubric:: Options

   .. rst:directive:option:: maxdepth: int

      Insert nested declarations as well, up to the total depth given.
      Use 0 for infinite depth and 1 for just the mentioned declaration.
      Defaults to 1.

      .. versionadded:: 3.5

   .. rst:directive:option:: noroot

      Skip the mentioned declarations and only render nested declarations.
      Requires ``maxdepth`` either 0 or at least 2.

      .. versionadded:: 3.5


Constrained Templates
~~~~~~~~~~~~~~~~~~~~~

.. warning:: The support for concepts is experimental. It is based on the
  current draft standard and the Concepts Technical Specification.
  The features may change as they evolve.

.. note:: Sphinx does not currently support ``requires`` clauses.

Placeholders
^^^^^^^^^^^^

Declarations may use the name of a concept to introduce constrained template
parameters, or the keyword ``auto`` to introduce unconstrained template
parameters::

   .. cpp:function:: void f(auto &&arg)

      A function template with a single unconstrained template parameter.

   .. cpp:function:: void f(std::Iterator it)

      A function template with a single template parameter, constrained by the
      Iterator concept.

Template Introductions
^^^^^^^^^^^^^^^^^^^^^^

Simple constrained function or class templates can be declared with a `template
introduction` instead of a template parameter list::

   .. cpp:function:: std::Iterator{It} void advance(It &it)

       A function template with a template parameter constrained to be an
       Iterator.

   .. cpp:class:: std::LessThanComparable{T} MySortedContainer

       A class template with a template parameter constrained to be
       LessThanComparable.

They are rendered as follows.

.. cpp:function:: std::Iterator{It} void advance(It &it)
   :no-contents-entry:
   :no-index-entry:

   A function template with a template parameter constrained to be an Iterator.

.. cpp:class:: std::LessThanComparable{T} MySortedContainer
   :no-contents-entry:
   :no-index-entry:

   A class template with a template parameter constrained to be
   LessThanComparable.

Note however that no checking is performed with respect to parameter
compatibility. E.g., ``Iterator{A, B, C}`` will be accepted as an introduction
even though it would not be valid C++.

Inline Expressions and Types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. rst:role:: cpp:expr
              cpp:texpr

   Insert a C++ expression or type either as inline code (``cpp:expr``)
   or inline text (``cpp:texpr``). For example::

      .. cpp:var:: int a = 42

      .. cpp:function:: int f(int i)

      An expression: :cpp:expr:`a * f(a)` (or as text: :cpp:texpr:`a * f(a)`).

      A type: :cpp:expr:`const MySortedContainer<int>&`
      (or as text :cpp:texpr:`const MySortedContainer<int>&`).

   will be rendered as follows:

   .. cpp:var:: int a = 42
      :no-contents-entry:
      :no-index-entry:

   .. cpp:function:: int f(int i)
      :no-contents-entry:
      :no-index-entry:

   An expression: :cpp:expr:`a * f(a)` (or as text: :cpp:texpr:`a * f(a)`).

   A type: :cpp:expr:`const MySortedContainer<int>&`
   (or as text :cpp:texpr:`const MySortedContainer<int>&`).

   .. versionadded:: 1.7
      The :rst:role:`cpp:expr` role.

   .. versionadded:: 1.8
      The :rst:role:`cpp:texpr` role.

Namespacing
~~~~~~~~~~~

Declarations in the C++ domain are as default placed in global scope.  The
current scope can be changed using three namespace directives.  They manage a
stack declarations where ``cpp:namespace`` resets the stack and changes a given
scope.

The ``cpp:namespace-push`` directive changes the scope to a given inner scope
of the current one.

The ``cpp:namespace-pop`` directive undoes the most recent
``cpp:namespace-push`` directive.

.. rst:directive:: .. cpp:namespace:: scope specification

   Changes the current scope for the subsequent objects to the given scope, and
   resets the namespace directive stack.  Note that the namespace does not need
   to correspond to C++ namespaces, but can end in names of classes, e.g.,::

      .. cpp:namespace:: Namespace1::Namespace2::SomeClass::AnInnerClass

   All subsequent objects will be defined as if their name were declared with
   the scope prepended. The subsequent cross-references will be searched for
   starting in the current scope.

   Using ``NULL``, ``0``, or ``nullptr`` as the scope will change to global
   scope.

   A namespace declaration can also be templated, e.g.,::

      .. cpp:class:: template<typename T> \
                     std::vector

      .. cpp:namespace:: template<typename T> std::vector

      .. cpp:function:: std::size_t size() const

   declares ``size`` as a member function of the class template
   ``std::vector``.  Equivalently this could have been declared using::

      .. cpp:class:: template<typename T> \
                     std::vector

         .. cpp:function:: std::size_t size() const

   or::

      .. cpp:class:: template<typename T> \
                     std::vector

.. rst:directive:: .. cpp:namespace-push:: scope specification

   Change the scope relatively to the current scope. For example, after::

      .. cpp:namespace:: A::B

      .. cpp:namespace-push:: C::D

   the current scope will be ``A::B::C::D``.

   .. versionadded:: 1.4

.. rst:directive:: .. cpp:namespace-pop::

   Undo the previous ``cpp:namespace-push`` directive (*not* just pop a scope).
   For example, after::

      .. cpp:namespace:: A::B

      .. cpp:namespace-push:: C::D

      .. cpp:namespace-pop::

   the current scope will be ``A::B`` (*not* ``A::B::C``).

   If no previous ``cpp:namespace-push`` directive has been used, but only a
   ``cpp:namespace`` directive, then the current scope will be reset to global
   scope.  That is, ``.. cpp:namespace:: A::B`` is equivalent to::

      .. cpp:namespace:: nullptr

      .. cpp:namespace-push:: A::B

   .. versionadded:: 1.4

Info field lists
~~~~~~~~~~~~~~~~~

All the C++ directives for declaring entities support the following
info fields (see also :ref:`info-field-lists`):

* ``tparam``: Description of a template parameter.

The :rst:dir:`cpp:function` directive additionally supports the
following fields:

* ``param``, ``parameter``, ``arg``, ``argument``: Description of a parameter.
* ``returns``, ``return``: Description of a return value.
* ``retval``, ``retvals``: An alternative to ``returns`` for describing
  the result of the function.
* `throws`, `throw`, `exception`: Description of a possibly thrown exception.

.. versionadded:: 4.3
   The ``retval`` field type.

.. _cpp-roles:

Cross-referencing
~~~~~~~~~~~~~~~~~

These roles link to the given declaration types:

.. rst:role:: cpp:any
              cpp:class
              cpp:struct
              cpp:func
              cpp:member
              cpp:var
              cpp:type
              cpp:concept
              cpp:enum
              cpp:enumerator

   Reference a C++ declaration by name (see below for details).  The name must
   be properly qualified relative to the position of the link.

   .. versionadded:: 2.0
      The :rst:role:`cpp:struct` role as alias for the :rst:role:`cpp:class`
      role.

.. admonition:: Note on References with Templates Parameters/Arguments

   These roles follow the Sphinx :ref:`xref-syntax` rules. This means care must
   be taken when referencing a (partial) template specialization, e.g. if the
   link looks like this: ``:cpp:class:`MyClass<int>```.
   This is interpreted as a link to ``int`` with a title of ``MyClass``.
   In this case, escape the opening angle bracket with a backslash,
   like this: ``:cpp:class:`MyClass\<int>```.

   When a custom title is not needed it may be useful to use the roles for
   inline expressions, :rst:role:`cpp:expr` and :rst:role:`cpp:texpr`, where
   angle brackets do not need escaping.

Declarations without template parameters and template arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For linking to non-templated declarations the name must be a nested name, e.g.,
``f`` or ``MyClass::f``.


Overloaded (member) functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When a (member) function is referenced using just its name, the reference
will point to an arbitrary matching overload.
The :rst:role:`cpp:any` and :rst:role:`cpp:func` roles use an alternative
format, which simply is a complete function declaration.
This will resolve to the exact matching overload.
As example, consider the following class declaration:

.. cpp:namespace-push:: overload_example
.. cpp:class:: C

   .. cpp:function:: void f(double d) const
   .. cpp:function:: void f(double d)
   .. cpp:function:: void f(int i)
   .. cpp:function:: void f()

References using the :rst:role:`cpp:func` role:

- Arbitrary overload: ``C::f``, :cpp:func:`C::f`
- Also arbitrary overload: ``C::f()``, :cpp:func:`C::f()`
- Specific overload: ``void C::f()``, :cpp:func:`void C::f()`
- Specific overload: ``void C::f(int)``, :cpp:func:`void C::f(int)`
- Specific overload: ``void C::f(double)``, :cpp:func:`void C::f(double)`
- Specific overload: ``void C::f(double) const``,
  :cpp:func:`void C::f(double) const`

Note that the :confval:`add_function_parentheses` configuration variable
does not influence specific overload references.

.. cpp:namespace-pop::


Templated declarations
^^^^^^^^^^^^^^^^^^^^^^

Assume the following declarations.

.. cpp:class:: Wrapper

   .. cpp:class:: template<typename TOuter> \
                  Outer

      .. cpp:class:: template<typename TInner> \
                     Inner

In general the reference must include the template parameter declarations,
and template arguments for the prefix of qualified names. For example:

- ``template\<typename TOuter> Wrapper::Outer``
  (:cpp:class:`template\<typename TOuter> Wrapper::Outer`)
- ``template\<typename TOuter> template\<typename TInner> Wrapper::Outer<TOuter>::Inner``
  (:cpp:class:`template\<typename TOuter> template\<typename TInner> Wrapper::Outer<TOuter>::Inner`)

Currently the lookup only succeed if the template parameter identifiers are
equal strings.  That is, ``template\<typename UOuter> Wrapper::Outer`` will not
work.

As a shorthand notation, if a template parameter list is omitted,
then the lookup will assume either a primary template or a non-template,
but not a partial template specialisation.
This means the following references work as well:

- ``Wrapper::Outer``
  (:cpp:class:`Wrapper::Outer`)
- ``Wrapper::Outer::Inner``
  (:cpp:class:`Wrapper::Outer::Inner`)
- ``template\<typename TInner> Wrapper::Outer::Inner``
  (:cpp:class:`template\<typename TInner> Wrapper::Outer::Inner`)

(Full) Template Specialisations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Assume the following declarations.

.. cpp:class:: template<typename TOuter> \
               Outer

  .. cpp:class:: template<typename TInner> \
                 Inner

.. cpp:class:: template<> \
               Outer<int>

  .. cpp:class:: template<typename TInner> \
                 Inner

  .. cpp:class:: template<> \
                 Inner<bool>

In general the reference must include a template parameter list for each
template argument list.  The full specialisation above can therefore be
referenced with ``template\<> Outer\<int>`` (:cpp:class:`template\<>
Outer\<int>`) and ``template\<> template\<> Outer\<int>::Inner\<bool>``
(:cpp:class:`template\<> template\<> Outer\<int>::Inner\<bool>`).  As a
shorthand the empty template parameter list can be omitted, e.g.,
``Outer\<int>`` (:cpp:class:`Outer\<int>`) and ``Outer\<int>::Inner\<bool>``
(:cpp:class:`Outer\<int>::Inner\<bool>`).

Partial Template Specialisations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Assume the following declaration.

.. cpp:class:: template<typename T> \
               Outer<T*>

References to partial specialisations must always include the template
parameter lists, e.g., ``template\<typename T> Outer\<T*>``
(:cpp:class:`template\<typename T> Outer\<T*>`).  Currently the lookup only
succeed if the template parameter identifiers are equal strings.

Configuration Variables
~~~~~~~~~~~~~~~~~~~~~~~

See :ref:`cpp-config`.

.. _domains-std:

The Standard Domain
-------------------

The so-called "standard" domain collects all markup that doesn't warrant a
domain of its own.  Its directives and roles are not prefixed with a domain
name.

The standard domain is also where custom object descriptions, added using the
:func:`~sphinx.application.Sphinx.add_object_type` API, are placed.

There is a set of directives allowing documenting command-line programs:

.. rst:directive:: .. option:: name args, name args, ...

   Describes a command line argument or switch.  Option argument names should
   be enclosed in angle brackets.  Examples::

      .. option:: dest_dir

         Destination directory.

      .. option:: -m <module>, --module <module>

         Run a module as a script.

   The directive will create cross-reference targets for the given options,
   referenceable by :rst:role:`option` (in the example case, you'd use something
   like ``:option:`dest_dir```, ``:option:`-m```, or ``:option:`--module```).

   .. versionchanged:: 5.3

      One can cross-reference including an option value: ``:option:`--module=foobar```,
      ,``:option:`--module[=foobar]``` or ``:option:`--module foobar```.

   Use :confval:`option_emphasise_placeholders` for parsing of
   "variable part" of a literal text (similarly to the :rst:role:`samp` role).

   ``cmdoption`` directive is a deprecated alias for the ``option`` directive.

.. rst:directive:: .. envvar:: name

   Describes an environment variable that the documented code or program uses
   or defines.  Referenceable by :rst:role:`envvar`.

.. rst:directive:: .. program:: name

   Like :rst:dir:`py:currentmodule`, this directive produces no output.
   Instead, it serves to notify Sphinx that all following :rst:dir:`option`
   directives document options for the program called *name*.

   If you use :rst:dir:`program`, you have to qualify the references in your
   :rst:role:`option` roles by the program name, so if you have the following
   situation ::

      .. program:: rm

      .. option:: -r

         Work recursively.

      .. program:: svn

      .. option:: -r <revision>

         Specify the revision to work upon.

   then ``:option:`rm -r``` would refer to the first option, while
   ``:option:`svn -r``` would refer to the second one.

   If ``None`` is passed to the argument, the directive will reset the
   current program name.

   The program name may contain spaces (in case you want to document
   subcommands like ``svn add`` and ``svn commit`` separately).

   .. versionadded:: 0.5

There is also a very generic object description directive, which is not tied to
any domain:

.. rst:directive:: .. describe:: text
               .. object:: text

   This directive produces the same formatting as the specific ones provided by
   domains, but does not create index entries or cross-referencing targets.
   Example::

      .. describe:: PAPER

         You can set this variable to select a paper size.


The JavaScript Domain
---------------------

The JavaScript domain (name **js**) provides the following directives:

.. rst:directive:: .. js:module:: name

   This directive sets the module name for object declarations that follow
   after. The module name is used in the global module index and in cross
   references. This directive does not create an object heading like
   :rst:dir:`py:class` would, for example.

   By default, this directive will create a linkable entity and will cause an
   entry in the global module index, unless the ``no-index`` option is
   specified.  If this option is specified, the directive will only update the
   current module name.

   .. versionadded:: 1.6
   .. versionchanged:: 5.2

      Module directives support body content.

.. rst:directive:: .. js:function:: name(signature)

   Describes a JavaScript function or method.  If you want to describe
   arguments as optional use square brackets as :ref:`documented <signatures>`
   for Python signatures.

   You can use fields to give more details about arguments and their expected
   types, errors which may be thrown by the function, and the value being
   returned::

      .. js:function:: $.getJSON(href, callback[, errback])

         :param string href: An URI to the location of the resource.
         :param callback: Gets called with the object.
         :param errback:
             Gets called in case the request fails. And a lot of other
             text so we need multiple lines.
         :throws SomeError: For whatever reason in that case.
         :returns: Something.

   This is rendered as:

   .. js:function:: $.getJSON(href, callback[, errback])
      :no-index:

      :param string href: An URI to the location of the resource.
      :param callback: Gets called with the object.
      :param errback:
          Gets called in case the request fails. And a lot of other
          text so we need multiple lines.
      :throws SomeError: For whatever reason in that case.
      :returns: Something.

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the function's parameters will be emitted on a single logical
      line, overriding :confval:`javascript_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

.. rst:directive:: .. js:method:: name(signature)

   This directive is an alias for :rst:dir:`js:function`, however it describes
   a function that is implemented as a method on a class object.

   .. versionadded:: 1.6

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the function's parameters will be emitted on a single logical
      line, overriding :confval:`javascript_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

.. rst:directive:: .. js:class:: name

   Describes a constructor that creates an object.  This is basically like a
   function but will show up with a `class` prefix::

      .. js:class:: MyAnimal(name[, age])

         :param string name: The name of the animal
         :param number age: an optional age for the animal

   This is rendered as:

   .. js:class:: MyAnimal(name[, age])
      :no-index:

      :param string name: The name of the animal
      :param number age: an optional age for the animal

   .. rst:directive:option:: single-line-parameter-list
      :type: no value

      Ensures that the function's parameters will be emitted on a single logical
      line, overriding :confval:`javascript_maximum_signature_line_length` and
      :confval:`maximum_signature_line_length`.

      .. versionadded:: 7.1

.. rst:directive:: .. js:data:: name

   Describes a global variable or constant.

.. rst:directive:: .. js:attribute:: object.name

   Describes the attribute *name* of *object*.

.. _js-roles:

These roles are provided to refer to the described objects:

.. rst:role:: js:mod
          js:func
          js:meth
          js:class
          js:data
          js:attr


The reStructuredText domain
---------------------------

The reStructuredText domain (name **rst**) provides the following directives:

.. rst:directive:: .. rst:directive:: name

   Describes a reST directive.  The *name* can be a single directive name or
   actual directive syntax (`..` prefix and `::` suffix) with arguments that
   will be rendered differently.  For example::

      .. rst:directive:: foo

         Foo description.

      .. rst:directive:: .. bar:: baz

         Bar description.

   will be rendered as:

   .. rst:directive:: foo
      :no-index:

      Foo description.

   .. rst:directive:: .. bar:: baz
      :no-index:

      Bar description.

.. rst:directive:: .. rst:directive:option:: name

   Describes an option for reST directive.  The *name* can be a single option
   name or option name with arguments which separated with colon (``:``).
   For example::

       .. rst:directive:: toctree

          .. rst:directive:option:: caption: caption of ToC

          .. rst:directive:option:: glob

   will be rendered as:

   .. rst:directive:: toctree
      :no-index:

      .. rst:directive:option:: caption: caption of ToC
         :no-index:

      .. rst:directive:option:: glob
         :no-index:

   .. rubric:: options

   .. rst:directive:option:: type: description of argument
      :type: text

      Describe the type of option value.

      For example::

         .. rst:directive:: toctree

            .. rst:directive:option:: maxdepth
               :type: integer or no value

      .. versionadded:: 2.1

.. rst:directive:: .. rst:role:: name

   Describes a reST role.  For example::

      .. rst:role:: foo

         Foo description.

   will be rendered as:

   .. rst:role:: foo
      :no-index:

      Foo description.

.. _rst-roles:

These roles are provided to refer to the described objects:

.. rst:role:: rst:dir
              rst:role

.. _math-domain:

The Math Domain
---------------

The math domain (name **math**) provides the following roles:

.. rst:role:: math:numref

   Role for cross-referencing equations defined by :rst:dir:`math` directive
   via their label.  Example::

      .. math:: e^{i\pi} + 1 = 0
         :label: euler

      Euler's identity, equation :math:numref:`euler`, was elected one of the
      most beautiful mathematical formulas.

   .. versionadded:: 1.8

More domains
------------

The sphinx-contrib_ repository contains more domains available as extensions;
currently Ada_, CoffeeScript_, Erlang_, HTTP_, Lasso_, MATLAB_, PHP_, and Ruby_
domains. Also available are domains for `Chapel`_, `Common Lisp`_, dqn_, Go_,
Jinja_, Operation_, and Scala_.

.. _sphinx-contrib: https://github.com/sphinx-contrib

.. _Ada: https://pypi.org/project/sphinxcontrib-adadomain/
.. _Chapel: https://pypi.org/project/sphinxcontrib-chapeldomain/
.. _CoffeeScript: https://pypi.org/project/sphinxcontrib-coffee/
.. _Common Lisp: https://pypi.org/project/sphinxcontrib-cldomain/
.. _dqn: https://pypi.org/project/sphinxcontrib-dqndomain/
.. _Erlang: https://pypi.org/project/sphinxcontrib-erlangdomain/
.. _Go: https://pypi.org/project/sphinxcontrib-golangdomain/
.. _HTTP: https://pypi.org/project/sphinxcontrib-httpdomain/
.. _Jinja: https://pypi.org/project/sphinxcontrib-jinjadomain/
.. _Lasso: https://pypi.org/project/sphinxcontrib-lassodomain/
.. _MATLAB: https://pypi.org/project/sphinxcontrib-matlabdomain/
.. _Operation: https://pypi.org/project/sphinxcontrib-operationdomain/
.. _PHP: https://pypi.org/project/sphinxcontrib-phpdomain/
.. _Ruby: https://github.com/sphinx-contrib/rubydomain
.. _Scala: https://pypi.org/project/sphinxcontrib-scaladomain/