1 ================================
2 Generating LaTeX with Docutils
3 ================================
5 :Author: Engelbert Gruber
6 :Contact: grubert@users.sourceforge.net
9 :Copyright: This document has been placed in the public domain.
17 Producing LaTeX code from reST input can be done in at least two ways:
19 a. Transform the internal markup into corresponding LaTeX markup.
20 For example, a section title would be written with the LaTeX section
21 command: ``\section{this section title}``.
23 This can be constrained by the LaTeX document class
24 and may require hacking around bugs/features in LaTeX,
25 but it produces a readable LaTeX file.
27 If you prefer this approach, try ``rst2latex``.
29 b. Use LaTeX as a typesetting system to produce the desired document structure
30 without bothering with the usual LaTeX idioms for representing
31 document structure information.
33 This is not constrained by a particular LaTeX document class
34 and therefore requires hacking around bugs/features in LaTeX.
35 But it produces a hard to read LaTeX file.
37 ``rst2newlatex`` adds a lot of LaTeX macros and uses LaTeX as a typesetter
38 without caring about producing readable LaTeX files.
44 Configuration can be done in two ways:
46 1. Options to the docutils tool: e.g. language selection.
47 2. Options to LaTeX via a stylesheet file.
49 The generated LaTeX documents should be kept processable by a standard
50 LaTeX installation (if such a thing exists), therefore the document
51 contains default settings. To allow *overwriting defaults* the stylesheet
54 Run ``rst2latex.py --help`` to see the command-line options, or have look in
58 ===================== ================================================
59 Configuration Issue Description
60 ===================== ================================================
61 papersize Default: a4paper. Paper geometry can be changed
62 using ``\geometry{xxx}`` entries.
66 * a4paper, b3paper, letterpaper, executivepaper,
68 * landscape, portrait, twoside.
70 and a ton of other option setting margins.
74 \geometry{a5paper,landscape}
75 --------------------- ------------------------------------------------
76 paragraph indent The default LaTeX behavior in most document classes
77 is the following: indent the first line in
78 a paragraph unless it is the first line of
79 a chapter, section, subsection, or
82 This is configurable. For example, you could
83 use the following lines to set paragraph
84 indentation to zero but add a vertical space
87 \setlength{\parindent}{0pt}
88 \setlength{\parskip}{6pt plus 2pt minus 1pt}
89 --------------------- ------------------------------------------------
90 admonitionwidth The width for admonitions.
91 Default: 0.9*textwidth, this can be changed
94 \setlength{\admonitionwidth}{0.7\textwidth}
95 --------------------- ------------------------------------------------
96 docinfowidth The width for the docinfo table.
97 Default: 0.9*textwidth, changed to e.g.::
99 \setlength{\docinfowidth}{0.7\textwidth}
100 --------------------- ------------------------------------------------
101 rubric style The header contains the definition of a new
102 LaTeX command rubric. Inserting::
104 \renewcommand{\rubric}[1]{\subsection*{
105 ~\hfill {\color{red} #1} \hfill ~}}
107 sets rubric to subsection style in red.
109 Default: subsection style italic.
110 --------------------- ------------------------------------------------
111 line spacing Is done with package *setspace*, which gives
112 singlespace, onehalfspace and doublespace
113 commands. To get documentwide double spacing,
114 add this to your stylesheet ::
116 \usepackage{setspace}
123 And yet another, add ``doublesp`` to the
124 documentoptions and e.g. ::
128 for bigger linespacing.
129 --------------------- ------------------------------------------------
130 use verbatim when When possibile, use verbatim for literal-blocks.
131 possible Compatibility alias for "--literal-env=verbatim".
133 A literal-block element, when processed by a
134 docutils-writer might have it's origin in a
135 markup with "::" syntax or a
136 ".. parsed-literal::" directive.
138 A LaTeX verbatim environment is only useable if
139 there are no elements contained in the
141 --------------------- ------------------------------------------------
142 font selection see below
143 ===================== ================================================
148 LaTeX offers three ways
151 Generates a PDF document directly from the LaTeX file. As always one
152 might need to call it twice (thrice) to get internal references correct.
155 Use ``latex`` to generate a dvi file and ``dvipdfm`` to produce a pdf file.
156 If you will take this approach, specify ``documentoptions=dvipdfm``.
159 Produce a dvi file with ``latex``, postscript with ``dvips`` and pdf with
162 see next section for font selection.
168 When generating pdf-files from LaTeX, use the pdflatex command, the files
169 are a lot smaller if postscript fonts are used. This *was* fixed by putting
170 ``\usepackage{times}`` into the stylesheet.
172 It is said that the typewriter font in computer modern font, the default
173 LaTeX font package, is too heavy compared to the others. There is a package
174 or some commands too fix this, which i currently cannot find.
176 Some people diagnose a similar unbalance for the postscript fonts, the
177 package to fix this is ``\usepackage{pslatex}``.
178 pslatex in contrast to the standard LaTeX fonts has a bold typewriter font.
180 As ``times`` does not use the appropriate mathematical fonts and ``pslatex``
181 does not work with T1 encodings one should use::
183 \usepackage{mathptmx}
184 \usepackage[scaled=.90]{helvet}
187 *font encoding* can be selected with option "font-encoding". Default
188 uses package "ae" for old style font encoding use "OT1".
193 The amount of hyphenation is influenced by ``\hyphenpenalty``, setting it to
194 10000 almost prevents hyphenation. As this produces lines with more spcea
195 between words one should increase LaTeX's ``\tolerance`` for this.
205 The generated LaTeX documents are in the input encoding per default.
207 * If the source document is in utf-8 encoding (or
208 ``--output-encoding=utf-8`` is set), LaTeX needs unicode support
209 (the ``ucs`` package). If this is not available, specify
210 a different output-encoding, e.g. ``latin1``.
212 * If LaTeX issues a Warning about unloaded/known characters adding ::
214 \PreloadUnicodePage{n}
216 where *n* is the unicode pagenumber, might help.
218 .. _LaTeX unicode: http://www.unruh.de/DniQ/latex/unicode/
220 * Unicode box drawing characters
222 - generate LaTeX code with ``--output-encoding=utf-8:strict``.
224 - In the latex file, edit the preamble to load "ucs" with "postscript"
225 option and also load the pstricks package::
227 \usepackage{shortvrb}
229 + \usepackage[postscript]{ucs}
230 + \usepackage{pstricks}
231 \usepackage[utf8x]{inputenc}
233 - Convert to PDF with ``latex``, ``dvips``, and ``ps2pdf``.
238 A table of figures can be generated by a command directly to LaTeX::
244 LaTeX also has a command ``\listoftables``.
249 The options ``--section-numbering`` and ``--use-latex-toc``, both
250 influence section numbering.
252 * If ``--use-latex-toc`` is specified the latex-writer generates
253 LaTeX output, so that LaTeX generates a table of contents and
254 generates section numbers. Usually one does not want to have
255 section numbers generated by docutils in this case, therefore
256 ``--no-section-numbering`` should be specified.
258 The advantage is that LaTeX does put page numbers into the
259 table of contents, but the section depth is limited by the
260 used LaTeX-documentclass, usually to three levels.
262 * If section numbering and LaTeX table of contents is used LaTeX and
263 docutils will number sections. To switch off displaying of LaTeX's
264 numbers one has to add following lines to the stylesheet ::
266 % no section number display
268 \def\@seccntformat#1{}
271 \renewcommand{\numberline}[1]{}
273 This enables to have the same section numbers as in other docutils-
274 writers and page numbers in the table of contents.
276 Number pages by chapter
277 -----------------------
279 This can be accomplished with ::
283 From the documentation
285 Basic operation of the package is to redefine ``\thepage`` to be
286 ``\thechapter-\arabic{page}``, and to cause the page number to be reset
287 (to 1) at the start of each chapter. So the pages of chapter 3 will
288 be numbered 3-1, 3-2, ..., and the pages of appendix B will be
289 numbered B-1, B-2, ...
291 See documentation for details and other possibilities.
296 Images are included in LaTeX by the graphicx package. The supported
297 image formats depend on the used driver (dvi, dvips, pdftex, ...).
299 If pdf-image inclusion in pdf files fails, specify
300 ``--graphicx-option=pdftex`` or ``--graphicx-option=auto``.
302 Wrapping text around images requires the wrapfig package.
304 Commands directly to LaTeX
305 ==========================
307 By means of the reST-raw directive one can give commands directly to
308 LaTeX, e.g. forcing a page break::
315 Or setting formulas in LaTeX::
319 $$x^3 + 3x^2a + 3xa^2 + a^3,$$
322 Or making a colorbox: If someone wants to get a red background for a textblock,
323 she/he can put \definecolor{bg}{rgb}{.9,0,0} into style.tex and in
324 reStructuredText do something like this::
327 Nobody expects the spanish inquisition.
330 .. |begincolorbox| raw:: latex
334 \\parbox{0.985\\linewidth}{
336 .. |endcolorbox| raw:: latex
345 Currently maketitle only shows the title and subtitle, date and author are shown
346 in the docinfo table.
348 To change the titlepage layout, e.g. see fancyhdr, one must redefine the
349 maketitle command in the stylesheet::
351 \renewcommand{\maketitle}{
354 \textsf{TITLE \@title} \\
360 ``\@title`` contains the title.
365 Open to be fixed or open to discussion.
370 Definitions in definition lists start on the same line as the term. Putting
371 ``\leavevmode`` after the term results in a new newline if the definition
372 starts with a item list or similar.
374 footnotes and citations
375 -----------------------
377 Initially both were implemented using figures, because hyperlinking back
378 and forth seemed to be impossible. Later images were put into figures.
380 This results in footnotes images and figures possibly being mixed at page
383 * Use LaTeX footnotes and citations for printing or more complex layout.
384 * Footnotes and citations done with figures might excell in hyperlink
387 If ``use-latex-citations`` is used a bibliography is inserted right at
388 the end of the document. *This should be customizable*.
393 :Tablewidth: reST-documents line length is assumed to be 80 characters. The
394 tablewidth is set relative to this value. If someone produces
395 documents with line length of 132 this will fail.
397 Table width is tried to fit in page even if it is wider than
398 the assumed linewidth, still assumed linewidth is a hook.
400 * In tools.txt the option tables right column, there should be some more spacing
401 between the description and the next paragraph "Default:".
403 Paragraph separation in tables is hairy.
404 see http://www.tex.ac.uk/cgi-bin/texfaq2html?label=struttab
406 - The strut solution did not work.
407 - setting extrarowheight added ad top of row not between paragraphs in
408 a cell. ALTHOUGH i set it to 2pt because, text is too close to the topline.
409 - baselineskip/stretch does not help.
410 * Should there be two hlines after table head and on table end ?
411 * Table: multicol cells are always {l}.
412 * The contents of a rowspan cell do not influence table height.
413 (Maybe if we put a tabular inside ?)
414 * Table heads and footer for longtable (firstpage lastpage ..).
415 * Table cells with multirow and multicolumn
416 * literal-blocks in table cells:
418 - If verbatim or flushleft is used one gets vertical space above and below.
419 - This is bad for the topmost paragraph in a cell, therefore the writer
421 - Ragged right fails on followup paragraphs as the vertical space would be
423 * Use tabularx column type ``X`` and let latex decide width.
424 * csv-tables do not have a colwidth.
430 * table-style booktabs: booktabs.sty 1.00 does not work with longtable.
431 * If default table-style is not booktabs, but the document contains a table
432 with class booktabs, one has to add the latex package booktabs. That means
435 \usepackage{booktabs}
437 into your latex-style.
442 * Selection of LaTeX fontsize configurable.
443 * Assumed reST linelength for table width setting configurable.
444 * literal-block indentation configurable.
445 * recognize LaTeX and replace by ``\LaTeX``.
446 * Support embed-stylesheet.
448 * Pdfbookmark level 4 (and greater) does not work (might be settable but OTOH).
449 * center subsection{Abstract} gives a LaTeX error here.
450 ``! LaTeX Error: Something's wrong--perhaps a missing \item.``
451 Committed a HACK: centering by hfill.
452 * Document errors are also too silent.
453 * Use optionlist for docinfo, the table does only work for single page.
454 * Consider peter funk's hooks for TeXpert:
456 * Define his own document preamble (including the choice to
457 choose his own documentclass. That would make the ``--documentclass``
458 option superfluous). I suggest to call this option ``--preamble``
459 * Use two additional hooks to put additional stuff just behind the
460 ``\begin{document}`` and just before the ``\end{document}`` macros.
461 Typical uses would be ``\tableofcontents``, ``\listoffigures`` and
462 ``\appendix``, ``\makeindex``, ``\makeglossary`` and some such
463 for larger documents.
465 * The indentional problematic error in docs/user/rst/demo.txt is not
467 * Footnotes are not all on the same page (as in
468 docs/user/rst/demo.txt) and do not link back and forth.
469 * No link to system errors.
470 * Hyperlinks are not hyphenated; this leads to bad spacing. See
471 docs/user/rst/demo.txt 2.14 directives.
472 * Meta keywords into PDF ?
473 * Pagestyle headings does not work, when sections are starred.
474 * For additional docinfo items: the field_body is inserted as text, i.e. no
476 * Multiple author entries in docinfo (same thing as in html).
477 * keep literal-blocks together on a page, avoid pagebreaks.
479 failed experiments up to now: samepage, minipage, pagebreak 1 to 4 before