Posts Tagged ‘rst’

Articles

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 wiki.py. In class WikiTranslator, add:

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

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

In class TWikiTranslator, add:

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

Done :)

Articles

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/rst2beamer.py to add sectnum_depth (set as 0) in BEAMER_DEFAULTS. After the changes, my rst2beamer.py at line 160 looks like:

BEAMER_DEFAULTS = {
    '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.

Articles

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 ./setup.py install

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

rst2html.py --version

To use LaTeX equations with rst directive:

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

Or with rst role:

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

When using rst2html.py, 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.

Articles

reStructuredText syntax highlighting in gedit

In howto on Nov 28, 2011 by theoryl Tagged: , , , , ,

A quick way to add reStructuredText syntax highlight to gedit 2.x is to “steal” from GMate, which consists of a set of plugins that makes gedit more similar to TextMate.

1. Download the .rst language specifications https://github.com/gmate/gmate/blob/master/lang-specs/rst.lang.
2. Put it into /usr/share/gtksourceview-2.0/language-specs/
3. Create .local/share/mime/packages/rst.xml with

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="text/restructured">
    <alias type="text/x-rst" />
    <comment xml:lang="en">reStructuredText document</comment>
    <glob pattern="*.rst"/>
  </mime-type>
</mime-info>

4. Do update-mime-database /usr/share/mime

That’s it. However, the syntax highlighting is quite limited (e.g. it doesn’t recognize directives, footnotes etc)