Debian Codegraph @

test/expensive_benchmarks/docutils_data/docs/user/latex.txt

raw
1 ================================
2 Generating LaTeX with Docutils
3 ================================
4
5 :Author: Engelbert Gruber, Günter Milde
6 :Contact: [email protected]
7 :Revision: $Revision$
8 :Date: $Date$
9 :Copyright: This document has been placed in the public domain.
10 :Abstract: This document covers topics specific to Docutils' LaTeX_ export.
11
12 .. contents::
13 .. sectnum::
14
15
16 LaTeX
17 =====
18
19 LaTeX__, is a document preparation system for high-quality typesetting. It
20 is most often used for medium-to-large technical or scientific documents but
21 it can be used for almost any form of publishing. There exists a wide
22 selection of `LaTeX Documentation on the net`_ and `books on LaTeX and
23 related topics`_. For an introduction to LaTeX see, e.g., `LaTeX2e for
24 authors`_.
25
26 __ http://www.latex-project.org/
27 .. _LaTeX2e for authors:
28 http://www.latex-project.org/guides/usrguide.pdf
29 .. _LaTeX Documentation on the net:
30 http://www.latex-project.org/guides/
31 .. _books on LaTeX and related topics:
32 http://www.latex-project.org/guides/books.html
33
34
35 .. _LaTeX packages:
36
37 LaTeX document classes and packages
38 -----------------------------------
39
40 Unlike HTML with CSS, LaTeX uses one common language for markup and style
41 definitions. Separation of content and style is realized by collecting style
42 definitions in LaTeX classes and packages, or the
43 `document preamble <LaTeX preamble_>`_.
44
45 LaTeX document classes and packages (similar to Python modules or C
46 libraries) provide means to extend or modify the LaTeX language by
47 redefining macros or providing new ones.
48
49 Using the `document class`_ and `style sheet`_ configuration options, you
50 can select from a *huge* selection of classes and packages (standard as well
51 as user contributed) coming with your TeX distribution or available at
52 CTAN_ as well as custom style sheets.
53
54 .. _CTAN: http://www.ctan.org
55
56
57 Docutils specific LaTeX macros
58 ------------------------------
59
60 Some Docutils objects have no LaTeX counterpart, they will be typeset
61 using a Docutils specific LaTeX *macro* (command, environment, or
62 length) to allow customization. By convention, special macros use the
63 prefix ``\DU``\ [#]_.
64
65 The `docutils.sty`_ LaTeX package providing required definitions is
66 part of Docutils ≥ 0.17 and available on CTAN since 2020-09-04.
67 The generated LaTeX documents should be kept processable by a standard LaTeX
68 installation. Therefore fallback definitions are included after the `custom
69 style sheets`_, if a macro is required in the document and
70 the `stylesheet`_ setting does not include "docutils".
71
72 * Custom `style sheets`_ can define alternative implementations with
73 ``\newcommand``, ``\newenvironment``, and ``\newlength`` followed by
74 ``\setlength``.
75
76 * Definitions with `raw LaTeX`_ are part of the document body. Use
77 ``\def``, ``\renewcommand`` or ``\renewenvironment``, and ``\setlength``.
78
79 See the test output standalone_rst_latex.tex_ for an example of the fallback
80 definitions and their use in the document.
81
82 .. [#] DU for Documentation Utilities = Docutils
83
84 .. _docutils.sty: https://ctan.org/pkg/docutils
85
86
87
88 Length units
89 ------------
90
91 LaTeX supports all `length units`_ defined for Docutils plus the
92 following less common units:
93
94 :pt: typewriter's (or LaTeX) point (1 pt = 1/72.27 in)
95 :dd: didôt (1 dd = 1238/1157 pt)
96 :cc: cîcero (1 cc = 12 dd)
97 :sp: scaled point (1sp = 1/65536pt)
98
99 .. attention:: Different definitions of the unit "pt"!
100
101 * In Docutils (as well as CSS) the unit symbol "pt" denotes the
102 `Postscript point` or `DTP point`.
103
104 * LaTeX uses "pt" for the `LaTeX point`, which is unknown to Docutils and
105 0.3 % smaller.
106
107 * The `DTP point` is available in LaTeX as "bp" (big point):
108
109 1 pt = 1/72.25 in < 1 bp = 1/72 in
110
111 Lengths specified in the document with unit "pt" will be given the
112 unit "bp" in the LaTeX source.
113
114 In `raw LaTeX`_ and `custom style sheets`_, the `DTP point` must be
115 specified as "bp", while "pt" is interpreted as `LaTeX point`.
116
117 The default length unit (added by Docutils to length specifications
118 without unit) is the "DTP point".
119
120 .. _length units: ../ref/rst/restructuredtext.html#length-units
121
122
123 PDF generation
124 ==============
125
126 In most cases, LaTeX code is not the desired end-format of the document.
127 LaTeX offers many ways to generate PDF documents from the LaTeX
128 source, including:
129
130 _`pdflatex`
131 Generates a PDF document directly from the LaTeX file.
132 Export your document with the _`LaTeX2e writer` (writer
133 name "``latex``", frontend tool rst2latex.py_).
134
135 _`xelatex` or _`lualatex`
136 The `XeTeX`_ and LuaTeX_ engines work with input files in UTF-8 encoding
137 and system fonts. Export your document with the _`XeLaTeX writer` (writer
138 name "``xetex``", frontend tool rst2xetex.py_).
139
140 You may need to call latex two or three times to get internal references
141 correct.
142
143 .. _documentoptions: config.html#documentoptions
144 .. _xetex: http://tug.org/xetex/
145 .. _luatex: http://luatex.org/
146 .. _rst2latex.py: tools.html#rst2latex-py
147 .. _rst2xetex.py: tools.html#rst2xetex-py
148
149 _`rubber`
150 The Rubber__ wrapper for LaTeX and friends can be used to automatically
151 run all programs the required number of times and delete "spurious" files.
152 This includes processing bibliographic references or indices, as well as
153 compilation or conversion of figures.
154
155 __ https://gitlab.com/latex-rubber/rubber/
156
157
158 Configuration
159 =============
160
161 .. contents:: :local:
162
163 .. _option:
164
165 Options/Settings
166 ----------------
167
168 Options can be specified as
169
170 * command-line options, or
171
172 * configuration settings.
173
174 Run ``rst2latex.py --help`` to get a list of available options;
175 see `Docutils Configuration`_ for details.
176
177 .. _Docutils Configuration: config.html
178
179 Classes
180 -------
181
182 The `"classes" attribute`_ is one of the common attributes, shared by all
183 Docutils elements.
184 In HTML, the common use is to provide selection criteria for style rules in
185 CSS stylesheets. As there is no comparable framework for LaTeX, Docutils
186 emulates some of this behaviour via `Docutils specific LaTeX macros`_.
187 Due to LaTeX limitations, class arguments are ignored for
188 some elements (e.g. a rubric_).
189
190 *Inline elements*
191 are handled via the ``\DUrole{}`` macro that calls the optional styling
192 command ``\DUrole«classargument»`` with one argument (the role content).
193 See `custom interpreted text roles`_.
194
195 *Block level elements*
196 are wrapped in "class environments":
197 ``\begin{DUclass}`` calls the optional styling command
198 ``\DUCLASS«classargument»{}``, ``\end{DUclass}`` tries
199 ``\endDUCLASS«classargument»``.
200
201 Customization is done by defining matching macros or environments.
202
203 Example 1:
204 Use small caps font inside elements with class value "custom".
205
206 *Inline elements*
207 The LaTeX function ``\textsc`` sets the argument in small caps::
208
209 \newcommand{\DUrolecustom}[1]{\textsc{#1}}
210
211 *Block-level elements*
212 The LaTeX directive (macro without argument) ``\scshape`` switches to
213 the small caps font. Its effect is confined to the wrapper ``DUclass``
214 environment::
215
216 \newcommand*{\DUCLASScustom}{\scshape}
217
218 Example 2:
219 It is even possible to locally redefine other LaTeX macros, e.g. to
220 turn bullet lists with class value "enumerateitems" into enumerated
221 lists::
222
223 \newcommand*{\DUCLASSenumerateitems}{%
224 \renewenvironment{itemize}{\begin{enumerate}}%
225 {\end{enumerate}}%
226 }
227
228 .. rubric:: Notes
229
230 * Class arguments may contain numbers and hyphens, which need special
231 treatment in LaTeX command names (see `class directive`_). The commands
232 ``\csname`` and ``\endcsname`` or the special command ``\@namedef`` can
233 help with the definition of corresponding macros or environments, e.g.::
234
235 \expandafter\newcommand\csname gg1\endcsname{Definition of gg1.}
236
237 or ::
238
239 \makeatletter
240 \@namedef{DUCLASSadmonition-test}{…}
241 \makeatother
242
243 * Elements can have multiple class arguments. In contrast to HTML/CSS, the
244 order of the class arguments cannot be ignored in LaTeX
245
246 * Class handling differs for some elements and class values:
247
248 * Class argument values starting with ``align-`` are transformed to
249 "align" argument values. Class argument values starting with
250 ``language-`` set the elements language property.
251
252 * The table element recognizes some special class values. See section
253 `table style`_.
254
255 * If the legacy-class-functions_ setting is True, the special macros
256 ``\DUadmonition`` and ``\DUtitle`` are written with a comma separated
257 list of class values as optional argument.
258
259 .. _"classes" attribute: ../ref/doctree.html#classes
260 .. _legacy-class-functions: config.html#legacy-class-functions
261
262 LaTeX code
263 ----------
264
265 Custom LaTeX code can be placed in `style sheets`_, the
266 `LaTeX preamble`_, the document body (`raw LaTeX`_), or custom templates_.
267
268 The functional tests that come with Docutils, can serve as example.
269
270 input:
271 standalone_rst_latex.txt_ (includes files from `tests/functional/input/data`_)
272 expected output:
273 standalone_rst_latex.tex_
274
275 .. _standalone_rst_latex.txt:
276 https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/test/functional/input/standalone_rst_latex.txt
277 .. _tests/functional/input/data:
278 https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/test/functional/input/data
279 .. _standalone_rst_latex.tex:
280 https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/test/functional/expected/standalone_rst_latex.tex
281
282
283 .. _style sheet:
284 .. _custom style sheets:
285
286 Style sheets
287 ````````````
288
289 A common way of LaTeX customization is the preparation of custom style
290 sheets, either as simple files with LaTeX code snippets or as home-made
291 `LaTeX packages`_ (see the clsguide_ for an introduction on LaTeX
292 package writing).
293
294 Options:
295 stylesheet_
296
297 It is possible to specify multiple style sheets and mix `LaTeX
298 packages`_ with custom style sheets.
299
300 You cannot specify package options with the stylesheet_ setting. If
301 you need to pass options to the package, use the ``\usepackage``
302 command in the `LaTeX preamble`_ or a custom style sheet.
303
304 Example 1:
305 Select Latin Modern fonts with the `lmodern` package::
306
307 --stylesheet=lmodern
308
309 Example 2:
310 Use the `preamble.tex` home-made custom style sheet together with
311 the package `kerkis` (Bookman fonts)::
312
313 --stylesheet=kerkis,preamble.tex
314
315 Example 3:
316 Select Palatino fonts with old-style numbers and true small-caps
317 with the LaTeX command ::
318
319 \usepackage[osf,sc]{mathpazo}
320
321 in the `LaTeX preamble`_ or `custom style sheets`_.
322
323 Stylesheet Repository
324 There is a `repository of user-contributed style sheets`_ in the
325 Docutils Sandbox_.
326
327 .. _clsguide: https://mirrors.ctan.org/macros/latex/base/clsguide.pdf
328 .. _stylesheet: config.html#stylesheet-latex-writers
329 .. _embed-stylesheet: config.html#embed-stylesheet-latex-writers
330 .. _repository of user-contributed style sheets:
331 ../../../sandbox/stylesheets/
332 .. _sandbox: ../../../sandbox/
333
334
335 LaTeX preamble
336 ``````````````
337
338 Configuration by LaTeX code in the document preamble is also possible
339 without a separate stylesheet. This way, packages can be loaded with
340 options or commands re-defined without the need to create a separate
341 file (new in Docutils 0.7).
342
343 Option:
344 latex-preamble_
345
346 Default:
347 used for `font setup`_
348
349 Example:
350 To use the better looking ``txtt`` font for monospaced text define the
351 latex-preamble_ setting in a configuration file::
352
353 latex-preamble: \renewcommand{\ttdefault}{txtt}
354 \usepackage{mathptmx} % Times
355 \usepackage[scaled=.92]{helvet} % Helvetica
356
357 .. _latex-preamble: config.html#latex-preamble
358 .. _PDF standard fonts: https://en.wikipedia.org/wiki/PDF#Standard_Type_1_Fonts
359 .. _Linux Libertine: http://www.linuxlibertine.org
360
361
362 Templates
363 `````````
364
365 Some customizations require commands at places other than the insertion
366 point of stylesheets or depend on the deletion/replacement of parts of the
367 document. This can be done via a custom template. See the `publisher
368 documentation`_ for a description of the document parts available in a
369 template file.
370
371 Option:
372 template_
373
374 In addition to the 'default.tex' template, the latex writer directory
375 contains the alternatives 'titlepage.tex' (separate title page) and
376 'titlingpage.tex'" (separate title page with the `memoir`_
377 `document class`_).
378
379 Example:
380 Print a title page including docinfo, dedication, and abstract::
381
382 --template=titlepage.tex
383
384 .. _publisher documentation: ../api/publisher.html
385 .. _template: config.html#template-latex-writers
386
387 Raw LaTeX
388 `````````
389
390 By means of the `raw directive`_ or a derived `custom role`_, one can
391 give commands directly to LaTeX. These can be both, styling as well as
392 printing commands.
393
394 Example:
395 Math formula::
396
397 .. raw:: latex
398
399 \[x^3 + 3x^2a + 3xa^2 + a^3,\]
400
401 (Drawback: the formula will be invisible in other output formats. Better
402 use the `math directive`_)
403
404 Most LaTeX code examples also work as raw LaTeX inside the document.
405 An exception are commands that need to be given in the document
406 preamble (e.g. package loading with ``\usepackage``, which can be
407 achieved with the ``--style-sheet`` or ``--latex-preamble`` command
408 line options instead). Remember to use *re-defining* commands for
409 customizing `Docutils specific LaTeX macros`_ with raw LaTeX.
410
411 Example:
412 Define the transition command as page break::
413
414 .. raw:: latex
415
416 \renewcommand*{\DUtransition}{\pagebreak[4]}
417
418 See also:
419 * Defining a macro for a `custom role`_.
420 * Forcing `page breaks`_.
421
422 .. _raw directive: ../ref/rst/directives.html#raw
423 .. _math directive: ../ref/rst/directives.html#math
424
425
426 How to configure the ...
427 ========================
428
429 admonitions
430 -----------
431
432 Admonitions__ are specially marked "topics" that can appear anywhere an
433 ordinary body element can.
434
435 __ ../ref/rst/directives.html#admonitions
436
437 Environment:
438 ``DUadmonition``
439
440 (Command ``\DUadmonition`` with legacy-class-functions_.)
441
442 Default:
443 Typeset in a frame (90 % of text width).
444
445 The admonition title is typeset with the ``\DUtitle`` command (see `titles`_).
446
447 Example 1:
448 A lighter layout without the frame::
449
450 \newenvironment{DUadmonition}%
451 {\begin{quote}}
452 {\end{quote}}
453
454 Example 2:
455 Print all admonitions in the margin::
456
457 \usepackage{environ}
458 \NewEnviron{DUadmonition}{\marginpar{\BODY}}
459
460 Example 3:
461 Use the ``.. note::`` admonition for a margin note::
462
463 \usepackage{environ}
464 \newcommand{\DUCLASSnote}{%
465 \RenewEnviron{DUadmonition}{\marginpar{\BODY}}%
466 \renewcommand{\DUtitle}[1]{}% suppress title ("Note")
467 }
468
469 .. caution:: Make sure there is enough space in the margin.
470 ``\marginpar`` fails in some places or with some content. See also the
471 environ_ and marginnote_ packages.
472
473 .. _environ: https://ctan.org/pkg/environ
474 .. _marginnote: https://ctan.org/pkg/marginnote
475
476
477 .. _custom role:
478
479 custom interpreted text roles
480 -----------------------------
481
482 The rst `role directive`_ allows defining custom `text roles`_ that mark
483 parts of inline text (spans) with class arguments (see section classes_).
484
485 Commands:
486 ``\DUrole``: dispatcher command
487
488 ``\DUrole«classargument»``: optional styling command with 1 argument (the
489 role content).
490
491 Default:
492 The default definition of ``\DUrole{«classargument»}{}`` calls the macro
493 named ``\DUrole«classargument»{}`` if it is defined and silently ignores
494 this class argument if not.
495
496 Example 1:
497 Typeset text in small caps::
498
499 .. role:: smallcaps
500
501 :smallcaps:`Fourier` transformation
502
503 This is transformed to the LaTeX code::
504
505 \DUrole{smallcaps}{Fourier} transformation
506
507 The definition ::
508
509 \newcommand{\DUrolesmallcaps}{\textsc}
510
511 as `raw LaTeX`_ or in the custom `style sheet`_ will give the expected
512 result (if the text font_ supports small caps).
513
514 Example 2:
515 Subscript text in normal size and *italic* shape::
516
517 .. role:: sub(subscript)
518
519 As "sub" inherits from the standard "subscript" role, the LaTeX macro
520 only needs to set the size and shape::
521
522 \newcommand{\DUrolesub}{\normalsize\itshape}
523
524 Example 3:
525 A role with several classes and a converted class name::
526
527 .. role:: custom4
528 :class: argI argII arg_3
529
530 is translated to the nested commands::
531
532 \DUrole{argi}{\DUrole{argii}{\DUrole{arg-3}{<content>}}}
533
534 With the definitions::
535
536 \newcommand{\DUroleargi}[1]{\textsc}
537 \newcommand{\DUroleargii}[1]{{\large #1}}
538 \makeatletter
539 \@namedef{DUrolearg-3}{\textbf}
540 \makeatother
541
542 in a `style sheet`_\ [#]_ or as `raw LaTeX`_ in the document source,
543 text styled with ``:custom4:`large bold small-caps``` will be typeset
544 accordingly.
545
546 .. [#] Leave out the ``\makeatletter`` - ``\makeatother`` pair if the style
547 sheet is a LaTeX package (``*.sty``).
548
549 .. _role directive: ../ref/rst/directives.html#role
550 .. _text roles: ../ref/rst/roles.html
551 .. _class directive: ../ref/rst/directives.html#class
552
553 definition lists
554 ----------------
555
556 ReStructuredText `definition lists`__ correspond to HTML ``<dl>`` list
557 objects.
558
559 Environment:
560 ``description``: LaTeX standard environment
561
562 Command:
563 ``\descriptionlabel``: styling macro for the description term
564
565 Default:
566 bold label text, hanging indent
567
568 Example:
569 A non-bold label can be achieved with::
570
571 \renewcommand\descriptionlabel[1]{\hspace\labelsep \normalfont #1}
572
573 __ ../ref/rst/restructuredtext.html#definition-lists
574
575
576 document class
577 --------------
578
579 There are hundreds of LaTeX document classes installed by modern
580 LaTeX distributions, provided by publishers, or available at CTAN_.
581
582 Popular document classes:
583 * article, report, book: standard document classes
584 * scrartcl, scrrprt, scrbook: KOMA-script_ classes
585 * memoir_: highly configurable class for larger documents
586
587 Option:
588 documentclass_
589
590 .. _KOMA-script: https://ctan.org/pkg/koma-script
591 .. _memoir: https://ctan.org/pkg/memoir
592 .. _documentclass: config.html#documentclass
593
594
595 document info
596 -------------
597
598 Content of the `bibliographic fields`__ at the top of a document.
599 By default, docinfo items are typeset as a table.
600
601 Options:
602 use-latex-docinfo_, use-latex-abstract_
603
604 Length:
605 ``\DUdocinfowidth``: the width for the `docinfo` table.
606
607 Default:
608 90 % of text width: ``0.9\textwidth``
609
610 Example:
611 set to 70 % of text width::
612
613 \newlength{\DUdocinfowidth}
614 \setlength{\DUdocinfowidth}{0.7\textwidth}
615
616 __ ../ref/rst/restructuredtext.html#bibliographic-fields
617
618 .. _use-latex-docinfo: config.html#use-latex-docinfo
619 .. _use-latex-abstract: config.html#use-latex-abstract
620
621
622 document title
623 --------------
624
625 A lone top-level section title is (usually) transformed to the document title
626 (see `section structure`_).
627
628 The format of the document title is defined by the `document class`_. The
629 "article" document class uses an in-page title and the "report" and "book"
630 classes write a separate title page. See the `TeX FAQ`_ on how to customize
631 the `style of document titles`_.
632
633 The default title page shows only title and subtitle, date and author
634 are shown in the `document info`_ table.
635
636 Options:
637 use-latex-docinfo_
638
639 ``--template=titlepage.tex`` Put docinfo and abstract into the title page.
640 A separate title page is used also with the "abstract" document class.
641
642 .. _section structure: rst/quickref.html#section-structure
643 .. _TeX FAQ: http://www.tex.ac.uk/faq
644 .. _style of document titles:
645 http://www.tex.ac.uk/cgi-bin/texfaq2html?label=titlsty
646
647
648 field lists
649 -----------
650
651 `Field lists`__ may be used as generic two-column table constructs in
652 documents.
653
654 Environment:
655 ``DUfieldlist``
656
657 Default:
658 Indented description list.
659
660 Example:
661 Use a description list customized with enumitem_::
662
663 \usepackage{enumitem}
664 \newenvironment{DUfieldlist}%
665 {\description[font=,style=sameline,leftmargin=8em]}
666 {\enddescription}
667 }
668
669 The `KOMA-script`_ classes provide a similar environment under the name
670 `labeling`.
671
672 .. _enumitem: https://ctan.org/pkg/enumitem
673 __ ../ref/rst/restructuredtext.html#field-lists
674
675
676 figure and table captions
677 -------------------------
678
679 The caption_ package provides many ways to customise the captions in
680 floating environments like figure and table.
681
682 The chngcntr_ package helps to configure the numbering of figure and table
683 caption numberings.
684
685 Some document classes (e.g. KOMA-script_) provide additional configuration.
686 Also see the related `LaTeX FAQ entry`__
687
688 Example
689 ::
690
691 \usepackage{caption}
692 \captionsetup{justification=raggedleft,singlelinecheck=false}
693
694 .. _caption: https://ctan.org/pkg/caption
695 .. _chngcntr: https://ctan.org/pkg/chngcntr
696 __ http://www.tex.ac.uk/cgi-bin/texfaq2html?label=running-nos
697
698
699 figure placement
700 ----------------
701
702 Figures_ might be typeset at the place of definition (default) or "float"
703 to a suitable place at the top or bottom of a page. This is implemented
704 using the float_ package.
705
706 Command:
707 ``\floatplacement``
708
709 The placement setting is valid from the point of definition until the next
710 ``\floatplacement`` command or the end of the document. See float.pdf_ for
711 details.
712
713 Default:
714 ``\floatplacement{figure}{H}`` (here definitely). This corresponds most
715 closely to the source and HTML placement (principle of least surprise).
716
717 Example 1:
718 In a custom `style sheet`_, set the default to let LaTeX find a suitable
719 place for figure floats::
720
721 \usepackage{float}
722 \floatplacement{figure}{htbp} % here, top, bottom, extra-page
723
724 Example 2:
725 To move all following figures to the top or bottom of the page write in
726 the document source::
727
728 .. raw:: latex
729
730 \floatplacement{figure}{tb}
731
732 .. _figures: ../ref/rst/directives.html#figure
733 .. _float: https://ctan.org/pkg/float
734 .. _float.pdf: https://mirrors.ctan.org/macros/latex/contrib/float/float.pdf
735
736
737 .. _font setup:
738
739 font
740 ----
741
742 The selected text font influences the *look*, the *feel*,
743 and the *readability* of the document (cf.
744 http://www.csarven.ca/web-typography).
745 Selecting a suitable font also solves the problem with `bad looking
746 PDF output`_.
747
748 Font selection is one of the main differences between LaTeX and XeTeX/LuaTeX:
749
750 LaTeX
751 cannot use the fonts of the operating system directly but needs
752 specially installed fonts with additional supporting files.
753
754 XeTeX/LuaTeX
755 can use system fonts and provides access to the full feature set of
756 modern OpenType_ fonts.
757
758 .. _OpenType: https://en.wikipedia.org/wiki/OpenType
759
760 The default font setup is done in the latex-preamble_:
761
762 LaTeX
763 `PDF standard fonts`_ (Times, Helvetica, Courier)
764
765 XeTeX/LuaTeX
766 `Linux Libertine`_, a free, high quality alternative to Times with a
767 wide coverage of glyphs, styles, and OpenType features.
768
769 Despite its name, Linux Libertine can be used on any operating
770 system that can handle OpenType fonts.
771
772 Alternative fonts can be selected by
773
774 LaTeX
775 a) specifying the corresponding LaTeX package(s) as argument to the
776 stylesheet_ option_ or with the ``\usepackage`` LaTeX command.
777
778 * packages can be combined,
779 * passing options to a package is only possible in a `style sheet`_
780 or the `LaTeX preamble`_.
781
782 b) changing the font-default macros ``\rmdefault``, ``\sfdefault``
783 and/or ``\ttdefault`` in a custom `style sheet`_, the `LaTeX
784 preamble`_ or `raw LaTeX`_.
785
786 Example 1:
787 Use `Latin Modern`_. `LaTeX code`_::
788
789 \usepackage{lmodern}
790
791 Command line argument::
792
793 --stylesheet=lmodern
794
795 Example 2:
796 The _`Times/Helvetica/Courier` `PDF standard fonts`_ are
797 selected by the LaTeX code [#]_::
798
799 \usepackage{mathptmx} % Times for serif and math
800 \usepackage[scaled=.90]{helvet} % downscaled Helvetica for sans serif
801 \usepackage{courier} % Courier for teletype (mono-space)
802
803 Since Docutils 0.7, this is the default value of the
804 `latex-preamble`_ option.
805
806 .. [#] When generating PDF-files from LaTeX, the `PDF standard
807 fonts`_ do not need to be embedded in the document. While this
808 results in smaller files, the actually used fonts on screen and in
809 print might differ! (For details see, e.g., the testflow_ package
810 documentation.)
811
812
813 Example 3:
814 Use the teletype font from the txfonts_ package. As there is no
815 package for this, we re-define the font macro with the `LaTeX code`_::
816
817 \renewcommand{\ttdefault}{txtt}
818
819
820 XeTeX/LuaTeX
821 using the macros of the fontspec_ package. Use some font-viewer or
822 -manager (e.g. fontmatrix_) to find out the correct names of the
823 fonts on your system.
824
825 Example:
826 DejaVu_, very wide coverage, screen optimized. As this font
827 runs wide, add ``DIV=10`` to the `documentoptions`_::
828
829 \setmainfont{DejaVu Serif}
830 \setsansfont{DejaVu Sans}
831 \setmonofont[HyphenChar=None]{DejaVu Sans Mono}
832
833 .. _fontspec: https://ctan.org/pkg/fontspec
834 .. _fontmatrix: http://fontmatrix.net/
835 .. _DejaVu: http://dejavu-fonts.org/
836 .. _documentoptions: config.html#documentoptions
837
838 choice of suitable fonts
839 ````````````````````````
840
841 High quality free fonts suitable for use with XeTeX/LuaTeX are, e.g., listed
842 at `Good Libre Fonts`_, `25 Best Free Quality Fonts`_ and the update
843 `19 More Free Quality Fonts`_.
844
845 The `LaTeX Font Catalogue`_ provides information and examples for a wide
846 range of fonts available for use with LaTeX. Here is just a selection:
847
848 a) The `Latin Modern`_ (LM) fonts are extended outline versions of the
849 standard TeX font Computer Modern (CM).
850
851 +1 simple invocation: ``--stylesheet=lmodern``
852
853 +1 keeps the traditional TeX "look and feel":
854
855 +1 generally accepted as high quality CM replacement,
856 +1 comprehensive math support,
857 +1 including optical sizes,
858 +1 compatible with extensions made to match CM,
859 -1 modern types are hard to read at low (screen) resolutions.
860
861 -1 not part of a minimal standard TeX installation
862
863 b) CM-Super_ is another outline CM replacement.
864
865 +1 simple invocation: modern LaTeX distributions use CM-Super
866 automatically instead of CM if it is installed.
867
868 -1 said to be of inferior quality compared to LM.
869
870 -1 not part of a minimal standard TeX installation,
871 bigger download size than Latin Modern (64 MB).
872
873 c) `Bera`_ (Bitstream Vera)
874
875 +1 simple invocation: ``--stylesheet=bera``
876
877 +1 optimized for on-screen viewing with goot hinting
878
879 -1 not part of a minimal standard TeX installation
880
881 d) PSNFSS_ Postscript fonts
882
883 +1 part of every standard TeX installation
884
885 +1 smaller PDF/Postscript document size if standard fonts are not
886 embedded
887
888 -1 restricted set of glyphs in the free versions [#]_
889
890 -1 different fonts for roman, sans-serif and typewriter fonts.
891
892 -1 invocation somewhat more complex, as several packages are
893 required for a complete font set, sometimes including package
894 options.
895
896 Roman (serif) PSNFSS fonts:
897
898 Bookman
899 good legibility but very wide.
900
901 Charter
902 bread-and-butter type optimized for printing on low-resolution
903 printers
904
905 New Century Schoolbook
906 good legibility but very wide.
907
908 Palatino
909 +1 recommended by font experts
910 +1 good LaTeX support including matching math fonts, small caps,
911 old-style figures
912 -1 bad rendering in xpdf viewer (auto-hinting leads to different
913 x-hight for different characters at some magnifications)
914 (this is fixed in recent versions).
915
916 Times
917 +1 the serif `PDF Standard Font`_,
918 -1 overused and quite narrow (devised for multi-column layouts).
919
920 Utopia
921 recommended by font experts
922
923
924 .. table:: Font packages for standard Postscript fonts
925 (cf. `Using common Postscript fonts with LaTeX`_)
926
927 ========= ============ ============= ============= =========
928 Package Roman Sans Serif Typewriter Math
929 ========= ============ ============= ============= =========
930 (none) CM Roman CM Sans Serif CM Typewriter CM Math
931
932 mathpazo Palatino Palatino
933
934 mathptmx Times Times
935
936 helvet Helvetica
937
938 avant Avant Garde
939
940 courier Courier
941
942 chancery Zapf
943 Chancery
944
945 bookman Bookman Avant Garde Courier
946
947 newcent New Century Avant Garde Courier
948 Schoolbook
949
950 charter Charter
951
952 utopia Utopia
953
954 fourier Utopia Fourier
955 ========= ============ ============= ============= =========
956
957 .. [#] Extended versions of the standard Postscript fonts including
958 accented chars, as well as real small-caps
959 and old-style numbers are available with the `TeX Gyre`_ bundle
960 which is part of, e.g., `TeX Live`_.
961
962
963 .. _LaTeX Font Catalogue: http://www.tug.dk/FontCatalogue/
964 .. _Latin Modern: https://ctan.org/pkg/lm
965 .. _CM-Super: https://ctan.org/pkg/cm-super
966 .. _bera: https://ctan.org/pkg/bera
967 .. _TeX Gyre: http://www.gust.org.pl/projects/e-foundry/tex-gyre
968 .. _PSNFSS: https://ctan.org/pkg/psnfss
969 .. _Using common PostScript fonts with LaTeX:
970 https://mirrors.ctan.org/macros/latex/required/psnfss/psnfss2e.pdf
971 .. _TeX Live: http://tug.org/texlive/
972 .. _txfonts: https://ctan.org/pkg/txfonts
973 .. _PDF Standard Font:
974 https://en.wikipedia.org/wiki/PDF#Standard_Type_1_Fonts
975 .. _testflow:
976 http://www.tex.ac.uk/tex-archive/help/Catalogue/entries/testflow.html
977 .. _Good Libre Fonts: http://typophile.com/node/18207
978 .. _25 Best Free Quality Fonts:
979 http://www.alvit.de/blog/article/20-best-license-free-official-fonts
980 .. _19 More Free Quality Fonts:
981 http://www.smashingmagazine.com/2006/10/11/17-more-free-quality-fonts/
982
983
984 font encoding
985 -------------
986
987 LaTeX font encodings are described in detail in the encguide_ which is
988 part of the LaTeX base documentation.
989
990 Option:
991 font-encoding_
992
993 Default:
994 "T1"
995
996 Example 1:
997 Use the (obsolete) LaTeX default encoding "OT1"::
998
999 --font-encoding=OT1
1000
1001 or (without loading the fontenc_ package)::
1002
1003 --font-encoding=""
1004
1005 This will improve the look on screen with the default Computer Modern
1006 fonts at the expense of problems with `search and text extraction`_
1007 The recommended way is to select a T1-encoded "Type 1" (vector)
1008 font, for example `Latin Modern`_
1009
1010 Example 2:
1011 Support for characters in the Unicode blocks Latin, Latin-1 Supplement,
1012 and Greek together with a T1-encoded "Type 1" (vector) font, for example
1013 `Latin Modern`_::
1014
1015 --font-encoding=LGR,T1 --stylesheet=lmodern
1016
1017 .. _encguide: https://mirrors.ctan.org/macros/latex/base/encguide.pdf
1018 .. _font-encoding: config.html#font-encoding
1019 .. _fontenc: https://ctan.org/pkg/fontenc
1020
1021
1022 font size
1023 ---------
1024
1025 Add font size in points to the document options, e.g.
1026 ``--documentoptions=12``, use e.g. the document classes provided by
1027 extsizes_ for values other than [10,11,12].
1028
1029 .. _extsizes: https://ctan.org/pkg/extsizes
1030
1031
1032 footnotes
1033 ---------
1034
1035 By default, footnotes are set with Docutils-specific wrappers around
1036 the standard ``\footnotemark`` and ``\footnotetext`` commands. You
1037 can configure the footnote layout similar to standard LaTeX footnotes
1038 in a custom `style sheet`_ or the `LaTeX preamble`_.
1039
1040 Further configuration is possible by alternative definitions of
1041 ``\DUfootnotemark`` and ``\DUfootnotetext``
1042
1043 Example 1:
1044 Set footnote text with a hanging indent.
1045
1046 * This is the default with KOMA-script_ classes, e.g::
1047
1048 --documentclass=scrartcl
1049
1050 (for further configuration, see the `KOMA-script Guide`_),
1051
1052 * with package footmisc_::
1053
1054 \usepackage[hang]{footmisc}
1055 \setlength{\footnotemargin}{0em}
1056
1057 (play with the ``\footnotemargin`` setting),
1058
1059 * redefine ``\DUfootnotetext`` inserting `\hangindent`::
1060
1061 \newcommand{\DUfootnotetext}[4]{%
1062 \begingroup%
1063 \renewcommand{\thefootnote}{%
1064 \protect\raisebox{1em}{\protect\hypertarget{#1}{}}%
1065 \protect\hyperlink{#2}{#3}}%
1066 \footnotetext{\hangindent=2em #4}%
1067 \endgroup%
1068 }
1069
1070 (adapt the ``\hangindent`` value).
1071
1072 Example 2:
1073 Footnote marks in normal font size, not superscript::
1074
1075 \usepackage{scrextend} % not required with KOMA-script document classes
1076 \deffootnote{1em}{1em}{\thefootnotemark\ }
1077
1078 (See the `KOMA-script Guide`_ for details and other options.)
1079
1080 Example 3:
1081 Place the footnote text where it appears in the source document (instead
1082 of at the page bottom). This can be used to get the effect of endnotes
1083 (needs the hanging_ package)::
1084
1085 \usepackage{hanging}
1086 \newcommand{\DUfootnotetext}[4]{%
1087 \par\noindent\raisebox{1em}{\hypertarget{#1}{}}%
1088 \hyperlink{#2}{#3}%
1089 \hangpara{\parindent}{1}#4%
1090 }
1091
1092 .. _footmisc: https://ctan.org/pkg/footmisc
1093 .. _hanging: https://ctan.org/pkg/hanging
1094
1095
1096 hyphenation
1097 -----------
1098
1099 The amount of hyphenation is influenced by ``\hyphenpenalty``, setting it to
1100 10000 almost prevents hyphenation. As this produces lines with more space
1101 between words one should increase Latex's ``\tolerance`` for this.
1102
1103 Example:
1104 ::
1105
1106 \hyphenpenalty=5000
1107 \tolerance=1000
1108
1109
1110 hyperlinks
1111 ----------
1112
1113 Options:
1114 hyperlink-color_, hyperref-options_
1115
1116 Hyperlinks are realized using the hyperref_ package. As it re-defines many
1117 standard LaTeX macros, this package is loaded last, *after* the style
1118 sheets.
1119
1120 However, you can load hyperref before a package that requires its
1121 presence in a `style sheet`_ or the `LaTeX preamble`_ (see example
1122 below). This will ignore options set with hyperlink-color_ and
1123 hyperref-options_.
1124
1125 URLs are typeset with the "url" package (loaded implicitly by "hyperref").
1126 The font of URLs can be defined with the ``\urlstyle`` command. Valid
1127 arguments are
1128
1129 :same: normal text font, Docutils default,
1130 :tt: teletype (monospaced), LaTeX default,
1131 :rm: roman,
1132 :sf: sans serif
1133
1134 Example:
1135 Custom loading of the hyperref package also switches to
1136 the LaTeX default (monospaced fonts for URLs). Reset to use the text
1137 font::
1138
1139 \usepackage[unicode,colorlinks=true,linkcolor=green]{hyperref}
1140 \urlstyle{same}
1141
1142 See also `non-breaking hyperlinks`_.
1143
1144 .. _hyperlink-color: config.html#hyperlink-color
1145 .. _hyperref-options: config.html#hyperref-options
1146
1147
1148 disable hyperlinks
1149 ``````````````````
1150
1151 To suppress the hyper-linking completely (e.g. for printing or to
1152 avoid clashes with other packages), set hyperref-options_ to "draft"
1153 or load the "nohyperref" package that comes with the "hyperref"
1154 bundle.
1155
1156 Option:
1157 ``--hyperref-options=draft``
1158
1159 `LaTeX code`_::
1160
1161 \usepackage{nohyperref,url}
1162 \urlstyle{same}
1163
1164 .. _hyperref: https://ctan.org/pkg/hyperref
1165
1166
1167 language
1168 --------
1169
1170 The global document language can be set with the language-code_
1171 configuration setting. The language of text parts can be set adding the
1172 language tag prefixed by "language-" to an element's classes_
1173 attribute, e.g. ``language-el`` for a Greek text part.
1174
1175 .. _language-code: config.html#language-code
1176
1177
1178 line blocks
1179 -----------
1180
1181 In `line blocks`__, newlines and leading whitespace are respected.
1182
1183 Environment:
1184 ``DUlineblock``: special list environment for line blocks
1185
1186 Length:
1187 ``\DUlineblockindent``: indentation of indented lineblock parts.
1188
1189 Default:
1190 2.5 times the font height: ``2.5em``
1191
1192 Example:
1193 set to the paragraph indentation::
1194
1195 \newlength{\DUlineblockindent}
1196 \setlength{\DUlineblockindent}{\parindent}
1197
1198 __ ../ref/rst/restructuredtext.html#line-blocks
1199
1200
1201 line spacing
1202 ------------
1203
1204 Commands:
1205 ``\linespread``: for small adjustments
1206
1207 ``\singlespacing``, ``\onehalfspacing``, and ``\doublespacing``: from
1208 package `setspace`
1209
1210 Example 1:
1211 Get document wide double spacing::
1212
1213 \usepackage{setspace}
1214 \doublespacing
1215
1216 Example 2:
1217 Increase line spacing by five percent for better readability::
1218
1219 \linespread{1.05}
1220
1221
1222 literal blocks
1223 --------------
1224
1225 No markup processing is done within a `literal block`__. It is left as-is,
1226 and is typically rendered in a monospaced typeface
1227
1228 Option:
1229 literal-block-env_
1230
1231 Example:
1232
1233 ``--literal-block-env=lstlisting``
1234
1235 The ``lstlisting`` environment is highly configurable (as documented in
1236 listings.pdf_) and provides syntax highlight for many programming languages,
1237 for instance ::
1238
1239 \renewcommand{\ttdefault}{txtt}
1240 \lstset{language=Python, morekeywords=[1]{yield}}
1241 \lstloadlanguages{Python}
1242 \lstset{
1243 basicstyle=\ttfamily,
1244 keywordstyle=\bfseries,
1245 commentstyle=\rmfamily\itshape,
1246 stringstyle=\slshape,
1247 }
1248 \lstset{showstringspaces=false}
1249 \lstset{columns=fullflexible,
1250 basewidth={0.5em,0.4em}}
1251
1252 and to get LaTeX syntax highlight for a code block with "listings"::
1253
1254 \lstloadlanguages{[LaTeX]TeX} % comma separated list of languages
1255 \newcommand{\DUCLASSlatex}{\lstset{language=[LaTeX]TeX}}
1256
1257 The indentation of literal blocks can be reset with ::
1258
1259 \lstset{resetmargins=true}
1260
1261 and/or configured with e. g.::
1262
1263 \lstset{xleftmargin=-2em}
1264
1265 __ ../ref/rst/restructuredtext.html#literal-blocks
1266 .. _literal-block-env: config.html#literal-block-env
1267 .. _listings.pdf:
1268 https://mirrors.ctan.org/macros/latex/contrib/listings/listings.pdf
1269
1270
1271 lists
1272 -----
1273
1274 Remove extra vertical whitespace between items of bullet lists and
1275 enumerated lists.
1276
1277 Example:
1278 Pass the class argument "compact" to the list::
1279
1280 .. class:: compact
1281
1282 * first item
1283 * second item
1284
1285 The following lines for the `LaTeX preamble`_ use the enumitem_ package to
1286 remove spacing from all lists with class argument "compact"::
1287
1288 \usepackage{enumitem}
1289 \newcommand*{\DUCLASScompact}{\setlist{noitemsep}}
1290
1291
1292 list of figures/tables
1293 ----------------------
1294
1295 Docutils does not support lists of figures or tables.
1296
1297 However, with LaTeX, they can be generated using `raw LaTeX`_ in the
1298 document source.
1299
1300 Commands:
1301 ``\listoffigures``: a list of figures
1302
1303 ``\listoftables``: a list of tables
1304
1305 Example:
1306 ::
1307
1308 .. raw:: latex
1309
1310 \listoffigures
1311
1312
1313 option list
1314 -----------
1315
1316 `Option lists`__ are two-column lists of command-line options and
1317 descriptions, documenting a program's options.
1318
1319 Environment:
1320 ``DUoptionlist``: environment for option lists,
1321
1322 Command:
1323 ``\DUoptionlistlabel``: set appearance of the options
1324
1325 Example:
1326 set command options with a bold monospace font::
1327
1328 \newcommand{\DUoptionlistlabel}{\texttt{\textbf{#1}} \hfill}
1329
1330 __ ../ref/rst/restructuredtext.html#option-lists
1331
1332
1333 page breaks
1334 -----------
1335
1336 * Page breaks before top-level sections are the default with a
1337 documentclass that provides "chapters", e.g. "book", "memoir" or
1338 "scrbook".
1339
1340 * Redefining the \section or \section* command in a
1341 style sheet is possible too.
1342
1343 * `Raw LaTeX`_ or a `custom role`_ can be used.
1344
1345 * The transition element can be re-defined to produce a page break,
1346
1347 Commands
1348 ``\newpage``: hard pagebreak at exactly this position
1349
1350 ``\pagebreak[2]``: recommended page break after line end (precedence 1...4)
1351
1352 Example:
1353 Define the transition command as page break with the `LaTeX code`_::
1354
1355 \newcommand*{\DUtransition}{\pagebreak[4]}
1356
1357 (use ``\renewcommand`` with `raw LaTeX`_).
1358
1359 page layout
1360 -----------
1361
1362 By default, paper size and margin settings are determined by the document
1363 class.
1364
1365 The following packages help to configure the page layout:
1366
1367 a) The `typearea`_ package (part of the `KOMA-script`_ bundle) calculates a
1368 *good* page layout (based on rules and recommendations of typography
1369 experts).
1370
1371 See the `KOMA-Script Guide`_ for details on what is a *good* layout and
1372 how this is achieved.
1373
1374 b) The `geometry`_ package is recommended if you have to follow guidelines
1375 with fixed values for the margins.
1376 For details see the `geometry manual`_.
1377
1378 Example 1:
1379 Let `typearea` determine the type area with ``DIV=calc`` in the
1380 documentoptions::
1381
1382 --documentoptions='a4paper,DIV=calc'
1383
1384 The ``DIV`` option can also be specified, like ``DIV=10``. It defines how
1385 "crowded" a page will be: larger values mean larger text area (at the
1386 expense of readability).
1387
1388 Example 2:
1389 `LaTeX code`_ to set margins with the geometry_ package::
1390
1391 \usepackage{geometry}
1392 \geometry{hmargin={3cm,0.8in},height=8in}
1393 \geometry{height=10in}.
1394
1395 .. _typearea: https://ctan.org/pkg/typearea
1396 .. _geometry: https://ctan.org/pkg/geometry
1397 .. _KOMA-Script Guide:
1398 https://mirrors.ctan.org/macros/latex/contrib/koma-script/doc/scrguien.pdf
1399 .. _geometry manual:
1400 https://mirrors.ctan.org/macros/latex/contrib/geometry/geometry.pdf
1401
1402
1403 page headers and footers
1404 ------------------------
1405
1406 With the fancyhdr_ package or the `KOMA-script`_ classes, you can define
1407 custom page head- and foot-lines.
1408
1409 The `"header" and "footer" directives`_ save their content in the macros
1410 ``\DUheader`` rsp. ``\DUfooter``. The macros can be used in LaTeX code and
1411 will be replaced by LaTeX with the content of the directives.
1412
1413 Example:
1414 `LaTeX code`_ to place left-aligned "header" and "footer" on every
1415 page with fancyhdr_::
1416
1417 \usepackage{fancyhdr}
1418 \fancyhead[L]{\DUheader}
1419 \fancyfoot{} % reset
1420 \fancyfoot[L]{\DUfooter}
1421 \pagestyle{fancy}
1422
1423
1424 .. _fancyhdr: http://www.ctan.org/pkg/fancyhdr
1425 .. _"header" and "footer" directives: ../ref/rst/directives.html#header
1426
1427
1428 page numbering
1429 --------------
1430
1431 Example:
1432 Number pages by chapter (using the chappg_ package)::
1433
1434 \usepackage{chappg}
1435
1436 See the `chappg documentation`_ for details.
1437
1438 .. _chappg: https://ctan.org/pkg/chappg
1439 .. _chappg documentation:
1440 https://mirrors.ctan.org/macros/latex/contrib/chappg/chappg.pdf
1441
1442
1443 paper size
1444 ----------
1445
1446 Paper geometry can be changed using ``--documentoptions`` or with the
1447 `geometry`_ package.
1448
1449 `LaTeX code`_::
1450
1451 \usepackage{geometry}
1452 \geometry{OPTIONLIST}
1453
1454 Default:
1455 a4paper
1456
1457 Some possibilities:
1458
1459 * a4paper, b3paper, letterpaper, executivepaper, legalpaper
1460 * landscape, portrait, twoside.
1461
1462 Example:
1463 Choose A5 pager in landscape orientation with command line argument::
1464
1465 --documentoptions=a5paper,landscape
1466
1467 The same with LaTeX commands in the `style sheet`_::
1468
1469 \usepackage{geometry}
1470 \geometry{a5paper,landscape}
1471
1472 For details see the `geometry manual`_.
1473
1474 paragraph indent
1475 ----------------
1476
1477 Default (in most document classes):
1478 Indent the first line in a paragraph unless it is the first line of a
1479 chapter, section, subsection, or subsubsection.
1480
1481 Example 1:
1482 To set paragraph indentation to zero but add a vertical space between
1483 load the `parskip` package with the command line argument::
1484
1485 --stylesheet=parskip
1486
1487 or in a custom `style sheet`_ with::
1488
1489 \usepackage{parskip}
1490
1491 Example 2:
1492 To suppress the indentation of a specific paragraph, you may give it the
1493 class "noindent" with, e.g. ::
1494
1495 .. class:: noindent
1496
1497 This paragraph should not be indented.
1498
1499 and define the `custom role`_ command::
1500
1501 \newcommand{\DUrolenoindent}[1]{\noindent #1}
1502
1503 rubric
1504 ------
1505
1506 A rubric__ is like an informal heading that doesn't correspond to the
1507 document's structure.
1508
1509 Command:
1510 ``\DUrubric``
1511
1512 Default:
1513 subsubsection style (unnumbered), italic
1514
1515 Example1:
1516 Set centred and red::
1517
1518 \newcommand*{\DUrubric}[1]{%
1519 \subsubsection*{\centerline{\color{red}#1}}}
1520
1521 .. note::
1522 Class attribute values are ignored because the "classes_ wrapper"
1523 interferes with LaTeX's formatting (spacing/indentation) of text following
1524 a section heading. Consider using a `topic element`_ or a container_.
1525
1526 __ ../ref/rst/directives.html#rubric
1527 .. _container: ../ref/rst/directives.html#container
1528
1529 section headings
1530 ----------------
1531
1532 Options: documentclass_, use-part-section_
1533
1534 Section headings are converted into LaTeX macros according to their level,
1535 the document class and the value of the use-part-section_ setting:
1536
1537 ===== ============= ================== ============= ==============
1538 Level article article with part book [#]_ book with part
1539 ===== ============= ================== ============= ==============
1540 1 section part chapter part
1541 2 subsection section section chapter
1542 3 subsubsection subsection subsection section
1543 4 paragraph subsubsection subsubsection subsection
1544 5 subparagraph paragraph paragraph subsubsection
1545 6 DUtitle subparagraph subparagraph paragraph
1546 7 DUtitle DUtitle DUtitle subparagraph
1547 ===== ============= ================== ============= ==============
1548
1549
1550 .. [#] One of the document classes 'book', 'memoir', 'report 'scrbook',
1551 or 'scrreprt'.
1552
1553 .. _use-part-section: config.html#use-part-section
1554
1555 section numbering
1556 -----------------
1557
1558 Sections are numbered if there is a `sectnum directive`_ in the document.
1559
1560 Option: sectnum_xform_
1561 ``--section-numbering``, ``--no-section-numbering``
1562
1563 If sectnum_xform_ is False, section numbers are generated by LaTeX. In this
1564 case the "prefix" and "suffix" arguments of the `sectnum directive`_ are
1565 ignored. The section number style is determined by the `document class`_
1566 and can be configured in a LaTeX `style sheet`_, e.g.::
1567
1568 \setcounter{secnumdepth}{5}
1569
1570 .. note:: The LaTeX name is 'secnumdepth' (without 't').
1571
1572 .. _sectnum directive: ../ref/rst/directives.html#sectnum
1573 .. _sectnum_xform: config.html#sectnum-xform
1574
1575
1576 sidebar
1577 -------
1578
1579 Sidebars__ are like miniature, parallel documents that occur inside other
1580 documents, providing related or reference material. They can be likened to
1581 super-footnotes; their content is outside of the flow of the document's main
1582 text.
1583
1584 Command:
1585 ``DUsidebar``
1586
1587 Default:
1588 Box with grey background.
1589
1590 Example:
1591 Use margin notes::
1592
1593 \newcommand{\DUsidebar}[1]{\marginpar{\flushleft #1}}
1594
1595 * Make sure the margin is wide enough to hold the note.
1596 * This fails with some constructs inside the `side bar` and where
1597 \marginpar cannot be used, e.g., inside floats, footnotes, or in frames
1598 made with the framed package (see marginnote_).
1599
1600 __ https://docutils.sourceforge.io/docutils/docs/ref/rst/directives.html#sidebar
1601
1602 size of a pixel
1603 ---------------
1604
1605 The *physical size* of a pixel depends on the resolution of the output
1606 device and is usually specified in *dots per inch* (DPI).
1607
1608 The *length unit* "px" is defined by the output format. For LaTeX, it is
1609 `defined in pdfTeX and LuaTeX`__ (the `xetex` writer emulates this
1610 definition).
1611
1612 Default:
1613 72 DPI, i.e. 1 px = 1/72 in. [#]_
1614
1615 Example:
1616 Set the value to match the CSS definition
1617 with the `LaTeX code`_::
1618
1619 \pdfpxdimen=1in
1620 \divide\pdfpxdimen by 96 % 1/96 inch
1621
1622 .. [#] The `CSS length unit ``px```_ defaults to 1/96 inch.
1623
1624 __ https://tex.stackexchange.com/questions/41370/
1625 what-are-the-possible-dimensions-sizes-units-latex-understands
1626 .. _CSS length unit ``px``: https://www.w3.org/TR/css-values-3/#px
1627 .. _reference pixel: https://www.w3.org/TR/css-values-3/#reference-pixel
1628
1629 table style
1630 ------------
1631
1632 A pre-configured *table style* can be globally selected via the table_style_
1633 setting or set for individual tables via a `class directive`_ or the class
1634 option of the `table directive`_.
1635
1636 Supported values:
1637
1638 standard
1639 Borders around all cells.
1640
1641 booktabs
1642 A line above and below the table and one after the head.
1643
1644 borderless
1645 No borders.
1646
1647 colwidths-auto
1648 Column width determination by LaTeX.
1649 Overridden by the `table directive`_'s "widths" option.
1650
1651 .. warning::
1652
1653 ``colwidths-auto`` is only suited for tables with simple cell content.
1654
1655 LaTeX puts the content of auto-sized columns on one line (merging
1656 paragraphs) and may fail with complex content.
1657
1658 .. eventually in future
1659
1660 align-left, align-center, align-right
1661 Align tables.
1662
1663 By default, *column widths* are computed from the source column widths.
1664 The `legacy_column_widths`_ setting selects the conversion algorithm.
1665 Custom column widths can be set with the "widths" option of the `table
1666 directive`_.
1667
1668 See also the section on problems with tables_ below.
1669
1670 .. _new_column_widths:
1671 .. _legacy_column_widths: config.html#legacy-column-widths
1672 .. _table_style: config.html#table-style-latex-writers
1673 .. _"widths" option:
1674 .. _table directive: ../ref/rst/directives.html#table
1675
1676
1677 table of contents
1678 -----------------
1679
1680 A `contents directive`_ is replaced by a table of contents (ToC).
1681
1682 Option: use-latex-toc_
1683 ``--use-latex-toc``, ``--use-docutils-toc``
1684
1685 With use-latex-toc (default since release 0.6):
1686
1687 * The ToC is generated by LaTeX (via the ``\tableofcontents`` command).
1688
1689 The layout depends on the chosen document class and can be configured in
1690 a custom `style sheet`_ (see e.g. the `KOMA-Script Guide`_ for the
1691 `KOMA-script`_ classes).
1692
1693 * The depth of the ToC and PDF-bookmarks can be configured
1694
1695 + with the "depth" argument of the `contents directive`_, or
1696
1697 + in a style sheet with e.g. ``\setcounter{tocdepth}{5}``.
1698
1699 * Local ToCs are done with the minitoc_ package. See the `minitoc
1700 documentation`_ for the numerous configuration options.
1701
1702 .. note::
1703 Minitoc supports local ToCs only at "part" and top section level
1704 ("chapter" or "section"). Local `contents` directives at lower levels
1705 are ignored (a warning is issued).
1706
1707 This is an intended feature of the minitoc_ package. If you really
1708 require local ToCs at lower level, turn off the use-latex-toc_ option.
1709
1710 .. _use-latex-toc: config.html#use-latex-toc
1711 .. _contents directive: ../ref/rst/directives.html#contents
1712 .. _minitoc: https://ctan.org/pkg/minitoc
1713 .. _minitoc documentation:
1714 https://mirrors.ctan.org/macros/latex/contrib/minitoc/minitoc.pdf
1715
1716
1717 title reference role
1718 --------------------
1719
1720 `Title reference`_ is the default `default role`_ for `interpreted text`_.
1721
1722 Command:
1723 ``\DUroletitlereference``
1724
1725 Default:
1726 use slanted font (``\textsl``)
1727
1728 Example:
1729 set title references with a bold monospace font::
1730
1731 \newcommand{\DUroletitlereference}[1]{\texttt{\textbf{#1}}}
1732
1733 .. _title reference: ../ref/rst/roles.html#title-reference
1734 .. _default role:
1735 ../ref/rst/directives.html#setting-the-default-interpreted-text-role
1736 .. _interpreted text: ../ref/rst/restructuredtext.html#interpreted-text
1737
1738
1739 titles
1740 ------
1741
1742 The titles of admonitions_, sidebar_, and `topic element`_ use
1743 the ``\DUtitle`` command.
1744
1745 Example 1:
1746 a centered and somewhat larger title for topcis::
1747
1748 \newcommand*{\DUCLASStopic}{
1749 \renewcommand*{\DUtitle}[1]{\subsection*{\centering #1}
1750 }
1751
1752 Example 2:
1753 a right-pointing hand as title for the "attention" directive::
1754
1755 \usepackage{pifont}
1756 \newcommand*{\DUCLASSattention}{
1757 \renewcommand*{\DUtitle}[1]{\ding{43}}
1758 }
1759
1760 The title argument is "swallowed" by the command.
1761 To have both, hand and title use::
1762
1763 \usepackage{pifont}
1764 \newcommand*{\DUCLASSattention}{
1765 \newcommand*{\DUtitle}[1]{\ding{43} #1}
1766 }
1767
1768
1769 text encoding
1770 -------------
1771
1772 The encoding of the LaTeX source file is Docutils' *output* encoding
1773 but LaTeX' *input* encoding.
1774
1775 Option: output-encoding_
1776 ``--output-encoding=OUTPUT-ENCODING``
1777
1778 Default:
1779 "utf-8"
1780
1781 Example:
1782 Encode the LaTeX source file with the ISO `latin-1` (west european)
1783 8-bit encoding (the default in Docutils versions up to 0.6.)::
1784
1785 --output-encoding=latin-1
1786
1787 Note:
1788 8-bit LaTeX comes with two options for UTF-8 support,
1789
1790 :utf8: by the standard `inputenc`_ package with only limited coverage
1791 (mainly accented characters).
1792
1793 :utf8x: supported by the `ucs`_ package covers a wider range of Unicode
1794 characters than does "utf8". It is, however, a non-standard
1795 extension and no longer developed.
1796
1797 Currently, the "latex2e" writer inserts ``\usepackage[utf8]{inputenc}``
1798 into the LaTeX source if it is UTF-8 encoded.
1799
1800 .. with utf8x:
1801 If LaTeX issues a Warning about unloaded/unknown characters adding ::
1802
1803 \PreloadUnicodePage{n}
1804
1805 (where *n* is the Unicode page-number) to the style sheet might help.
1806
1807 .. _LaTeX Unicode: http://www.unruh.de/DniQ/latex/unicode/
1808 .. _output-encoding: config.html#output-encoding
1809 .. _inputenc: https://ctan.org/pkg/inputenc
1810 .. _ucs: https://ctan.org/pkg/unicode
1811
1812
1813 topic element
1814 -------------
1815
1816 A topic_ is like a block quote with a title, or a self-contained section
1817 with no subsections. Topics and rubrics can be used at places where a
1818 `section title`_ is not allowed (e.g. inside a directive).
1819
1820 Example:
1821 Use a standard paragraph for a topic::
1822
1823 \newcommand{\DUCLASStopic}{%
1824 \renewenvironment{quote}{}{}%
1825 }
1826
1827 .. _topic: ../ref/rst/directives.html#topic
1828 .. _section title: ../ref/rst/restructuredtext.html#sections
1829
1830
1831 transition element
1832 ------------------
1833
1834 Transitions__ are commonly seen in novels and short fiction, as a gap
1835 spanning one or more lines, marking text divisions or signaling changes in
1836 subject, time, point of view, or emphasis.
1837
1838 Command:
1839 ``\DUtransition``
1840
1841 Default:
1842 A horizontal line, 1/3 of text width
1843
1844 Example 1:
1845 Use three stars::
1846
1847 \newcommand*{\DUtransition}{\centering{}*\quad*\quad*}
1848
1849 Alternatively use the more elaborated version in `transition-stars.sty`_.
1850
1851 Example 2:
1852 If paragraphs are separated by indentation, you can simply use a vertical
1853 space::
1854
1855 \newcommand*{\DUtransition}{\vspace{2ex}}
1856
1857 __ https://docutils.sourceforge.io/docutils/docs/ref/rst/restructuredtext.html#transitions
1858 .. _transition-stars.sty: ../../../sandbox/stylesheets/transition-stars.sty
1859
1860
1861 Changes
1862 =======
1863
1864 * The Docutils HISTORY_ lists all changes during the history of docutils.
1865 Important changes are summarized in the RELEASE-NOTES_.
1866
1867 .. _HISTORY: ../../HISTORY.html
1868 .. _RELEASE-NOTES: ../../RELEASE-NOTES.html
1869
1870
1871 Problems
1872 ========
1873
1874 Troubleshooting
1875 ---------------
1876
1877 Bad looking PDF output
1878 ``````````````````````
1879
1880 What I am looking for when I try Docutils is if the PDF files I can get
1881 are of high quality. Unfortunately that never is the case.
1882
1883 So am I just stupid or is there a way to get really high quality pdf from
1884 Docutils?
1885
1886 Make sure the default font is not a bitmap font.
1887
1888 There is `Latin Modern`_ if you like the look of the standard font on paper,
1889 but want nice pdf. Or select something else like Times, Palatino, ... via
1890 configuration `options/settings`_. See font_ and font-encoding_.
1891
1892
1893 footnote mark and text at different pages
1894 `````````````````````````````````````````
1895
1896 Docutils stores the footnote text in a separate node, at the position where
1897 it is specified in the input document. With the default settings, the
1898 footnote is put at the bottom of the page where the footnote text is located,
1899 maybe far away from the footnote mark (see e.g. `<rst/demo.txt>`_).
1900
1901 To get footnote mark and text at the same page, keep footnote mark and
1902 footnote text close together.
1903
1904
1905 non-breaking hyperlinks
1906 ```````````````````````
1907
1908 If you convert with ``latex`` (as opposed to ``pdflatex``), hyperlinks will
1909 not wrap and sometimes stick into the margin.
1910
1911 Wrong:
1912 ::
1913
1914 \usepackage[breaklinks=true]{hyperref}
1915
1916 "breaklinks" is an internal option that indicates whether the chosen
1917 driver can handle split links. (It might work to *disable* link breaking.)
1918
1919 Right:
1920 Use one of the following:
1921
1922 a) compile with pdflatex_,
1923
1924 b) use the package breakurl_,
1925
1926 c) (for printout) `disable hyperlinks`_ using the package "nohyperref".
1927
1928 See also the `Link text doesn’t break at end line`_ LaTeX FAQ entry.
1929
1930 .. _breakurl: https://ctan.org/pkg/breakurl
1931 .. _Link text doesn’t break at end line:
1932 http://www.tex.ac.uk/cgi-bin/texfaq2html?label=breaklinks
1933
1934
1935 Glyph not defined in PD1 encoding
1936 `````````````````````````````````
1937
1938 If a section title or other link contains non-Latin (e.g. Cyrillic)
1939 characters, the LaTeX log contains lots of warnings like::
1940
1941 Package hyperref Warning: Glyph not defined in PD1 encoding,
1942 (hyperref) removing `\CYRZ' on input line 6.
1943 ...
1944
1945 This can be solved with the "unicode" hyperref_option_ setting::
1946
1947 --hyperref-option=unicode
1948
1949 (works also with non-unicode input/output encoding (e.g. "koi8r" or
1950 "latin1"). Newer versions of hyperref default to "unicode=true".
1951
1952 .. _hyperref_option: config.html#stylesheet-latex-writers
1953
1954
1955 image inclusion
1956 ```````````````
1957
1958 Images__ are included in LaTeX with the help of the `graphicx` package. The
1959 supported file formats depend on the used driver:
1960
1961 * pdflatex_, lualatex, and xelatex_ work with PNG, JPG, or PDF,
1962 but **not EPS**.
1963 * Standard latex_ can include **only EPS** graphics, no other format.
1964 * latex + dvipdfmx works with EPS and JPG (add 'dvipdfmx' to the
1965 documentoptions_ or graphicx-option_ setting
1966 and 'bmpsize' to the stylesheet_ setting).
1967
1968 If PDF-image inclusion in PDF files fails, specifying
1969 ``--graphicx-option=pdftex`` might help.
1970
1971 For details see grfguide.pdf_.
1972
1973 The Rubber_ wrapper can be used for automatic image conversion.
1974
1975 Docutils expects an URI as pointer to the image file. The latex writer
1976 transforms this URI to a local path. By default, LaTeX does not accept
1977 spaces and more than one dot in the filename. If using "traditional"
1978 filenames is not an option, adding grffile_ to the `style sheets`_
1979 can help.
1980
1981 __ ../ref/rst/directives.html#images
1982 .. _grfguide.pdf:
1983 https://mirrors.ctan.org/macros/latex/required/graphics/grfguide.pdf
1984 .. _grffile: https://ctan.org/pkg/grffile
1985 .. _graphicx-option: config.html#graphicx-option
1986
1987
1988 Why are my images too big?
1989 ``````````````````````````
1990
1991 HTML-browsers use the actual screen resolution (usually around
1992 100 DPI).
1993
1994 The CSS specification suggests:
1995
1996 It is recommended that the reference pixel be the visual angle of one
1997 pixel on a device with a pixel density of 96 DPI and a distance from the
1998 reader of an arm's length.
1999
2000 -- https://www.w3.org/TR/CSS2/syndata.html#length-units
2001
2002 This is why pixmap images without size specification or objects with a size
2003 specified in ``px`` tend to come too large in the PDF.
2004
2005 Solution:
2006 Specify the image size in fixed units (``pt``, ``cm``, ``in``) or
2007 configure the `size of a pixel`_ (length unit px).
2008
2009
2010 Error ``illegal unit px``
2011 `````````````````````````
2012
2013 If you convert the LaTeX source with a legacy program, you might get this
2014 error.
2015
2016 The unit "px" was introduced by the `pdfTeX` converter on 2005-02-04.
2017 `pdfTeX` is used also for conversion into DVI format in all modern LaTeX
2018 distributions (since ca. 2006).
2019
2020 If updating LaTeX is not an option, just remove the "px" from the length
2021 specification. HTML/CSS will default to "px" while the `latexe2` writer
2022 will add the fallback unit "bp".
2023
2024
2025 Error ``Symbol \textcurrency not provided`` ...
2026 ```````````````````````````````````````````````
2027
2028 The currency sign (\\u00a4) is not supported by all fonts (some have
2029 an Euro sign at its place). You might see an error like::
2030
2031 ! Package textcomp Error: Symbol \textcurrency not provided by
2032 (textcomp) font family ptm in TS1 encoding.
2033 (textcomp) Default family used instead.
2034
2035 (which in case of font family "ptm" is a false positive). Add either
2036
2037 :warn: turn the error in a warning, use the default symbol (bitmap), or
2038 :force,almostfull: use the symbol provided by the font at the users
2039 risk,
2040
2041 to the document options or use a different font package.
2042
2043
2044 Warning: language … not supported
2045 `````````````````````````````````
2046
2047 The "latex" writer uses the LaTeX package Babel_ and the "xetex" writer
2048 uses Polyglossia_ for language_ support (hyphenation rules, auto-text
2049 localisations and typographic rules). Polyglossia_ supports more
2050 languages, so switching to the "xetex_" writer may help.
2051
2052 For short quotes or if language support is provided by the user via other
2053 `LaTeX document classes and packages`_, the warning can be ignored.
2054
2055 .. _Babel: https://ctan.org/pkg/babel
2056 .. _Polyglossia: https://ctan.org/pkg/polyglossia
2057
2058
2059 Search and text extraction
2060 ``````````````````````````
2061
2062 Search for text that contains characters outside the ASCII range might
2063 fail. See font_ and `font encoding`_ (as well as `Searching PDF files`_
2064 for background information).
2065
2066 It may help to load the `cmap` package (via `style sheets`_ or the custom
2067 `LaTeX preamble`_ (see also `Proper use of cmap and mmmap`_).
2068
2069 .. _Searching PDF files:
2070 http://www.tex.ac.uk/cgi-bin/texfaq2html?label=srchpdf
2071 .. _Proper use of cmap and mmmap:
2072 https://tex.stackexchange.com/questions/64409/proper-use-of-cmap-and-mmap
2073
2074
2075 Unicode box drawing and block characters
2076 ````````````````````````````````````````
2077
2078 The easiest solution is to use xelatex_ for `PDF generation`_.
2079
2080 With "traditional" TeX engines (e.g. pdflatex_):
2081
2082 - Generate LaTeX code with `output-encoding`_ "utf-8".
2083
2084 - Add the pmboxdraw_ package to the `style sheets`_.
2085 (For shaded boxes also add the `color` package.)
2086
2087 Unfortunately, this defines only a subset of the characters
2088 (see pmboxdraw.pdf_ for a list).
2089
2090 .. _pmboxdraw: https://ctan.org/pkg/pmboxdraw
2091 .. _pmboxdraw.pdf:
2092 https://mirrors.ctan.org/macros/latex/contrib/pmboxdraw/pmboxdraw.pdf
2093
2094
2095 Bugs and open issues
2096 --------------------
2097
2098 Open to be fixed or open to discussion.
2099
2100 See also the entries in the `Docutils TODO list`_,
2101 the BUGS_ documentation and the `SourceForge Bug Tracker`_.
2102
2103 .. _Docutils TODO list: ../dev/todo.html#latex-writer
2104 .. _bugs: ../../BUGS.html
2105 .. _SourceForge Bug Tracker: https://sourceforge.net/p/docutils/bugs/
2106
2107
2108 Footnotes and citations
2109 ```````````````````````
2110
2111 Initially both were implemented using figure floats, because hyperlinking
2112 back and forth seemed to be impossible. Later the `figure` directive was
2113 added that puts images into figure floats.
2114
2115 This results in footnotes, citations, and figures possibly being mixed at
2116 page foot.
2117
2118 Workaround:
2119 Select citation handling with the use_latex_citations_ option.
2120
2121 If ``use-latex-citations`` is used, a bibliography is inserted right at
2122 the end of the document. *This should be customizable*.
2123
2124 If ``use-latex-citations`` is used adjacent citation references (separated
2125 only by a single space or a newline) are combined to a single citation
2126 group, i.e. ``[cite1]_ [cite2]_`` results in ``\cite{cite1,cite2}``.
2127 The appearance in the output can be configured in a `style sheet`_.
2128
2129 .. _use_latex_citations: config.html#use-latex-citations
2130
2131
2132 Tables
2133 ``````
2134
2135 * Too wide tables (cf. `bug #422`_):
2136
2137 Try the new_column_widths_ algorithm or use the `"widths" option`_ to
2138 manually set the table column widths.
2139
2140 * Table cells with both multirow and multicolumn are currently not possible.
2141
2142 .. _bug #422: https://sourceforge.net/p/docutils/bugs/422/
2143
2144
2145 Figures
2146 ```````
2147
2148 * Figures are always as wide as the containing text. The "figwidth" argument
2149 is currently not supported. As a consequence, the "align" argument has no
2150 effect.
2151
2152 * Wrapping text around figures is currently not supported. (Requires the
2153 `wrapfig`_ package.)
2154
2155 .. _wrapfig: https://ctan.org/pkg/wrapfig
2156
2157
2158 Miscellaneous
2159 `````````````
2160
2161 * Pdfbookmark level 4 (and greater) does not work (might be settable but
2162 complicated).
2163
2164 * Hyperlinks are not hyphenated; this leads to bad spacing. See
2165 docs/user/rst/demo.txt 2.14 directives.
2166
2167 * Pagestyle headings does not work, when sections are starred. Use LaTeX for
2168 the section numbering with the `options/settings`_
2169 ``--no-section-numbers`` (command line) or ``sectnum_xform: False``
2170 (config file).