Denigma
hevok @hevok November 13, 2012
Tutorial #rest

Rendering

A data entry can be rendered in various forms, like html and pdf. Specifically for pdf outputs rst2pdf is used.

This renders a data entry output as a legal size, serif document with code in murphy style:

$ rst2pdf article.rst -o article.pdf -s serif,murphy,legal

(perldoc looks better though)

In order to leverage the full set of UTF8 characters one should use a font that supports those encodings such as Dejavu:

$ rst2pdf article.rst -o article.pdf -s serif,dejavu,legal

Code syntax highlighting works via the code-block directive:

.. code-block:: python

import this # Test for something in here: print something, "more"

import this

Test

for something in here: print something, "more"

ReStructuredText can highlight itself:

.. code-block:: rest

reST Test =========

.. class:: test

reST Test

.. class:: test

The linenos option can be used to display line numbers

System Message: ERROR/3 (, line 51)

Error in "code-block" directive: unknown option: "linenos".

.. code-block:: python :linenos:

def func(x,y):
    """Adds up x and y."""
    print(x+y) # Do heavy calculation.

System Message: ERROR/3 (, line 58)

Error in "code-block" directive: unknown option: "linenos".

.. code-block:: python :linenos:

def func(x,y):
    """Adds up x and y."""
    print(x+y) # Do heavy calculation.

Python in console

print("Console online") Console online

Python traceback

System Message: ERROR/3 (, line 74)

Content block expected for the "code-block" directive; none found.

.. code-block:: pytb

Code can also be included into a document:

.. code-block:: python :include: setup.py

start-at:string Will start here

Page Counters

raw pdf can be used to control the page count:

.. raw:: pdf

SetPageCounter 1 lowerroman

SetPageCounter By default sets the counter to 0 and the style to arabic numerals SetPageCounter number style Used to specifically start a page number with the specific style

Possible styles are:

  • loweroman: i, ii, iii

  • roman: I, II, III

  • arabic: 1, 2, 3

  • loweralpha: a, b, c

  • alpha: A, B, C

romans start at 1. Arabic can start at 0, and alphas cannot go beyond 26 (of course).

Page Breaks

PageBreak, EvenPageBreak or OddPageBreak can be used to break a page. Each of these can take an additional arguments which os the name of next page template:

.. raw:: pdf

PageBreak oneColumn

TwoColumn would create a two columned page in the following.

Math

For formula and equation use the math directive:

.. math::

\frac{2 \pm \sqrt{7}}{3}

\begin{equation} \frac{2 \pm \sqrt{7}}{3} \end{equation}

For mathematical symbols use the math role or directive:

:math:\pi

(\pi)