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 Default is to always use the mbox environment.
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/
223 A table of figures can be generated by a command directly to LaTeX::
229 LaTeX also has a command ``\listoftables``.
234 The options ``--section-numbering`` and ``--use-latex-toc``, both
235 influence section numbering.
237 * If ``--use-latex-toc`` is specified the latex-writer generates
238 LaTeX output, so that LaTeX generates a table of contents and
239 generates section numbers. Usually one does not want to have
240 section numbers generated by docutils in this case, therefore
241 ``--no-section-numbering`` should be specified.
243 The advantage is that LaTeX does put page numbers into the
244 table of contents, but the section depth is limited by the
245 used LaTeX-documentclass, usually to three levels.
247 * If section numbering and LaTeX table of contents is used LaTeX and
248 docutils will number sections. To switch off displaying of LaTeX's
249 numbers one has to add following lines to the stylesheet ::
251 % no section number display
253 \def\@seccntformat#1{}
256 \renewcommand{\numberline}[1]{}
258 This enables to have the same section numbers as in other docutils-
259 writers and page numbers in the table of contents.
261 Number pages by chapter
262 -----------------------
264 This can be accomplished with ::
268 From the documentation
270 Basic operation of the package is to redefine ``\thepage`` to be
271 ``\thechapter-\arabic{page}``, and to cause the page number to be reset
272 (to 1) at the start of each chapter. So the pages of chapter 3 will
273 be numbered 3-1, 3-2, ..., and the pages of appendix B will be
274 numbered B-1, B-2, ...
276 See documentation for details and other possibilities.
281 Images are included in LaTeX by the graphicx package. The supported
282 image formats depend on the used driver (dvi, dvips, pdftex, ...).
284 If pdf-image inclusion in pdf files fails, specify
285 ``--graphicx-option=pdftex`` or ``--graphicx-option=auto``.
287 Wrapping text around images requires the wrapfig package.
289 Commands directly to LaTeX
290 ==========================
292 By means of the reST-raw directive one can give commands directly to
293 LaTeX, e.g. forcing a page break::
300 Or setting formulas in LaTeX::
304 $$x^3 + 3x^2a + 3xa^2 + a^3,$$
307 Or making a colorbox: If someone wants to get a red background for a textblock,
308 she/he can put \definecolor{bg}{rgb}{.9,0,0} into style.tex and in
309 reStructuredText do something like this::
312 Nobody expects the spanish inquisition.
315 .. |begincolorbox| raw:: latex
319 \\parbox{0.985\\linewidth}{
321 .. |endcolorbox| raw:: latex
330 Currently maketitle only shows the title and subtitle, date and author are shown
331 in the docinfo table.
333 To change the titlepage layout, e.g. see fancyhdr, one must redefine the
334 maketitle command in the stylesheet::
336 \renewcommand{\maketitle}{
339 \textsf{TITLE \@title} \\
345 ``\@title`` contains the title.
350 Open to be fixed or open to discussion.
355 Definitions in definition lists start on the same line as the term. Putting
356 ``\leavevmode`` after the term results in a new newline if the definition
357 starts with a item list or similar.
359 footnotes and citations
360 -----------------------
362 Initially both were implemented using figures, because hyperlinking back
363 and forth seemed to be impossible. Later images were put into figures.
365 This results in footnotes images and figures possibly being mixed at page
368 * Use LaTeX footnotes and citations for printing or more complex layout.
369 * Footnotes and citations done with figures might excell in hyperlink
372 If ``use-latex-citations`` is used a bibliography is inserted right at
373 the end of the document. *This should be customizable*.
378 :Tablewidth: reST-documents line length is assumed to be 80 characters. The
379 tablewidth is set relative to this value. If someone produces
380 documents with line length of 132 this will fail.
382 Table width is tried to fit in page even if it is wider than
383 the assumed linewidth, still assumed linewidth is a hook.
385 * In tools.txt the option tables right column, there should be some more spacing
386 between the description and the next paragraph "Default:".
388 Paragraph separation in tables is hairy.
389 see http://www.tex.ac.uk/cgi-bin/texfaq2html?label=struttab
391 - The strut solution did not work.
392 - setting extrarowheight added ad top of row not between paragraphs in
393 a cell. ALTHOUGH i set it to 2pt because, text is too close to the topline.
394 - baselineskip/stretch does not help.
395 * Should there be two hlines after table head and on table end ?
396 * Table: multicol cells are always {l}.
397 * The contents of a rowspan cell do not influence table height.
398 (Maybe if we put a tabular inside ?)
399 * Table heads and footer for longtable (firstpage lastpage ..).
400 * Table cells with multirow and multicolumn
401 * literal-blocks in table cells:
403 - If verbatim or flushleft is used one gets vertical space above and below.
404 - This is bad for the topmost paragraph in a cell, therefore the writer
406 - Ragged right fails on followup paragraphs as the vertical space would be
408 * Use tabularx column type ``X`` and let latex decide width.
409 * csv-tables do not have a colwidth.
415 * table-style booktabs: booktabs.sty 1.00 does not work with longtable.
416 * If default table-style is not booktabs, but the document contains a table
417 with class booktabs, one has to add the latex package booktabs. That means
420 \usepackage{booktabs}
422 into your latex-style.
427 * Selection of LaTeX fontsize configurable.
428 * Assumed reST linelength for table width setting configurable.
429 * literal-block indentation configurable.
430 * recognize LaTeX and replace by ``\LaTeX``.
431 * Support embed-stylesheet.
433 * Pdfbookmark level 4 (and greater) does not work (might be settable but OTOH).
434 * center subsection{Abstract} gives a LaTeX error here.
435 ``! LaTeX Error: Something's wrong--perhaps a missing \item.``
436 Committed a HACK: centering by hfill.
437 * Document errors are also too silent.
438 * Use optionlist for docinfo, the table does only work for single page.
439 * Consider peter funk's hooks for TeXpert:
441 * Define his own document preamble (including the choice to
442 choose his own documentclass. That would make the ``--documentclass``
443 option superfluous). I suggest to call this option ``--preamble``
444 * Use two additional hooks to put additional stuff just behind the
445 ``\begin{document}`` and just before the ``\end{document}`` macros.
446 Typical uses would be ``\tableofcontents``, ``\listoffigures`` and
447 ``\appendix``, ``\makeindex``, ``\makeglossary`` and some such
448 for larger documents.
450 * The indentional problematic error in docs/user/rst/demo.txt is not
452 * Footnotes are not all on the same page (as in
453 docs/user/rst/demo.txt) and do not link back and forth.
454 * No link to system errors.
455 * Hyperlinks are not hyphenated; this leads to bad spacing. See
456 docs/user/rst/demo.txt 2.14 directives.
457 * Meta keywords into PDF ?
458 * Pagestyle headings does not work, when sections are starred.
459 * For additional docinfo items: the field_body is inserted as text, i.e. no
461 * Multiple author entries in docinfo (same thing as in html).
462 * keep literal-blocks together on a page, avoid pagebreaks.
464 failed experiments up to now: samepage, minipage, pagebreak 1 to 4 before