LaTeX, is a document preparation system for high-quality typesetting. It
is most often used for medium-to-large technical or scientific documents but
it can be used for almost any form of publishing. There exists a wide
selection of LaTeX Documentation on the net and books on LaTeX and
related topics. For an introduction to LaTeX see, e.g., LaTeX2e for
authors.
Unlike HTML with CSS, LaTeX uses one common language for markup and style
definitions. Separation of content and style is realized by collecting style
definitions in LaTeX classes and packages, or the
document preamble.
LaTeX document classes and packages (similar to Python modules or C
libraries) provide means to extend or modify the LaTeX language by
redefining macros or providing new ones.
Using the document class and style sheet configuration options, you
can select from a huge selection of classes and packages (standard as well
as user contributed) coming with your TeX distribution or available at
CTAN as well as custom style sheets.
Some Docutils objects have no LaTeX counterpart, they will be typeset
using a Docutils specific LaTeX macro (command, environment, or
length) to allow customization. By convention, special macros use the
prefix \DU[1].
The docutils.sty LaTeX package providing required definitions is
part of Docutils ≥ 0.17 and available on CTAN since 2020-09-04.
The generated LaTeX documents should be kept processable by a standard LaTeX
installation. Therefore fallback definitions are included after the custom
style sheets, if a macro is required in the document and
the stylesheet setting does not include "docutils".
Custom style sheets can define alternative implementations with
\newcommand, \newenvironment, and \newlength followed by
\setlength.
Definitions with raw LaTeX are part of the document body. Use
\def, \renewcommand or \renewenvironment, and \setlength.
See the test output standalone_rst_latex.tex for an example of the fallback
definitions and their use in the document.
In LaTeX, the size of the pixel unitcan be configured. It defaults to 1 px = 1/72 in
while the CSS3 pixel unit is defined as 1 px = 1/96 in.
LaTeX uses "pt" for the American point (TeX point), 1 pt = 1/72.25 in.
The DTP point (Postscript point) used in CSS is available in LaTeX
as big point, 1 bp = 1/72 in.
Lengths specified in the source with unit "pt" are written with unit
"bp" by the LaTeX writer. In raw LaTeX and custom style sheets,
the DTP point must be specified as "bp", while "pt" is interpreted as
TeX point.
The default length unit (added by the latex writer to length values
without unit) is the DTP point "bp". It will change to "px" in
Docutils 1.0.
In most cases, LaTeX code is not the desired end-format of the document.
LaTeX offers many ways to generate PDF documents from the LaTeX
source, including:
pdflatex
Generates a PDF document directly from the LaTeX file.
Export your document with the LaTeX2e writer (writer
name "latex", frontend tool rst2latex).
xelatex or lualatex
The XeTeX and LuaTeX engines work with input files in UTF-8 encoding
and system fonts. Export your document with the XeLaTeX writer (writer
name "xetex", frontend tool rst2xetex).
You may need to call LaTeX two or three times to get internal references
correct.
rubber
The Rubber wrapper for LaTeX and friends can be used to automatically
run all programs the required number of times and delete "spurious" files.
This includes processing bibliographic references or indices, as well as
compilation or conversion of figures.
The "classes" attribute is one of the common attributes, shared by all
Docutils elements.
In HTML, the common use is to provide selection criteria for style rules in
CSS stylesheets. As there is no comparable framework for LaTeX, Docutils
emulates some of this behaviour via Docutils specific LaTeX macros.
Due to LaTeX limitations, class arguments are ignored for
some elements (e.g. a rubric).
Inline elements
are handled via the \DUrole{} macro that calls the optional styling
command \DUrole«classargument» with one argument (the role content).
See custom interpreted text roles.
Block level elements
are wrapped in "class environments":
\begin{DUclass} calls the optional styling command
\DUCLASS«classargument»{}, \end{DUclass} tries
\endDUCLASS«classargument».
Customization is done by defining matching macros or environments.
Example 1:
Use small caps font inside elements with class value "custom".
Inline elements
The LaTeX function \textsc sets the argument in small caps:
\newcommand{\DUrolecustom}[1]{\textsc{#1}}
Block-level elements
The LaTeX directive (macro without argument) \scshape switches to
the small caps font. Its effect is confined to the wrapper DUclass
environment:
\newcommand*{\DUCLASScustom}{\scshape}
Example 2:
It is even possible to locally redefine other LaTeX macros, e.g. to
turn bullet lists with class value "enumerateitems" into enumerated
lists:
Class arguments may contain numbers and hyphens, which need special
treatment in LaTeX command names (see class directive). The commands
\csname and \endcsname or the special command \@namedef can
help with the definition of corresponding macros or environments, e.g.:
\expandafter\newcommand\csname gg1\endcsname{Definition of gg1.}
Elements can have multiple class arguments. In contrast to HTML/CSS, the
order of the class arguments cannot be ignored in LaTeX
Class handling differs for some elements and class values:
Class argument values starting with align- are transformed to
"align" argument values. Class argument values starting with
language- set the elements language property.
The table element recognizes some special class values. See section
table style.
If the legacy-class-functions setting is True, the special macros
\DUadmonition and \DUtitle are written with a comma separated
list of class values as optional argument.
A common way of LaTeX customization is the preparation of custom style
sheets, either as simple files with LaTeX code snippets or as home-made
LaTeX packages (see the clsguide for an introduction on LaTeX
package writing).
It is possible to specify multiple style sheets and mix LaTeX
packages with custom style sheets.
You cannot specify package options with the stylesheet setting. If
you need to pass options to the package, use the \usepackage
command in the LaTeX preamble or a custom style sheet.
Example 1:
Select Latin Modern fonts with the lmodern package:
--stylesheet=lmodern
Example 2:
Use the preamble.tex home-made custom style sheet together with
the package kerkis (Bookman fonts):
--stylesheet=kerkis,preamble.tex
Example 3:
Select Palatino fonts with old-style numbers and true small-caps
with the LaTeX command
Configuration by LaTeX code in the document preamble is also possible
without a separate stylesheet. This way, packages can be loaded with
options or commands re-defined without the need to create a separate
file (new in Docutils 0.7).
Some customizations require commands at places other than the insertion
point of stylesheets or depend on the deletion/replacement of parts of the
document. This can be done via a custom template. See the publisher
documentation for a description of the document parts available in a
template file.
In addition to the 'default.tex' template, the latex writer directory
contains the alternatives 'titlepage.tex' (separate title page) and
'titlingpage.tex'" (separate title page with the memoirdocument class).
Example:
Print a title page including docinfo, dedication, and abstract:
By means of the raw directive or a derived custom role, one can
give commands directly to LaTeX. These can be both, styling as well as
printing commands.
Example:
Math formula:
.. raw:: latex
\[x^3 + 3x^2a + 3xa^2 + a^3,\]
(Drawback: the formula will be invisible in other output formats. Better
use the math directive)
Most LaTeX code examples also work as raw LaTeX inside the document.
An exception are commands that need to be given in the document
preamble (e.g. package loading with \usepackage, which can be
achieved with the --style-sheet or --latex-preamble command
line options instead). Remember to use re-defining commands for
customizing Docutils specific LaTeX macros with raw LaTeX.
The rst role directive allows defining custom text roles that mark
parts of inline text (spans) with class arguments (see section classes).
Commands:
\DUrole: dispatcher command
\DUrole«classargument»: optional styling command with 1 argument (the
role content).
Default:
The default definition of \DUrole{«classargument»}{} calls the macro
named \DUrole«classargument»{} if it is defined and silently ignores
this class argument if not.
A lone top-level section title is (usually) transformed to the document title
(see section structure).
The format of the document title is defined by the document class. The
"article" document class uses an in-page title and the "report" and "book"
classes write a separate title page. See the TeX FAQ on how to customize
the style of document titles.
The default title page shows only title and subtitle, date and author
are shown in the document info table.
Figures might be typeset at the place of definition (default) or "float"
to a suitable place at the top or bottom of a page. This is implemented
using the float package.
Command:
\floatplacement
The placement setting is valid from the point of definition until the next
\floatplacement command or the end of the document. See float.pdf for
details.
Default:
\floatplacement{figure}{H} (here definitely). This corresponds most
closely to the source and HTML placement (principle of least surprise).
Example 1:
In a custom style sheet, set the default to let LaTeX find a suitable
place for figure floats:
\usepackage{mathptmx} % Times for serif and math
\usepackage[scaled=.90]{helvet} % downscaled Helvetica for sans serif
\usepackage{courier} % Courier for teletype (mono-space)
Since Docutils 0.7, this is the default value of the
latex-preamble option.
Example 3:
Use the teletype font from the txfonts package. As there is no
package for this, we re-define the font macro with the LaTeX code:
\renewcommand{\ttdefault}{txtt}
XeTeX/LuaTeX
using the macros of the fontspec package. Use some font-viewer or
-manager (e.g. fontmatrix) to find out the correct names of the
fonts on your system.
Example:
DejaVu, very wide coverage, screen optimized. As this font
runs wide, add DIV=10 to the documentoptions:
\setmainfont{DejaVu Serif}
\setsansfont{DejaVu Sans}
\setmonofont[HyphenChar=None]{DejaVu Sans Mono}
different fonts for roman, sans-serif and typewriter fonts.
-1
invocation somewhat more complex, as several packages are
required for a complete font set, sometimes including package
options.
Roman (serif) PSNFSS fonts:
Bookman
good legibility but very wide.
Charter
bread-and-butter type optimized for printing on low-resolution
printers
New Century Schoolbook
good legibility but very wide.
Palatino
+1
recommended by font experts
+1
good LaTeX support including matching math fonts, small caps,
old-style figures
-1
bad rendering in xpdf viewer (auto-hinting leads to different
x-hight for different characters at some magnifications)
(this is fixed in recent versions).
This will improve the look on screen with the default Computer Modern
fonts at the expense of problems with search and text extraction
The recommended way is to select a T1-encoded "Type 1" (vector)
font, for example Latin Modern
Example 2:
Support for characters in the Unicode blocks Latin, Latin-1 Supplement,
and Greek together with a T1-encoded "Type 1" (vector) font, for example
Latin Modern:
Add font size in points to the document options, e.g.
--documentoptions=12, use e.g. the document classes provided by
extsizes for values other than [10,11,12].
By default, footnotes are set with Docutils-specific wrappers around
the standard \footnotemark and \footnotetext commands. You
can configure the footnote layout similar to standard LaTeX footnotes
in a custom style sheet or the LaTeX preamble.
Further configuration is possible by alternative definitions of
\DUfootnotemark and \DUfootnotetext
Example 1:
Set footnote text with a hanging indent.
This is the default with KOMA-script classes, e.g:
Place the footnote text where it appears in the source document (instead
of at the page bottom). This can be used to get the effect of endnotes
(needs the hanging package):
The amount of hyphenation is influenced by \hyphenpenalty, setting it to
10000 almost prevents hyphenation. As this produces lines with more space
between words one should increase Latex's \tolerance for this.
URLs are typeset with the "url" package (loaded implicitly by "hyperref").
The font of URLs can be defined with the \urlstyle command. Valid
arguments are
same:
normal text font, Docutils default,
tt:
teletype (monospaced), LaTeX default,
rm:
roman,
sf:
sans serif
Example:
Custom loading of the hyperref package also switches to
the LaTeX default (monospaced fonts for URLs). Reset to use the text
font:
To suppress the hyper-linking completely (e.g. for printing or to
avoid clashes with other packages), set hyperref-options to "draft"
or load the "nohyperref" package that comes with the "hyperref"
bundle.
The global document language can be set with the language-code
configuration setting. The language of text parts can be set adding the
language tag prefixed by "language-" to an element's classes
attribute, e.g. language-el for a Greek text part.
The lstlisting environment is highly configurable (as documented in
listings.pdf) and provides syntax highlight for many programming languages,
for instance
By default, paper size and margin settings are determined by the document
class.
The following packages help to configure the page layout:
The typearea package (part of the KOMA-script bundle) calculates a
good page layout (based on rules and recommendations of typography
experts).
See the KOMA-Script Guide for details on what is a good layout and
how this is achieved.
The geometry package is recommended if you have to follow guidelines
with fixed values for the margins.
For details see the geometry manual.
Example 1:
Let typearea determine the type area with DIV=calc in the
documentoptions:
--documentoptions='a4paper,DIV=calc'
The DIV option can also be specified, like DIV=10. It defines how
"crowded" a page will be: larger values mean larger text area (at the
expense of readability).
With the fancyhdr package or the KOMA-script classes, you can define
custom page head- and foot-lines.
The "header" and "footer" directives save their content in the macros
\DUheader rsp. \DUfooter. The macros can be used in LaTeX code and
will be replaced by LaTeX with the content of the directives.
Example:
LaTeX code to place left-aligned "header" and "footer" on every
page with fancyhdr:
If sectnum_xform is False, section numbers are generated by LaTeX. In this
case the "prefix" and "suffix" arguments of the sectnum directive are
ignored. The section number style is determined by the document class
and can be configured in a LaTeX style sheet, e.g.:
Sidebars are like miniature, parallel documents that occur inside other
documents, providing related or reference material. They can be likened to
super-footnotes; their content is outside of the flow of the document's main
text.
Make sure the margin is wide enough to hold the note.
This fails with some constructs inside the side bar and where
marginpar cannot be used, e.g., inside floats, footnotes, or in frames
made with the framed package (see marginnote).
A pre-configured table style can be globally selected via the table_style
setting or set for individual tables via a class directive or the class
option of the table directive.
Supported values:
standard
Borders around all cells.
booktabs
A line above and below the table and one after the head.
borderless
No borders around table cells.
colwidths-auto
Column width determination by LaTeX.
Overridden by the table directive's "widths" option.
By default, column widths are computed from the source column widths.
The legacy_column_widths setting selects the conversion algorithm.
Custom column widths can be set with the "widths" option of the table
directive.
See also the section on problems with tables below.
Encode the LaTeX source file with the ISO latin-1 (west european)
8-bit encoding (the default in Docutils versions up to 0.6.):
--output-encoding=latin-1
Note:
8-bit LaTeX comes with two options for UTF-8 support,
utf8:
by the standard inputenc package with only limited coverage
(mainly accented characters).
utf8x:
supported by the ucs package covers a wider range of Unicode
characters than does "utf8". It is, however, a non-standard
extension and no longer developed.
Currently, the "latex2e" writer inserts \usepackage[utf8]{inputenc}
into the LaTeX source if it is UTF-8 encoded.
A topic is like a block quote with a title, or a self-contained section
with no subsections. Topics and rubrics can be used at places where a
section title is not allowed (e.g. inside a directive).
Transitions are commonly seen in novels and short fiction, as a gap
spanning one or more lines, marking text divisions or signaling changes in
subject, time, point of view, or emphasis.
What I am looking for when I try Docutils is if the PDF files I can get
are of high quality. Unfortunately that never is the case.
So am I just stupid or is there a way to get really high quality pdf from
Docutils?
Make sure the default font is not a bitmap font.
There is Latin Modern if you like the look of the standard font on paper,
but want nice pdf. Or select something else like Times, Palatino, ... via
configuration options/settings. See font and font-encoding.
Docutils stores the footnote text in a separate node, at the position where
it is specified in the input document. With the default settings, the
footnote is put at the bottom of the page where the footnote text is located,
maybe far away from the footnote mark (see e.g. rst/demo.rst).
To get footnote mark and text at the same page, keep footnote mark and
footnote text close together.
The Rubber wrapper can be used for automatic image conversion.
Docutils expects a URI-reference as pointer to the image ressource.
LaTeX requires it to refer to a local file.
By default, LaTeX does not accept spaces and more than one dot in the
filename. If using "traditional" filenames is not an option, loading the
grffile package may help.
If you convert the LaTeX source with a legacy program, you might get this
error.
The unit "px" was introduced by the pdfTeX converter on 2005-02-04.
pdfTeX is used also for conversion into DVI format in all modern LaTeX
distributions (since ca. 2006).
The currency sign (\u00a4) is not supported by all fonts (some have
an Euro sign at its place). You might see an error like:
! Package textcomp Error: Symbol \textcurrency not provided by
(textcomp) font family ptm in TS1 encoding.
(textcomp) Default family used instead.
(which in case of font family "ptm" is a false positive).
Add either warn (turn the error in a warning, use the default (bitmap)
symbol), or force,almostfull (use the symbol provided by the font at
the users risk) to the document options or use a different font package.
The "latex" writer uses the LaTeX package Babel and the "xetex" writer
uses Polyglossia for language support (hyphenation rules, auto-text
localisations and typographic rules). Polyglossia supports more
languages, so switching to the "xetex" writer may help.
Search for text that contains characters outside the ASCII range might
fail. See font and font encoding (as well as Searching PDF files
for background information).
Initially both were implemented using figure floats, because hyperlinking
back and forth seemed to be impossible. Later the figure directive was
added that puts images into figure floats.
This results in footnotes, citations, and figures possibly being mixed at
page foot.
If use-latex-citations is used, a bibliography is inserted right at
the end of the document. This should be customizable.
If use-latex-citations is used adjacent citation references (separated
only by a single space or a newline) are combined to a single citation
group, i.e. [cite1]_ [cite2]_ results in \cite{cite1,cite2}.
The appearance in the output can be configured in a style sheet.
Figures are always as wide as the containing text. The "figwidth" argument
is currently not supported. As a consequence, the "align" argument has no
effect.
Wrapping text around figures is currently not supported. (Requires the
wrapfig package.)
Pdfbookmark level 4 (and greater) does not work (might be settable but
complicated).
Hyperlinks are not hyphenated; this leads to bad spacing. See
docs/user/rst/demo.rst 2.14 directives.
Pagestyle headings does not work, when sections are starred. Use LaTeX for
the section numbering with the options/settings--no-section-numbers (command line) or sectnum_xform: False
(config file).