Posts Tagged ‘docutils’


rst2wiki with math support

In howto on Jul 3, 2012 by theoryl Tagged: , , , , , ,

Another post about reStructuredText: can you convert reStructuredText into Wiki format? I found in Docutils sandbox a tool: rst2wiki. It currently supports conversion to TWiki and Atlassian Confluence. rst2wiki is available through SVN (web-access)

In Docutils >= 0.8, there is “math” support; on the other hand, TWiki can display LaTeX equations if MathModePlugin is installed and set up properly. The syntax is

<latex [attr="value"]* > formula </latex>

In order to use rst2wiki with math support, we will modify In class WikiTranslator, add:

    # Start Math
    def visit_math(self, node):
        if self.math_start:

    def depart_math(self, node):
        if self.math_end:
    # End Math

In class TWikiTranslator, add:

        self.math_start = '<latex>'
        self.math_end = '</latex>'

Done :)



rst2beamer ‘sectnum_depth’ error

In howto on Jun 28, 2012 by theoryl Tagged: , , , ,

I’m using rst2beamer 0.6.6, with Docutils 0.9 and Python 2.6.5 on Ubuntu 10.04. When I tried to call rst2beamer, there is an error/incompatibility with the latex2e writer that comes with Python 2.6:

AttributeError: Values instance has no attribute ‘sectnum_depth’

To debug this, I edited /usr/local/lib/python2.6/dist-packages/rst2beamer-0.6.6-py2.6.egg/ to add sectnum_depth (set as 0) in BEAMER_DEFAULTS. After the changes, my at line 160 looks like:

    'use_latex_toc': True,
    'output_encoding': 'latin-1',
    'documentclass': 'beamer',
    'documentoptions': 't',#text is at the top of each slide rather than centered.  Changing to 'c' centers the text on each slide (vertically)
    'sectnum_depth': 0,

Now rst2beamer works for me.


Docutils 0.8 in Ubuntu 10.04

In howto on Apr 23, 2012 by theoryl Tagged: , , , , , ,

I wonder if I’m the only person having trouble upgrading Docutils in Ubuntu Lucid Lynx. Docutils is a text processing package, written in Python and for Python, that implements reStructuredText — a plaintext markup language. The Ubuntu 10.04 repository has a really old version 0.6.3. It is missing a feature that is very important to me: the “math” role and directive (added in 0.8).

To upgrade the current version of Docutils, first uninstall the old version. That seems to be the source of all the trouble that I was having. (Before I uninstalled it, all the docutils commands still called the old version 0.6.3). So:

sudo apt-get remove python-docutils

The installation is fairly simple. Download either the snapshot or the stable release listed on the homepage. Then:

tar -xvzf docutils-0.8.1.tar.gz
cd docutils-0.8.1
sudo ./ install

You can check if you have install successfully by doing e.g. --version

To use LaTeX equations with rst directive:

.. math::
    e^{i\pi} = -1

Or with rst role:

:math:`e^{i\pi} = -1`

When using, one can use --math-output command line option to specify the math display format: MathJax (default), HTML, MathML or LaTeX. To get fancy with math in reStructuredText, see this post.