While I'm fine with writing "real" documents in full-blown LaTeX, I often switch to reStructuredText as a lightweight markup language for simplish documents (like meeting notes and stuff). I was quite happy with my workflow (file.txt -> rst2latex-2.6.py -> pdflatex -> file.pdf) until I recently decided that I wanted to use the memoir class, just as I do for my real documents.

The documentation for reStructuredText states that this class is supported via the --documentclass=memoir option. However, my document now fails to compile because of some command fragility issue I don't really understand :

Titles and section titles are converted to something in the lines of :

  This it the title%

which article seems fine with, but which memoir chokes on (about 15 errors in the log file).

Is this an obvious but undocumented bug, or did I do something obviously wrong in the first place ?

Minimal (not)working example :


rm -f test.*

cat >> test.txt <<EOF
This it the title

this is dummy text

rst2latex-2.6.py -V
rst2latex-2.6.py --verbose --documentclass=memoir test.txt test.tex
pdflatex -interaction=nonstopmode test.tex 

As for the output, I get out of it :

rst2latex-2.6.py (Docutils 0.9 [release], Python 2.6.8, on darwin)
This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011/MacPorts 2011_5)
(...then the usual latex yada yada, including about 15 "errors"...)
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.

In case it is useful, here is the complete (and incorrect) LateX document produced by docutils :

% generated by Docutils <http://docutils.sourceforge.net/>
\usepackage{fixltx2e} % LaTeX patches, \textsubscript
\usepackage{cmap} % fix search and cut-and-paste in Acrobat

%%% Custom LaTeX preamble
% PDF Standard Fonts
\usepackage{mathptmx} % Times

%%% User specified packages and stylesheets

%%% Fallback definitions for Docutils-specific commands

% hyperlinks:
  \urlstyle{same} % normal text font (alternatives: tt, rm, sf)
  pdftitle={This it the title},

%%% Title Data
  This it the title%

%%% Body

this is dummy text

  • 1
    Would you please attach also the generated .tex file?
    – egreg
    Commented Jun 7, 2012 at 14:17
  • 1
    I suggest using Pandoc to process the reStructured text file.
    – Sveinung
    Commented Jun 8, 2012 at 7:41
  • @Sveinung thanks heaps for telling me about pandoc. I've just dropped docutils for pandoc, and I think I won't need to look back ever (I'm not even going to report the "bug" to docutils :-)
    – Gyom
    Commented Jun 13, 2012 at 10:23
  • 3
    @Gyom: Note that pandoc does not support all the features of ReST.
    – Aditya
    Commented Jun 13, 2012 at 23:49

2 Answers 2


The problem is in the produced code

%%% Title Data
  This it the title%

that works in article and other classes, but not in memoir because of untimely expansions.

A workaround would be persuading rst2latex to put \protect before \phantomsection and \label, but I really don't understand those commands inside \title should do.

  • I agree with your interpretation. My question is: why does docutils claim that it supports memoir when it generates such code (which clear purpose I don't understand either, btw) ?
    – Gyom
    Commented Jun 7, 2012 at 15:24
  • Well the intention clearly is to make it possible to set a hyperlink to the title. As \title just saves its contents, it wouldn't be possible to put \phantomsection and \label outside its argument. I agree with egreg they need to be protected when put in such a place. Commented Jun 7, 2012 at 15:38
  • 1
    @Gyom The question you pose should be directed to the developers of DocUtils.
    – egreg
    Commented Jun 7, 2012 at 15:52
  • The implementation uses the same code to handle regular sectioning as well: chapters, sections and so on all get their \phantomsection and their \label. This does make some more sense, but yet it still upsets memoir. And now I wonder where I should report the bug: is that a memoir problem, or a docutils bug ?
    – Gyom
    Commented Jun 7, 2012 at 15:53
  • @Gyom Definitely a problem with DocUtils. From what I can see in the primer documentation, section numbers are not automatically computed, so it would be much easier to set secnumdepth to -1000 and use \chapter, \section without *, \phantomsection and \addcontentsline.
    – egreg
    Commented Jun 7, 2012 at 16:04


I suggest you the following answer, that explains that this instructions is needed when hyperref is used with section headers not included in the TOC (sectional commands with an star) or when you include manually a title in the TOC, to reference correctly the heading and not a different paragraph.

  • thanks for that. However I now use ''pandoc'' (as per suggested in the comments above) and am much happier with it than Rst. cheers.
    – Gyom
    Commented Feb 8, 2013 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .