Configuração LaTeX¶
Unlike the HTML builders, the latex
builder does not
benefit from prepared themes. The Opções para saída LaTeX, and particularly the
latex_elements variable, provides much of the
interface for customization. For example:
# inside conf.py
latex_engine = 'xelatex'
latex_elements = {
'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}
''',
'fncychap': r'\usepackage[Bjornstrup]{fncychap}',
'printindex': r'\footnotesize\raggedright\printindex',
}
latex_show_urls = 'footnote'
Nota
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.
Chaves que podem ser sobrepostas são:
'tamanhopapel'
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
px
when used in image attributeswidth
andheight
. The default value is'0.75bp'
which achieves96px=1in
(in TeX1in = 72bp = 72.27pt
.) To obtain for example100px=1in
use'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'
Novo na versão 1.5.
'passoptionstopackages'
A string which will be positioned early in the preamble, designed to contain
\\PassOptionsToPackage{options}{foo}
commands.Dica
It may be also used for loading LaTeX packages very early in the preamble. For example package
fancybox
is incompatible with being loaded via the'preamble'
key, it must be loaded earlier.Default:
''
Novo na versão 1.4.
'babel'
Inclusão do pacote
babel
, padrão'\\usepackage{babel}'
(a string adequada do idioma do documento é transmitida como opção de classe eenglish
é utilizada se não houver linguagem.) Para documentos em japonês, o padrão é a cadeia vazia.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
babel
overpolyglossia
.Dica
After modifiying 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)Alterado na versão 1.5: Para
latex_engine
configurar para'xelatex'
, o padrão é'\\usepackage{polyglossia}\n\\setmainlanguage{<language>}'
.Alterado na versão 1.6:
'lualatex'
usa mesmo padrão de'xelatex'
Alterado na versão 1.7.6: For French,
xelatex
andlualatex
default to usingbabel
, notpolyglossia
.'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.Alterado na versão 1.2: Padrão para
''
quandolanguage
usa script Cirílico.Alterado na versão 2.0: Incorporates some font substitution commands to help support occasional Greek or Cyrillic in a document using
'pdflatex'
engine.-
Alterado na versão 4.0.0:
The font substitution commands added at
2.0
have 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'
Inclusão do pacote “fncychap” (que cria títulos de capítulos extravagantes), padrão
'\\usepackage[Bjarne]{fncychap}'
para documentação em inglês (esta opção é ligeiramente customizada pelo Sphinx),'\\usepackage[Sonny]{fncychap}'
para documentos internacionalizados (porque o estilo “Bjarne” usa números escritos em inglês). Outros estilos “fncychap” que você pode experimentar são “Lenny”, “Glenn”, “Conny”, “Rejne” e “Bjornstrup”. Você também pode definir isso para''
para desabilitar o 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.txt
of 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"]
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)Novo na versão 1.3.
'atendofbody'
Additional document content (right before the indices).
Default:
''
Novo na versão 1.5.
'extrapackages'
Additional LaTeX packages. For example:
latex_elements = { 'packages': r'\usepackage{isodate}' }
The specified LaTeX packages will be loaded before hyperref package and packages loaded from Sphinx extensions.
Dica
If you’d like to load additional LaTeX packages after hyperref, use
'preamble'
key instead.Default:
''
Novo na versão 2.3.
'footer'
Additional footer content (before the indices).
Default:
''
Obsoleto desde a versão 1.5: Usar chave
'atendofbody'
no lugar.
Chaves que não precisam ser sobrepostas, menos nesses casos especiais:
'extraclassoptions'
Padrão termo vazio. Exemplo:
'extraclassoptions': 'openany'
permite capítulos (para documentos do tipo'manual'
) iniciar em qualquer página.Default:
''
Novo na versão 1.2.
Alterado na versão 1.6: Adic. nessa documentação.
'maxlistdepth'
LaTeX permite por padrão pelo menos 6 níveis para listas subordinadas e ambientes de citação, com pelo menos 4 listas numeradas, 4 listas com marcadores. Configurações para essa chave por exemplo: para
'10'
(como termo) irá permitir até 10 níveis hierárquicos (de todos tipos). Deixando em branco significa obedecer padrões LaTeX.Aviso
Usando essa chave pode ocasionar incompatibilidade com alguns pacotes LaTeX ou classes especiais que possuem suas configurações.
Configurando chave irá silenciosamente ignorado se
\usepackage{enumitem}
for executado dentro de um preambulo de documento. Usar comandos dedicados do pacote LaTeX.
Default:
6
Novo na versão 1.5.
'inputenc'
“inputenc” package inclusion.
Default:
'\\usepackage[utf8]{inputenc}'
when using pdflatex, else''
Alterado na versão 1.4.3: Anteriormente
'\\usepackage[utf8]{inputenc}'
era usado por todos compiladores.'cmappkg'
“cmap” package inclusion.
Default:
'\\usepackage{cmap}'
Novo na versão 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.Atenção
Do not use this key for a
latex_engine
other than'pdflatex'
.If Greek is main language, do not use this key. Since Sphinx 2.2.1,
xelatex
will be used automatically aslatex_engine
.The TeX installation may need some extra packages. For example, on Ubuntu xenial, packages
texlive-lang-greek
andcm-super
are needed forLGR
to work. Andtexlive-lang-cyrillic
andcm-super
are needed for support of Cyrillic.
Alterado na versão 1.5: Padrão para
'\\usepackage{fontspec}'
quandolatex_engine
for'xelatex'
.Alterado na versão 1.6:
'lualatex'
usesfontspec
per default like'xelatex'
.Alterado na versão 2.0:
'lualatex'
executes\defaultfontfeatures[\rmfamily,\sffamily]{}
to disable TeX ligatures transforming << and >> as escaping working withpdflatex/xelatex
failed withlualatex
.Alterado na versão 2.0: Detection of
LGR
,T2A
,X2
to trigger support of occasional Greek or Cyrillic letters ('pdflatex'
).Alterado na versão 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) despitesmartquotes
being set toFalse
.'fontsubstitution'
Ignored if
'fontenc'
was not configured to useLGR
orX2
(orT2A
). In case'fontpkg'
key is configured for usage with some TeX fonts known to be available in theLGR
orX2
encodings, set this one to be the empty string. Else leave to its default.Ignored with
latex_engine
other than'pdflatex'
.Novo na versão 4.0.0.
'textgreek'
For the support of occasional Greek letters.
It is ignored with
'platex'
,'xelatex'
or'lualatex'
aslatex_engine
and defaults to either the empty string or to'\\usepackage{textalpha}'
for'pdflatex'
depending on whether the'fontenc'
key was used withLGR
or 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 inmath
context. For example:math:`α`
(U+03B1) will render as \(\alpha\).Default:
'\\usepackage{textalpha}'
or''
iffontenc
does not include theLGR
option.Novo na versão 2.0.
'geometry'
inclusão do pacote “geometry”, padrão é:
'\\usepackage{geometry}'
com um
[dvipdfm]
adicional para documentos em Japonês. O arquivo de estilo Sphinx LaTeX executa:\PassOptionsToPackage{hmargin=1in,vmargin=1in,marginpar=0.5in}{geometry}
que pode ser configurado via opção correspondente ‘sphinxsetup’ opção.
Default:
'\\usepackage{geometry}'
(or'\\usepackage[dvipdfm]{geometry}'
for Japanese documents)Novo na versão 1.5.
Alterado na versão 1.5.2: opção
dvipdfm
selatex_engine
é'platex'
.Novo na versão 1.5.3: Os termos ‘sphinxsetup’ para margens.
Alterado na versão 1.5.3: O local do arquivo LaTeX foi movido após usepackage{sphinx}` e
\sphinxsetup{..}
, consequentemente também após inserção chave'fontpkg'
. Dessa maneira pode configurar opções do layout do papel de uma maneira especial para documentos Japoneses: o largura do texto será em múltiplos de zenkaku e a altura do texto será um inteiro múltiplo da linha base. Ver documentação hmargin para detalhes.'hyperref'
inclusão pacote “hyperref” ; também carrega pacote “hypcap” e requisitos
\urlstyle{same}
. Isso é afeito após o arquivosphinx.sty
ter sido carregado e antes de executar conteúdos da chave'preamble'
.Atenção
Carga dos pacotes “hyperref” e “hypcap” é obrigatória.
Novo na versão 1.5: Previamente era feito internamente do
sphinx.sty
.'maketitle'
“maketitle” call. Override if you want to generate a differently styled title page.
Dica
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'
Alterado na versão 1.8.3: Original
\maketitle
from document class is not overwritten, hence is re-usable as part of some custom setting for this key.Novo na versão 1.8.3:
\sphinxbackoftitlepage
optional 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'
Alterado na versão 1.5: Anteriormente, o significado de
\tableofcontents
foi modificado pelo Sphinx. Isso criou uma incompatibilidade com pacotes dedicados, modificando-o também comotocloft
ouetoc
.'transition'
Commands used to display transitions. Override if you want to display transitions differently.
Default:
'\n\n\\bigskip\\hrule\\bigskip\n\n'
Novo na versão 1.2.
Alterado na versão 1.6: Remova o
{}
desnecessário após\\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 installidxlayout
LaTeX 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 theidxlayout
approach described in the documentation of the'makeindex'
key).Default:
'\\printindex'
'fvset'
Customization of
fancyvrb
LaTeX 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}'
Novo na versão 1.8.
Alterado na versão 2.0: For
'xelatex'
and'lualatex'
defaults to'\\fvset{fontsize=\\small}'
as this is adapted to the relative widths of the FreeFont family.Alterado na versão 4.0.0: Changed default for
'pdflatex'
. Previously it was using'\\fvset{fontsize=\\small}'
.
Chaves que configuram outras opções e podem ser sobrepostas são:
'docclass'
'classoptions'
'title'
'release'
'author'
The sphinxsetup
configuration setting¶
Novo na versão 1.5.
The 'sphinxsetup'
key of latex_elements
provides a LaTeX-type customization interface:
latex_elements = {
'sphinxsetup': 'key1=value1, key2=value2, ...',
}
It 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,...}
The colors used in the above are provided by the svgnames
option of the
“xcolor” package:
latex_elements = {
'passoptionstopackages': r'\PassOptionsToPackage{svgnames}{xcolor}',
}
It is possible to insert further uses of the \sphinxsetup
LaTeX macro
directly into the body of the document, via the help of the raw
directive. This chapter is styled in the PDF output using the following at the
start of the chaper:
.. raw:: latex
\begingroup
\sphinxsetup{%
verbatimwithframe=false,
VerbatimColor={named}{OldLace},
TitleColor={named}{DarkGoldenrod},
hintBorderColor={named}{LightCoral},
attentionborder=3pt,
attentionBorderColor={named}{Crimson},
attentionBgColor={named}{FloralWhite},
noteborder=2pt,
noteBorderColor={named}{Olive},
cautionborder=3pt,
cautionBorderColor={named}{Cyan},
cautionBgColor={named}{LightCyan}}
The below is included at the end of the chapter:
.. raw:: latex
\endgroup
LaTeX syntax for boolean keys requires lowercase true
or false
e.g 'sphinxsetup': "verbatimwrapslines=false"
. If setting the
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 quotes to enclose values, whether numerical or strings.
bookmarksdepth
Controls the depth of the collapsable 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 thehyperref
LaTeX docs.Default:
5
Novo na versão 4.0.0.
hmargin, vmargin
The dimensions of the horizontal (resp. vertical) margins, passed as
hmargin
(resp.vmargin
) option to thegeometry
package. 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
geometry
package 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}
)Dica
For Japanese
'manual'
docclass with pointsize11pt
or12pt
, use thenomag
extra document class option (cf.'extraclassoptions'
key oflatex_elements
) or so-called TeX “true” units:'sphinxsetup': 'hmargin=1.5truein, vmargin=1.5truein, marginpar=5zw',
Novo na versão 1.5.3.
marginpar
The
\marginparwidth
LaTeX dimension. For Japanese documents, the value is modified to be the closest integer multiple of the zenkaku width.Default:
0.5in
Novo na versão 1.5.3.
verbatimwithframe
Boolean to specify if
code-block
s and literal includes are framed. Setting it tofalse
does not deactivate use of package “framed”, because it is still in use for the optional background colour.Default:
true
.verbatimwrapslines
Boolean 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
verbatimforcewraps
Boolean to specify if long lines in
code-block
‘s contents should be forcefully wrapped to never overflow due to long strings.Nota
It is assumed that the Pygments LaTeXFormatter has not been used with its
texcomments
or similar options which allow additional (arbitrary) LaTeX mark-up.Also, in case of
latex_engine
set to'pdflatex'
, only the default LaTeX handling of Unicode code points, i.e.utf8
notutf8x
is allowed.Default:
false
Novo na versão 3.5.0.
verbatimmaxoverfull
A number. If an unbreakable long string has length larger than the total linewidth plus this number of characters, and if
verbatimforcewraps
mode is on, the input line will be reset using the forceful algorithm which applies breakpoints at each character.Default:
3
Novo na versão 3.5.0.
verbatimmaxunderfull
A number. If
verbatimforcewraps
mode 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
0
to force all input lines to be hard wrapped at the current avaiable 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:
100
Novo na versão 3.5.0.
verbatimhintsturnover
Boolean to specify if code-blocks display “continued on next page” and “continued from previous page” hints in case of pagebreaks.
Default:
true
Novo na versão 1.6.3.
Alterado na versão 1.7: the default changed from
false
totrue
.verbatimcontinuedalign
,verbatimcontinuesalign
Horizontal position relative to the framed contents: either
l
(left aligned),r
(right aligned) orc
(centered).Default:
r
Novo na versão 1.7.
parsedliteralwraps
Boolean to specify if long lines in parsed-literal‘s contents should wrap.
Default:
true
Novo na versão 1.5.2: set this option value to
false
to recover former behaviour.inlineliteralwraps
Boolean 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:
true
Novo na versão 1.5: set this option value to
false
to recover former behaviour.Alterado na versão 2.3.0: added potential breakpoint at
\
characters.verbatimvisiblespace
When 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}
verbatimcontinued
A 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$}}
Alterado na versão 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 accomodate various font sizes (e.g. code-blocks can be in footnotes).
TitleColor
The colour for titles (as configured via use of package “titlesec”.)
Default:
{rgb}{0.126,0.263,0.361}
Aviso
Colours set via
'sphinxsetup'
must obey the syntax of the argument of thecolor/xcolor
packages\definecolor
command.InnerLinkColor
A colour passed to
hyperref
as value oflinkcolor
andcitecolor
.Default:
{rgb}{0.208,0.374,0.486}
.OuterLinkColor
A colour passed to
hyperref
as value offilecolor
,menucolor
, andurlcolor
.Default:
{rgb}{0.216,0.439,0.388}
VerbatimColor
The background colour for
code-block
s.Default:
{rgb}{1,1,1}
(white)VerbatimBorderColor
The frame color.
Default:
{rgb}{0,0,0}
(black)VerbatimHighlightColor
The color for highlighted lines.
Default:
{rgb}{0.878,1,1}
Novo na versão 1.6.6.
Nota
Starting with this colour, and for all others following, the names declared to “color” or “xcolor” are prefixed with “sphinx”.
verbatimsep
The separation between code lines and the frame.
Default:
\fboxsep
verbatimborder
The width of the frame around
code-block
s.Default:
\fboxrule
shadowsep
The separation between contents and frame for contents and topic boxes.
Default:
5pt
shadowsize
The width of the lateral “shadow” to the right.
Default:
4pt
shadowrule
The width of the frame around topic boxes.
Default:
\fboxrule
noteBorderColor
,hintBorderColor
,importantBorderColor
,tipBorderColor
The colour for the two horizontal rules used by Sphinx in LaTeX for styling a note type admonition.
Default:
{rgb}{0,0,0}
(black)noteborder
,hintborder
,importantborder
,tipborder
The width of the two horizontal rules.
Default:
0.5pt
warningBorderColor
,cautionBorderColor
,attentionBorderColor
,dangerBorderColor
,errorBorderColor
The colour for the admonition frame.
Default: {rgb}{0,0,0}
(black)
warningBgColor
,cautionBgColor
,attentionBgColor
,dangerBgColor
,errorBgColor
The background colours for the respective admonitions.
Default:
{rgb}{1,1,1}
(white)warningborder
,cautionborder
,attentionborder
,dangerborder
,errorborder
The width of the frame.
Default:
1pt
AtStartFootnote
LaTeX macros inserted at the start of the footnote text at bottom of page, after the footnote number.
Default:
\mbox{ }
BeforeFootnote
LaTeX macros inserted before the footnote mark. The default removes possible space before it (else, TeX could insert a line break there).
Default:
\leavevmode\unskip
Novo na versão 1.5.
HeaderFamily
default
\sffamily\bfseries
. Sets the font used by headings.
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.
Dica
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.
Alterado na versão 4.0.0: split of sphinx.sty
into multiple smaller units, to facilitate
customization of many aspects simultaneously.
Macros¶
Text styling commands:
\sphinxstrong
,\sphinxbfcode
,\sphinxemail
,\sphinxtablecontinued
,\sphinxtitleref
,\sphinxmenuselection
,\sphinxaccelerator
,\sphinxcrossref
,\sphinxtermref
,\sphinxoptional
.
Novo na versão 1.4.5: Use of
\sphinx
prefixed macro names to limit possibilities of conflict with LaTeX packages.More text styling:
\sphinxstyleindexentry
,\sphinxstyleindexextra
,\sphinxstyleindexpageref
,\sphinxstyletopictitle
,\sphinxstylesidebartitle
,\sphinxstyleothertitle
,\sphinxstylesidebarsubtitle
,\sphinxstyletheadfamily
,\sphinxstyleemphasis
,\sphinxstyleliteralemphasis
,\sphinxstylestrong
,\sphinxstyleliteralstrong
,\sphinxstyleabbreviation
,\sphinxstyleliteralintitle
,\sphinxstylecodecontinued
,\sphinxstylecodecontinues
.
Novo na versão 1.5: These macros were formerly hard-coded as non customizable
\texttt
,\emph
, etc…Novo na versão 1.6:
\sphinxstyletheadfamily
which defaults to\sffamily
and allows multiple paragraphs in header cells of tables.Novo na versão 1.6.3:
\sphinxstylecodecontinued
e\sphinxstylecodecontinues
.Novo na versão 3.0:
\sphinxkeyboard
\sphinxtableofcontents
: A wrapper (defined differently insphinxhowto.cls
and insphinxmanual.cls
) of standard\tableofcontents
. The macro\sphinxtableofcontentshook
is executed during its expansion right before\tableofcontents
itself.Alterado na versão 1.5: Formerly, the meaning of
\tableofcontents
was modified by Sphinx.Alterado na versão 2.0: Hard-coded redefinitions of
\l@section
and\l@subsection
formerly 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.\sphinxmaketitle
: Used as the default setting of the'maketitle'
latex_elements
key. Defined in the class filessphinxmanual.cls
andsphinxhowto.cls
.Alterado na versão 1.8.3: Formerly,
\maketitle
from 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_elements
to add a custom definition of\sphinxbackoftitlepage
.Novo na versão 1.8.3.
\sphinxcite
: A wrapper of standard\cite
for citation references.
Ambientes¶
A figure may have an optional legend with arbitrary body elements: they are rendered in a
sphinxlegend
environment. The default definition issues\small
, and ends with\par
.Novo na versão 1.5.6: Formerly, the
\small
was hardcoded in LaTeX writer and the ending\par
was 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 (colours, border thickness) specific to each type, which can be set via'sphinxsetup'
string.Alterado na versão 1.5: Use of public environment names, separate customizability of the parameters, such as
noteBorderColor
,noteborder
,warningBgColor
,warningBorderColor
,warningborder
, …The contents directive (with
:local:
option) and the topic directive are implemented by environmentsphinxShadowBox
.Novo na versão 1.4.2: Former code refactored into an environment allowing page breaks.
Alterado na versão 1.5: Options
shadowsep
,shadowsize
,shadowrule
.The literal blocks (via
::
orcode-block
), are implemented usingsphinxVerbatim
environment which is a wrapper ofVerbatim
environment from packagefancyvrb.sty
. It adds the handling of the top caption and the wrapping of long lines, and a frame which allows pagebreaks. Inside tables the used environment issphinxVerbatimintable
(it does not draw a frame, but allows a caption).Alterado na versão 1.5:
Verbatim
keeps exact same meaning as infancyvrb.sty
(also under the nameOriginalVerbatim
);sphinxVerbatimintable
is used inside tables.Novo na versão 1.5: Options
verbatimwithframe
,verbatimwrapslines
,verbatimsep
,verbatimborder
.Novo na versão 1.6.6: Support for
:emphasize-lines:
optionNovo na versão 1.6.6: Easier customizability of the formatting via exposed to user LaTeX macros such as
\sphinxVerbatimHighlightLine
.The bibliography uses
sphinxthebibliography
and the Python Module index as well as the general index both usesphinxtheindex
; these environments are wrappers of thethebibliography
and respectivelytheindex
environments as provided by the document class (or packages).Alterado na versão 1.5: Formerly, the original environments were modified by Sphinx.
Miscelânea¶
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\sphinxAtStartPar
does nothing.Novo na versão 3.5.0.
The section, subsection, … headings are set using titlesec’s
\titleformat
command.For the
'manual'
docclass, the chapter headings can be customized using fncychap’s commands\ChNameVar
,\ChNumVar
,\ChTitleVar
. Filesphinx.sty
has custom re-definitions in case of fncychap optionBjarne
.Alterado na versão 1.5: Formerly, use of fncychap with other styles than
Bjarne
was dysfunctional.
Dica
As an experimental feature, Sphinx can use user-defined template file for
LaTeX source if you have a file named _templates/latex.tex_t
in your
project.
Additional files longtable.tex_t
, tabulary.tex_t
and
tabular.tex_t
can be added to _templates/
to configure some aspects
of table rendering (such as the caption position).
Novo na versão 1.6: currently all template variables are unstable and undocumented.