# reStructuredText Interpreted Text Roles

Contact:
docutils-develop@lists.sourceforge.net
Revision:
$Revision$
Date:
$Date$

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.

## Customization

Custom interpreted text roles may be defined in a document with the "role" directive. Customization details are listed with each role.

A class option is recognized by the "role" directive for most interpreted text roles. A description is provided in the "role" directive documentation.

## Standard Roles

### :abbreviation:

Aliases:

:ab:

DTD Element:

abbreviation

Customization:
Options:
Content:

None.

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

Aliases:

:ac:

DTD Element:

acronym

Customization:
Options:
Content:

None.

An acronym.

### :code:

Aliases:

None

DTD Element:

literal

Customization:
Options:

class, language

Content:

None.

(New in Docutils 0.9.)

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 build custom roles with the code language specified in the "language" option.

For example, the following creates a LaTeX-specific "latex" role:

.. role:: latex(code)
:language: latex

Content of the new role is parsed and tagged by the Pygments syntax highlighter. See the code directive for more info on parsing and display of code in reStructuredText.

In addition to "class", the following option is recognized:

languagetext

Name of the code's language. See supported languages and markup formats for recognized values.

### :emphasis:

Aliases:

None

DTD Element:

emphasis

Customization:
Options:
Content:

None.

Implements emphasis. These are equivalent:

*text*
:emphasis:text

### :literal:

Aliases:

None

DTD Element:

literal

Customization:
Options:
Content:

None.

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

DTD Element:

math

Customization:
Options:

class

Content:

None.

(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:

DTD Element:

reference

Customization:
Options:
Content:

None.

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:

DTD Element:

reference

Customization:
Options:
Content:

None.

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

### :strong:

Aliases:

None

DTD Element:

strong

Customization:
Options:
Content:

None.

Implements strong emphasis. These are equivalent:

**text**
:strong:text

### :subscript:

Aliases:

:sub:

DTD Element:

subscript

Customization:
Options:
Content:

None.

Implements subscripts.

### :superscript:

Aliases:

:sup:

DTD Element:

superscript

Customization:
Options:
Content:

None.

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

### :title-reference:

Aliases:

:title:, :t:.

DTD Element:

title_reference

Customization:
Options:
Content:

None.

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

DTD Element:

raw

Customization:
Options:

class, format

Content:

None

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 build custom roles based on the "raw" role. One or more formats (Writer names) must be provided in a "format" option.

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.`

In addition to "class", the following option is recognized:

formattext

One or more space-separated output format names (Writer names).