# reStructuredText Interpreted Text Roles

Author:

  David Goodger

Contact:
  docutils-develop@lists.sourceforge.net
Revision:
  10287
Date:
  2026-01-07
Copyright:
  This document has been placed in the public domain.

Abstract

This document describes the interpreted text roles implemented in the reference reStructuredText parser.

Interpreted text uses backquotes (`) around the text. An explicit role marker may optionally appear before or after the text, delimited with colons. For example:

    This is `interpreted text` using the default role.

    This is :title:`interpreted text` using an explicit role.

A "default role" may be defined by applications of reStructuredText; it is used if no explicit :role: prefix or suffix is given. The default "default role" is ":title-reference:". It can be changed using the "default-role" directive.

See the Interpreted Text section in the reStructuredText Markup Specification for syntax details. For details on the hierarchy of elements, please see The Docutils Document Tree and the Docutils Generic DTD XML document type definition. For interpreted text role implementation details, see Creating reStructuredText Interpreted Text Roles.

## Standard Roles

### :abbreviation:

Aliases:

  :ab:

Doctree Element:

  <abbreviation>

An abbreviation used in the document. An example of an abbreviation is ‘St’ being used instead of ‘Street’.

### :acronym:

Aliases:

  :ac:

Doctree Element:

  <acronym>

An acronym.

### :code:

Aliases:

  None

Doctree Element:

  <literal>

Customization options:

  class, language

The :code: role marks its content as code in a formal language.

For syntax highlight of inline code, the "role" directive can be used to create custom roles. For example, the following creates a role "tex" to mark up and highlight LaTeX examples:

    .. role:: tex(code)

A different highlight language can be specified in the "language" option:

    .. role:: js(code)
       :language: javascript+mozpreproc

Content of the new role is parsed and tagged by the Pygments syntax highlighter. See the "code" directive for more info on syntax highlight in Docutils.

New in Docutils 0.9. Since Docutils 0.23, the highlight language of derived roles defaults to the role name.

### :emphasis:

Aliases:

  None

Doctree Element:

  <emphasis>

Implements emphasis. These are equivalent:

    *text*
    :emphasis:`text`

### :literal:

Aliases:

  None

Doctree Element:

  <literal>

Implements inline literal text. These are equivalent:

    ``text``
    :literal:`text`

Care must be taken with backslash-escapes though. These are not equivalent:

    ``text \ and \ backslashes``
    :literal:`text \ and \ backslashes`

The backslashes in the first line are preserved (and do nothing), whereas the backslashes in the second line escape the following spaces.

### :math:

Aliases:

  None

Doctree Element:

  <math>

(New in Docutils 0.8.)

The math role marks its content as mathematical notation (inline formula).

The input format is LaTeX math syntax without the “math delimiters“ ($ $), for example:

    The area of a circle is :math:`A_\text{c} = (\pi/4) d^2`.

See the "math" directive (producing display formulas) for more info on mathematical notation in reStructuredText.

### :pep-reference:

Aliases:

  :PEP:

Doctree Element:

  <reference>

The :pep-reference: role is used to create an HTTP reference to a PEP (Python Enhancement Proposal). The :PEP: alias is usually used. The content must be a number, for example:

    See :PEP:`287` for more information about reStructuredText.

This is equivalent to:

    See `PEP 287`__ for more information about reStructuredText.

    __ https://peps.python.org/pep-0287

### :rfc-reference:

Aliases:

  :RFC:

Doctree Element:

  <reference>

The :rfc-reference: role is used to create an HTTP reference to an RFC (Internet Request for Comments). The :RFC: alias is usually used. The content must be a number [1], for example:

    See :RFC:`2822` for information about email headers.

This is equivalent to:

    See `RFC 2822`__ for information about email headers.

    __ https://tools.ietf.org/html/rfc2822.html

[1]

You can link to a specific section by saying :rfc:`number#anchor`. (New in Docutils 0.15.)

Warning

The anchor (anything following a #) is appended to the reference without any checks and not shown in the link text.

It is recommended to use hyperlink references for anything more complex than a single RFC number.

### :strong:

Aliases:

  None

Doctree Element:

  <strong>

Implements strong emphasis. These are equivalent:

    **text**
    :strong:`text`

### :subscript:

Aliases:

  :sub:

Doctree Element:

  <subscript>

Implements subscripts.

Tip

Whitespace or punctuation is required around interpreted text, but often not desired with subscripts & superscripts. Backslash-escaped whitespace can be used; the whitespace will be removed from the processed document:

    H\ :sub:`2`\ O
    E = mc\ :sup:`2`

In such cases, readability of the plain text can be greatly improved with substitutions [2]:

    The chemical formula for pure water is |H2O|.

    .. |H2O| replace:: H\ :sub:`2`\ O

See the reStructuredText spec for further information on character-level markup and the substitution mechanism.

[2]

Alternatives are the :math: role ( E = m c 2 ) or literal Unicode characters (H₂O)

### :superscript:

Aliases:

  :sup:

Doctree Element:

  <superscript>

Implements superscripts. See the tip in :subscript: above.

### :title-reference:

Aliases:

  :title:, :t:

Doctree Element:

  <title_reference>

The :title-reference: role is used to describe the titles of books, periodicals, and other materials. It is the equivalent of the HTML "cite" element, and it is expected that HTML writers will typically render "title_reference" elements using "cite".

Since title references are typically rendered with italics, they are often marked up using *emphasis*, which is misleading and vague. The "title_reference" element provides accurate and unambiguous descriptive markup.

Let's assume :title-reference: is the default interpreted text role (see below) for this example:

    `Design Patterns` [GoF95]_ is an excellent read.

The following document fragment (pseudo-XML) will result from processing:

    <paragraph>
        <title_reference>
            Design Patterns

        <citation_reference refname="gof95">
            GoF95
         is an excellent read.

:title-reference: is the default interpreted text role in the standard reStructuredText parser. This means that no explicit role is required. Applications of reStructuredText may designate a different default role, in which case the explicit :title-reference: role must be used to obtain a title_reference element.

## Specialized Roles

### :raw:

Aliases:

  None

Doctree Element:

  <raw>

Customization options:

  class, format

The "raw" role indicates non-reStructuredText data that is to be passed untouched to the Writer. It is the inline equivalent of the "raw" directive; see its documentation for details on the semantics.

The "raw" role cannot be used directly. The "role" directive must first be used to create custom roles based on the "raw" role. One or more formats (Writer names) must be provided in a "format" option.

Warning

The "raw" role is a stop-gap measure allowing the author to bypass reStructuredText's markup. It is a "power-user" feature that should not be overused or abused. The use of "raw" ties documents to specific output formats and makes them less portable.

If you often need to use "raw"-derived interpreted text roles or the "raw" directive, that is a sign either of overuse/abuse or that functionality may be missing from reStructuredText. Please describe your situation in a message to the Docutils-users mailing list.

For example, the following creates an HTML-specific "raw-html" role:

    .. role:: raw-html(raw)
       :format: html

This role can now be used directly to pass data untouched to the HTML Writer. For example:

    If there just *has* to be a line break here,
    :raw-html:`<br />`
    it can be accomplished with a "raw"-derived role.
    But the line block syntax should be considered first.

Tip

Roles based on "raw" should clearly indicate their origin, so they are not mistaken for reStructuredText markup. Using a "raw-" prefix for role names is recommended.

## Roles Defined in Standard Definition Files

The reStructuredText Standard Definition Files html-roles.txt and s5defs.txt define additional roles for semantic inline markup and for use in S5/HTML slide shows (colors, font sizes, display options).

## Custom Roles

Custom interpreted text roles can be defined in a document with the "role" directive. The new role may be based on an existing role. The "role" directive may be called with options to customize the generated roles.