Notes on lists and tables.
[docutils.git] / docs / user / latex.txt
blobd7b8b5fcec1cfcfa056cd27e4f6b0cb9e7475218
1 ================================
2  Generating LaTeX with Docutils
3 ================================
5 :Author: Engelbert Gruber
6 :Contact: grubert@users.sourceforge.net
7 :Revision: $Revision$
8 :Date: $Date$
9 :Copyright: This document has been placed in the public domain.
11 .. contents::
14 Introduction
15 ============
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.
41 Options
42 =======
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
52 is included at last.
54 Run ``rst2latex.py --help`` to see the command-line options, or have look in
55 config documentation.
58 =====================  ================================================
59 Configuration Issue    Description
60 =====================  ================================================
61 papersize              Default: a4paper. Paper geometry can be changed  
62                        using ``\geometry{xxx}`` entries.
64                        Some possibilities:
66                        * a4paper, b3paper, letterpaper, executivepaper,
67                          legalpaper
68                        * landscape, portrait, twoside.
70                        and a ton of other option setting margins.
72                        An example::
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 
80                        subsubsection.
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 
85                        between paragraphs.::
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 
92                        e.g.::
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} 
117                          \doublespacing
119                        Another way ::
121                          \linespread{1.55}
123                        And yet another, add ``doublesp`` to the
124                        documentoptions and e.g. ::
126                          \setstretch{1.7}
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 
140                        literal-block.
141 ---------------------  ------------------------------------------------
142 font selection         see below
143 =====================  ================================================
145 PDF generation
146 --------------
148 LaTeX offers three ways
150 pdflatex :
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.
154 latex dvipdfm :
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``.
158 latex dvips ps2pdf :
159   Produce a dvi file with ``latex``, postscript with ``dvips`` and pdf with
160   ``ps2pdf``.
162 see next section for font selection.
165 Font selection
166 --------------
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}
185   \usepackage{courier}
187 *font encoding* can be selected with option "font-encoding". Default
188 uses package "ae" for old style font encoding use "OT1". 
190 Hyphenation
191 -----------
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.
197 E.g. try ::
199   \hyphenpenalty=5000
200   \tolerance=1000
202 Unicode
203 -------
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 Table of figures
221 ----------------
223 A table of figures can be generated by a command directly to LaTeX::
225   .. raw:: latex
227      \listoffigures
229 LaTeX also has a command ``\listoftables``.
231 Section numbering
232 -----------------
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
252     \makeatletter
253     \def\@seccntformat#1{}
254     \makeatother
255     % no numbers in toc
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 ::
266   \usepackage{chappg}
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.
278 Images
279 ------
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``.
288 Commands directly to LaTeX
289 ==========================
291 By means of the reST-raw directive one can give commands directly to 
292 LaTeX, e.g. forcing a page break::
294   .. raw:: latex
296      \newpage
299 Or setting formulas in LaTeX::
301   .. raw:: latex
303      $$x^3 + 3x^2a + 3xa^2 + a^3,$$
306 Or making a colorbox: If someone wants to get a red background for a textblock,
307 she/he can put \definecolor{bg}{rgb}{.9,0,0} into style.tex and in
308 reStructuredText do something like this::
310   |begincolorbox|
311   Nobody expects the spanish inquisition.
312   |endcolorbox|
314   .. |begincolorbox| raw:: latex
316      \\begin{center}
317      \\colorbox{bg}{
318      \\parbox{0.985\\linewidth}{
320   .. |endcolorbox| raw:: latex
322      }}
323      \\end{center}
326 Custom title page
327 -----------------
329 Currently maketitle only shows the title and subtitle, date and author are shown 
330 in the docinfo table.
332 To change the titlepage layout, e.g. see fancyhdr, one must redefine the
333 maketitle command in the stylesheet::
335   \renewcommand{\maketitle}{
336     \begin{titlepage}
337       \begin{center}
338       \textsf{TITLE \@title} \\
339       Date: \today
340       \end{center}
341     \end{titlepage}
342   }
344 ``\@title`` contains the title.
346 Problems
347 ========
349 Open to be fixed or open to discussion.
351 Lists
352 -----
354 Definitions in definition lists start on the same line as the term. Putting 
355 ``\leavevmode`` after the term results in a new newline if the definition
356 starts with a item list or similar.
358 footnotes and citations
359 -----------------------
361 Initially both were implemented using figures, because hyperlinking back
362 and forth seemed to be impossible. Later images were put into figures.
364 This results in footnotes images and figures possibly being mixed at page 
365 foot.
367 * Use LaTeX footnotes and citations for printing or more complex layout.
368 * Footnotes and citations done with figures might excell in hyperlink
369   support.
371 If ``use-latex-citations`` is used a bibliography is inserted right at
372 the end of the document. *This should be customizable*.
374 Tables
375 ------
377 :Tablewidth: reST-documents line length is assumed to be 80 characters. The
378              tablewidth is set relative to this value. If someone produces
379              documents with line length of 132 this will fail.
381              Table width is tried to fit in page even if it is wider than
382              the assumed linewidth, still assumed linewidth is a hook. 
384 * In tools.txt the option tables right column, there should be some more spacing
385   between the description and the next paragraph "Default:".
387   Paragraph separation in tables is hairy. 
388   see http://www.tex.ac.uk/cgi-bin/texfaq2html?label=struttab
390   - The strut solution did not work.
391   - setting extrarowheight added ad top of row not between paragraphs in
392     a cell. ALTHOUGH i set it to 2pt because, text is too close to the topline.
393   - baselineskip/stretch does not help.
394 * Should there be two hlines after table head and on table end ?
395 * Table: multicol cells are always {l}.
396 * The contents of a rowspan cell do not influence table height.
397   (Maybe if we put a tabular inside ?)
398 * Table heads and footer for longtable (firstpage lastpage ..).
399 * Table cells with multirow and multicolumn
400 * literal-blocks in table cells: 
402   - If verbatim or flushleft is used one gets vertical space above and below.
403   - This is bad for the topmost paragraph in a cell, therefore the writer
404     uses raggedright. 
405   - Ragged right fails on followup paragraphs as the vertical space would be
406     missing.
407 * Use tabularx column type ``X`` and let latex decide width.
408 * csv-tables do not have a colwidth.
411 Notes
412 ~~~~~
414 * table-style booktabs: booktabs.sty 1.00 does not work with longtable.
415 * If default table-style is not booktabs, but the document contains a table 
416   with class booktabs, one has to add the latex package booktabs. That means
417   put the line ::
419     \usepackage{booktabs}
421   into your latex-style.
423 Miscellaneous
424 -------------
426 * Selection of LaTeX fontsize configurable.
427 * Assumed reST linelength for table width setting configurable.
428 * literal-block indentation configurable.
429 * recognize LaTeX and replace by ``\LaTeX``.
430 * Support embed-stylesheet.
431 * Sidebar handling.
432 * Pdfbookmark level 4 (and greater) does not work (might be settable but OTOH).
433 * center subsection{Abstract} gives a LaTeX error here.
434   ``! LaTeX Error: Something's wrong--perhaps a missing \item.``
435   Committed a HACK: centering by hfill.
436 * Document errors are also too silent.
437 * Use optionlist for docinfo, the table does only work for single page.
438 * Consider peter funk's hooks for TeXpert:
439   
440   * Define his own document preamble (including the choice to
441     choose his own documentclass.  That would make the ``--documentclass``
442     option superfluous).  I suggest to call this option ``--preamble``
443   * Use two additional hooks to put additional stuff just behind the 
444     ``\begin{document}`` and just before the ``\end{document}`` macros.
445     Typical uses would be ``\tableofcontents``, ``\listoffigures`` and
446     ``\appendix``, ``\makeindex``, ``\makeglossary`` and some such 
447     for larger documents.
449 * The indentional problematic error in docs/user/rst/demo.txt is not
450   referring anywhere.
451 * Footnotes are not all on the same page (as in
452   docs/user/rst/demo.txt) and do not link back and forth.
453 * No link to system errors.
454 * Hyperlinks are not hyphenated; this leads to bad spacing. See
455   docs/user/rst/demo.txt 2.14 directives.
456 * Meta keywords into PDF ?
457 * Pagestyle headings does not work, when sections are starred.
458 * For additional docinfo items: the field_body is inserted as text, i.e. no
459   markup is done.
460 * Multiple author entries in docinfo (same thing as in html).
461 * keep literal-blocks together on a page, avoid pagebreaks.
463   failed experiments up to now: samepage, minipage, pagebreak 1 to 4 before
464   the block.