| 1 |
.. include:: ../../header2.rst |
| 2 |
|
| 3 |
========================================= |
| 4 |
reStructuredText Interpreted Text Roles |
| 5 |
========================================= |
| 6 |
|
| 7 |
:Author: David Goodger |
| 8 |
:Contact: [email protected] |
| 9 |
:Revision: $Revision: 10287 $ |
| 10 |
:Date: $Date: 2026-01-07 14:40:59 +0100 (Mi, 07. Jan 2026) $ |
| 11 |
:Copyright: This document has been placed in the public domain. |
| 12 |
:Abstract: |
| 13 |
This document describes the interpreted text roles implemented in the |
| 14 |
reference reStructuredText parser. |
| 15 |
|
| 16 |
Interpreted text uses backquotes (`) around the text. An explicit |
| 17 |
role marker may optionally appear before or after the text, delimited |
| 18 |
with colons. For example:: |
| 19 |
|
| 20 |
This is `interpreted text` using the default role. |
| 21 |
|
| 22 |
This is :title:`interpreted text` using an explicit role. |
| 23 |
|
| 24 |
A "default role" may be defined by applications of reStructuredText; it |
| 25 |
is used if no explicit ``:role:`` prefix or suffix is given. The |
| 26 |
default "default role" is "`:title-reference:`_". It can be changed |
| 27 |
using the `"default-role" directive`_. |
| 28 |
|
| 29 |
See the `Interpreted Text`_ section in the `reStructuredText Markup |
| 30 |
Specification`_ for syntax details. For details on the hierarchy of |
| 31 |
elements, please see `The Docutils Document Tree`_ and the `Docutils |
| 32 |
Generic DTD`_ XML document type definition. For interpreted text role |
| 33 |
implementation details, see `Creating reStructuredText Interpreted |
| 34 |
Text Roles`_. |
| 35 |
|
| 36 |
|
| 37 |
.. contents:: |
| 38 |
|
| 39 |
|
| 40 |
Standard Roles |
| 41 |
============== |
| 42 |
|
| 43 |
|
| 44 |
-------------- |
| 45 |
:abbreviation: |
| 46 |
-------------- |
| 47 |
|
| 48 |
.. class:: field-indent-12em |
| 49 |
|
| 50 |
:Aliases: \:ab: |
| 51 |
:Doctree Element: `\<abbreviation>`_ |
| 52 |
|
| 53 |
An abbreviation used in the document. |
| 54 |
An example of an abbreviation is ‘St’ being used instead of ‘Street’. |
| 55 |
|
| 56 |
|
| 57 |
--------- |
| 58 |
:acronym: |
| 59 |
--------- |
| 60 |
|
| 61 |
.. class:: field-indent-12em |
| 62 |
|
| 63 |
:Aliases: \:ac: |
| 64 |
:Doctree Element: `\<acronym>`_ |
| 65 |
|
| 66 |
An acronym. |
| 67 |
|
| 68 |
|
| 69 |
------ |
| 70 |
:code: |
| 71 |
------ |
| 72 |
|
| 73 |
.. class:: field-indent-12em |
| 74 |
|
| 75 |
:Aliases: None |
| 76 |
:Doctree Element: `\<literal>`_ |
| 77 |
:Customization_ options: `class <"class" option_>`__, |
| 78 |
`language <"language" option_>`__ |
| 79 |
|
| 80 |
The :code: role marks its content as code in a formal language. |
| 81 |
|
| 82 |
For syntax highlight of inline code, the `"role" directive`_ can be |
| 83 |
used to create `custom roles`_. For example, the following creates |
| 84 |
a role "tex" to mark up and highlight LaTeX examples:: |
| 85 |
|
| 86 |
.. role:: tex(code) |
| 87 |
|
| 88 |
A different `highlight language`_ can be specified in the |
| 89 |
`"language" option`_:: |
| 90 |
|
| 91 |
.. role:: js(code) |
| 92 |
:language: javascript+mozpreproc |
| 93 |
|
| 94 |
Content of the new role is parsed and tagged by the Pygments_ syntax |
| 95 |
highlighter. See the `"code" directive`_ for more info on syntax highlight |
| 96 |
in Docutils. |
| 97 |
|
| 98 |
New in Docutils 0.9. Since Docutils 0.23, the highlight language of |
| 99 |
derived roles defaults to the role name. |
| 100 |
|
| 101 |
.. _customization: `custom roles`_ |
| 102 |
.. _Pygments: https://pygments.org/ |
| 103 |
.. _highlight language: https://pygments.org/languages/ |
| 104 |
|
| 105 |
|
| 106 |
---------- |
| 107 |
:emphasis: |
| 108 |
---------- |
| 109 |
|
| 110 |
.. class:: field-indent-12em |
| 111 |
|
| 112 |
:Aliases: None |
| 113 |
:Doctree Element: `\<emphasis>`_ |
| 114 |
|
| 115 |
Implements emphasis. These are equivalent:: |
| 116 |
|
| 117 |
*text* |
| 118 |
:emphasis:`text` |
| 119 |
|
| 120 |
|
| 121 |
--------- |
| 122 |
:literal: |
| 123 |
--------- |
| 124 |
|
| 125 |
.. class:: field-indent-12em |
| 126 |
|
| 127 |
:Aliases: None |
| 128 |
:Doctree Element: `\<literal>`_ |
| 129 |
|
| 130 |
Implements inline literal text. These are equivalent:: |
| 131 |
|
| 132 |
``text`` |
| 133 |
:literal:`text` |
| 134 |
|
| 135 |
Care must be taken with backslash-escapes though. These are *not* |
| 136 |
equivalent:: |
| 137 |
|
| 138 |
``text \ and \ backslashes`` |
| 139 |
:literal:`text \ and \ backslashes` |
| 140 |
|
| 141 |
The backslashes in the first line are preserved (and do nothing), |
| 142 |
whereas the backslashes in the second line escape the following |
| 143 |
spaces. |
| 144 |
|
| 145 |
|
| 146 |
------ |
| 147 |
:math: |
| 148 |
------ |
| 149 |
|
| 150 |
.. class:: field-indent-12em |
| 151 |
|
| 152 |
:Aliases: None |
| 153 |
:Doctree Element: `\<math>`_ |
| 154 |
|
| 155 |
(New in Docutils 0.8.) |
| 156 |
|
| 157 |
The ``math`` role marks its content as mathematical notation (inline |
| 158 |
formula). |
| 159 |
|
| 160 |
The input format is LaTeX math syntax without the “math delimiters“ |
| 161 |
(``$ $``), for example:: |
| 162 |
|
| 163 |
The area of a circle is :math:`A_\text{c} = (\pi/4) d^2`. |
| 164 |
|
| 165 |
See the `"math" directive`_ (producing display formulas) for more info |
| 166 |
on mathematical notation in reStructuredText. |
| 167 |
|
| 168 |
|
| 169 |
--------------- |
| 170 |
:pep-reference: |
| 171 |
--------------- |
| 172 |
|
| 173 |
.. class:: field-indent-12em |
| 174 |
|
| 175 |
:Aliases: \:PEP: |
| 176 |
:Doctree Element: `\<reference>`_ |
| 177 |
|
| 178 |
The :pep-reference: role is used to create an HTTP reference to a |
| 179 |
PEP (Python Enhancement Proposal). The :PEP: alias is usually |
| 180 |
used. The content must be a number, for example:: |
| 181 |
|
| 182 |
See :PEP:`287` for more information about reStructuredText. |
| 183 |
|
| 184 |
This is equivalent to:: |
| 185 |
|
| 186 |
See `PEP 287`__ for more information about reStructuredText. |
| 187 |
|
| 188 |
__ https://peps.python.org/pep-0287 |
| 189 |
|
| 190 |
|
| 191 |
--------------- |
| 192 |
:rfc-reference: |
| 193 |
--------------- |
| 194 |
|
| 195 |
.. class:: field-indent-12em |
| 196 |
|
| 197 |
:Aliases: \:RFC: |
| 198 |
:Doctree Element: `\<reference>`_ |
| 199 |
|
| 200 |
The :rfc-reference: role is used to create an HTTP reference to an |
| 201 |
RFC (Internet Request for Comments). The :RFC: alias is usually |
| 202 |
used. The content must be a number [#]_, for example:: |
| 203 |
|
| 204 |
See :RFC:`2822` for information about email headers. |
| 205 |
|
| 206 |
This is equivalent to:: |
| 207 |
|
| 208 |
See `RFC 2822`__ for information about email headers. |
| 209 |
|
| 210 |
__ https://tools.ietf.org/html/rfc2822.html |
| 211 |
|
| 212 |
.. [#] You can link to a specific section by saying |
| 213 |
``:rfc:`number#anchor```. (New in Docutils 0.15.) |
| 214 |
|
| 215 |
.. Warning:: The anchor (anything following a ``#``) is appended to |
| 216 |
the reference without any checks and not shown in the link text. |
| 217 |
|
| 218 |
It is recommended to use `hyperlink references`_ for |
| 219 |
anything more complex than a single RFC number. |
| 220 |
|
| 221 |
|
| 222 |
-------- |
| 223 |
:strong: |
| 224 |
-------- |
| 225 |
|
| 226 |
.. class:: field-indent-12em |
| 227 |
|
| 228 |
:Aliases: None |
| 229 |
:Doctree Element: `\<strong>`_ |
| 230 |
|
| 231 |
Implements strong emphasis. These are equivalent:: |
| 232 |
|
| 233 |
**text** |
| 234 |
:strong:`text` |
| 235 |
|
| 236 |
|
| 237 |
----------- |
| 238 |
:subscript: |
| 239 |
----------- |
| 240 |
|
| 241 |
.. class:: field-indent-12em |
| 242 |
|
| 243 |
:Aliases: \:sub: |
| 244 |
:Doctree Element: `\<subscript>`_ |
| 245 |
|
| 246 |
Implements subscripts. |
| 247 |
|
| 248 |
.. Tip:: |
| 249 |
|
| 250 |
Whitespace or punctuation is required around interpreted text, but |
| 251 |
often not desired with subscripts & superscripts. |
| 252 |
Backslash-escaped whitespace can be used; the whitespace will be |
| 253 |
removed from the processed document:: |
| 254 |
|
| 255 |
H\ :sub:`2`\ O |
| 256 |
E = mc\ :sup:`2` |
| 257 |
|
| 258 |
In such cases, readability of the plain text can be greatly |
| 259 |
improved with substitutions [#]_:: |
| 260 |
|
| 261 |
The chemical formula for pure water is |H2O|. |
| 262 |
|
| 263 |
.. |H2O| replace:: H\ :sub:`2`\ O |
| 264 |
|
| 265 |
See `the reStructuredText spec`__ for further information on |
| 266 |
`character-level markup`__ and `the substitution mechanism`__. |
| 267 |
|
| 268 |
.. [#] Alternatives are the `:math:`_ role (:math:`E=mc^2`) |
| 269 |
or literal Unicode characters (H₂O) |
| 270 |
|
| 271 |
__ restructuredtext.html |
| 272 |
__ restructuredtext.html#character-level-inline-markup-1 |
| 273 |
__ restructuredtext.html#substitution-references |
| 274 |
|
| 275 |
|
| 276 |
------------- |
| 277 |
:superscript: |
| 278 |
------------- |
| 279 |
|
| 280 |
.. class:: field-indent-12em |
| 281 |
|
| 282 |
:Aliases: \:sup: |
| 283 |
:Doctree Element: `\<superscript>`_ |
| 284 |
|
| 285 |
Implements superscripts. See the tip in `:subscript:`_ above. |
| 286 |
|
| 287 |
|
| 288 |
----------------- |
| 289 |
:title-reference: |
| 290 |
----------------- |
| 291 |
|
| 292 |
.. class:: field-indent-12em |
| 293 |
|
| 294 |
:Aliases: \:title:, :t: |
| 295 |
:Doctree Element: `\<title_reference>`_ |
| 296 |
|
| 297 |
The :title-reference: role is used to describe the titles of |
| 298 |
books, periodicals, and other materials. It is the equivalent of the |
| 299 |
HTML "cite" element, and it is expected that HTML writers will |
| 300 |
typically render "title_reference" elements using "cite". |
| 301 |
|
| 302 |
Since title references are typically rendered with italics, they are |
| 303 |
often marked up using ``*emphasis*``, which is misleading and vague. |
| 304 |
The "title_reference" element provides accurate and unambiguous |
| 305 |
descriptive markup. |
| 306 |
|
| 307 |
Let's assume :title-reference: is the default interpreted text |
| 308 |
role (see below) for this example:: |
| 309 |
|
| 310 |
`Design Patterns` [GoF95]_ is an excellent read. |
| 311 |
|
| 312 |
The following document fragment (pseudo-XML_) will result from |
| 313 |
processing:: |
| 314 |
|
| 315 |
<paragraph> |
| 316 |
<title_reference> |
| 317 |
Design Patterns |
| 318 |
|
| 319 |
<citation_reference refname="gof95"> |
| 320 |
GoF95 |
| 321 |
is an excellent read. |
| 322 |
|
| 323 |
`:title-reference:`_ is the default interpreted text role in the |
| 324 |
standard reStructuredText parser. This means that no explicit role is |
| 325 |
required. Applications of reStructuredText may designate a different |
| 326 |
default role, in which case the explicit :title-reference: role |
| 327 |
must be used to obtain a ``title_reference`` element. |
| 328 |
|
| 329 |
|
| 330 |
Specialized Roles |
| 331 |
================= |
| 332 |
|
| 333 |
----- |
| 334 |
:raw: |
| 335 |
----- |
| 336 |
|
| 337 |
.. class:: field-indent-12em |
| 338 |
|
| 339 |
:Aliases: None |
| 340 |
:Doctree Element: `\<raw>`_ |
| 341 |
:Customization_ options: `class <"class" option_>`__, |
| 342 |
`format <"format" option_>`__ |
| 343 |
|
| 344 |
The "raw" role indicates non-reStructuredText data that is to be |
| 345 |
passed untouched to the Writer. It is the inline equivalent of the |
| 346 |
`"raw" directive`_; see its documentation for details on the |
| 347 |
semantics. |
| 348 |
|
| 349 |
**The "raw" role cannot be used directly.** The `"role" directive`_ must |
| 350 |
first be used to create `custom roles`_ based on the "raw" role. One or |
| 351 |
more formats (Writer names) must be provided in a `"format" option`_. |
| 352 |
|
| 353 |
.. WARNING:: |
| 354 |
The "raw" role is a stop-gap measure allowing the author to bypass |
| 355 |
reStructuredText's markup. It is a "power-user" feature that |
| 356 |
should not be overused or abused. The use of "raw" ties documents |
| 357 |
to specific output formats and makes them less portable. |
| 358 |
|
| 359 |
If you often need to use "raw"-derived interpreted text roles or |
| 360 |
the "raw" directive, that is a sign either of overuse/abuse or that |
| 361 |
functionality may be missing from reStructuredText. Please |
| 362 |
describe your situation in a message to the Docutils-users_ mailing |
| 363 |
list. |
| 364 |
|
| 365 |
.. _Docutils-users: ../../user/mailing-lists.html#docutils-user |
| 366 |
|
| 367 |
For example, the following creates an HTML-specific "raw-html" role:: |
| 368 |
|
| 369 |
.. role:: raw-html(raw) |
| 370 |
:format: html |
| 371 |
|
| 372 |
This role can now be used directly to pass data untouched to the HTML |
| 373 |
Writer. For example:: |
| 374 |
|
| 375 |
If there just *has* to be a line break here, |
| 376 |
:raw-html:`<br />` |
| 377 |
it can be accomplished with a "raw"-derived role. |
| 378 |
But the line block syntax should be considered first. |
| 379 |
|
| 380 |
.. Tip:: Roles based on "raw" should clearly indicate their origin, so |
| 381 |
they are not mistaken for reStructuredText markup. Using a "raw-" |
| 382 |
prefix for role names is recommended. |
| 383 |
|
| 384 |
|
| 385 |
Roles Defined in Standard Definition Files |
| 386 |
========================================== |
| 387 |
|
| 388 |
The `reStructuredText Standard Definition Files`_ ``html-roles.txt`` and |
| 389 |
``s5defs.txt`` define additional roles for `semantic inline markup`_ |
| 390 |
and for use in `S5/HTML slide shows`_ (colors, font sizes, display options). |
| 391 |
|
| 392 |
|
| 393 |
Custom Roles |
| 394 |
============ |
| 395 |
|
| 396 |
Custom interpreted text roles can be defined in a document with the |
| 397 |
`"role" directive`_. The new role may be based on an existing role. |
| 398 |
The "role" directive may be called with options_ to customize the |
| 399 |
generated roles. |
| 400 |
|
| 401 |
|
| 402 |
.. References |
| 403 |
|
| 404 |
.. _reStructuredText Markup Specification: restructuredtext.html |
| 405 |
.. _Interpreted Text: restructuredtext.html#interpreted-text |
| 406 |
.. _hyperlink references: restructuredtext.html#hyperlink-references |
| 407 |
|
| 408 |
.. _reStructuredText Standard Definition Files: definitions.html |
| 409 |
.. _semantic inline markup: definitions.html#additional-roles-for-html |
| 410 |
.. _S5/HTML slide shows: definitions.html#s5-html-definitions |
| 411 |
|
| 412 |
.. _The Docutils Document Tree: ../doctree.html |
| 413 |
.. _class names: ../doctree.html#classname |
| 414 |
.. _classes attribute: ../doctree.html#classes |
| 415 |
.. _format attribute: ../doctree.html#format |
| 416 |
.. _pseudo-XML: ../doctree.html#pseudo-xml |
| 417 |
|
| 418 |
.. _Docutils Generic DTD: ../docutils.dtd |
| 419 |
.. _Creating reStructuredText Interpreted Text Roles: |
| 420 |
../../howto/rst-roles.html |
| 421 |
.. _writer names: ../../user/config.html#writer-docutils-application |
| 422 |
|
| 423 |
.. _"class" directive: directives.html#role-class |
| 424 |
.. _"code" directive: directives.html#code |
| 425 |
.. _"default-role" directive: directives.html#default-role |
| 426 |
.. _"role" directive: directives.html#role |
| 427 |
.. _"math" directive: directives.html#math |
| 428 |
.. _"raw" directive: directives.html#raw |
| 429 |
.. _options: directives.html#role-options |
| 430 |
.. _"class" option: directives.html#role-directive-class-option |
| 431 |
.. _"format" option: directives.html#format |
| 432 |
.. _"language" option: directives.html#language |
| 433 |
|
| 434 |
.. _<abbreviation>: ../doctree.html#abbreviation |
| 435 |
.. _<acronym>: ../doctree.html#acronym |
| 436 |
.. _<emphasis>: ../doctree.html#emphasis |
| 437 |
.. _<literal>: ../doctree.html#literal |
| 438 |
.. _<math>: ../doctree.html#math |
| 439 |
.. _<reference>: ../doctree.html#reference |
| 440 |
.. _<raw>: ../doctree.html#raw |
| 441 |
.. _<strong>: ../doctree.html#strong |
| 442 |
.. _<subscript>: ../doctree.html#subscript |
| 443 |
.. _<superscript>: ../doctree.html#superscript |
| 444 |
.. _<title_reference>: ../doctree.html#title-reference |