LaTeX customization¶
Unlike the HTML builders, the latex builder does not
benefit from prepared themes. The Options for LaTeX output, and particularly the
latex_elements variable, provides much of the
interface for customization. For example:
# inside conf.py
latex_engine = 'xelatex'
latex_elements = {
'passoptionstopackages': r'''
\PassOptionsToPackage{svgnames}{xcolor}
''',
'fontpkg': r'''
\setmainfont{DejaVu Serif}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}
''',
'preamble': r'''
\usepackage[titles]{tocloft}
\cftsetpnumwidth {1.25cm}\cftsetrmarg{1.5cm}
\setlength{\cftchapnumwidth}{0.75cm}
\setlength{\cftsecindent}{\cftchapnumwidth}
\setlength{\cftsecnumwidth}{1.25cm}
''',
'sphinxsetup': 'TitleColor=DarkGoldenrod',
'fncychap': r'\usepackage[Bjornstrup]{fncychap}',
'printindex': r'\footnotesize\raggedright\printindex',
}
latex_show_urls = 'footnote'
Note
Keep in mind that backslashes must be doubled in Python string literals to avoid interpretation as escape sequences. Alternatively, you may use raw strings as is done above.
The latex_elements configuration setting¶
A dictionary that contains LaTeX snippets overriding those Sphinx usually puts
into the generated .tex files. Its 'sphinxsetup' key is described
separately. It allows also local configurations
inserted in generated files, via raw directives. For example, in
the PDF documentation this chapter is styled especially, as will be described
later.
Keys that you may want to override include:
'papersize'Paper size option of the document class (
'a4paper'or'letterpaper')Default:
'letterpaper''pointsize'Point size option of the document class (
'10pt','11pt'or'12pt')Default:
'10pt''pxunit'The value of the
pxwhen used in image attributeswidthandheight. The default value is'0.75bp'which achieves96px=1in(in TeX1in = 72bp = 72.27pt.) To obtain for example100px=1inuse'0.01in'or'0.7227pt'(the latter leads to TeX computing a more precise value, due to the smaller unit used in the specification); for72px=1in, simply use'1bp'; for90px=1in, use'0.8bp'or'0.803pt'.Default:
'0.75bp'Added in version 1.5.
'passoptionstopackages'A string which will be positioned early in the preamble, designed to contain
\\PassOptionsToPackage{options}{foo}commands.Hint
It may be also used for loading LaTeX packages very early in the preamble. For example package
fancyboxis incompatible with being loaded via the'preamble'key, it must be loaded earlier.Default:
''Added in version 1.4.
'babel'“babel” package inclusion, default
'\\usepackage{babel}'(the suitable document language string is passed as class option, andenglishis used if no language.) For Japanese documents, the default is the empty string.With XeLaTeX and LuaLaTeX, Sphinx configures the LaTeX document to use polyglossia, but one should be aware that current babel has improved its support for Unicode engines in recent years and for some languages it may make sense to prefer
babeloverpolyglossia.Hint
After modifying a core LaTeX key like this one, clean up the LaTeX build repertory before next PDF build, else left-over auxiliary files are likely to break the build.
Default:
'\\usepackage{babel}'(for Japanese documents)Changed in version 1.5: For
latex_engineset to'xelatex', the default is'\\usepackage{polyglossia}\n\\setmainlanguage{<language>}'.Changed in version 1.6:
'lualatex'uses same default setting as'xelatex'Changed in version 1.7.6: For French with
'xelatex'(not'lualatex') the default is to usebabel, notpolyglossia.Changed in version 7.4.0: For French with
'lualatex'the default is to usebabel.'fontpkg'Font package inclusion. The default is:
r"""\usepackage{tgtermes} \usepackage{tgheros} \renewcommand\ttdefault{txtt} """
For
'xelatex'and'lualatex'however the default is to use the GNU FreeFont.Changed in version 1.2: Defaults to
''when thelanguageuses the Cyrillic script.Changed in version 2.0: Incorporates some font substitution commands to help support occasional Greek or Cyrillic in a document using
'pdflatex'engine.Changed in version 4.0.0:
The font substitution commands added at
2.0have been moved to the'fontsubstitution'key, as their presence here made it complicated for user to customize the value of'fontpkg'.The default font setting has changed: it still uses Times and Helvetica clones for serif and sans serif, but via better, more complete TeX fonts and associated LaTeX packages. The monospace font has been changed to better match the Times clone.
'fncychap'Inclusion of the “fncychap” package (which makes fancy chapter titles), default
'\\usepackage[Bjarne]{fncychap}'for English documentation (this option is slightly customized by Sphinx),'\\usepackage[Sonny]{fncychap}'for internationalized docs (because the “Bjarne” style uses numbers spelled out in English). Other “fncychap” styles you can try are “Lenny”, “Glenn”, “Conny”, “Rejne” and “Bjornstrup”. You can also set this to''to disable fncychap.Default:
'\\usepackage[Bjarne]{fncychap}'for English documents,'\\usepackage[Sonny]{fncychap}'for internationalized documents, and''for Japanese documents.'preamble'Additional preamble content. One may move all needed macros into some file
mystyle.tex.txtof the project source repertory, and get LaTeX to import it at run time:'preamble': r'\input{mystyle.tex.txt}', # or, if the \ProvidesPackage LaTeX macro is used in a file mystyle.sty 'preamble': r'\usepackage{mystyle}',
It is then needed to set appropriately
latex_additional_files, for example:latex_additional_files = ["mystyle.sty"]
Do not use
.texas suffix, else the file is submitted itself to the PDF build process, use.tex.txtor.styas in the examples above.Default:
'''figure_align'Latex figure float alignment. Whenever an image doesn’t fit into the current page, it will be ‘floated’ into the next page but may be preceded by any other text. If you don’t like this behavior, use ‘H’ which will disable floating and position figures strictly in the order they appear in the source.
Default:
'htbp'(here, top, bottom, page)Added in version 1.3.
'atendofbody'Additional document content (right before the indices).
Default:
''Added in version 1.5.
'extrapackages'Additional LaTeX packages. For example:
latex_elements = { 'extrapackages': r'\usepackage{isodate}' }
The specified LaTeX packages will be loaded before hyperref package and packages loaded from Sphinx extensions.
Hint
If you’d like to load additional LaTeX packages after hyperref, use
'preamble'key instead.Default:
''Added in version 2.3.
'footer'Additional footer content (before the indices).
Default:
''Deprecated since version 1.5: Use
'atendofbody'key instead.
Keys that don’t need to be overridden unless in special cases are:
'extraclassoptions'The default is the empty string. Example:
'extraclassoptions': 'openany'will allow chapters (for documents of the'manual'type) to start on any page.Default:
''Added in version 1.2.
Changed in version 1.6: Added this documentation.
'maxlistdepth'LaTeX allows by default at most 6 levels for nesting list and quote-like environments, with at most 4 enumerated lists, and 4 bullet lists. Setting this key for example to
'10'(as a string) will allow up to 10 nested levels (of all sorts). Leaving it to the empty string means to obey the LaTeX default.Warning
Using this key may prove incompatible with some LaTeX packages or special document classes which do their own list customization.
The key setting is silently ignored if
\usepackage{enumitem}is executed inside the document preamble. Use then rather the dedicated commands of this LaTeX package.
Default:
6Added in version 1.5.
'inputenc'“inputenc” package inclusion.
Default:
'\\usepackage[utf8]{inputenc}'when using pdflatex, else''.Note
If using
utf8xin place ofutf8it is mandatory to extend the LaTeX preamble with suitable\PreloadUnicodePage{<number>}commands, as per theutf8xdocumentation (texdoc ucson a TeXLive based TeX installation). Else, unexpected and possibly hard-to-spot problems (i.e. not causing a build crash) may arise in the PDF, in particular regarding hyperlinks.Even if these precautions are taken, PDF build via
pdflatexengine may crash due to upstream LaTeX not being fully compatible withutf8x. For example, in certain circumstances related to code-blocks, or attempting to include images whose filenames contain Unicode characters. Indeed, starting in 2015, upstream LaTeX withpdflatexengine has somewhat enhanced native support for Unicode and is becoming more and more incompatible withutf8x. In particular, since the October 2019 LaTeX release, filenames can use Unicode characters, and even spaces. At Sphinx level this means e.g. that the image and figure directives are now compatible with such filenames for PDF via LaTeX output. But this is broken ifutf8xis in use.Changed in version 1.4.3: Previously
'\\usepackage[utf8]{inputenc}'was used for all compilers.'cmappkg'“cmap” package inclusion.
Default:
'\\usepackage{cmap}'Added in version 1.2.
'fontenc'Customize this from its default
'\\usepackage[T1]{fontenc}'to:'\\usepackage[X2,T1]{fontenc}'if you need occasional Cyrillic letters (физика частиц),'\\usepackage[LGR,T1]{fontenc}'if you need occasional Greek letters (Σωματιδιακή φυσική).
Use
[LGR,X2,T1]rather if both are needed.Attention
Do not use this key for a
latex_engineother than'pdflatex'.If Greek is main language, do not use this key. Since Sphinx 2.2.1,
xelatexwill be used automatically aslatex_engine.The TeX installation may need some extra packages. For example, on Ubuntu xenial, packages
texlive-lang-greekandcm-superare needed forLGRto work. Andtexlive-lang-cyrillicandcm-superare needed for support of Cyrillic.
Changed in version 1.5: Defaults to
'\\usepackage{fontspec}'whenlatex_engineis'xelatex'.Changed in version 1.6:
'lualatex'usesfontspecper default like'xelatex'.Changed in version 2.0:
'lualatex'executes\defaultfontfeatures[\rmfamily,\sffamily]{}to disable TeX ligatures transforming<<and>>as escaping working withpdflatex/xelatexfailed withlualatex.Changed in version 2.0: Detection of
LGR,T2A,X2to trigger support of occasional Greek or Cyrillic letters ('pdflatex').Changed in version 2.3.0:
'xelatex'executes\defaultfontfeatures[\rmfamily,\sffamily]{}in order to avoid contractions of--into en-dash or transforms of straight quotes into curly ones in PDF (in non-literal text paragraphs) despitesmartquotesbeing set toFalse.'fontsubstitution'Ignored if
'fontenc'was not configured to useLGRorX2(orT2A). In case'fontpkg'key is configured for usage with some TeX fonts known to be available in theLGRorX2encodings, set this one to be the empty string. Else leave to its default.Ignored with
latex_engineother than'pdflatex'.Added in version 4.0.0.
'textgreek'For the support of occasional Greek letters.
It is ignored with
'platex','xelatex'or'lualatex'aslatex_engineand defaults to either the empty string or to'\\usepackage{textalpha}'for'pdflatex'depending on whether the'fontenc'key was used withLGRor not. Only expert LaTeX users may want to customize this key.It can also be used as
r'\usepackage{textalpha,alphabeta}'to let'pdflatex'support Greek Unicode input inmathcontext. For example:math:`α`(U+03B1) will render as \(\alpha\).Default:
'\\usepackage{textalpha}'or''iffontencdoes not include theLGRoption.Added in version 2.0.
'geometry'“geometry” package inclusion, the default definition is:
'\\usepackage{geometry}'
with an additional
[dvipdfm]for Japanese documents. The Sphinx LaTeX style file executes:\PassOptionsToPackage{hmargin=1in,vmargin=1in,marginpar=0.5in}{geometry}
which can be customized via corresponding ‘sphinxsetup’ options.
Default:
'\\usepackage{geometry}'(or'\\usepackage[dvipdfm]{geometry}'for Japanese documents)Added in version 1.5.
Changed in version 1.5.2:
dvipdfmoption iflatex_engineis'platex'.Added in version 1.5.3: The ‘sphinxsetup’ keys for the margins.
Changed in version 1.5.3: The location in the LaTeX file has been moved to after
\usepackage{sphinx}and\sphinxsetup{..}, hence also after insertion of'fontpkg'key. This is in order to handle the paper layout options in a special way for Japanese documents: the text width will be set to an integer multiple of the zenkaku width, and the text height to an integer multiple of the baseline. See the hmargin documentation for more.'hyperref'“hyperref” package inclusion; also loads package “hypcap” and issues
\urlstyle{same}. This is done aftersphinx.styfile is loaded and before executing the contents of'preamble'key.Attention
Loading of packages “hyperref” and “hypcap” is mandatory.
Added in version 1.5: Previously this was done from inside
sphinx.sty.'maketitle'“maketitle” call. Override if you want to generate a differently styled title page.
Hint
If the key value is set to
r'\newcommand\sphinxbackoftitlepage{<Extra material>}\sphinxmaketitle', then<Extra material>will be typeset on back of title page ('manual'docclass only).Default:
'\\sphinxmaketitle'Changed in version 1.8.3: Original
\maketitlefrom document class is not overwritten, hence is reusable as part of some custom setting for this key.Added in version 1.8.3:
\sphinxbackoftitlepageoptional macro. It can also be defined inside'preamble'key rather than this one.'releasename'Value that prefixes
'release'element on title page. As for title and author used in the tuples oflatex_documents, it is inserted as LaTeX markup.Default:
'Release''tableofcontents'“tableofcontents” call. The default of
'\\sphinxtableofcontents'is a wrapper of unmodified\tableofcontents, which may itself be customized by user loaded packages. Override if you want to generate a different table of contents or put content between the title page and the TOC.Default:
'\\sphinxtableofcontents'Changed in version 1.5: Previously the meaning of
\tableofcontentsitself was modified by Sphinx. This created an incompatibility with dedicated packages modifying it also such as “tocloft” or “etoc”.'transition'Commands used to display transitions. Override if you want to display transitions differently.
Default:
'\n\n\\bigskip\\hrule\\bigskip\n\n'Added in version 1.2.
Changed in version 1.6: Remove unneeded
{}after\\hrule.'makeindex'“makeindex” call, the last thing before
\begin{document}. With'\\usepackage[columns=1]{idxlayout}\\makeindex'the index will use only one column. You may have to installidxlayoutLaTeX package.Default:
'\\makeindex''printindex'“printindex” call, the last thing in the file. Override if you want to generate the index differently, append some content after the index, or change the font. As LaTeX uses two-column mode for the index it is often advisable to set this key to
'\\footnotesize\\raggedright\\printindex'. Or, to obtain a one-column index, use'\\def\\twocolumn[#1]{#1}\\printindex'(this trick may fail if using a custom document class; then try theidxlayoutapproach described in the documentation of the'makeindex'key).Default:
'\\printindex''fvset'Customization of
fancyvrbLaTeX package.The default value is
'\\fvset{fontsize=auto}'which means that the font size will adjust correctly if a code-block ends up in a footnote. You may need to modify this if you use custom fonts:'\\fvset{fontsize=\\small}'if the monospace font is Courier-like.Default:
'\\fvset{fontsize=auto}'Added in version 1.8.
Changed in version 2.0: For
'xelatex'and'lualatex'defaults to'\\fvset{fontsize=\\small}'as this is adapted to the relative widths of the FreeFont family.Changed in version 4.0.0: Changed default for
'pdflatex'. Previously it was using'\\fvset{fontsize=\\small}'.Changed in version 4.1.0: Changed default for Chinese documents to
'\\fvset{fontsize=\\small,formatcom=\\xeCJKVerbAddon}'
Keys that are set by other options and therefore should not be overridden are:
'docclass'
'classoptions'
'title'
'release'
'author'
The sphinxsetup configuration setting¶
Added in version 1.5.
The 'sphinxsetup' key of latex_elements
provides a LaTeX-type customization interface:
latex_elements = {
'sphinxsetup': 'key1=value1, key2=value2, ...',
}
LaTeX syntax for boolean keys requires lowercase true or false
e.g 'sphinxsetup': "verbatimwrapslines=false". If setting a
boolean key to true, =true is optional.
Spaces around the commas and equal signs are ignored, spaces inside LaTeX
macros may be significant.
Do not use ticks/quotes to enclose string or numerical values.
The 'sphinxsetup' defaults to empty.
If non-empty, it will be passed as argument to the
\sphinxsetup macro inside the document preamble, like this:
\usepackage{sphinx}
\sphinxsetup{key1=value1, key2=value2,...}
It is possible to insert uses of the \sphinxsetup LaTeX macro directly
into the body of the document, via the raw directive:
.. raw:: latex
\begingroup
\sphinxsetup{%
TitleColor=DarkGoldenrod,
... more comma separated key=value using LaTeX syntax ...
}
All elements here will be under the influence of the raw ``\sphinxsetup``
settings.
.. raw:: latex
\endgroup
From here on, the raw ``\sphinxsetup`` has no effect anymore.
This is the technique which has been used to style especially the present part
of the documentation for the PDF output. The actually used options will be
found at top of doc/latex.rst at the development repository.
The color used in the above example is available from having passed the
svgnames option to the “xcolor” package:
latex_elements = {
'passoptionstopackages': r'\PassOptionsToPackage{svgnames}{xcolor}',
}
bookmarksdepthControls the depth of the collapsible bookmarks panel in the PDF. May be either a number (e.g.
3) or a LaTeX sectioning name (e.g.subsubsection, i.e. without backslash). For details, refer to thehyperrefLaTeX docs.Default:
5Added in version 4.0.0.
hmargin, vmarginThe dimensions of the horizontal (resp. vertical) margins, passed as
hmargin(resp.vmargin) option to thegeometrypackage. Example:'sphinxsetup': 'hmargin={2in,1.5in}, vmargin={1.5in,2in}, marginpar=1in',
Japanese documents currently accept only the one-dimension format for these parameters. The
geometrypackage is then passed suitable options to get the text width set to an exact multiple of the zenkaku width, and the text height set to an integer multiple of the baselineskip, with the closest fit for the margins.Default:
1in(equivalent to{1in,1in})Hint
For Japanese
'manual'docclass with pointsize11ptor12pt, use thenomagextra document class option (cf.'extraclassoptions'key oflatex_elements) or so-called TeX “true” units:'sphinxsetup': 'hmargin=1.5truein, vmargin=1.5truein, marginpar=5zw',
Added in version 1.5.3.
marginparThe
\marginparwidthLaTeX dimension. For Japanese documents, the value is modified to be the closest integer multiple of the zenkaku width.Default:
0.5inAdded in version 1.5.3.
verbatimwithframeBoolean to specify if
code-blocks and literal includes are framed. Setting it tofalsedoes not deactivate use of package “framed”, because it is still in use for the optional background color.Default:
true.verbatimwrapslinesBoolean to specify if long lines in
code-block‘s contents are wrapped.If
true, line breaks may happen at spaces (the last space before the line break will be rendered using a special symbol), and at ASCII punctuation characters (i.e. not at letters or digits). Whenever a long string has no break points, it is moved to next line. If its length is longer than the line width it will overflow.Default:
true
verbatimforcewrapsBoolean to specify if long lines in
code-block‘s contents should be forcefully wrapped to never overflow due to long strings.Note
It is assumed that the Pygments LaTeXFormatter has not been used with its
texcommentsor similar options which allow additional (arbitrary) LaTeX mark-up.Also, in case of
latex_engineset to'pdflatex', only the default LaTeX handling of Unicode code points, i.e.utf8notutf8xis allowed.Default:
falseAdded in version 3.5.0.
verbatimmaxoverfullA number. If an unbreakable long string has length larger than the total linewidth plus this number of characters, and if
verbatimforcewrapsmode is on, the input line will be reset using the forceful algorithm which applies breakpoints at each character.Default:
3Added in version 3.5.0.
verbatimmaxunderfullA number. If
verbatimforcewrapsmode applies, and if after applying the line wrapping at spaces and punctuation, the first part of the split line is lacking at least that number of characters to fill the available width, then the input line will be reset using the forceful algorithm.As the default is set to a high value, the forceful algorithm is triggered only in overfull case, i.e. in presence of a string longer than full linewidth. Set this to
0to force all input lines to be hard wrapped at the current available linewidth:latex_elements = { 'sphinxsetup': "verbatimforcewraps, verbatimmaxunderfull=0", }
This can be done locally for a given code-block via the use of raw latex directives to insert suitable
\sphinxsetup(before and after) into the latex file.Default:
100Added in version 3.5.0.
verbatimhintsturnoverBoolean to specify if code-blocks display “continued on next page” and “continued from previous page” hints in case of page breaks.
Default:
trueAdded in version 1.6.3.
Changed in version 1.7: the default changed from
falsetotrue.verbatimcontinuedalign,verbatimcontinuesalignHorizontal position relative to the framed contents: either
l(left aligned),r(right aligned) orc(centered).Default:
rAdded in version 1.7.
parsedliteralwrapsBoolean to specify if long lines in parsed-literal‘s contents should wrap.
Default:
trueAdded in version 1.5.2: set this option value to
falseto recover former behavior.inlineliteralwrapsBoolean to specify if line breaks are allowed inside inline literals: but extra potential break-points (additionally to those allowed by LaTeX at spaces or for hyphenation) are currently inserted only after the characters
. , ; ? ! /and\. Due to TeX internals, white space in the line will be stretched (or shrunk) in order to accommodate the linebreak.Default:
trueAdded in version 1.5: set this option value to
falseto recover former behavior.Changed in version 2.3.0: added potential breakpoint at
\characters.verbatimvisiblespaceWhen a long code line is split, the last space character from the source code line right before the linebreak location is typeset using this.
Default:
\textcolor{red}{\textvisiblespace}verbatimcontinuedA LaTeX macro inserted at start of continuation code lines. Its (complicated…) default typesets a small red hook pointing to the right:
\makebox[2\fontcharwd\font`\x][r]{\textcolor{red}{\tiny$\hookrightarrow$}}Changed in version 1.5: The breaking of long code lines was added at 1.4.2. The default definition of the continuation symbol was changed at 1.5 to accommodate various font sizes (e.g. code-blocks can be in footnotes).
Note
Values for color keys must either:
obey the syntax of the
\definecolorLaTeX command, e.g. something such asVerbatimColor={rgb}{0.2,0.3,0.5}or{RGB}{37,23,255}or{gray}{0.75}or{HTML}{808080}or …or obey the syntax of the
\colorletcommand from packagexcolore.g.VerbatimColor=red!10orred!50!greenor-red!75orMyPreviouslyDefinedColoror… Refer to xcolor documentation for this syntax.
Changed in version 5.3.0: Formerly only the \definecolor syntax was accepted.
TitleColorThe color for titles (as configured via use of package “titlesec”.)
Default:
{rgb}{0.126,0.263,0.361}InnerLinkColorA color passed to
hyperrefas value oflinkcolorandcitecolor.Default:
{rgb}{0.208,0.374,0.486}.OuterLinkColorA color passed to
hyperrefas value offilecolor,menucolor, andurlcolor.Default:
{rgb}{0.216,0.439,0.388}VerbatimColorThe background color for
code-blocks.Default:
{RGB}{242,242,242}(same as{gray}{0.95}).Changed in version 6.0.0: Formerly, it was
{rgb}{1,1,1}(white).VerbatimBorderColorThe frame color.
Default:
{RGB}{32,32,32}Changed in version 6.0.0: Formerly it was
{rgb}{0,0,0}(black).VerbatimHighlightColorThe color for highlighted lines.
Default:
{rgb}{0.878,1,1}Added in version 1.6.6.
TableRowColorHeaderSets the background color for (all) the header rows of tables.
It will have an effect only if either the
latex_table_stylecontains'colorrows'or if the table is assigned thecolorrowsclass. It is ignored for tables withnocolorrowsclass.As for the other
'sphinxsetup'keys, it can also be set or modified from a\sphinxsetup{...}LaTeX command inserted via the raw directive, or also from a LaTeX environment associated to a container class and using such\sphinxsetup{...}.Default:
{gray}{0.86}There is also
TableMergeColorHeader. If used, sets a specific color for merged single-row cells in the header.Added in version 5.3.0.
TableRowColorOddSets the background color for odd rows in tables (the row count starts at
1at the first non-header row). Has an effect only if thelatex_table_stylecontains'colorrows'or for specific tables assigned thecolorrowsclass.Default:
{gray}{0.92}There is also
TableMergeColorOdd.Added in version 5.3.0.
TableRowColorEvenSets the background color for even rows in tables.
Default
{gray}{0.98}There is also
TableMergeColorEven.Added in version 5.3.0.
verbatimsepThe separation between code lines and the frame.
See Additional CSS-like 'sphinxsetup' keys for its alias
pre_paddingand additional keys.Default:
\fboxsepverbatimborderThe width of the frame around
code-blocks. See also Additional CSS-like 'sphinxsetup' keys forpre_border-width.Default:
\fboxruleshadowsepThe separation between contents and frame for contents and topic boxes.
See Additional CSS-like 'sphinxsetup' keys for the alias
div.topic_padding.Default:
5ptshadowsizeThe width of the lateral “shadow” to the right and bottom.
See Additional CSS-like 'sphinxsetup' keys for
div.topic_box-shadowwhich allows to configure separately the widths of the vertical and horizontal shadows.Default:
4ptChanged in version 6.1.2: Fixed a regression introduced at
5.1.0which modified unintentionally the width of topic boxes and worse had made usage of this key break PDF builds.shadowruleThe width of the frame around topic boxes. See also Additional CSS-like 'sphinxsetup' keys for
div.topic_border-width.Default:
\fboxrule
Important
At 7.4.0 all admonitions (not only danger-type) use the possibilities which were added at 5.1.0 and 6.2.0. All defaults have changed.
iconpackage
The name of the LaTeX package used for icons in the admonition titles. It defaults to
fontawesome5or to fall-backfontawesome. In case neither one is available the option value will automatically default tonone, which means that no attempt at loading a package is done. Independently of this setting, arbitrary LaTeX code can be associated to each admonition type viadiv.<type>_icon-titlekeys which are described in the Additional CSS-like 'sphinxsetup' keys section. If these keys are not used, Sphinx will either apply its default choices of icons (iffontawesome{5,}is available) or not draw the icon at all. Notice that if fall-backfontawesomeis used the common icon for caution and danger will default to “bolt” not “radiation”, which is only found infontawesome5.Added in version 7.4.0.
noteBorderColor,hintBorderColor,importantBorderColor,tipBorderColorThe color for the admonition border.
Default:
{RGB}{134,152,155}.Changed in version 7.4.0.
noteBgColor,hintBgColor,importantBgColor,tipBgColorThe color for the admonition background.
Default:
{RGB}{247,247,247}.Added in version 6.2.0.
Changed in version 7.4.0.
noteTextColor,hintTextColor,importantTextColor,tipTextColorThe color for the admonition contents.
Default: unset (contents text uses ambient text color, a priori black)
Added in version 6.2.0: To be considered experimental until 7.0.0. These options have aliases
div.note_TeXcolor(etc) described in Additional CSS-like 'sphinxsetup' keys. Using the latter will let Sphinx switch to a more complex LaTeX code, which supports the customizability described in Additional CSS-like 'sphinxsetup' keys.noteTeXextras,hintTeXextras,importantTeXextras,tipTeXextrasSome extra LaTeX code (such as
\bfseriesor\footnotesize) to be executed at start of the contents.Default: empty
Added in version 6.2.0: To be considered experimental until 7.0.0. These options have aliases
div.note_TeXextras(etc) described in Additional CSS-like 'sphinxsetup' keys.noteborder,hintborder,importantborder,tipborderThe width of the border. See Additional CSS-like 'sphinxsetup' keys for keys allowing to configure separately each border width.
Default:
0.5pt
warningBorderColor,cautionBorderColor,attentionBorderColor,dangerBorderColor,errorBorderColorThe color for the admonition border.
Default:
{RGB}{148,0,0}except forerrorwhich usesred.Changed in version 7.4.0.
warningBgColor,cautionBgColor,attentionBgColor,dangerBgColor,errorBgColorThe background color for the admonition background.
Default:
{RGB}{247,247,247}.Changed in version 7.4.0.
warningborder,cautionborder,attentionborder,dangerborder,errorborderThe width of the admonition frame. See Additional CSS-like 'sphinxsetup' keys for keys allowing to configure separately each border width.
Default:
1ptexcept forerrorwhich uses1.25pt.Changed in version 7.4.0.
AtStartFootnoteLaTeX macros inserted at the start of the footnote text at bottom of page, after the footnote number.
Default:
\mbox{ }BeforeFootnoteLaTeX macros inserted before the footnote mark. The default removes possible space before it (else, TeX could insert a line break there).
Default:
\leavevmode\unskipAdded in version 1.5.
HeaderFamilydefault
\sffamily\bfseries. Sets the font used by headings.
Additional CSS-like 'sphinxsetup' keys¶
Added in version 5.1.0: For code-block, topic and contents directive,
and strong-type admonitions (warning, error, …).
Added in version 6.2.0: Also the note, hint, important and tip
admonitions can be styled this way. Using for them any of the listed
options will trigger usage of a more complex LaTeX code than the one used
per default (sphinxheavybox vs sphinxlightbox). Setting the new
noteBgColor (or hintBgColor, …) also triggers usage of
sphinxheavybox for note (or hint, …).
Added in version 7.4.0: For all admonition types, the default configuration does set a background
color (hence the richer sphinxheavybox is always used).
Important
Further, all admonition titles are by default styled using a colored row and an icon, which are modeled on the current rendering of Sphinx own docs at https://www.sphinx-doc.org. CSS-named alike keys are added to set the foreground and background colors for the title as well as the LaTeX code for the icon.
Perhaps in future these 5.1.0 (and 6.2.0) novel settings will be optionally
imported from some genuine CSS external file, but currently they have to be used
via the 'sphinxsetup' interface (or the \sphinxsetup LaTeX command
inserted via the raw directive) and the CSS syntax is only imitated.
Important
Low-level LaTeX errors causing a build failure can happen if the input syntax is not respected.
In particular colors must be input as for the other color related options previously described, i.e. either in the
\definecolorsyntax or via the\colorletsyntax:...<other options> div.warning_border-TeXcolor={rgb}{1,0,0},% \definecolor syntax div.error_background-TeXcolor=red!10,% \colorlet syntax ...<other options>A colon in place of the equal sign will break LaTeX.
...border-widthor...paddingexpect a single dimension: they can not be used so far with space separated dimensions....top-right-radiuset al. values may be either a single or two space separated dimensions.Dimension specifications must use TeX units such as
ptorcmorin. Thepxunit is recognized bypdflatexandlualatexbut not byxelatexorplatex.It is allowed for such specifications to be so-called “dimensional expressions”, e.g.
\fboxsep+2ptor0.5\baselineskipare valid inputs. The expressions will be evaluated only at the typesetting time. Be careful though if using as in these examples TeX control sequences to double the backslash or to employ a raw Python string for the value of the ‘sphinxsetup’ key.As a rule, avoid inserting unneeded spaces in the key values: especially for the radii an input such
2 pt 3ptwill break LaTeX. Beware also that\fboxsep \fboxsepwill not be seen as space separated in LaTeX. You must use something such as{\fboxsep} \fboxsep. Or use directly3pt 3ptwhich is a priori equivalent and simpler.
The options are all named in a similar pattern which depends on a prefix,
which is then followed by an underscore, then the property name.
Directive |
Option prefix |
LaTeX environment |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
further admonition types |
|
|
|
|
|
|
|
Here are now these options as well as their common defaults.
Replace below <prefix> by the actual prefix as explained above. Don’t
forget the underscore separating the prefix from the property names.
<prefix>_border-top-width,<prefix>_border-right-width,<prefix>_border-bottom-width,<prefix>_border-left-width,<prefix>_border-width. The latter can (currently) be only a single dimension which then sets all four others.The default is that all those dimensions are equal. They are set to:
<prefix>_box-decoration-breakcan be set to eithercloneorsliceand configures the behavior at page breaks. It defaults tosliceforcode-block(i.e. for<prefix>=pre) since 6.0.0. For other directives the default isclone.<prefix>_padding-top,<prefix>_padding-right,<prefix>_padding-bottom,<prefix>_padding-left,<prefix>_padding. The latter can (currently) be only a single dimension which then sets all four others.The defaults:
all four
3ptforcode-block,6pt,7pt,6pt,7ptfor all “light” admonitions as well as theseealsoandtododirectives.6pt,6.5pt,6pt,6.5ptfor the strong admonition types except error which uses horizontal padding of6.25pt.
Changed in version 7.4.0: All defaults were changed, except for
code-block. Admonitions are set-up so that left (or right) padding plus left (or right) border-width add up always to7.5pt, so contents align well vertically across admonition types on same page in PDF. This is only a property of defaults, not a constraint on possible user choices.<prefix>_border-top-left-radius,<prefix>_border-top-right-radius,<prefix>_border-bottom-right-radius,<prefix>_border-bottom-left-radius,<prefix>_border-radius. This last key sets the first four to its assigned value. Each key value can be either a single, or two, dimensions which are then space separated.The defaults:
3ptforcode-block(since 6.0.0) and all corners,12ptfor the bottom right corner of topic, other corners are straight,0pt, i.e. straight corners for all other directives.
See a remark above about traps with spaces in LaTeX.
<prefix>_box-shadowis special in so far as it may be:the
nonekeyword,or a single dimension (giving both x-offset and y-offset),
or two dimensions (separated by a space),
or two dimensions followed by the keyword
inset.
The x-offset and y-offset may be negative. The default is
none, except for the topic or contents directives, for which it is4pt 4pt, i.e. the shadow has a width of4ptand extends to the right and below the frame. The lateral shadow then extends into the page right margin.<prefix>_border-TeXcolor,<prefix>_background-TeXcolor,<prefix>_box-shadow-TeXcolor,<prefix>_TeXcolor. These are colors.Since 6.0.0 the border and background colors of
code-block, default respectively to{RGB}{32,32,32}(i.e.{HTML}{202020}), and{RGB}{242,242,242}(i.e.{gray}{0.95}or{HTML}{F2F2F2}).At 7.4.0 other directives acquire non-black/white default border and background colors. Here they are using
xcolorhexadecimal notation (which requires always 6 hexadecimal digits):{HTML}{F7F7F7}serves as background color to all.{HTML}{86989B}is border color of light admonitions (inclusive ofseealsoandtodo) as well as of topic and contents directives.{HTML}{940000}is border color or warning-type admonitions, except error which uses{HTML}{B40000}.
The only directives displaying a shadow per default are topic and contents (handled identically at LaTeX level) and their shadow color is
{HTML}{6C6C6C}. For all others the default shadow color is black.The
<prefix>_TeXcolorstands for the CSS property “color”, i.e. it influences the text color of the contents. As for the three other options, the namingTeXcoloris to stress that the input syntax is the TeX one for colors not an HTML/CSS one. If packagexcoloris available in the LaTeX installation, one can use directly named colors as key values. Consider passing options such asdvipsnames,svgnamesorx11namestoxcolorvia'passoptionstopackages'key oflatex_elements.If
<prefix>_TeXcoloris set, a\colorcommand is inserted at start of the directive contents; for admonitions, this happens after the heading which reproduces the admonition type.<prefix>_TeXextras: if set, its value must be some LaTeX command or commands, for example\itshape. These commands will be inserted at the start of the contents; for admonitions, this happens after the heading which reproduces the admonition type.
The next keys, for admonitions only, were all three added at 7.4.0. The default colors are the ones applying to the current HTML rendering of Sphinx own docs at https://www.sphinx-doc.org.
div.<type>_title-background-TeXcolor: the background color for the title.Important
The colored title-row is produced as a result of the Sphinx default definitions for the various
\sphinxstyle<type>titlecommands, see Macros. Custom redefinitions of these commands are possible, but to re-use the colors and the icon, it is needed to check in Sphinx LaTeX source code how the default definitions are done.div.<type>_title-foreground-TeXcolor: the color to be used for the icon (it applies only to the icon, not to the title of the admonition).div.<type>_title-icon: the LaTeX code responsible for producing the icon. For example, the default for note isdiv.note_title-icon=\faIcon{info-circle}. This uses a command from the LaTeXfontawesome5package, which is loaded automatically if available.If neither
fontawesome5nor fall-backfontawesome(for which the associated command is\faicon, not\faIcon) are found, or if theiconpackagekey of ‘sphinxsetup’ is set to load some other user-chosen package, or no package at all, all thetitle-iconsdefault to empty LaTeX code. It is up to user to employ this interface to inject the icon (or anything else) into the PDF output.
Note
All directives support
box-decoration-breakto be set toslice.Changed in version 6.2.0: Formerly, only
code-blockdid. The default remainsclonefor all other directives, but this will probably change at 7.0.0.The corners of rounded boxes may be elliptical.
Changed in version 6.2.0: Formerly, only circular rounded corners were supported and a rounded corner forced the whole frame to use the same constant width from
<prefix>_border-width.Inset shadows are incompatible with rounded corners. In case both are specified the inset shadow will simply be ignored.
Changed in version 6.2.0: Formerly it was to the contrary the rounded corners which were ignored in case an inset shadow was specified.
<prefix>_TeXcolorand<prefix>_TeXextrasare new with 6.2.0.Usefulness is doubtful in the case of
code-block:pre_TeXcolorwill influence only the few non-Pygments highlighted tokens; it does color the line numbers, but if one wants to color only them one has to go through thefancyvrbinterface.pre_TeXextras=\footnotesizefor example may be replaced by usage of thelatex_elementskey'fvset'. For'lualatex'or'xelatex'Sphinx includes in the preamble already\fvset{fontsize=\small}and this inducesfancyvrbinto overriding a\footnotesizecoming frompre_TeXextras. One has to usepre_TeXextras=\fvset{fontsize=\footnotesize}syntax. Simpler to set directly thelatex_elementskey'fvset'…
Consider these options experimental and that some implementation details may change. For example if the
pre_TeXextrasLaTeX commands were put by Sphinx in another location it could override the'fvset'effect, perhaps this is what will be done in a future release.Rounded boxes are done using the pict2e interface to some basic PDF graphics operations. If this LaTeX package can not be found the build will proceed and render all boxes with straight corners.
Elliptic corners use the ellipse LaTeX package which extends pict2e. If this LaTeX package can not be found rounded corners will be circular arcs (or straight if pict2e is not available).
The following legacy behavior is currently not customizable:
For
code-block, padding and border-width and shadow (if one adds one) will go into the margin; the code lines remain at the same place independently of the values of the padding and border-width, except for being shifted vertically of course to not overwrite other text due to the width of the border or external shadow.For topic (and contents) the shadow (if on right) goes into the page margin, but the border and the extra padding are kept within the text area. Same for admonitions.
The contents and topic directives are governed by the same options with
div.topicprefix: the Sphinx LaTeX mark-up uses for both directives the samesphinxShadowBoxenvironment which has currently no additional branching, contrarily to thesphinxadmonitionenvironment which branches according to the admonition directive name, e.g. either tosphinxnoteorsphinxwarningetc…
LaTeX macros and environments¶
The “LaTeX package” file sphinx.sty loads various components
providing support macros (aka commands), and environments, which are used in
the mark-up produced on output from the latex builder, before conversion
to pdf via the LaTeX toolchain. Also the “LaTeX class” files
sphinxhowto.cls and sphinxmanual.cls define or customize some
environments. All of these files can be found in the latex build repertory.
Some of these provide facilities not available from pre-existing LaTeX packages and work around LaTeX limitations with lists, table cells, verbatim rendering, footnotes, etc…
Others simply define macros with public names to make overwriting their defaults easy via user-added contents to the preamble. We will survey most of those public names here, but defaults have to be looked at in their respective definition files.
Hint
Sphinx LaTeX support code is split across multiple smaller-sized files.
Rather than adding code to the preamble via
latex_elements['preamble'] it is
also possible to replace entirely one of the component files of Sphinx
LaTeX code with a custom version, simply by including a modified copy in
the project source and adding the filename to the
latex_additional_files list. Check the LaTeX build repertory
for the filenames and contents.
Changed in version 4.0.0: split of sphinx.sty into multiple smaller units, to facilitate
customization of many aspects simultaneously.
Macros¶
Text styling commands:
Name
maps argument #1 to:\sphinxstrong\textbf{#1}\sphinxcode\texttt{#1}\sphinxbfcode\textbf{\sphinxcode{#1}}\sphinxemail\textsf{#1}\sphinxtablecontinued\textsf{#1}\sphinxtitleref\emph{#1}\sphinxmenuselection\emph{#1}\sphinxguilabel\emph{#1}\sphinxkeyboard\sphinxcode{#1}\sphinxaccelerator\underline{#1}\sphinxcrossref\emph{#1}\sphinxtermref\emph{#1}\sphinxsamedocref\emph{#1}\sphinxparam\emph{#1}\sphinxtypeparam\emph{#1}\sphinxoptional[#1]with larger brackets, see sourceAdded in version 1.4.5: Use of
\sphinxprefixed macro names to limit possibilities of conflict with LaTeX packages.Added in version 1.8:
\sphinxguilabelAdded in version 3.0:
\sphinxkeyboardAdded in version 6.2.0:
\sphinxparam,\sphinxsamedocrefAdded in version 7.1.0:
\sphinxparamcommawhich defaults to a comma followed by a space and\sphinxparamcommaoneperlinewhich is used for one-parameter-per-line signatures (seemaximum_signature_line_length). It defaults to\texttt{,}to make these end-of-line separators more distinctive.Signatures of Python functions are rendered as
name<space>(parameters)orname<space>[type parameters]<space>(parameters)(see PEP 695) where the length of<space>is set to0ptby default. This can be changed via\setlength{\sphinxsignaturelistskip}{1ex}for instance.More text styling:
Name
maps argument #1 to:\sphinxstyleindexentry\texttt{#1}\sphinxstyleindexextra(\emph{#1})(with a space upfront)\sphinxstyleindexpageref, \pageref{#1}\sphinxstyleindexpagemain\textbf{#1}\sphinxstyleindexlettergroup{\Large\sffamily#1}\nopagebreak\vspace{1mm}\sphinxstyleindexlettergroupDefaultcheck source, too long for here
\sphinxstyletopictitle\textbf{#1}\par\medskip\sphinxstylesidebartitle\textbf{#1}\par\medskip\sphinxstyleothertitle\textbf{#1}\sphinxstylesidebarsubtitle~\\\textbf{#1} \smallskip\sphinxstyletheadfamily\sffamily(this one has no argument)\sphinxstyleemphasis\emph{#1}\sphinxstyleliteralemphasis\emph{\sphinxcode{#1}}\sphinxstylestrong\textbf{#1}\sphinxstyleliteralstrong\sphinxbfcode{#1}\sphinxstyleabbreviation\textsc{#1}\sphinxstyleliteralintitle\sphinxcode{#1}\sphinxstylecodecontinued{\footnotesize(#1)}}\sphinxstylecodecontinues{\footnotesize(#1)}}\sphinxstylenotetitle\sphinxdotitlerowwithicon{note}{#1}\sphinxstylehinttitle\sphinxdotitlerowwithicon{hint}{#1}\sphinxstyleimportanttitlesimilar
\sphinxstyletiptitlesimilar
\sphinxstylewarningtitlesimilar
\sphinxstylecautiontitlesimilar
\sphinxstyleattentiontitlesimilar
\sphinxstyledangertitlesimilar
\sphinxstyleerrortitlesimilar
\sphinxstyleseealsotitlesimilar
\sphinxstyletodotitlesimilar
Note
To let this table fit on the page width in PDF output we have lied a bit and the actual definition of
\sphinxstylenotetitleis:\newcommand\sphinxstylenotetitle[1]% {\sphinxdotitlerowwithicon{note}{\sphinxremovefinalcolon{#1}}}
The same remark applies to all other similar commands associated with admonitions.
Added in version 1.5: These macros were formerly hard-coded as non customizable
\texttt,\emph, etc…Added in version 1.6:
\sphinxstyletheadfamilywhich defaults to\sffamilyand allows multiple paragraphs in header cells of tables.Added in version 1.6.3:
\sphinxstylecodecontinuedand\sphinxstylecodecontinues.Added in version 1.8:
\sphinxstyleindexlettergroup,\sphinxstyleindexlettergroupDefault.Added in version 6.2.0:
\sphinxstylenotetitleet al. The#1is the localized name of the directive, with a final colon. Wrap it as\sphinxremovefinalcolon{#1}if this final colon is to be removed.Added in version 7.4.0: The
\sphinxdotitlerowwithiconLaTeX command, whose first argument is the admonition type, so that it can recover the associated colours and icon for the title row, and the second argument gets typeset after the icon.Todo
The fact that we must employ
\sphinxremovefinalcolonis a legacy artefact from old ill-designed Sphinx LaTeX writer, which postfixes (still today) the title with a colon automatically.\sphinxtableofcontents: A wrapper (defined differently insphinxhowto.clsand insphinxmanual.cls) of standard\tableofcontents. The macro\sphinxtableofcontentshookis executed during its expansion right before\tableofcontentsitself.Changed in version 1.5: Formerly, the meaning of
\tableofcontentswas modified by Sphinx.Changed in version 2.0: Hard-coded redefinitions of
\l@sectionand\l@subsectionformerly done during loading of'manual'docclass are now executed later via\sphinxtableofcontentshook. This macro is also executed by the'howto'docclass, but defaults to empty with it.Hint
If adding to preamble the loading of
tocloftpackage, also add to preamble\renewcommand\sphinxtableofcontentshook{}else it will reset\l@sectionand\l@subsectioncancellingtocloftcustomization.\sphinxmaketitle: Used as the default setting of the'maketitle'latex_elementskey. Defined in the class filessphinxmanual.clsandsphinxhowto.cls.Changed in version 1.8.3: Formerly,
\maketitlefrom LaTeX document class was modified by Sphinx.\sphinxbackoftitlepage: For'manual'docclass, and if it is defined, it gets executed at end of\sphinxmaketitle, before the final\clearpage. Use either the'maketitle'key or the'preamble'key oflatex_elementsto add a custom definition of\sphinxbackoftitlepage.Added in version 1.8.3.
\sphinxcite: A wrapper of standard\citefor citation references.
The \sphinxbox command¶
Added in version 6.2.0.
The \sphinxbox[key=value,...]{inline text} command can be used to “box”
inline text elements with all the customizability which has been described in
Additional CSS-like 'sphinxsetup' keys. It is a LaTeX command with one optional argument, which
is a comma-separated list of key=value pairs, as for The sphinxsetup configuration setting.
Here is the complete list of keys. They don’t use any prefix.
border-width,border-top-width,border-right-width,border-bottom-width,border-left-width,padding,padding-top,padding-right,padding-bottom,padding-left,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,box-shadow,border-TeXcolor,background-TeXcolor,box-shadow-TeXcolor,TeXcolor,TeXextras,and
addstrutwhich is a boolean key, i.e. to be used asaddstrut=true, oraddstrutalone where=trueis omitted, oraddstrut=false.
This last key is specific to \sphinxbox and it means to add a \strut
so that heights and depths are equalized across various instances on the same
line with varying contents. The default is addstrut=false.
Important
Perhaps the default will turn into addstrut=true at 7.0.0 depending on
feedback until then.
The combination addstrut, padding-bottom=0pt, padding-top=1pt is often
satisfactory.
Refer to Additional CSS-like 'sphinxsetup' keys for important syntax information regarding the
other keys. The default
configuration uses no shadow, a border-width of \fboxrule, a padding of
\fboxsep, circular corners with radii \fboxsep and background and
border colors as for the default rendering of code-blocks.
When a \sphinxbox usage is nested within another one, it will ignore the
options of the outer one: it first resets all options to their default state
as they were prior to applying the outer box options, then it applies its own
specific ones.
One can modify these defaults via the command \sphinxboxsetup{key=value,...}.
The effect is cumulative, if one uses this command multiple times. Here the
options are a mandatory argument so are within curly braces, not square
brackets.
Here is some example of use:
latex_elements = {
'preamble': r'''
% modify globally the defaults
\sphinxboxsetup{border-width=2pt,%
border-radius=4pt,%
background-TeXcolor=yellow!20}
% configure some styling element with some extra specific options:
\protected\def\sphinxkeyboard#1{\sphinxbox[border-TeXcolor=green]{\sphinxcode{#1}}}
''',
}
A utility \newsphinxbox is provided to create a new boxing macro, say
\foo which will act exactly like \sphinxbox but with a given extra
configuration:
% the specific options to \foo are within brackets
\newsphinxbox[border-radius=0pt, box-shadow=2pt 2pt]{\foo}
% then use this \foo, possibly with some extra options still:
\protected\def\sphinxguilabel#1{\foo{#1}}
\protected\def\sphinxmenuselection#1{\foo[box-shadow-TeXcolor=gray]{#1}}
Boxes rendered with \foo obey as the ones using directly \sphinxbox
the current configuration as set possibly mid-way in document via
\sphinxboxsetup (from a raw LaTeX mark-up), the only difference
is that they have an initial additional set of default extras.
In the above examples, you can probably use \renewcommand syntax if you
prefer it to \protected\def (with [1] in place of #1 then).
Environments¶
A figure may have an optional legend with arbitrary body elements: they are rendered in a
sphinxlegendenvironment. The default definition issues\small, and ends with\par.Added in version 1.5.6: Formerly, the
\smallwas hardcoded in LaTeX writer and the ending\parwas lacking.Environments associated with admonitions:
sphinxnote,sphinxhint,sphinximportant,sphinxtip,sphinxwarning,sphinxcaution,sphinxattention,sphinxdanger,sphinxerror.
They may be
\renewenvironment‘d individually, and must then be defined with one argument (it is the heading of the notice, for exampleWarning:for warning directive, if English is the document language). Their default definitions use either the sphinxheavybox (for the last 5 ones) or the sphinxlightbox environments, configured to use the parameters (colors, border thickness) specific to each type, which can be set via'sphinxsetup'string.Changed in version 1.5: Use of public environment names, separate customizability of the parameters, such as
noteBorderColor,noteborder,warningBgColor,warningBorderColor,warningborder, …Environment for the
seealsodirective:sphinxseealso. It takes one argument which will be the localized stringSee alsofollowed with a colon.Added in version 6.1.0.
Changed in version 6.2.0: Colon made part of the mark-up rather than being inserted by the environment for coherence with how admonitions are handled generally.
Environment for the
tododirective:sphinxtodo. It takes one argument which will be the localized stringTodofollowed with a colon.Added in version 7.4.0.
The contents directive (with
:local:option) and the topic directive are implemented by environmentsphinxShadowBox.Added in version 1.4.2: Former code refactored into an environment allowing page breaks.
Changed in version 1.5: Options
shadowsep,shadowsize,shadowrule.The literal blocks (via
::orcode-block), are implemented usingsphinxVerbatimenvironment which is a wrapper ofVerbatimenvironment from packagefancyvrb.sty. It adds the handling of the top caption and the wrapping of long lines, and a frame which allows page breaks. Inside tables the used environment issphinxVerbatimintable(it does not draw a frame, but allows a caption).Changed in version 1.5:
Verbatimkeeps exact same meaning as infancyvrb.sty(also under the nameOriginalVerbatim);sphinxVerbatimintableis used inside tables.Added in version 1.5: Options
verbatimwithframe,verbatimwrapslines,verbatimsep,verbatimborder.Added in version 1.6.6: Support for
:emphasize-lines:optionAdded in version 1.6.6: Easier customizability of the formatting via exposed to user LaTeX macros such as
\sphinxVerbatimHighlightLine.The bibliography uses
sphinxthebibliographyand the Python Module index as well as the general index both usesphinxtheindex; these environments are wrappers of thethebibliographyand respectivelytheindexenvironments as provided by the document class (or packages).Changed in version 1.5: Formerly, the original environments were modified by Sphinx.
Miscellany¶
Every text paragraph in document body starts with
\sphinxAtStartPar. Currently, this is used to insert a zero width horizontal skip which is a trick to allow TeX hyphenation of the first word of a paragraph in a narrow context (like a table cell). For'lualatex'which does not need the trick, the\sphinxAtStartPardoes nothing.Added in version 3.5.0.
The section, subsection, … headings are set using titlesec’s
\titleformatcommand.For the
'manual'docclass, the chapter headings can be customized using fncychap’s commands\ChNameVar,\ChNumVar,\ChTitleVar. Filesphinx.styhas custom re-definitions in case of fncychap optionBjarne.Changed in version 1.5: Formerly, use of fncychap with other styles than
Bjarnewas dysfunctional.
Docutils container directives are supported in LaTeX output: to let a container class with name
fooinfluence the final PDF via LaTeX, it is only needed to define in the preamble an environmentsphinxclassfoo. A simple example would be:\newenvironment{sphinxclassred}{\color{red}}{}
Currently the class names must contain only ASCII characters and avoid characters special to LaTeX such as
\.Added in version 4.1.0.
Hint
As an experimental feature, Sphinx can use user-defined template file for
LaTeX source if you have a file named _templates/latex.tex.jinja in your
project.
Additional files longtable.tex.jinja, tabulary.tex.jinja and
tabular.tex.jinja can be added to _templates/ to configure some
aspects of table rendering (such as the caption position).
Added in version 1.6: currently all template variables are unstable and undocumented.
Changed in version 7.4: Added support for the .jinja file extension, which is preferred.
The old file names remain supported.
(latex.tex_t, longtable.tex_t, tabulary.tex_t, and tabular.tex_t)