Debian Codegraph @

doc/latex.rst

raw
1 LaTeX customization
2 ===================
3
4 .. module:: latex
5 :synopsis: LaTeX specifics.
6
7 .. role:: code-tex(code)
8 :language: LaTeX
9
10 .. _contents: https://docutils.sourceforge.io/docs/ref/rst/directives.html#table-of-contents
11
12 .. raw:: latex
13
14 \begingroup
15 \sphinxsetup{%
16 TitleColor=DarkGoldenrod,
17 pre_border-width=2pt,
18 pre_border-right-width=8pt,
19 pre_padding=5pt,
20 pre_border-radius=5pt,
21 pre_background-TeXcolor=OldLace,
22 pre_border-TeXcolor=Gold!90,
23 pre_box-shadow=6pt 6pt,
24 pre_box-shadow-TeXcolor=gray!20,
25 %
26 div.warning_border-width=3pt,
27 div.warning_padding=6pt,
28 div.warning_padding-right=18pt,
29 div.warning_padding-bottom=18pt,
30 div.warning_border-TeXcolor=DarkCyan,
31 div.warning_background-TeXcolor=LightCyan,
32 div.warning_box-shadow=-12pt -12pt inset,
33 div.warning_box-shadow-TeXcolor=Cyan,
34 %
35 attentionborder=3pt,
36 attentionBorderColor=Crimson,
37 attentionBgColor=FloralWhite,
38 %
39 noteborder=1pt,
40 noteBorderColor=Olive,
41 noteBgColor=Olive!10,
42 div.note_border-top-width=0pt,
43 div.note_border-bottom-width=0pt,
44 hintBorderColor=LightCoral,
45 }
46 \relax
47
48 Unlike :ref:`the HTML builders <html-themes>`, the ``latex`` builder does not
49 benefit from prepared themes. The :ref:`latex-options`, and particularly the
50 :ref:`latex_elements <latex_elements_confval>` variable, provides much of the
51 interface for customization. For example:
52
53 .. code-block:: latex
54
55 # inside conf.py
56 latex_engine = 'xelatex'
57 latex_elements = {
58 'passoptionstopackages': r'''
59 \PassOptionsToPackage{svgnames}{xcolor}
60 ''',
61 'fontpkg': r'''
62 \setmainfont{DejaVu Serif}
63 \setsansfont{DejaVu Sans}
64 \setmonofont{DejaVu Sans Mono}
65 ''',
66 'preamble': r'''
67 \usepackage[titles]{tocloft}
68 \cftsetpnumwidth {1.25cm}\cftsetrmarg{1.5cm}
69 \setlength{\cftchapnumwidth}{0.75cm}
70 \setlength{\cftsecindent}{\cftchapnumwidth}
71 \setlength{\cftsecnumwidth}{1.25cm}
72 ''',
73 'sphinxsetup': 'TitleColor=DarkGoldenrod',
74 'fncychap': r'\usepackage[Bjornstrup]{fncychap}',
75 'printindex': r'\footnotesize\raggedright\printindex',
76 }
77 latex_show_urls = 'footnote'
78
79 .. note::
80
81 Keep in mind that backslashes must be doubled in Python string literals to
82 avoid interpretation as escape sequences. Alternatively, you may use raw
83 strings as is done above.
84
85 .. _latex_elements_confval:
86
87 The ``latex_elements`` configuration setting
88 --------------------------------------------
89
90 A dictionary that contains LaTeX snippets overriding those Sphinx usually puts
91 into the generated ``.tex`` files. Its ``'sphinxsetup'`` key is described
92 :ref:`separately <latexsphinxsetup>`. It allows also local configurations
93 inserted in generated files, via :dudir:`raw` directives. For example, in
94 the PDF documentation this chapter is styled especially, as will be described
95 later.
96
97 Keys that you may want to override include:
98
99 ``'papersize'``
100 Paper size option of the document class (``'a4paper'`` or
101 ``'letterpaper'``)
102
103 Default: ``'letterpaper'``
104
105 ``'pointsize'``
106 Point size option of the document class (``'10pt'``, ``'11pt'`` or
107 ``'12pt'``)
108
109 Default: ``'10pt'``
110
111 ``'pxunit'``
112 The value of the ``px`` when used in image attributes ``width`` and
113 ``height``. The default value is ``'0.75bp'`` which achieves
114 ``96px=1in`` (in TeX ``1in = 72bp = 72.27pt``.) To obtain for
115 example ``100px=1in`` use ``'0.01in'`` or ``'0.7227pt'`` (the latter
116 leads to TeX computing a more precise value, due to the smaller unit
117 used in the specification); for ``72px=1in``, simply use ``'1bp'``; for
118 ``90px=1in``, use ``'0.8bp'`` or ``'0.803pt'``.
119
120 Default: ``'0.75bp'``
121
122 .. versionadded:: 1.5
123
124 ``'passoptionstopackages'``
125 A string which will be positioned early in the preamble, designed to
126 contain :code-tex:`\\PassOptionsToPackage{options}{foo}` commands.
127
128 .. hint::
129
130 It may be also used for loading LaTeX packages very early in the
131 preamble. For example package ``fancybox`` is incompatible with
132 being loaded via the ``'preamble'`` key, it must be loaded earlier.
133
134 Default: ``''``
135
136 .. versionadded:: 1.4
137
138 ``'babel'``
139 "babel" package inclusion, default :code-tex:`r'\\usepackage{babel}'` (the
140 suitable document language string is passed as class option, and
141 ``english`` is used if no language.) For Japanese documents, the
142 default is the empty string.
143
144 With XeLaTeX and LuaLaTeX, Sphinx configures the LaTeX document to use
145 `polyglossia`_, but one should be aware that current `babel`_ has
146 improved its support for Unicode engines in recent years and for some
147 languages it may make sense to prefer ``babel`` over ``polyglossia``.
148
149 .. _`polyglossia`: https://ctan.org/pkg/polyglossia
150 .. _`babel`: https://ctan.org/pkg/babel
151
152 .. hint::
153
154 After modifying a core LaTeX key like this one, clean up the LaTeX
155 build repertory before next PDF build, else left-over auxiliary
156 files are likely to break the build.
157
158 Default: :code-tex:`r'\\usepackage{babel}'` (for Japanese documents)
159
160 .. versionchanged:: 1.5
161 For :confval:`latex_engine` set to ``'xelatex'``, the default
162 is ``'\\usepackage{polyglossia}\n\\setmainlanguage{<language>}'``.
163
164 .. versionchanged:: 1.6
165 ``'lualatex'`` uses same default setting as ``'xelatex'``
166
167 .. versionchanged:: 1.7.6
168 For French with ``'xelatex'`` (not ``'lualatex'``) the default is to
169 use ``babel``, not ``polyglossia``.
170
171 .. versionchanged:: 7.4.0
172 For French with ``'lualatex'`` the default is to use ``babel``.
173
174 .. _fontpkg:
175
176 ``'fontpkg'``
177 Font package inclusion. The default with ``'pdflatex'`` is::
178
179 r"""\usepackage{tgtermes}
180 \usepackage{tgheros}
181 \renewcommand\ttdefault{txtt}
182 """
183
184 For ``'xelatex'`` and ``'lualatex'`` on the other hand the
185 :code-tex:`\\setmainfont`, :code-tex:`\\setsansfont` and
186 :code-tex:`\\setmonofont` commands of LaTeX package ``fontspec`` (included
187 via :ref:`fontenc`) are used to set up the OpenType fonts GNU FreeSerif,
188 FreeSans, and FreeMono (scaled with ratio ``0.9``) as document fonts.
189
190 .. versionchanged:: 1.2
191 Defaults to ``''`` when the :confval:`language` uses the Cyrillic
192 script.
193
194 .. versionchanged:: 2.0
195 Incorporates some font substitution commands to help support occasional
196 Greek or Cyrillic in a document using ``'pdflatex'`` engine.
197 At 4.0.0 these commands were moved to the ``'fontsubstitution'`` key.
198
199 .. versionchanged:: 4.0.0
200 The default font setting was changed. As shown above it still uses
201 Times and Helvetica clones for serif and sans serif, but via better,
202 more complete TeX fonts and associated LaTeX packages. The monospace
203 font has been changed to better match the Times clone.
204
205 .. versionchanged:: 8.1.0
206 The monospace font FreeMono used with Unicode engines is loaded at scale
207 ``0.9``. This replaces the former mechanism via :ref:`fvset` which
208 configured code-blocks to use :code-tex:`\\small`. Inline literals now
209 fit better in their surrounding text, and it is easier to set up custom
210 fonts, as :ref:`fvset` does not intervene anymore by default.
211
212 ``'fncychap'``
213 Inclusion of the "fncychap" package (which makes fancy chapter titles),
214 default :code-tex:`r'\\usepackage[Bjarne]{fncychap}'` for English documentation
215 (this option is slightly customized by Sphinx),
216 :code-tex:`r'\\usepackage[Sonny]{fncychap}'` for internationalized docs (because
217 the "Bjarne" style uses numbers spelled out in English). Other
218 "fncychap" styles you can try are "Lenny", "Glenn", "Conny", "Rejne" and
219 "Bjornstrup". You can also set this to ``''`` to disable fncychap.
220
221 Default: :code-tex:`r'\\usepackage[Bjarne]{fncychap}'` for English
222 documents, :code-tex:`r'\\usepackage[Sonny]{fncychap}'` for
223 internationalized documents, and ``''`` for Japanese documents.
224
225 .. _preamble:
226
227 ``'preamble'``
228 Additional preamble content. One may move all needed macros into some file
229 :file:`mystyle.tex.txt` of the project source repertory, and get LaTeX to
230 import it at run time::
231
232 'preamble': r'\input{mystyle.tex.txt}',
233 # or, if the \ProvidesPackage LaTeX macro is used in a file mystyle.sty
234 'preamble': r'\usepackage{mystyle}',
235
236 It is then needed to set appropriately :confval:`latex_additional_files`,
237 for example:
238
239 .. code-block:: python
240
241 latex_additional_files = ["mystyle.sty"]
242
243 Do not use ``.tex`` as suffix, else the file is submitted itself to the PDF
244 build process, use ``.tex.txt`` or ``.sty`` as in the examples above.
245
246 Default: ``''``
247
248 ``'figure_align'``
249 Latex figure float alignment. Whenever an image doesn't fit into the current
250 page, it will be 'floated' into the next page but may be preceded by any
251 other text. If you don't like this behavior, use 'H' which will disable
252 floating and position figures strictly in the order they appear in the
253 source.
254
255 Default: ``'htbp'`` (here, top, bottom, page)
256
257 .. versionadded:: 1.3
258
259 ``'atendofbody'``
260 Additional document content (right before the indices).
261
262 Default: ``''``
263
264 .. versionadded:: 1.5
265
266 ``'extrapackages'``
267 Additional LaTeX packages. For example:
268
269 .. code-block:: latex
270
271 latex_elements = {
272 'extrapackages': r'\usepackage{isodate}'
273 }
274
275 The specified LaTeX packages will be loaded before
276 hyperref package and packages loaded from Sphinx extensions.
277
278 .. hint::
279 If you'd like to load additional LaTeX packages after hyperref, use
280 ``'preamble'`` key instead.
281
282 Default: ``''``
283
284 .. versionadded:: 2.3
285
286 ``'footer'``
287 Additional footer content (before the indices).
288
289 Default: ``''``
290
291 .. deprecated:: 1.5
292 Use ``'atendofbody'`` key instead.
293
294 Keys that don't need to be overridden unless in special cases are:
295
296 ``'extraclassoptions'``
297 The default is the empty string. Example: ``'extraclassoptions':
298 'openany'`` will allow chapters (for documents of the ``'manual'``
299 type) to start on any page.
300
301 Default: ``''``
302
303 .. versionadded:: 1.2
304
305 .. versionchanged:: 1.6
306 Added this documentation.
307
308 ``'maxlistdepth'``
309 LaTeX allows by default at most 6 levels for nesting list and
310 quote-like environments, with at most 4 enumerated lists, and 4 bullet
311 lists. Setting this key for example to ``'10'`` (as a string) will
312 allow up to 10 nested levels (of all sorts). Leaving it to the empty
313 string means to obey the LaTeX default.
314
315 .. warning::
316
317 - Using this key may prove incompatible with some LaTeX packages
318 or special document classes which do their own list customization.
319
320 - The key setting is silently *ignored* if ``\usepackage{enumitem}``
321 is executed inside the document preamble. Use then rather the
322 dedicated commands of this LaTeX package.
323
324 Default: ``6``
325
326 .. versionadded:: 1.5
327
328 ``'inputenc'``
329 "inputenc" package inclusion.
330
331 Default: :code-tex:`r'\\usepackage[utf8]{inputenc}'` when using pdflatex, else
332 ``''``.
333
334 .. note::
335
336 If using ``utf8x`` in place of ``utf8`` it is mandatory to extend the
337 LaTeX preamble with suitable ``\PreloadUnicodePage{<number>}`` commands,
338 as per the ``utf8x`` documentation (``texdoc ucs`` on a TeXLive based
339 TeX installation). Else, unexpected and possibly hard-to-spot problems
340 (i.e. not causing a build crash) may arise in the PDF, in particular
341 regarding hyperlinks.
342
343 Even if these precautions are taken, PDF build via ``pdflatex`` engine
344 may crash due to upstream LaTeX not being fully compatible with
345 ``utf8x``. For example, in certain circumstances related to
346 code-blocks, or attempting to include images whose filenames contain
347 Unicode characters. Indeed, starting in 2015, upstream LaTeX with
348 ``pdflatex`` engine has somewhat enhanced native support for Unicode and
349 is becoming more and more incompatible with ``utf8x``. In particular,
350 since the October 2019 LaTeX release, filenames can use Unicode
351 characters, and even spaces. At Sphinx level this means e.g. that the
352 :dudir:`image` and :dudir:`figure` directives are now compatible with
353 such filenames for PDF via LaTeX output. But this is broken if
354 ``utf8x`` is in use.
355
356 .. versionchanged:: 1.4.3
357 Previously :code-tex:`r'\\usepackage[utf8]{inputenc}'` was used for all
358 compilers.
359
360 ``'cmappkg'``
361 "cmap" package inclusion.
362
363 Default: :code-tex:`r'\\usepackage{cmap}'`
364
365 .. versionadded:: 1.2
366
367 .. _fontenc:
368
369 ``'fontenc'``
370 Its default, for ``'pdflatex'`` as :confval:`latex_engine`, is
371 :code-tex:`r'\\usepackage[T1]{fontenc}'`. Replace it (if using
372 ``'pdflatex'``) with:
373
374 - :code-tex:`r'\\usepackage[X2,T1]{fontenc}'` if you need occasional
375 Cyrillic letters (физика частиц),
376
377 - :code-tex:`r'\\usepackage[LGR,T1]{fontenc}'` if you need occasional
378 Greek letters (Σωματιδιακή φυσική),
379
380 - :code-tex:`r'\\usepackage[LGR,X2,T1]{fontenc}'` if you need both.
381
382 The TeX installation may need some extra packages. For example, on Ubuntu
383 xenial:
384
385 - ``texlive-lang-greek`` and ``cm-super`` are needed for Greek (``LGR``),
386
387 - ``texlive-lang-cyrillic`` and ``cm-super`` are needed for Cyrillic
388 (``X2``).
389
390 With ``'xelatex'`` and ``'lualatex'``, support for Greek and Cyrillic is
391 out-of-the-box: this :ref:`fontenc` key defaults to including the LaTeX
392 package ``fontspec`` (with some extras described below) and selects the GNU
393 FreeSerif font as body font. See :ref:`fontpkg`.
394
395 .. versionchanged:: 1.5
396 Defaults to :code-tex:`r'\\usepackage{fontspec}'` if
397 :confval:`latex_engine` is set to ``'xelatex'``.
398
399 .. versionchanged:: 1.6
400 Defaults to :code-tex:`r'\\usepackage{fontspec}'` if
401 :confval:`latex_engine` is set to ``'lualatex'``.
402
403 .. versionchanged:: 2.0
404 ``'lualatex'`` executes additionally
405 :code-tex:`\\defaultfontfeatures[\\rmfamily,\\sffamily]{}` to disable TeX
406 ligatures for ``<<`` and ``>>``.
407
408 .. versionchanged:: 2.0
409 Extra LaTeX configuration is automatically executed if ``LGR``, ``T2A``,
410 or ``X2`` are detected in this key, in order to support occasional Greek
411 or Cyrillic with ``'pdflatex'``.
412
413 .. versionchanged:: 2.2.1
414 Documents having Greek as main language default to ``'xelatex'`` and
415 should not set the :ref:`fontenc` key, which will load ``fontspec``.
416
417 .. versionchanged:: 2.3.0
418 ``'xelatex'`` executes
419 :code-tex:`\\defaultfontfeatures[\\rmfamily,\\sffamily]{}` in order to
420 avoid contractions of ``--`` into en-dash and also transforms of
421 straight quotes into curly quotes (which otherwise would happen even
422 with :confval:`smartquotes` set to ``False``).
423
424 ``'fontsubstitution'``
425 Ignored if ``'fontenc'`` was not configured to use ``LGR`` or ``X2`` (or
426 ``T2A``). In case :ref:`fontpkg` key is configured for usage with some
427 TeX fonts known to be available in the ``LGR`` or ``X2`` encodings, set
428 this one to be the empty string. Else leave to its default.
429
430 Ignored with :confval:`latex_engine` other than ``'pdflatex'``.
431
432 .. versionadded:: 4.0.0
433
434 ``'textgreek'``
435 For the support of occasional Greek letters.
436
437 It is ignored with ``'platex'``, ``'xelatex'`` or ``'lualatex'`` as
438 :confval:`latex_engine` and defaults to either the empty string or
439 to :code-tex:`r'\\usepackage{textalpha}'` for ``'pdflatex'`` depending on
440 whether the ``'fontenc'`` key was used with ``LGR`` or not. Only
441 expert LaTeX users may want to customize this key.
442
443 It can also be used as ``r'\usepackage{textalpha,alphabeta}'`` to let
444 ``'pdflatex'`` support Greek Unicode input in :rst:dir:`math` context.
445 For example ``:math:`α``` (U+03B1) will render as :math:`\alpha`.
446
447 Default: :code-tex:`r'\\usepackage{textalpha}'` or ``''`` if ``fontenc`` does not
448 include the ``LGR`` option.
449
450 .. versionadded:: 2.0
451
452 ``'geometry'``
453 "geometry" package inclusion, defaults to
454 :code-tex:`r'\\usepackage{geometry}'` or
455 :code-tex:`r'\\usepackage[dvipdfm]{geometry}'` for Japanese documents.
456 The Sphinx LaTeX style file executes additionally:
457
458 .. code-block:: latex
459
460 \PassOptionsToPackage{hmargin=1in,vmargin=1in,marginpar=0.5in}{geometry}
461
462 which can be customized via corresponding :ref:`'sphinxsetup' options
463 <latexsphinxsetup>`.
464
465 .. versionadded:: 1.5
466
467 .. versionchanged:: 1.5.2
468 ``dvipdfm`` option if :confval:`latex_engine` is ``'platex'``.
469
470 .. versionadded:: 1.5.3
471 The :ref:`'sphinxsetup' keys for the margins
472 <latexsphinxsetuphmargin>`.
473
474 .. versionchanged:: 1.5.3
475 The location in the LaTeX file has been moved to after
476 :code-tex:`\\usepackage{sphinx}` and :code-tex:`\\sphinxsetup{..}`,
477 hence also after
478 insertion of :ref:`fontpkg` key. This is in order to handle the paper
479 layout options in a special way for Japanese documents: the text
480 width will be set to an integer multiple of the *zenkaku* width, and
481 the text height to an integer multiple of the baseline. See the
482 :ref:`hmargin <latexsphinxsetuphmargin>` documentation for more.
483
484 ``'hyperref'``
485 "hyperref" package inclusion; also loads package "hypcap" and issues
486 :code-tex:`\\urlstyle{same}`. This is done after :file:`sphinx.sty` file
487 is loaded and before executing the contents of ``'preamble'`` key.
488
489 .. attention::
490
491 Loading of packages "hyperref" and "hypcap" is mandatory.
492
493 .. versionadded:: 1.5
494 Previously this was done from inside :file:`sphinx.sty`.
495
496 ``'maketitle'``
497 "maketitle" call. Override if you want to generate a differently styled
498 title page.
499
500 .. hint::
501
502 If the key value is set to
503 :code-tex:`r'\\newcommand\\sphinxbackoftitlepage{<Extra
504 material>}\\sphinxmaketitle'`, then ``<Extra material>`` will be
505 typeset on back of title page (``'manual'`` docclass only).
506
507 Default: :code-tex:`r'\\sphinxmaketitle'`
508
509 .. versionchanged:: 1.8.3
510 Original :code-tex:`\\maketitle` from document class is not overwritten,
511 hence is reusable as part of some custom setting for this key.
512
513 .. versionadded:: 1.8.3
514 :code-tex:`\\sphinxbackoftitlepage` optional macro. It can also be defined
515 inside ``'preamble'`` key rather than this one.
516
517 ``'releasename'``
518 Value that prefixes ``'release'`` element on title page. As for *title* and
519 *author* used in the tuples of :confval:`latex_documents`, it is inserted as
520 LaTeX markup.
521
522 Default: ``'Release'``
523
524 ``'tableofcontents'``
525 "tableofcontents" call. The default of
526 :code-tex:`r'\\sphinxtableofcontents'` is a wrapper of unmodified
527 :code-tex:`\\tableofcontents`, which may itself be customized by user
528 loaded packages. Override if you want to generate a different table of
529 contents or put content between the title page and the TOC.
530
531 Default: :code-tex:`r'\\sphinxtableofcontents'`
532
533 .. versionchanged:: 1.5
534 Previously the meaning of :code-tex:`\\tableofcontents` itself was
535 modified by Sphinx. This created an incompatibility with dedicated
536 packages modifying it also such as "tocloft" or "etoc".
537
538 ``'transition'``
539 Commands used to display transitions. Override if you want to display
540 transitions differently.
541
542 Default: :code-tex:`'\\n\\n\\\\bigskip\\\\hrule\\\\bigskip\\n\\n'`
543
544 .. versionadded:: 1.2
545
546 .. versionchanged:: 1.6
547 Remove unneeded ``{}`` formerly located after :code-tex:`\\hrule`.
548
549 ``'makeindex'``
550 "makeindex" call, the last thing before ``\begin{document}``. With
551 :code-tex:`r'\\usepackage[columns=1]{idxlayout}\\makeindex'` the index will
552 use only one column. You may have to install ``idxlayout`` LaTeX package.
553
554 Default: :code-tex:`r'\\makeindex'`
555
556 ``'printindex'``
557 "printindex" call, the last thing in the file. Override if you want to
558 generate the index differently, append some content after the index, or
559 change the font. As LaTeX uses two-column mode for the index it is often
560 advisable to set this key to
561 :code-tex:`r'\\footnotesize\\raggedright\\printindex'`. Or, to obtain a
562 one-column index, use :code-tex:`r'\\def\\twocolumn[#1]{#1}\\printindex'`
563 (this trick may fail if using a custom document class; then try the
564 ``idxlayout`` approach described in the documentation of the
565 ``'makeindex'`` key).
566
567 Default: :code-tex:`r'\\printindex'`
568
569 .. _fvset:
570
571 ``'fvset'``
572 Customization of ``fancyvrb`` LaTeX package.
573
574 The default value is :code-tex:`r'\\fvset{fontsize=auto}'` which means that
575 the font size will adjust correctly if a code-block ends up in a footnote.
576 You may need to modify this when using a custom monospace font, for example
577 set it to :code-tex:`r'\\fvset{fontsize=\\small}'` if it is Courier-like
578 (for Unicode engines, it is recommended to use rather the ``Scale``
579 interface of :code-tex:`\\setmonofont` LaTeX command from ``fontspec``).
580
581 Default: :code-tex:`r'\\fvset{fontsize=auto}'`
582
583 .. versionadded:: 1.8
584
585 .. versionchanged:: 2.0
586 For ``'xelatex'`` and ``'lualatex'`` defaults to
587 :code-tex:`r'\\fvset{fontsize=\\small}'` as this
588 is adapted to the relative widths of the FreeFont family.
589
590 .. versionchanged:: 4.0.0
591 Changed default for ``'pdflatex'``. Previously it was using
592 :code-tex:`r'\\fvset{fontsize=\\small}'`.
593
594 .. versionchanged:: 4.1.0
595 Changed default for Chinese documents to
596 :code-tex:`r'\\fvset{fontsize=\\small,formatcom=\\xeCJKVerbAddon}'`
597
598 .. versionchanged:: 8.1.0
599 Changed default for ``'xelatex'`` and ``'lualatex'`` to be also
600 :code-tex:`r'\\fvset{fontsize=auto}'`. The rescaling for default
601 monospace font FreeMono is now set via the LaTeX package ``fontspec``
602 interface rather. See :ref:`fontpkg`.
603
604 Keys that are set by other options and therefore should not be overridden are:
605
606 ``'docclass'``
607 ``'classoptions'``
608 ``'title'``
609 ``'release'``
610 ``'author'``
611
612
613 .. _latexsphinxsetup:
614
615 The ``sphinxsetup`` configuration setting
616 -----------------------------------------
617
618 .. versionadded:: 1.5
619
620 The ``'sphinxsetup'`` key of :ref:`latex_elements <latex_elements_confval>`
621 provides a LaTeX-type customization interface::
622
623 latex_elements = {
624 'sphinxsetup': 'key1=value1, key2=value2, ...',
625 }
626
627 LaTeX syntax for boolean keys requires *lowercase* ``true`` or ``false``
628 e.g ``'sphinxsetup': "verbatimwrapslines=false"``. If setting a
629 boolean key to ``true``, ``=true`` is optional.
630 Spaces around the commas and equal signs are ignored, spaces inside LaTeX
631 macros may be significant.
632 Do not use ticks/quotes to enclose string or numerical values.
633
634 The ``'sphinxsetup'`` defaults to empty.
635 If non-empty, it will be passed as argument to the
636 ``\sphinxsetup`` macro inside the document preamble, like this::
637
638 \usepackage{sphinx}
639 \sphinxsetup{key1=value1, key2=value2,...}
640
641 It is possible to insert uses of the ``\sphinxsetup`` LaTeX macro directly
642 into the body of the document, via the ``raw`` directive:
643
644 .. code-block:: latex
645
646 .. raw:: latex
647
648 \begingroup
649 \sphinxsetup{%
650 TitleColor=DarkGoldenrod,
651 ... more comma separated key=value using LaTeX syntax ...
652 }
653
654 All elements here will be under the influence of the raw ``\sphinxsetup``
655 settings.
656
657 .. raw:: latex
658
659 \endgroup
660
661 From here on, the raw ``\sphinxsetup`` has no effect anymore.
662
663 This is the technique which has been used to style especially the present part
664 of the documentation for the PDF output. The actually used options will be
665 found at top of :file:`doc/latex.rst` at the `development repository`_.
666
667 .. _development repository: https://github.com/sphinx-doc/sphinx
668
669 The color used in the above example is available from having passed the
670 ``svgnames`` option to the "xcolor" package::
671
672 latex_elements = {
673 'passoptionstopackages': r'\PassOptionsToPackage{svgnames}{xcolor}',
674 }
675
676 ``bookmarksdepth``
677 Controls the depth of the collapsible bookmarks panel in the PDF.
678 May be either a number (e.g. ``3``) or a LaTeX sectioning name (e.g.
679 ``subsubsection``, i.e. without backslash).
680 For details, refer to the ``hyperref`` LaTeX docs.
681
682 Default: ``5``
683
684 .. versionadded:: 4.0.0
685
686 .. _latexsphinxsetuphmargin:
687
688 ``hmargin, vmargin``
689 The dimensions of the horizontal (resp. vertical) margins, passed as
690 ``hmargin`` (resp. ``vmargin``) option to the ``geometry`` package.
691 Example::
692
693 'sphinxsetup': 'hmargin={2in,1.5in}, vmargin={1.5in,2in}, marginpar=1in',
694
695 Japanese documents currently accept only the one-dimension format for
696 these parameters. The ``geometry`` package is then passed suitable options
697 to get the text width set to an exact multiple of the *zenkaku* width, and
698 the text height set to an integer multiple of the baselineskip, with the
699 closest fit for the margins.
700
701 Default: ``1in`` (equivalent to ``{1in,1in}``)
702
703 .. hint::
704
705 For Japanese ``'manual'`` docclass with pointsize ``11pt`` or ``12pt``,
706 use the ``nomag`` extra document class option (cf.
707 ``'extraclassoptions'`` key of :confval:`latex_elements`) or so-called
708 TeX "true" units::
709
710 'sphinxsetup': 'hmargin=1.5truein, vmargin=1.5truein, marginpar=5zw',
711
712 .. versionadded:: 1.5.3
713
714 ``marginpar``
715 The :code-tex:`\\marginparwidth` LaTeX dimension. For Japanese documents,
716 the value is modified to be the closest integer multiple of the *zenkaku*
717 width.
718
719 Default: ``0.5in``
720
721 .. versionadded:: 1.5.3
722
723 ``mathnumsep``
724 This defaults to the string (without quotes!) as set by
725 :confval:`math_numsep` (which itself defaults to ``'.'``). Use it if
726 a different setting is needed for LaTeX output.
727
728 .. versionadded:: 8.1.0
729
730 ``literalblockcappos``
731 Decides the caption position: either ``b`` ("bottom") or ``t`` ("top").
732
733 Default: ``t``
734
735 .. versionadded:: 1.7
736
737 ``verbatimwithframe``
738 Boolean to specify if :rst:dir:`code-block`\ s and literal includes are
739 framed. Setting it to ``false`` does not deactivate use of package
740 "framed", because it is still in use for the optional background color.
741
742 Default: ``true``.
743
744 ``verbatimwrapslines``
745 Boolean to specify if long lines in :rst:dir:`code-block`\ 's contents are
746 wrapped.
747
748 If ``true``, line breaks may happen at spaces (the last space before the
749 line break will be rendered using a special symbol), and at ASCII
750 punctuation characters (i.e. not at letters or digits). Whenever a long
751 string has no break points, it is moved to next line. If its length is
752 longer than the line width it will overflow.
753
754 Default: ``true``
755
756 .. _latexsphinxsetupforcewraps:
757
758 ``verbatimforcewraps``
759 Boolean to specify if long lines in :rst:dir:`code-block`\ 's contents
760 should be forcefully wrapped to never overflow due to long strings.
761
762 .. note::
763
764 It is assumed that the Pygments_ LaTeXFormatter has not been used with
765 its ``texcomments`` or similar options which allow additional
766 (arbitrary) LaTeX mark-up.
767
768 Also, in case of :confval:`latex_engine` set to ``'pdflatex'``, only
769 the default LaTeX handling of Unicode code points, i.e. ``utf8`` not
770 ``utf8x`` is allowed.
771
772 .. _Pygments: https://pygments.org/
773
774 Default: ``false``
775
776 .. versionadded:: 3.5.0
777
778 ``verbatimmaxoverfull``
779 A number. If an unbreakable long string has length larger than the total
780 linewidth plus this number of characters, and if ``verbatimforcewraps``
781 mode is on, the input line will be reset using the forceful algorithm
782 which applies breakpoints at each character.
783
784 Default: ``3``
785
786 .. versionadded:: 3.5.0
787
788 ``verbatimmaxunderfull``
789 A number. If ``verbatimforcewraps`` mode applies, and if after applying
790 the line wrapping at spaces and punctuation, the first part of the split
791 line is lacking at least that number of characters to fill the available
792 width, then the input line will be reset using the forceful algorithm.
793
794 As the default is set to a high value, the forceful algorithm is triggered
795 only in overfull case, i.e. in presence of a string longer than full
796 linewidth. Set this to ``0`` to force all input lines to be hard wrapped
797 at the current available linewidth::
798
799 latex_elements = {
800 'sphinxsetup': "verbatimforcewraps, verbatimmaxunderfull=0",
801 }
802
803 This can be done locally for a given code-block via the use of raw latex
804 directives to insert suitable ``\sphinxsetup`` (before and after) into the
805 latex file.
806
807 Default: ``100``
808
809 .. versionadded:: 3.5.0
810
811 ``verbatimhintsturnover``
812 Boolean to specify if code-blocks display "continued on next page" and
813 "continued from previous page" hints in case of page breaks.
814
815 Default: ``true``
816
817 .. versionadded:: 1.6.3
818 .. versionchanged:: 1.7
819 the default changed from ``false`` to ``true``.
820
821 ``verbatimcontinuedalign``, ``verbatimcontinuesalign``
822 Horizontal position relative to the framed contents: either ``l`` (left
823 aligned), ``r`` (right aligned) or ``c`` (centered).
824
825 Default: ``r``
826
827 .. versionadded:: 1.7
828
829 ``parsedliteralwraps``
830 Boolean to specify if long lines in :dudir:`parsed-literal`\ 's contents
831 should wrap.
832
833 Default: ``true``
834
835 .. versionadded:: 1.5.2
836 set this option value to ``false`` to recover former behavior.
837
838 ``inlineliteralwraps``
839 Boolean to specify if line breaks are allowed inside inline literals: but
840 extra potential break-points (additionally to those allowed by LaTeX at
841 spaces or for hyphenation) are currently inserted only after the characters
842 ``. , ; ? ! /`` and ``\``. Due to TeX internals, white space in the line
843 will be stretched (or shrunk) in order to accommodate the linebreak.
844
845 Default: ``true``
846
847 .. versionadded:: 1.5
848 set this option value to ``false`` to recover former behavior.
849
850 .. versionchanged:: 2.3.0
851 added potential breakpoint at ``\`` characters.
852
853 ``verbatimvisiblespace``
854 When a long code line is split, the last space character from the source
855 code line right before the linebreak location is typeset using this.
856
857 Default: ``\textcolor{red}{\textvisiblespace}``
858
859 ``verbatimcontinued``
860 A LaTeX macro inserted at start of continuation code lines. Its
861 (complicated...) default typesets a small red hook pointing to the right:
862
863 .. code-block:: latex
864
865 \makebox[2\fontcharwd\font`\x][r]{\textcolor{red}{\tiny$\hookrightarrow$}}
866
867 .. versionchanged:: 1.5
868 The breaking of long code lines was added at 1.4.2. The default
869 definition of the continuation symbol was changed at 1.5 to accommodate
870 various font sizes (e.g. code-blocks can be in footnotes).
871
872 .. note::
873
874 Values for color keys must either:
875
876 - obey the syntax of the :code-tex:`\\definecolor` LaTeX command, e.g. something
877 such as ``VerbatimColor={rgb}{0.2,0.3,0.5}`` or ``{RGB}{37,23,255}`` or
878 ``{gray}{0.75}`` or ``{HTML}{808080}`` or
879 ...
880
881 - or obey the syntax of the :code-tex:`\\colorlet` command from package ``xcolor``
882 e.g. ``VerbatimColor=red!10`` or ``red!50!green`` or ``-red!75`` or
883 ``MyPreviouslyDefinedColor`` or... Refer to xcolor_ documentation for
884 this syntax.
885
886 .. _xcolor: https://ctan.org/pkg/xcolor
887
888 .. versionchanged:: 5.3.0
889 Formerly only the :code-tex:`\\definecolor` syntax was accepted.
890
891 ``TitleColor``
892 The color for titles (as configured via use of package "titlesec".)
893
894 Default: ``{rgb}{0.126,0.263,0.361}``
895
896 ``InnerLinkColor``
897 A color passed to ``hyperref`` as value of ``linkcolor`` and
898 ``citecolor``.
899
900 Default: ``{rgb}{0.208,0.374,0.486}``.
901
902 ``OuterLinkColor``
903 A color passed to ``hyperref`` as value of ``filecolor``, ``menucolor``,
904 and ``urlcolor``.
905
906 Default: ``{rgb}{0.216,0.439,0.388}``
907
908 ``VerbatimColor``
909 The background color for :rst:dir:`code-block`\ s.
910
911 Default: ``{RGB}{242,242,242}`` (same as ``{gray}{0.95}``).
912
913 .. versionchanged:: 6.0.0
914
915 Formerly, it was ``{rgb}{1,1,1}`` (white).
916
917 ``VerbatimBorderColor``
918 The frame color.
919
920 Default: ``{RGB}{32,32,32}``
921
922 .. versionchanged:: 6.0.0
923
924 Formerly it was ``{rgb}{0,0,0}`` (black).
925
926 ``VerbatimHighlightColor``
927 The color for highlighted lines.
928
929 Default: ``{rgb}{0.878,1,1}``
930
931 .. versionadded:: 1.6.6
932
933 .. _tablecolors:
934
935 ``TableRowColorHeader``
936 Sets the background color for (all) the header rows of tables.
937
938 It will have an effect only if either the :confval:`latex_table_style`
939 contains ``'colorrows'`` or if the table is assigned the ``colorrows``
940 class. It is ignored for tables with ``nocolorrows`` class.
941
942 As for the other ``'sphinxsetup'`` keys, it can also be set or modified
943 from a :code-tex:`\\sphinxsetup{...}` LaTeX command inserted via the
944 :dudir:`raw` directive, or also from a LaTeX environment associated to a
945 `container class <latexcontainer_>`_ and using such
946 :code-tex:`\\sphinxsetup{...}`.
947
948 Default: ``{gray}{0.86}``
949
950 There is also ``TableMergeColorHeader``. If used, sets a specific color
951 for merged single-row cells in the header.
952
953 .. versionadded:: 5.3.0
954
955 ``TableRowColorOdd``
956 Sets the background color for odd rows in tables (the row count starts at
957 ``1`` at the first non-header row). Has an effect only if the
958 :confval:`latex_table_style` contains ``'colorrows'`` or for specific
959 tables assigned the ``colorrows`` class.
960
961 Default: ``{gray}{0.92}``
962
963 There is also ``TableMergeColorOdd``.
964
965 .. versionadded:: 5.3.0
966
967 ``TableRowColorEven``
968 Sets the background color for even rows in tables.
969
970 Default ``{gray}{0.98}``
971
972 There is also ``TableMergeColorEven``.
973
974 .. versionadded:: 5.3.0
975
976 ``verbatimsep``
977 The separation between code lines and the frame.
978
979 See :ref:`additionalcss` for its alias ``pre_padding`` and
980 additional keys.
981
982 Default: :code-tex:`\\fboxsep`
983
984 ``verbatimborder``
985 The width of the frame around :rst:dir:`code-block`\ s. See also
986 :ref:`additionalcss` for ``pre_border-width``.
987
988 Default: :code-tex:`\\fboxrule`
989
990 .. important::
991
992 Since 8.1.0 it is possible to style separately the :dudir:`topic`,
993 contents_, and :dudir:`sidebar` directives, and their defaults differ.
994 See :ref:`additionalcss`. The next three keys are kept as legacy
995 interface not distinguishing between the three directives.
996
997 ``shadowsep``
998 This legacy option sets the padding (same in all directions) simultaneously
999 for the :dudir:`topic`, contents_, and :dudir:`sidebar` directives.
1000
1001 ``shadowsize``
1002 This legacy option sets the shadow width simultaneously for the
1003 :dudir:`topic`, contents_, and :dudir:`sidebar` directives.
1004
1005 ``shadowrule``
1006 This legacy option sets the border-width (same on all sides) simultaneously
1007 for the :dudir:`topic`, contents_, and :dudir:`sidebar` directives.
1008
1009 .. important::
1010
1011 At 7.4.0 all admonitions (not only danger-type) use the possibilities
1012 which were added at 5.1.0 and 6.2.0. All defaults have changed.
1013
1014 ``iconpackage``
1015
1016 The name of the LaTeX package used for rendering icons in the admonition
1017 titles. Its default is set dynamically to either ``fontawesome7``,
1018 ``fontawesome6``,
1019 ``fontawesome5``, ``fontawesome``, or ``none``, in decreasing order of
1020 priority and depending on whether
1021 packages with those names exist in the used LaTeX installation. The LaTeX
1022 code for each admonition icon will use ``\faIcon`` command if with
1023 ``fontawesome{5,6,7}`` and
1024 ``\faicon`` if with ``fontawesome``.
1025 If no "Font Awesome" related package is found (or if the option is set
1026 forcefully to ``none``) the icons are silently dropped. User can set this
1027 option to some specific package and must configure then the
1028 ``div.note_title-icon`` and similar keys to use then that LaTeX package
1029 interface (see the :ref:`additionalcss` section about this).
1030
1031 .. versionadded:: 7.4.0
1032
1033 |notebdcolors|
1034 The color for the admonition border.
1035
1036 Default: ``{RGB}{134,152,155}``.
1037
1038 .. versionchanged:: 7.4.0
1039
1040 |notebgcolors|
1041 The color for the admonition background.
1042
1043 Default: ``{RGB}{247,247,247}``.
1044
1045 .. versionadded:: 6.2.0
1046
1047 .. versionchanged:: 7.4.0
1048
1049 |notetextcolors|
1050 The color for the admonition contents.
1051
1052 Default: unset (contents text uses ambient text color, a priori black)
1053
1054 .. versionadded:: 6.2.0
1055
1056 To be considered experimental until 7.0.0. These options have aliases
1057 ``div.note_TeXcolor`` (etc) described in :ref:`additionalcss`. Using
1058 the latter will let Sphinx switch to a more complex LaTeX code,
1059 which supports the customizability described in :ref:`additionalcss`.
1060
1061 |notetexextras|
1062 Some extra LaTeX code (such as :code-tex:`\\bfseries` or
1063 :code-tex:`\\footnotesize`) to be executed at start of the contents.
1064
1065 Default: empty
1066
1067 .. versionadded:: 6.2.0
1068
1069 To be considered experimental until 7.0.0. These options have aliases
1070 ``div.note_TeXextras`` (etc) described in :ref:`additionalcss`.
1071
1072 ``noteborder``, ``hintborder``, ``importantborder``, ``tipborder``
1073 The width of the border. See
1074 :ref:`additionalcss` for keys allowing to configure separately each
1075 border width.
1076
1077 Default: ``0.5pt``
1078
1079 .. only:: not latex
1080
1081 |warningbdcolors|
1082 The color for the admonition border.
1083
1084 Default: ``{RGB}{148,0,0}`` except for ``error`` which uses ``red``.
1085
1086 .. versionchanged:: 7.4.0
1087
1088 .. only:: latex
1089
1090 |wgbdcolorslatex|
1091 The color for the admonition border.
1092
1093 Default: ``{RGB}{148,0,0}`` except for ``error`` which uses ``red``.
1094
1095 .. versionchanged:: 7.4.0
1096
1097 |warningbgcolors|
1098 The background color for the admonition background.
1099
1100 Default: ``{RGB}{247,247,247}``.
1101
1102 .. versionchanged:: 7.4.0
1103
1104 |warningborders|
1105 The width of the admonition frame. See
1106 :ref:`additionalcss` for keys allowing to configure separately each
1107 border width.
1108
1109 Default: ``1pt`` except for ``error`` which uses ``1.25pt``.
1110
1111 .. versionchanged:: 7.4.0
1112
1113 ``AtStartFootnote``
1114 LaTeX macros inserted at the start of the footnote text at bottom of page,
1115 after the footnote number.
1116
1117 Default: :code-tex:`\\mbox{ }`
1118
1119 ``BeforeFootnote``
1120 LaTeX macros inserted before the footnote mark. The default removes
1121 possible space before it (else, TeX could insert a line break there).
1122
1123 Default: :code-tex:`\\leavevmode\\unskip`
1124
1125 .. versionadded:: 1.5
1126
1127 ``HeaderFamily``
1128 default :code-tex:`\\sffamily\\bfseries`. Sets the font used by headings.
1129
1130
1131 .. |notebdcolors| replace:: ``noteBorderColor``, ``hintBorderColor``,
1132 ``importantBorderColor``, ``tipBorderColor``
1133
1134 .. |notebgcolors| replace:: ``noteBgColor``, ``hintBgColor``,
1135 ``importantBgColor``, ``tipBgColor``
1136
1137 .. |notetextcolors| replace:: ``noteTextColor``, ``hintTextColor``,
1138 ``importantTextColor``, ``tipTextColor``
1139
1140 .. |notetexextras| replace:: ``noteTeXextras``, ``hintTeXextras``,
1141 ``importantTeXextras``, ``tipTeXextras``
1142
1143 .. |warningbdcolors| replace:: ``warningBorderColor``, ``cautionBorderColor``,
1144 ``attentionBorderColor``, ``dangerBorderColor``,
1145 ``errorBorderColor``
1146
1147 .. |wgbdcolorslatex| replace:: ``warningBorderColor``, and
1148 ``(caution|attention|danger|error)BorderColor``
1149
1150 .. else latex goes into right margin, as it does not hyphenate the names
1151
1152 .. |warningbgcolors| replace:: ``warningBgColor``, ``cautionBgColor``,
1153 ``attentionBgColor``, ``dangerBgColor``,
1154 ``errorBgColor``
1155
1156 .. |warningborders| replace:: ``warningborder``, ``cautionborder``,
1157 ``attentionborder``, ``dangerborder``,
1158 ``errorborder``
1159
1160 .. _additionalcss:
1161
1162 Additional CSS-like ``'sphinxsetup'`` keys
1163 -------------------------------------------
1164
1165 .. versionadded:: 5.1.0
1166
1167 For :rst:dir:`code-block`, :dudir:`topic` and contents_ directive,
1168 and strong-type admonitions (:dudir:`warning`, :dudir:`error`, ...).
1169
1170 .. versionadded:: 6.2.0
1171
1172 Also the :dudir:`note`, :dudir:`hint`, :dudir:`important` and :dudir:`tip`
1173 admonitions can be styled this way. Using for them *any* of the listed
1174 options will trigger usage of a more complex LaTeX code than the one used
1175 per default (``sphinxheavybox`` vs ``sphinxlightbox``). Setting the new
1176 ``noteBgColor`` (or ``hintBgColor``, ...) also triggers usage of
1177 ``sphinxheavybox`` for :dudir:`note` (or :dudir:`hint`, ...).
1178
1179 .. versionadded:: 7.4.0
1180
1181 For *all* admonition types, the default configuration does set a background
1182 color (hence the richer ``sphinxheavybox`` is always used).
1183
1184 .. important::
1185
1186 Further, all admonition titles are by default styled using a colored row
1187 and an icon, which are modeled on the current rendering of Sphinx own
1188 docs at https://www.sphinx-doc.org. CSS-named alike keys are added to
1189 set the foreground and background colors for the title as well as the
1190 LaTeX code for the icon.
1191
1192 .. versionadded:: 7.4.0
1193 Customizability of the :rst:dir:`seealso` and
1194 :rst:dir:`todo` directives.
1195
1196 .. versionadded:: 8.1.0
1197 Separate customizability and new defaults for the
1198 :dudir:`topic`, contents_, and :dudir:`sidebar` directives.
1199
1200 Perhaps in future these 5.1.0 (and 6.2.0) novel settings will be optionally
1201 imported from some genuine CSS external file, but currently they have to be used
1202 via the ``'sphinxsetup'`` interface (or the :code-tex:`\\sphinxsetup` LaTeX command
1203 inserted via the :dudir:`raw` directive) and the CSS syntax is only imitated.
1204
1205 .. important:: Low-level LaTeX errors causing a build failure can happen if
1206 the input syntax is not respected.
1207
1208 * In particular colors must be input as for the other color related options
1209 previously described, i.e. either in the :code-tex:`\\definecolor` syntax
1210 or via the :code-tex:`\\colorlet` syntax::
1211
1212 ...<other options>
1213 div.warning_border-TeXcolor={rgb}{1,0,0},% \definecolor syntax
1214 div.error_background-TeXcolor=red!10,% \colorlet syntax
1215 ...<other options>
1216
1217 * A colon in place of the equal sign will break LaTeX.
1218
1219 * ``...border-width`` or ``...padding`` expect a *single* dimension: they can not
1220 be used so far with space separated dimensions.
1221
1222 * ``...top-right-radius`` et al. values may be either a single or *two* space
1223 separated dimensions.
1224
1225 * Dimension specifications must use TeX units such as ``pt`` or ``cm`` or
1226 ``in``. The ``px`` unit is recognized by ``pdflatex`` and ``lualatex``
1227 but not by ``xelatex`` or ``platex``.
1228
1229 * It is allowed for such specifications to be so-called "dimensional
1230 expressions", e.g. :code-tex:`\\fboxsep+2pt` or
1231 :code-tex:`0.5\\baselineskip` are valid inputs. The expressions will be
1232 evaluated only at the typesetting time. Be careful though if using as in
1233 these examples TeX control sequences to double the backslash or to employ
1234 a raw Python string for the value of the :ref:`'sphinxsetup'
1235 <latexsphinxsetup>` key.
1236
1237 * As a rule, avoid inserting unneeded spaces in the key values: especially
1238 for the radii an input such ``2 pt 3pt`` will break LaTeX. Beware also
1239 that :code-tex:`\\fboxsep \\fboxsep` will not be seen as space separated
1240 in LaTeX. You must use something such as ``{\fboxsep} \fboxsep``. Or
1241 use directly ``3pt 3pt`` which is a priori equivalent and simpler.
1242
1243 The options are all named in a similar pattern which depends on a ``prefix``,
1244 which is then followed by an underscore, then the property name.
1245
1246 .. csv-table::
1247 :header: Directive, Option prefix, LaTeX environment
1248
1249 :rst:dir:`code-block`, ``pre``, ``sphinxVerbatim``
1250 :rst:dir:`literalinclude`, ``pre``, ``sphinxVerbatim``
1251 :dudir:`topic`, ``div.topic``, ``sphinxtopic``
1252 contents_, ``div.contents``, ``sphinxcontents``
1253 :dudir:`sidebar`, ``div.sidebar``, ``sphinxsidebar``
1254 :dudir:`note`, ``div.note``, ``sphinxnote``
1255 :dudir:`warning`, ``div.warning``, ``sphinxwarning``
1256 further admonition types ``<type>``, ``div.<type>``, ``sphinx<type>``
1257 :rst:dir:`seealso`, ``div.seealso``, ``sphinxseealso``
1258 :rst:dir:`todo`, ``div.todo``, ``sphinxtodo``
1259
1260 Here are now these options as well as their common defaults.
1261 Replace below ``<prefix>`` by the actual prefix as explained above. Don't
1262 forget the underscore separating the prefix from the property names.
1263
1264 - | ``<prefix>_border-top-width``,
1265 | ``<prefix>_border-right-width``,
1266 | ``<prefix>_border-bottom-width``,
1267 | ``<prefix>_border-left-width``,
1268 | ``<prefix>_border-width``. The latter can (currently) be only a *single*
1269 dimension which then sets all four others.
1270
1271 The default is that all those dimensions are equal. They are set to:
1272
1273 * ``0.4pt`` for :rst:dir:`code-block`,
1274 * ``0.5pt`` for :dudir:`topic` and contents_ directive,
1275 * ``1pt`` for :dudir:`sidebar` directive,
1276 * ``0.5pt`` for :dudir:`note` and other "light" admonitions,
1277 * ``0.5pt`` for :rst:dir:`seealso` and :rst:dir:`todo` directives,
1278 * ``1pt`` for :dudir:`warning` and other "strong" admonitions except
1279 :dudir:`error` which uses ``1.25pt``.
1280
1281 .. versionchanged:: 7.4.0
1282 Changed defaults for :dudir:`topic` and :dudir:`error`.
1283
1284 .. versionchanged:: 8.1.0
1285 Distinct from :dudir:`topic` defaults for :dudir:`sidebar`.
1286
1287 - ``<prefix>_box-decoration-break`` can be set to either ``clone`` or
1288 ``slice`` and configures the behavior at page breaks.
1289 It defaults to ``slice`` for :rst:dir:`code-block` (i.e. for ``<prefix>=pre``)
1290 since 6.0.0. For other directives the default is ``clone``.
1291 - | ``<prefix>_padding-top``,
1292 | ``<prefix>_padding-right``,
1293 | ``<prefix>_padding-bottom``,
1294 | ``<prefix>_padding-left``,
1295 | ``<prefix>_padding``. The latter can (currently) be only a *single*
1296 dimension which then sets all four others.
1297
1298 The defaults:
1299
1300 * all four ``3pt`` for :rst:dir:`code-block`,
1301 * ``6pt``, ``7pt``, ``6pt``, ``7pt`` for :dudir:`topic`,
1302 * ``10pt``, ``7pt``, ``12pt``, ``7pt`` for contents_,
1303 * ``6pt``, ``5.5pt``, ``6pt``, ``5.5pt`` for :dudir:`sidebar`,
1304 * ``6pt``, ``7pt``, ``6pt``, ``7pt`` for all "light" admonitions as well
1305 as the :rst:dir:`seealso` and :rst:dir:`todo` directives.
1306 * ``6pt``, ``6.5pt``, ``6pt``, ``6.5pt`` for the strong admonition types
1307 except :dudir:`error` which uses horizontal padding of ``6.25pt``.
1308
1309 .. versionchanged:: 7.4.0
1310
1311 All defaults were changed, except for :rst:dir:`code-block`. Admonitions
1312 are set-up so that left (or right) padding plus left (or right)
1313 border-width add up always to ``7.5pt``, so contents align well
1314 vertically across admonition types on same page in PDF. This is only a
1315 property of defaults, not a constraint on possible user choices.
1316
1317 .. versionchanged:: 8.1.0
1318 Separate defaults for :dudir:`topic`, contents_, and :dudir:`sidebar`.
1319
1320 - | ``<prefix>_border-top-left-radius``,
1321 | ``<prefix>_border-top-right-radius``,
1322 | ``<prefix>_border-bottom-right-radius``,
1323 | ``<prefix>_border-bottom-left-radius``,
1324 | ``<prefix>_border-radius``. This last key sets the first four to
1325 its assigned value. Each key value can be either a single, or *two*,
1326 dimensions which are then space separated.
1327
1328 The defaults:
1329
1330 * ``3pt`` for :rst:dir:`code-block` (since 6.0.0) and all corners,
1331 * ``8pt`` for all corners of :dudir:`topic`,
1332 * ``12pt`` for the bottom right corner of contents_, others use ``0pt``,
1333 * ``12pt`` for the top-left and bottom-right corners for :dudir:`sidebar`,
1334 ``0pt`` for top-right and bottom-left.
1335 * all radii set to ``5pt`` for :dudir:`note`, :dudir:`hint` and
1336 :dudir:`tip`,
1337 * ``0pt``, i.e. straight corners for all other directives.
1338
1339 .. versionchanged:: 7.4.0
1340 :dudir:`topic` and :dudir:`note`\ -like
1341 admonitions acquire (at least one) rounded corners.
1342
1343 .. versionchanged:: 8.1.0
1344 Separate defaults for :dudir:`topic`, contents_, and :dudir:`sidebar`.
1345
1346 See a remark above about traps with spaces in LaTeX.
1347 - ``<prefix>_box-shadow`` is special in so far as it may be:
1348
1349 * the ``none`` keyword,
1350 * or a single dimension (giving both x-offset and y-offset),
1351 * or two dimensions (separated by a space),
1352 * or two dimensions followed by the keyword ``inset``.
1353
1354 The x-offset and y-offset may be negative. A negative x-offset means
1355 that the shadow is on the left. The shadow extends into the page margin,
1356 whether the offset is positive or negative.
1357
1358 The default is ``none`` *except* for the contents_ directive which uses
1359 ``4pt 4pt``.
1360
1361 .. versionchanged:: 8.1.0
1362 No shadow per default for :dudir:`topic` and :dudir:`sidebar`.
1363
1364 - | ``<prefix>_border-TeXcolor``,
1365 | ``<prefix>_background-TeXcolor``,
1366 | ``<prefix>_box-shadow-TeXcolor``,
1367 | ``<prefix>_TeXcolor``.
1368 These are colors.
1369
1370 Since 6.0.0 the border and background colors of :rst:dir:`code-block`,
1371 default respectively to ``{RGB}{32,32,32}`` (i.e. ``{HTML}{202020}``), and
1372 ``{RGB}{242,242,242}`` (i.e. ``{gray}{0.95}`` or ``{HTML}{F2F2F2}``).
1373
1374 At 7.4.0 other directives acquire non-black/white default border and
1375 background colors. Here they are using ``xcolor`` hexadecimal notation
1376 (which requires always 6 hexadecimal digits):
1377
1378 - ``{HTML}{F7F7F7}`` serves as background color to all.
1379 - ``{HTML}{86989B}`` is border color of light admonitions (inclusive of
1380 :rst:dir:`seealso` and :rst:dir:`todo`) as well as of :dudir:`topic`,
1381 contents_ and :dudir:`sidebar` directives.
1382 - ``{HTML}{940000}`` is border color of :dudir:`warning`-type admonitions,
1383 except :dudir:`error` which uses ``{HTML}{B40000}``.
1384
1385 The only directives displaying a shadow per default are contents_ and
1386 :dudir:`sidebar`. The shadow-color for the former is ``{HTML}{6C6C6C}``
1387 and for the latter ``{HTML}{9EACAF}``.
1388
1389 The ``<prefix>_TeXcolor`` stands for the CSS property "color", i.e. it
1390 influences the text color of the contents. As for the three other options,
1391 the naming ``TeXcolor`` is to stress that the input syntax is the TeX one
1392 for colors not an HTML/CSS one. If package ``xcolor`` is available in the
1393 LaTeX installation, one can use directly named colors as key values.
1394 Consider passing options such as ``dvipsnames``, ``svgnames`` or ``x11names``
1395 to ``xcolor`` via ``'passoptionstopackages'`` key of :confval:`latex_elements`.
1396
1397 If ``<prefix>_TeXcolor`` is set, a :code-tex:`\\color` command is inserted at
1398 start of the directive contents; for admonitions, this happens after the
1399 heading which reproduces the admonition type.
1400
1401 - ``<prefix>_TeXextras``: if set, its value must be some LaTeX command or
1402 commands, for example :code-tex:`\\itshape`. These commands will be
1403 inserted at the start of the contents; for admonitions, this happens after
1404 the heading which reproduces the admonition type.
1405
1406 The next keys, for admonitions, :dudir:`topic`, contents_, and
1407 :dudir:`sidebar`, were all three added at 7.4.0 (and 8.1.0 for the latter three).
1408
1409 - ``div.<type>_title-background-TeXcolor``: the background color for the title.
1410
1411 .. important::
1412
1413 The colored title-row is produced as a result of the Sphinx default
1414 definitions for the various :code-tex:`\\sphinxstyle<type>title`
1415 commands, which employ the :code-tex:`\\sphinxdotitlerow` LaTeX command.
1416 See :ref:`latex-macros`.
1417
1418 - ``div.<type>_title-foreground-TeXcolor``: the color to be used for the icon
1419 (it applies only to the icon, not to the title of the admonition).
1420
1421 - ``div.<type>_title-icon``: the LaTeX code responsible for producing the
1422 icon for the given ``<admonition type>``.
1423 For example the default for :dudir:`note` is
1424 ``div.note_title-icon=\faIcon{info-circle}`` with ``fontawesome5``, but
1425 ``div.note_title-icon=\faIcon{circle-info}`` with ``fontawesome6``
1426 and ``fontawesome7``.
1427 If you want to modify the icons used by Sphinx, employ in these keys
1428 the ``\faIcon`` LaTeX command if one of ``fontawesome5``, ``6`` or ``7`` is
1429 on your LaTeX installation.
1430 If your system only provides the
1431 ``fontawesome`` package use its command ``\faicon`` (not ``\faIcon``)
1432 in order to modify the choice of icons. The ``iconpackage`` key of
1433 ``'sphinxsetup'`` can be used to force usage of one among
1434 ``fontawesome{,5,6,7}`` or be the name of some other icon-providing package.
1435 In that latter case you must configure the ``div.<type>_title-icon`` keys
1436 to use the LaTeX commands appropriate to that custom icon package.
1437
1438 .. note::
1439
1440 - All directives support ``box-decoration-break`` to be set to ``slice``.
1441
1442 .. versionchanged:: 6.2.0
1443
1444 Formerly, only :rst:dir:`code-block` did. The default remains
1445 ``clone`` for all other directives, but this will probably change at
1446 7.0.0.
1447
1448 - The corners of rounded boxes may be elliptical.
1449
1450 .. versionchanged:: 6.2.0
1451
1452 Formerly, only circular rounded corners were supported and a rounded
1453 corner forced the whole frame to use the same constant width from
1454 ``<prefix>_border-width``.
1455
1456 - Inset shadows are incompatible with rounded corners. In case
1457 both are specified the inset shadow will simply be ignored.
1458
1459 .. versionchanged:: 6.2.0
1460
1461 Formerly it was to the contrary the rounded corners which were ignored
1462 in case an inset shadow was specified.
1463
1464 - ``<prefix>_TeXcolor`` and ``<prefix>_TeXextras`` are new with 6.2.0.
1465
1466 Usefulness is doubtful in the case of :rst:dir:`code-block`:
1467
1468 - ``pre_TeXcolor`` will influence only the few non-Pygments highlighted
1469 tokens; it does color the line numbers, but if one wants to color
1470 *only* them one has to go through the ``fancyvrb`` interface.
1471
1472 - ``pre_TeXextras=\footnotesize`` (as an example) is equivalent to setting
1473 :ref:`fvset` key value to :code-tex:`r'\\fvset{fontsize=\\footnotesize}'`.
1474
1475 Consider these options experimental and that some implementation details
1476 may change. For example if the ``pre_TeXextras`` LaTeX commands were put
1477 by Sphinx in another location it could override the :ref:`fvset` effect,
1478 perhaps this is what will be done in a future release.
1479
1480 - Rounded boxes are done using the pict2e_ interface to some basic PDF
1481 graphics operations. If this LaTeX package can not be found the build
1482 will proceed and render all boxes with straight corners.
1483
1484 - Elliptic corners use the ellipse_ LaTeX package which extends pict2e_.
1485 If this LaTeX package can not be found rounded corners will be circular
1486 arcs (or straight if pict2e_ is not available).
1487
1488 .. _pict2e: https://ctan.org/pkg/pict2e
1489 .. _ellipse: https://ctan.org/pkg/ellipse
1490
1491
1492 The following legacy behavior applies:
1493
1494 - For :rst:dir:`code-block` or :rst:dir:`literalinclude`, padding and
1495 border-width and shadow (if any) will go into the margin; the code
1496 lines remain at the same place independently of the values of the padding
1497 and border-width, except for being shifted vertically of course to not
1498 overwrite other text due to the width of the border or external shadow.
1499
1500 - For the other directives, shadows extend horizontally into the page margins,
1501 but the border and the extra padding are kept within the text area.
1502
1503 - :rst:dir:`code-block` and :rst:dir:`literalinclude` use the same LaTeX
1504 environment and commands and are not separately customizable.
1505
1506
1507 LaTeX macros and environments
1508 -----------------------------
1509
1510 The "LaTeX package" file :file:`sphinx.sty` loads various components
1511 providing support macros (aka commands), and environments, which are used in
1512 the mark-up produced on output from the ``latex`` builder, before conversion
1513 to ``pdf`` via the LaTeX toolchain. Also the "LaTeX class" files
1514 :file:`sphinxhowto.cls` and :file:`sphinxmanual.cls` define or customize some
1515 environments. All of these files can be found in the latex build repertory.
1516
1517 Some of these provide facilities not available from pre-existing LaTeX
1518 packages and work around LaTeX limitations with lists, table cells, verbatim
1519 rendering, footnotes, etc...
1520
1521 Others simply define macros with public names to make overwriting their
1522 defaults easy via user-added contents to the preamble. We will survey most of
1523 those public names here, but defaults have to be looked at in their respective
1524 definition files.
1525
1526 .. hint::
1527
1528 Sphinx LaTeX support code is split across multiple smaller-sized files.
1529 Rather than adding code to the preamble via
1530 `latex_elements <latex_elements_confval_>`_\ [``'preamble'``] it is
1531 also possible to replace entirely one of the component files of Sphinx
1532 LaTeX code with a custom version, simply by including a modified copy in
1533 the project source and adding the filename to the
1534 :confval:`latex_additional_files` list. Check the LaTeX build repertory
1535 for the filenames and contents.
1536
1537 .. versionchanged:: 4.0.0
1538 split of :file:`sphinx.sty` into multiple smaller units, to facilitate
1539 customization of many aspects simultaneously.
1540
1541 .. _latex-macros:
1542
1543 Macros
1544 ~~~~~~
1545
1546 - Text styling commands:
1547
1548 .. csv-table::
1549 :header: Name, ``maps argument #1 to:``
1550 :align: left
1551 :class: longtable
1552 :delim: ;
1553
1554 ``\sphinxstrong``; ``\textbf{#1}``
1555 ``\sphinxcode``; ``\texttt{#1}``
1556 ``\sphinxbfcode``; ``\textbf{\sphinxcode{#1}}``
1557 ``\sphinxemail``; ``\textsf{#1}``
1558 ``\sphinxtablecontinued``; ``\textsf{#1}``
1559 ``\sphinxtitleref``; ``\emph{#1}``
1560 ``\sphinxmenuselection``; ``\emph{#1}``
1561 ``\sphinxguilabel``; ``\emph{#1}``
1562 ``\sphinxkeyboard``; ``\sphinxcode{#1}``
1563 ``\sphinxaccelerator``; ``\underline{#1}``
1564 ``\sphinxcrossref``; ``\emph{#1}``
1565 ``\sphinxtermref``; ``\emph{#1}``
1566 ``\sphinxsamedocref``; ``\emph{#1}``
1567 ``\sphinxparam``; ``\emph{#1}``
1568 ``\sphinxtypeparam``; ``\emph{#1}``
1569 ``\sphinxoptional``; ``[#1]`` with larger brackets, see source
1570
1571 .. versionadded:: 1.4.5
1572 Use of ``\sphinx`` prefixed macro names to limit possibilities of conflict
1573 with LaTeX packages.
1574
1575 .. versionadded:: 1.8
1576 :code-tex:`\\sphinxguilabel`
1577
1578 .. versionadded:: 3.0
1579 :code-tex:`\\sphinxkeyboard`
1580
1581 .. versionadded:: 6.2.0
1582 :code-tex:`\\sphinxparam`, :code-tex:`\\sphinxsamedocref`
1583
1584 .. versionadded:: 7.1.0
1585 :code-tex:`\\sphinxparamcomma` which defaults to a comma followed by a
1586 space and :code-tex:`\\sphinxparamcommaoneperline`. It is sed for
1587 one-parameter-per-line signatures (see
1588 :confval:`maximum_signature_line_length`) and defaults to
1589 :code-tex:`\\texttt{,}`.
1590
1591 Signatures of Python functions are rendered as
1592 ``name<space>(parameters)`` or ``name<space>[type
1593 parameters]<space>(parameters)`` (see :pep:`695`) where the length of
1594 ``<space>`` is set to ``0pt`` by default. This can be changed via
1595 :code-tex:`\\setlength{\\sphinxsignaturelistskip}{1ex}` for instance.
1596
1597 - More text styling:
1598
1599 .. csv-table::
1600 :header: Name, ``maps argument #1 to:``
1601 :align: left
1602 :class: longtable
1603 :delim: ;
1604
1605 ``\sphinxstyleindexentry``; ``\texttt{#1}``
1606 ``\sphinxstyleindexextra``; ``(\emph{#1})`` (with a space upfront)
1607 ``\sphinxstyleindexpageref``; ``, \pageref{#1}``
1608 ``\sphinxstyleindexpagemain``; ``\textbf{#1}``
1609 ``\sphinxstyleindexlettergroup``; ``{\Large\sffamily#1}\nopagebreak\vspace{1mm}``
1610 ``\sphinxstyleindexlettergroupDefault``; check source, too long for here
1611 ``\sphinxstyletopictitle``; ``\textbf{#1}\par\medskip``
1612 ``\sphinxstylesidebartitle``; ``\textbf{#1}\par\medskip``
1613 ``\sphinxstyleothertitle``; ``\textbf{#1}``
1614 ``\sphinxstylesidebarsubtitle``; ``~\\\textbf{#1} \smallskip``
1615 ``\sphinxstyletheadfamily``; ``\sffamily`` (*this one has no argument*)
1616 ``\sphinxstyleemphasis``; ``\emph{#1}``
1617 ``\sphinxstyleliteralemphasis``; ``\emph{\sphinxcode{#1}}``
1618 ``\sphinxstylestrong``; ``\textbf{#1}``
1619 ``\sphinxstyleliteralstrong``; ``\sphinxbfcode{#1}``
1620 ``\sphinxstyleabbreviation``; ``\textsc{#1}``
1621 ``\sphinxstyleliteralintitle``; ``\sphinxcode{#1}``
1622 ``\sphinxstylecodecontinued``; ``{\footnotesize(#1)}}``
1623 ``\sphinxstylecodecontinues``; ``{\footnotesize(#1)}}``
1624 ``\sphinxstylenotetitle``; ``\sphinxdotitlerow{note}{#1}``
1625 ``\sphinxstylehinttitle``; ``\sphinxdotitlerow{hint}{#1}``
1626 ``\sphinxstyleimportanttitle``; ``\sphinxdotitlerow{important}{#1}``
1627 ``\sphinxstyletiptitle``; ``\sphinxdotitlerow{tip}{#1}``
1628 ``\sphinxstylewarningtitle``; ``\sphinxdotitlerow{warning}{#1}``
1629 ``\sphinxstylecautiontitle``; ``\sphinxdotitlerow{caution}{#1}``
1630 ``\sphinxstyleattentiontitle``; ``\sphinxdotitlerow{attention}{#1}``
1631 ``\sphinxstyledangertitle``; ``\sphinxdotitlerow{danger}{#1}``
1632 ``\sphinxstyleerrortitle``; ``\sphinxdotitlerow{error}{#1}``
1633 ``\sphinxstyleseealsotitle``; ``\sphinxdotitlerow{seealso}{#1}``
1634 ``\sphinxstyletodotitle``; ``\sphinxdotitlerow{todo}{#1}``
1635 ``\sphinxstyletopictitle``; ``\sphinxdotitlerow{topic}{#1}``
1636 ``\sphinxstylecontentstitle``; ``\sphinxdotitlerow{contents}{#1}``
1637 ``\sphinxstylesidebartitle``; ``\sphinxdotitlerow{sidebar}{#1}``
1638
1639 .. note::
1640
1641 To let this table fit on the page width in PDF output we have lied a bit.
1642 For instance, the actual definition of :code-tex:`\\sphinxstylenotetitle` is:
1643
1644 .. code-block:: latex
1645
1646 \newcommand\sphinxstylenotetitle[1]%
1647 {\sphinxdotitlerow{note}{\sphinxremovefinalcolon{#1}}}
1648
1649 The same remark applies to all other similar commands associated with
1650 admonitions. The :dudir:`topic`, contents_, and :dudir:`sidebar` do not
1651 use :code-tex:`\\sphinxremovefinalcolon` as they don't need it.
1652
1653 .. versionadded:: 1.5
1654 These macros were formerly hard-coded as non customizable :code-tex:`\\texttt`,
1655 :code-tex:`\\emph`, etc...
1656
1657 .. versionadded:: 1.6
1658 :code-tex:`\\sphinxstyletheadfamily` which defaults to
1659 :code-tex:`\\sffamily` and allows
1660 multiple paragraphs in header cells of tables.
1661
1662 .. versionadded:: 1.6.3
1663 :code-tex:`\\sphinxstylecodecontinued` and
1664 :code-tex:`\\sphinxstylecodecontinues`.
1665
1666 .. versionadded:: 1.8
1667 :code-tex:`\\sphinxstyleindexlettergroup`,
1668 :code-tex:`\\sphinxstyleindexlettergroupDefault`.
1669
1670 .. versionadded:: 6.2.0
1671 :code-tex:`\\sphinxstylenotetitle` et al. The ``#1`` is the localized
1672 name of the directive, with a final colon. Wrap it as
1673 :code-tex:`\\sphinxremovefinalcolon{#1}` if this final colon is to be
1674 removed.
1675
1676 .. versionadded:: 7.4.0
1677 Added the :code-tex:`\\sphinxdotitlerowwithicon` LaTeX command.
1678
1679 .. versionchanged:: 8.1.0
1680 :code-tex:`\\sphinxdotitlerowwithicon` now detects automatically if an icon is
1681 associated or not with the rendered element used as first argument.
1682
1683 .. versionadded:: 8.1.0 Make :code-tex:`\\sphinxdotitlerow` an alias to
1684 :code-tex:`\\sphinxdotitlerowwithicon`.
1685
1686 .. versionadded:: 8.1.0
1687 Titles of :dudir:`topic`, contents_, and :dudir:`sidebar` directives are
1688 also styled using :code-tex:`\\sphinxdotitlerow` (they have no default icons
1689 associated with them).
1690
1691 - :code-tex:`\\sphinxtableofcontents`: A wrapper (defined differently in
1692 :file:`sphinxhowto.cls` and in :file:`sphinxmanual.cls`) of standard
1693 :code-tex:`\\tableofcontents`. The macro
1694 :code-tex:`\\sphinxtableofcontentshook` is executed during its expansion right
1695 before :code-tex:`\\tableofcontents` itself.
1696
1697 .. versionchanged:: 1.5
1698 Formerly, the meaning of :code-tex:`\\tableofcontents` was modified by Sphinx.
1699
1700 .. versionchanged:: 2.0
1701 Hard-coded redefinitions of :code-tex:`\\l@section` and
1702 :code-tex:`\\l@subsection` formerly done during loading of ``'manual'``
1703 docclass are now executed later via
1704 :code-tex:`\\sphinxtableofcontentshook`. This macro is also executed by
1705 the ``'howto'`` docclass, but defaults to empty with it.
1706
1707 .. hint::
1708
1709 If adding to preamble the loading of ``tocloft`` package, also add to
1710 preamble :code-tex:`\\renewcommand\\sphinxtableofcontentshook{}` else it
1711 will reset :code-tex:`\\l@section` and :code-tex:`\\l@subsection`
1712 cancelling ``tocloft`` customization.
1713
1714 - :code-tex:`\\sphinxmaketitle`: Used as the default setting of the ``'maketitle'``
1715 :confval:`latex_elements` key.
1716 Defined in the class files :file:`sphinxmanual.cls` and
1717 :file:`sphinxhowto.cls`.
1718
1719 .. versionchanged:: 1.8.3
1720 Formerly, :code-tex:`\\maketitle` from LaTeX document class was modified by
1721 Sphinx.
1722
1723 - :code-tex:`\\sphinxbackoftitlepage`: For ``'manual'`` docclass, and if it is
1724 defined, it gets executed at end of :code-tex:`\\sphinxmaketitle`, before
1725 the final :code-tex:`\\clearpage`. Use either the ``'maketitle'`` key or
1726 the ``'preamble'`` key of :confval:`latex_elements` to add a custom
1727 definition of :code-tex:`\\sphinxbackoftitlepage`.
1728
1729 .. versionadded:: 1.8.3
1730
1731 - :code-tex:`\\sphinxcite`: A wrapper of standard :code-tex:`\\cite` for
1732 citation references.
1733
1734
1735 .. _sphinxbox:
1736
1737 The :code-tex:`\\sphinxbox` command
1738 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1739
1740 .. versionadded:: 6.2.0
1741
1742 The :code-tex:`\\sphinxbox[key=value,...]{inline text}` command can be used to "box"
1743 inline text elements with all the customizability which has been described in
1744 :ref:`additionalcss`. It is a LaTeX command with one optional argument, which
1745 is a comma-separated list of key=value pairs, as for :ref:`latexsphinxsetup`.
1746 Here is the complete list of keys. They don't use any prefix.
1747
1748 - ``border-width``,
1749 - ``border-top-width``, ``border-right-width``, ``border-bottom-width``,
1750 ``border-left-width``,
1751 - ``padding``,
1752 - ``padding-top``, ``padding-right``, ``padding-bottom``, ``padding-left``,
1753 - ``border-radius``,
1754 - ``border-top-left-radius``, ``border-top-right-radius``,
1755 ``border-bottom-right-radius``, ``border-bottom-left-radius``,
1756 - ``box-shadow``,
1757 - ``border-TeXcolor``, ``background-TeXcolor``, ``box-shadow-TeXcolor``,
1758 ``TeXcolor``,
1759 - ``TeXextras``,
1760 - and ``addstrut`` which is a boolean key, i.e. to be used as ``addstrut=true``,
1761 or ``addstrut`` alone where ``=true`` is omitted, or ``addstrut=false``.
1762
1763 This last key is specific to :code-tex:`\\sphinxbox` and it means to add a
1764 :code-tex:`\\strut` so that heights and depths are equalized across various
1765 instances on the same line with varying contents. The default is
1766 ``addstrut=false``. The combination ``addstrut, padding-bottom=0pt,
1767 padding-top=1pt`` is often satisfactory.
1768
1769 Refer to :ref:`additionalcss` for important syntax information regarding the
1770 other keys. The default configuration uses no shadow, a border-width of
1771 :code-tex:`\\fboxrule`, a padding of :code-tex:`\\fboxsep`, circular corners
1772 with radii :code-tex:`\\fboxsep` and background and border colors as for the
1773 default rendering of code-blocks.
1774
1775 When a :code-tex:`\\sphinxbox` usage is nested within another one, it will ignore the
1776 options of the outer one: it first resets all options to their default state
1777 as they were prior to applying the outer box options, then it applies its own
1778 specific ones.
1779
1780 One can modify these defaults via the command
1781 :code-tex:`\\sphinxboxsetup{key=value,...}`. The effect is cumulative, if one
1782 uses this command multiple times. Here the options are a mandatory argument
1783 so are within curly braces, not square brackets.
1784
1785 Here is some example of use:
1786
1787 .. code-block:: latex
1788
1789 latex_elements = {
1790 'preamble': r'''
1791 % modify globally the defaults
1792 \sphinxboxsetup{border-width=2pt,%
1793 border-radius=4pt,%
1794 background-TeXcolor=yellow!20}
1795 % configure some styling element with some extra specific options:
1796 \protected\def\sphinxkeyboard#1{\sphinxbox[border-TeXcolor=green]{\sphinxcode{#1}}}
1797 ''',
1798 }
1799
1800 A utility :code-tex:`\\newsphinxbox` is provided to create a new boxing macro,
1801 say :code-tex:`\\foo` which will act exactly like :code-tex:`\\sphinxbox` but
1802 with a given extra configuration:
1803
1804 .. code-block:: latex
1805
1806 % the specific options to \foo are within brackets
1807 \newsphinxbox[border-radius=0pt, box-shadow=2pt 2pt]{\foo}
1808 % then use this \foo, possibly with some extra options still:
1809 \protected\def\sphinxguilabel#1{\foo{#1}}
1810 \protected\def\sphinxmenuselection#1{\foo[box-shadow-TeXcolor=gray]{#1}}
1811
1812 Boxes rendered with :code-tex:`\\foo` obey as the ones using directly
1813 :code-tex:`\\sphinxbox` the current configuration as set possibly mid-way in
1814 document via :code-tex:`\\sphinxboxsetup` (from a :dudir:`raw` LaTeX mark-up),
1815 the only difference is that they have an initial additional set of default
1816 extras.
1817
1818 In the above examples, you can probably use :code-tex:`\\renewcommand` syntax
1819 if you prefer it to :code-tex:`\\protected\\def` (with ``[1]`` in place of
1820 ``#1`` then).
1821
1822
1823 Environments
1824 ~~~~~~~~~~~~
1825
1826 - A :dudir:`figure` may have an optional legend with arbitrary body
1827 elements: they are rendered in a ``sphinxlegend`` environment. The default
1828 definition issues :code-tex:`\\small`, and ends with :code-tex:`\\par`.
1829
1830 .. versionadded:: 1.5.6
1831 Formerly, the :code-tex:`\\small` was hardcoded in LaTeX writer and the ending
1832 :code-tex:`\\par` was lacking.
1833
1834 - Environments associated with admonitions:
1835
1836 - ``sphinxnote``,
1837 - ``sphinxhint``,
1838 - ``sphinximportant``,
1839 - ``sphinxtip``,
1840 - ``sphinxwarning``,
1841 - ``sphinxcaution``,
1842 - ``sphinxattention``,
1843 - ``sphinxdanger``,
1844 - ``sphinxerror``.
1845
1846 They may be :code-tex:`\\renewenvironment`
1847 'd individually, and must then be defined with one argument (it is the heading
1848 of the notice, for example ``Warning:`` for :dudir:`warning` directive, if
1849 English is the document language). Their default definitions use either the
1850 *sphinxheavybox* (for the last 5 ones) or the *sphinxlightbox*
1851 environments, configured to use the parameters (colors, border thickness)
1852 specific to each type, which can be set via ``'sphinxsetup'`` string.
1853
1854 .. versionchanged:: 1.5
1855 Use of public environment names, separate customizability of the
1856 parameters, such as ``noteBorderColor``, ``noteborder``,
1857 ``warningBgColor``, ``warningBorderColor``, ``warningborder``, ...
1858
1859 - Environment for the :rst:dir:`seealso` directive: ``sphinxseealso``.
1860 It takes one argument which will be the localized string ``See also``
1861 followed with a colon.
1862
1863 .. versionadded:: 6.1.0
1864 .. versionchanged:: 6.2.0
1865 Colon made part of the mark-up rather than being inserted by the
1866 environment for coherence with how admonitions are handled generally.
1867
1868 - Environment for the :rst:dir:`todo` directive: ``sphinxtodo``.
1869 It takes one argument, namely the localization of ``Todo``
1870 (with a colon at the end; the default rendering will remove that
1871 colon and put the localized string in its own colored title-row).
1872
1873 .. versionadded:: 7.4.0
1874
1875 - The :dudir:`topic`, contents_ and :dudir:`sidebar` directives
1876 are associated with respectively ``sphinxtopic``, ``sphinxcontents``,
1877 and ``sphinxsidebar`` environments.
1878
1879 .. versionadded:: 1.4.2
1880 Former code refactored into an environment allowing page breaks.
1881
1882 .. versionchanged:: 1.5
1883 Options ``shadowsep``, ``shadowsize``, ``shadowrule``.
1884
1885 .. versionadded:: 8.1.0
1886 Separate environments (all three wrappers around ``sphinxShadowBox``)
1887 and separate customizability.
1888
1889 - The literal blocks (via ``::`` or :rst:dir:`code-block`), and literal
1890 includes (:rst:dir:`literalinclude`) are
1891 implemented using ``sphinxVerbatim`` environment which is a wrapper of
1892 ``Verbatim`` environment from package ``fancyvrb.sty``. It adds the handling
1893 of the top caption and the wrapping of long lines, and a frame which allows
1894 page breaks. Inside tables the used
1895 environment is ``sphinxVerbatimintable`` (it does not draw a frame, but
1896 allows a caption).
1897
1898 .. versionchanged:: 1.5
1899 ``Verbatim`` keeps exact same meaning as in ``fancyvrb.sty`` (also
1900 under the name ``OriginalVerbatim``); ``sphinxVerbatimintable`` is used
1901 inside tables.
1902
1903 .. versionadded:: 1.5
1904 Options ``verbatimwithframe``, ``verbatimwrapslines``,
1905 ``verbatimsep``, ``verbatimborder``.
1906
1907 .. versionadded:: 1.6.6
1908 Support for ``:emphasize-lines:`` option
1909
1910 .. versionadded:: 1.6.6
1911 Easier customizability of the formatting via exposed to user LaTeX macros
1912 such as :code-tex:`\\sphinxVerbatimHighlightLine`.
1913
1914 - The bibliography uses ``sphinxthebibliography`` and the Python Module index
1915 as well as the general index both use ``sphinxtheindex``; these environments
1916 are wrappers of the ``thebibliography`` and respectively ``theindex``
1917 environments as provided by the document class (or packages).
1918
1919 .. versionchanged:: 1.5
1920 Formerly, the original environments were modified by Sphinx.
1921
1922 Miscellany
1923 ~~~~~~~~~~
1924
1925 - Every text paragraph in document body starts with :code-tex:`\\sphinxAtStartPar`.
1926 Currently, this is used to insert a zero width horizontal skip which
1927 is a trick to allow TeX hyphenation of the first word of a paragraph
1928 in a narrow context (like a table cell). For ``'lualatex'`` which
1929 does not need the trick, the :code-tex:`\\sphinxAtStartPar` does nothing.
1930
1931 .. versionadded:: 3.5.0
1932
1933 - The section, subsection, ... headings are set using *titlesec*'s
1934 :code-tex:`\\titleformat` command.
1935
1936 - For the ``'manual'`` docclass, the chapter headings can be customized using
1937 *fncychap*'s commands :code-tex:`\\ChNameVar`, :code-tex:`\\ChNumVar`,
1938 :code-tex:`\\ChTitleVar`. File :file:`sphinx.sty` has custom re-definitions in
1939 case of *fncychap* option ``Bjarne``.
1940
1941 .. versionchanged:: 1.5
1942 Formerly, use of *fncychap* with other styles than ``Bjarne`` was
1943 dysfunctional.
1944
1945 - The :dudir:`role` directive allows to mark inline text with class arguments.
1946 This is handled in LaTeX output via the :code-tex:`\\DUrole` dispatcher
1947 command `as in Docutils <classarguments_>`_. Object signatures also use
1948 :code-tex:`\\DUrole` for some components, with one or two-letters class
1949 names as in HTML output.
1950
1951 .. versionchanged:: 8.1.0
1952 When multiple classes are injected via a a custom role, the LaTeX output
1953 uses nested :code-tex:`\\DUrole`'s as in the `Docutils documentation
1954 <classarguments_>`_. Formerly it used a single :code-tex:`\\DUrole` with
1955 comma separated classes, making the LaTeX customization more arduous.
1956
1957 .. _classarguments: https://docutils.sourceforge.io/docs/user/latex.html#custom-interpreted-text-roles
1958
1959 .. _latexcontainer:
1960
1961 - Docutils :dudir:`container` directives are supported in LaTeX output: to
1962 let a container class with name ``foo`` influence the final PDF via LaTeX,
1963 it is only needed to define in the preamble an environment
1964 ``sphinxclassfoo``. A simple example would be:
1965
1966 .. code-block:: latex
1967
1968 \newenvironment{sphinxclassred}{\color{red}}{}
1969
1970 Currently the class names must contain only ASCII characters and avoid
1971 characters special to LaTeX such as ``\``.
1972
1973 .. versionadded:: 4.1.0
1974
1975 .. hint::
1976
1977 As an experimental feature, Sphinx can use user-defined template file for
1978 LaTeX source if you have a file named ``_templates/latex.tex.jinja`` in your
1979 project.
1980
1981 Additional files ``longtable.tex.jinja``, ``tabulary.tex.jinja`` and
1982 ``tabular.tex.jinja`` can be added to ``_templates/`` to configure some
1983 aspects of table rendering (such as the caption position).
1984
1985 .. versionadded:: 1.6
1986 currently all template variables are unstable and undocumented.
1987
1988 .. versionchanged:: 7.4
1989 Added support for the ``.jinja`` file extension, which is preferred.
1990 The old file names remain supported.
1991 (``latex.tex_t``, ``longtable.tex_t``, ``tabulary.tex_t``, and ``tabular.tex_t``)
1992
1993 .. raw:: latex
1994
1995 \endgroup