http://docutils.sourceforge.net/docs/rst/quickref.html
Being a cheat-sheet for reStructuredText
Updated 2003-06-10
Copyright: This document has been placed in the public domain.
The full details of the markup may be found on the reStructuredText page. This document is just intended as a reminder.
Links that look like "(details)" point into the HTML version of the full reStructuredText specification document. These are relative links; if they don't work, please use the master "Quick reStructuredText" document.
What it does -- It generates LaTeX suitable as input to the "Documenting Python" system.
How to run it:
$ docutils/tools/documenting_python.py --documentclass=howto infile.rst
The following docinfo items, fields, and topics are supported:
\begin{abstract} \noindent [stuff] \end{abstract}
Example: -- Here is (the first few lines of) a sample input rST file:
:author: Dave Kuhlman :date: 2003/06/05 :revision: 1.27 :copyright: This document has been placed in the public domain. You may do with it as you wish. You may copy, modify, redistribute, reattribute, sell, buy, rent, lease, destroy, or improve it, quote it at length, excerpt, incorporate, collate, fold, staple, or mutilate it, or do anything else to it that your or anyone else's heart desires. :abstract: This is a test document, containing at least one example of each reStructuredText construct. ====================================== reStructuredText Test Document (title) ====================================== o o o
If we run the above through this command:
$ ../docutils/tools/documenting_python.py --documentclass=howto testdocpy1.rst
And, here is what the above rST would generate:
\documentclass{howto} %% generator Docutils: http://docutils.sourceforge.net/ \title{reStructuredText Test Document (title)} \release{1.27} \date{2003/06/05} \author{Dave Kuhlman} \begin{document} \maketitle \ifhtml \chapter*{Front Matter\label{front}} \fi This document has been placed in the public domain. You may do with it as you wish. You may copy, modify, redistribute, reattribute, sell, buy, rent, lease, destroy, or improve it, quote it at length, excerpt, incorporate, collate, fold, staple, or mutilate it, or do anything else to it that your or anyone else's heart desires. \begin{abstract} \noindent This is a test document, containing at least one example of each reStructuredText construct. \end{abstract} \tableofcontents o o o
If a section title matches the string "see also" (case insensitive, then hyperlinks are treated slightly differently. In particular, we generate "\seeurl{}".
(details)
Inline markup allows words and phrases within text to have character styles (like italics and boldface) and functionality (like hyperlinks).
Plain text | Typical result | Notes | Doc Py |
---|---|---|---|
*emphasis* | emphasis | Normally rendered as italics. | \emph{some text} |
**strong emphasis** | strong emphasis | Normally rendered as boldface. | \strong{some text} |
`interpreted text` | (see note at right) | The rendering and meaning of interpreted text is domain- or application-dependent. It can be used for things like index entries or explicit descriptive markup (like program identifiers). | |
``inline literal`` | inline literal
| Normally rendered as monospaced text. Spaces should be preserved, but line breaks will not be. |
Generates \code{word}, if no embedded whitespace. Generates \samp{some text}, if there is embedded whitespace. |
reference_ | reference | A simple, one-word hyperlink reference. See Hyperlinks. |
\ulink{label}{url} In "See Also" section: \seeurl{url}{label} |
`phrase reference`_ | phrase reference | A hyperlink reference with spaces or punctuation needs to be quoted with backquotes. See Hyperlinks. |
\ulink{label}{url} In "See Also" section: \seeurl{url}{label} |
anonymous__ | anonymous | With two underscores instead of one, both simple and phrase references may be anonymous (the reference text is not repeated at the target). See Hyperlinks. | |
_`inline internal target` | inline internal target | A crossreference target within text. See Hyperlinks. | |
|substitution reference| | (see note at right) | The result is substituted in from the substitution definition. It could be text, an image, a hyperlink, or a combination of these and others. | |
footnote reference [1]_ | footnote reference 1 | See Footnotes. | |
citation reference [CIT2002]_ | citation reference [CIT2002] | See Citations. | |
http://docutils.sf.net/ | http://docutils.sf.net/ | A standalone hyperlink. | \url{http://docutils.sf.net/} |
Asterisk, backquote, vertical bar, and underscore are inline delimiter characters. Asterisk, backquote, and vertical bar act like quote marks; matching characters surround the marked-up word or phrase, whitespace or other quoting is required outside them, and there can't be whitespace just inside them. If you want to use inline delimiter characters literally, escape (with backslash) or quote them (with double backquotes; i.e. use inline literals).
In detail, the reStructuredText specification says that in inline markup, the following rules apply to start-strings and end-strings (inline markup delimiters):
Also remember that inline markup may not be nested (well, except that inline literals can contain any of the other inline markup delimiter characters, but that doesn't count because nothing is processed).
(details)
reStructuredText uses backslashes ("\") to override the special meaning given to markup characters and get the literal characters themselves. To get a literal backslash, use an escaped backslash ("\\"). For example:
Raw reStructuredText | Typical result | Doc Py |
---|---|---|
*escape* ``with`` "\" | escape with "" | |
\*escape* \``with`` "\\" | *escape* ``with`` "\" | $\backslash$ |
In Python strings it will, of course, be necessary to escape any backslash characters so that they actually reach reStructuredText. The simplest way to do this is to use raw strings:
Python string | Typical result |
---|---|
r"""\*escape* \`with` "\\"""" | *escape* `with` "\" |
"""\\*escape* \\`with` "\\\\"""" | *escape* `with` "\" |
"""\*escape* \`with` "\\"""" | escape with "" |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
=====
Title ===== Subtitle -------- Titles are underlined (or over- and underlined) with a printing nonalphanumeric 7-bit ASCII character. Recommended choices are "``= - ` : ' " ~ ^ _ * + # < >``". The underline/overline must be at least as long as the title text. |
Title
Subtitle Titles are underlined (or over- and underlined) with a printing nonalphanumeric 7-bit ASCII character. Recommended choices are "= - ` : ' " ~ ^ _ * + # < >". The underline/overline must be at least as long as the title text. |
\chapter{Title} \section{Subtitle} \subsection{Subsubtitle} |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
This is a paragraph. Paragraphs line up at their left
|
This is a paragraph. Paragraphs line up at their left edges, and are normally separated by blank lines. |
This is a paragraph. Paragraphs line up at their left edges, and are normally separated by blank lines. |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
Bullet lists:
- This is item 1
- Bullets are "-", "*" or "+".
Note that a blank line is required
| Bullet lists:
Note that a blank line is required before the first item and after the last, but is optional between items. |
\begin{itemize} \item This is item 1 \item This is item 2 \end{itemize} Note: Embedded lists are supported. |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
Enumerated lists:
3. This is the first item
| Enumerated lists:
|
\begin{enumerate} \item This is item 1 \item This is item 2 \end{enumerate} Note: Embedded lists are supported. |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
Definition lists:
what Definition lists associate a term with a definition. how The term is a one-line phrase, and the definition is one or more paragraphs or body elements, indented relative to the term. Blank lines are not allowed between term and definition. | Definition lists:
| \begin{description} \item[label 1]Some descriptive text. \item[label 2]More descriptive text. \end{description} |
(details)
Plain text | Typical result | ||||||||
---|---|---|---|---|---|---|---|---|---|
:Authors:
Tony J. (Tibs) Ibbs, David Goodger (and sundry other good-natured folks) :Version: 1.0 of 2001/08/08
|
|
Field lists are used as part of an extension syntax, such as options for directives, or database-like records meant for further processing. Field lists may also be used as generic two-column table constructs in documents.
(details)
Plain text | Typical result | Doc Py | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
-a command-line option "a"
|
| \programopt{-a} \longprogramopt{long} \programopt{/V} |
There must be at least two spaces between the option and the description.
(details)
Plain text | Typical result | Doc Py |
---|---|---|
A paragraph containing only two colons
indicates that the following indented text is a literal block. :: Whitespace, newlines, blank lines, and all kinds of markup (like *this* or \this) is preserved by literal blocks. The paragraph containing only '::' will be omitted from the result. The ``::`` may be tacked onto the very end of any paragraph. The ``::`` will be omitted if it is preceded by whitespace. The ``::`` will be converted to a single colon if preceded by text, like this:: It's very convenient to use this form. Literal blocks end when text returns to the preceding paragraph's indentation. This means that something like:: We start here and continue here and end here. is possible. |
A paragraph containing only two colons indicates that the following indented text is a literal block. Whitespace, newlines, blank lines, and all kinds of markup (like *this* or \this) is preserved by literal blocks. The paragraph containing only '::' will be omitted from the result. The :: may be tacked onto the very end of any paragraph. The :: will be omitted if it is preceded by whitespace. The :: will be converted to a single colon if preceded by text, like this: It's very convenient to use this form. Literal blocks end when text returns to the preceding paragraph's indentation. This means that something like: We start here and continue here and end here. is possible. | A paragraph containing only two colons indicates that the following indented text is a literal block. \begin{verbatim} Whitespace, newlines, blank lines, and all kinds of markup (like *this* or \this) is preserved by literal blocks. The paragraph containing only '::' will be omitted from the result. \end{verbatim} The :: may be tacked onto the very end of any paragraph. The :: will be omitted if it is preceded by whitespace. The :: will be converted to a single colon if preceded by text, like this: \begin{verbatim} It's very convenient to use this form. \end{verbatim} Literal blocks end when text returns to the preceding paragraph's indentation. This means that something like: \begin{verbatim} We start here and continue here and end here. \end{verbatim} is possible. |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
Block quotes are just:
Indented paragraphs, and they may nest. |
Block quotes are just:
| Block quotes are just: \begin{quotation} Indented paragraphs \end{quotation} |
(details)
Plain text | Typical result | Doc Py |
---|---|---|
Doctest blocks are interactive
>>> print "This is a doctest block."
|
Doctest blocks are interactive Python sessions. They begin with ">>>" and end with a blank line. >>> print "This is a doctest block."
| \begin{verbatim} >>> print "This is a doctest block." \end{verbatim} |
"The doctest module searches a module's docstrings for text that looks like an interactive Python session, then executes all such sessions to verify they still work exactly as shown." (From the doctest docs.)
(details)
There are two syntaxes for tables in reStructuredText. Grid tables are complete but cumbersome to create. Simple tables are easy to create but limited (no row spans, etc.).
Plain text | Typical result | Doc Py | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Grid table: +------------+------------+-----------+
|
Grid table:
| Two-column table: \begin{tableii}{l|l}{character}{Heading 1} {Heading 2} \lineii{value 1-1}{value 1-2} \lineii{value 2-1}{value 2-2} \end{tableii} Three-column table: \begin{tableiii}{l|l|l}{character} {Heading 1}{Heading 2}{Heading 3} \lineiii{value 1-1}{value 1-2}{value 1-3} \lineiii{value 2-1}{value 2-2}{value 2-3} \end{tableii} |
||||||||||||||||||
Simple table: ===== ===== ======
|
Simple table:
|
Notes and limitations:
|
(details)
Plain text | Typical result | Doc Py |
---|---|---|
A transition marker is a horizontal line
------------ A transition should not begin or end a
|
A transition marker is a horizontal line of 4 or more repeated punctuation characters. A transition should not begin or end a section or document, nor should two transitions be immediately adjacent. |
A transition marker is a horizontal line of 4 or more repeated punctuation characters. \hrule{}A transition should not begin or end a section or document, nor should two transitions be immediately adjacent. |
Transitions are commonly seen in novels and short fiction, as a gap spanning one or more lines, marking text divisions or signaling changes in subject, time, point of view, or emphasis.
Explicit markup blocks are used for constructs which float (footnotes), have no direct paper-document representation (hyperlink targets, comments), or require specialized processing (directives). They all begin with two periods and whitespace, the "explicit markup start".
(details)
Plain text | Typical result | Doc Py | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Footnote references, like [5]_.
Note that footnotes may get rearranged, e.g., to the bottom of the "page". .. [5] A numerical footnote. Note
|
Footnote references, like 5.
Note that footnotes may get rearranged, e.g., to the bottom of
the "page".
| Footnote references, like\footnote{A numerical footnote. Note there's no colon after the ].}. Note that footnotes may get rearranged, e.g., to the bottom of the "page". | ||||||||||
Autonumbered footnotes are
possible, like using [#]_ and [#]_. .. [#] This is the first one.
They may be assigned 'autonumber
.. [#third] a.k.a. third_ .. [#fourth] a.k.a. fourth_ |
Autonumbered footnotes are possible, like using 1 and 2.
They may be assigned 'autonumber labels' - for instance, 4 and 3.
|
Autonumbered footnotes are possible, like using\footnote{This is the first one.} and \footnote{This is the second one.}. They may be assigned 'autonumber labels' - for instance, \footnote{a.k.a. third} and \footnote{a.k.a. fourth}. [Note: Re-ordering of footnotes is not supported in DocPy.] |
||||||||||
Auto-symbol footnotes are also
possible, like this: [*]_ and [*]_. .. [*] This is the first one.
|
Auto-symbol footnotes are also
possible, like this: *
and †.
| [Not supported in DocPy.] |
The numbering of auto-numbered footnotes is determined by the order of the footnotes, not of the references. For auto-numbered footnote references without autonumber labels ("[#]_"), the references and footnotes must be in the same relative order. Similarly for auto-symbol footnotes ("[*]_").
(details)
Plain text | Typical result | ||||||
---|---|---|---|---|---|---|---|
Citation references, like [CIT2002]_.
Note that citations may get rearranged, e.g., to the bottom of the "page". .. [CIT2002] A citation
Citation labels contain alphanumerics,
Given a citation like [this]_, one
.. [this] here. |
Citation references, like [CIT2002].
Note that citations may get rearranged, e.g., to the bottom of
the "page".
Citation labels contain alphanumerics, underlines, hyphens and fullstops. Case is not significant. Given a citation like [this], one can also refer to it like this.
|
(details)
Plain text | Typical result | Doc Py | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
External hyperlinks, like Python_.
.. _Python: http://www.python.org/ |
|
External hyperlinks, like \ulink{Python}{http://www.python.org/}. |
"Fold-in" is the representation typically used in HTML documents (think of the indirect hyperlink being "folded in" like ingredients into a cake), and "call-out" is more suitable for printed documents, where the link needs to be presented explicitly, for example as a footnote.
Plain text | Typical result | ||||
---|---|---|---|---|---|
Internal crossreferences, like example_.
.. _example: This is an example crossreference target. |
|
(details)
Plain text | Typical result |
---|---|
Python_ is `my favourite
programming language`__. .. _Python: http://www.python.org/ __ Python_ |
The second hyperlink target (the line beginning with "__") is both an indirect hyperlink target (indirectly pointing at the Python website via the "Python_" reference) and an anonymous hyperlink target. In the text, a double-underscore suffix is used to indicate an anonymous hyperlink reference. In an anonymous hyperlink target, the reference text is not repeated. This is useful for references with long text or throw-away references, but the target should be kept close to the reference to prevent them going out of sync.
(details)
Section titles, footnotes, and citations automatically generate hyperlink targets (the title text or footnote/citation label is used as the hyperlink name).
Plain text | Typical result |
---|---|
Titles are targets, too
======================= Implict references, like `Titles are targets, too`_. |
Titles are targets, too
Implict references, like Titles are targets, too. |
(details)
Directives are a general-purpose extension mechanism, a way of adding support for new constructs without adding new syntax. For a description of all standard directives, see reStructuredText Directives.
Plain text | Typical result |
---|---|
For instance:
.. image:: images/ball1.gif |
For instance:
|
(details)
Substitutions are like inline directives, allowing graphics and arbitrary constructs within text.
Plain text | Typical result |
---|---|
The |biohazard| symbol must be
used on containers used to
dispose of medical waste.
.. |biohazard| image:: biohazard.png |
The symbol must be used on containers used to dispose of medical waste. |
(details)
Any text which begins with an explicit markup start but doesn't use the syntax of any of the constructs above, is a comment.
Plain text | Typical result | Doc Py |
---|---|---|
.. This text will not be shown
(but, for instance, in HTML might be rendered as an HTML comment) | % This text will not be shown % (but, for instance, in HTML might be % rendered as an HTML comment) |
|
An empty "comment" does not
"consume" following blocks. .. So this block is not "lost",
|
An empty "comment" does not
"consume" following blocks.
So this block is not "lost", despite its indentation. |
Users who have questions or need assistance with Docutils or reStructuredText should post a message to the Docutils-Users mailing list. The Docutils project web site has more information.
Authors: Tibs (tony@lsl.co.uk or tibs@tibsnjoan.co.uk) and David Goodger (goodger@users.sourceforge.net)