LaTeX个性化

与:ref:htmlbuilders`不同,1 ``latex``构建器不从准备好的主题中获益。:ref:`latex options,尤其是:ref:`latex_elements 2 `变量,为定制提供了许多接口。例如:

# 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'

备注

请记住,在Python字符串文本中,反斜杠必须加倍,以避免解释为转义序列。或者,您可以像上面那样使用原始字符串。

“latex_elements”配置设置

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.

您可能想要覆盖的键包括:

“’papersize’”

document类的纸张大小选项(“a4paper”或“letterpaper”)

默认:“信纸”

'pointsize'

11pt``10pt``size

默认: '10pt'

'pxunit'

“px”在图像属性“width”和“height”中使用时的值。默认值为`’0.75bp``,实现了96px=1in`(在TeX``1in=72bp=72.27pt``),例如得到`100px=1in``使用``0.01in``或`’0.7227pt``(后者导致TeX计算更精确的值,因为规范中使用的单位较小);对于72px=1in``,只需使用`’1bp```;对于90px=1in```,使用“0.8bp”或“0.803pt”。

默认: '0.75bp'

Added in version 1.5.

'passoptionstopackages'

一个字符串,将放在前导码的前面,设计为包含`\PassOptionsToPackage{options}{foo}``命令。

提示

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.

默认: ''

Added in version 1.4.

'babel'

“babel”包包含,默认为“`”\usepackage{babel}`”(适当的文档语言字符串作为类选项传递,如果没有语言,则使用“english`”)。对于日语文档,默认为空字符串。

在Xeletex和LuaLaTeX中,Sphinx将LaTeX文档配置为使用“polyglossia”,但应该注意的是,最近几年,当前的“babel”改进了对Unicode引擎的支持,对于某些语言,它可能更喜欢“babel”而不是“polyglossia”。

提示

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.

默认: '\\usepackage{babel}' (``’’``对于日语文件)

在 1.5 版本发生变更: 对于:confval:latex_engine`设置为’’xelatex’`,默认值为’`’\usepackage{polyglossia}n\setmainlanguage{}```。

在 1.6 版本发生变更: “lualatex”使用与“xelatex”相同的默认设置

在 1.7.6 版本发生变更: 对于法语,xelatex``和``lualatex``默认使用``babel``,而不是``polyglossia```。

“字体包”

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.

在 1.2 版本发生变更: 当:confval:“language”使用西里尔字母时,默认为“”。

在 2.0 版本发生变更: Incorporates some font substitution commands to help support occasional Greek or Cyrillic in a document using 'pdflatex' engine.

在 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'

包含“fncychap”包(这会产生花哨的章节标题),对于英文文档(这个选项是由Sphinx稍微定制的),默认为“’\usepackage[Bjarne]{fncychap}``”,对于国际化文档,`\\usepackage[Sonny]{fncychap}```(因为“Bjarne”样式使用英语拼写的数字)。你可以尝试的其他“fncychap”风格有“Lenny”、“Glenn”、“Conny”、“Rejne”和“Bjornstrup”。您也可以将其设置为“`”,以禁用fncychap。

Default: '\\usepackage[Bjarne]{fncychap}' for English documents, '\\usepackage[Sonny]{fncychap}' for internationalized documents, and '' for Japanese documents.

“序言”

附加序言内容。可以将所有需要的宏移到某个文件中:file:`mystyle.tex.txt`项目源代码库,并在运行时将其导入:

'preamble': r'\input{mystyle.tex.txt}',
# or, if the \ProvidesPackage LaTeX macro is used in a file mystyle.sty
'preamble': r'\usepackage{mystyle}',

然后需要适当地设置:confval:latex_additional_files,例如:

latex_additional_files = ["mystyle.sty"]

Do not use .tex as suffix, else the file is submitted itself to the PDF build process, use .tex.txt or .sty as in the examples above.

默认: ''

'图符对齐'

Latex图形浮动对齐。当一个图像不适合当前页面时,它将被“浮动”到下一个页面,但前面可能会有其他文本。如果您不喜欢这种行为,请使用’H’,它将严格按照浮动和位置数字在源中出现的顺序禁用它们。

默认值:`’htbp’`(此处,顶部,底部,页面)

Added in version 1.3.

'atendofbody'

附加文档内容(在索引之前)。

默认: ''

Added in version 1.5.

'附加包裹'

附加LaTeX包。例如:

latex_elements = {
    'extrapackages': r'\usepackage{isodate}'
}

指定的LaTeX包将在hyperref包和从Sphinx extensions加载包之前加载。

提示

如果您想在hyperref之后加载其他LaTeX包,请改用“`preamble”``键。

默认: ''

Added in version 2.3.

'页脚'

附加页脚内容(在索引之前)。

默认: ''

自 1.5 版本弃用: 请改用’’atendofbody’``键。

不需要重写的键,除非在特殊情况下是:

'附加类选项'

默认为空字符串。例如:``extraclassoptions’:’openany``允许章节(对于`’manual``类型的文档)从任何页面开始。

默认: ''

Added in version 1.2.

在 1.6 版本发生变更: 添加这个文档。

'最大列表深度'

默认情况下,LaTeX最多允许6个级别用于嵌套列表和引用类环境,最多包含4个枚举列表和4个项目符号列表。例如,将此键设置为“10”(字符串形式)将允许最多10个嵌套级别(各种类型)。将其保留为空字符串意味着遵守LaTeX默认设置。

警告

  • 使用此密钥可能会被证明与某些LaTeX包或特殊文档类不兼容,这些类执行自己的列表自定义。

  • 如果在文档前导码内执行“usepackage{enumitem}`”,则键设置将被静默*忽略*。然后使用这个LaTeX包的专用命令。

默认值: 6

Added in version 1.5.

'inputenc'

包含“inputenc”包。

Default: '\\usepackage[utf8]{inputenc}' when using pdflatex, else ''.

备注

If using utf8x in place of utf8 it is mandatory to extend the LaTeX preamble with suitable \PreloadUnicodePage{<number>} commands, as per the utf8x documentation (texdoc ucs on 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 pdflatex engine may crash due to upstream LaTeX not being fully compatible with utf8x. 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 with pdflatex engine has somewhat enhanced native support for Unicode and is becoming more and more incompatible with utf8x. 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 if utf8x is in use.

在 1.4.3 版本发生变更: 以前,`’\usepackage[utf8]{inputenc}``用于所有编译器。

'cmappkg'

包含“cmap”软件包。

默认值: '\\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.

注意

  • 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 as latex_engine.

  • The TeX installation may need some extra packages. For example, on Ubuntu xenial, packages texlive-lang-greek and cm-super are needed for LGR to work. And texlive-lang-cyrillic and cm-super are needed for support of Cyrillic.

在 1.5 版本发生变更: 默认为’’\ usepackage{fontspec}```当:confval:latex引擎’是’’xelatex’``

在 1.6 版本发生变更: ``“lualatex”在默认情况下使用“fontspec”,例如“xelatex”。

在 2.0 版本发生变更: 'lualatex' executes \defaultfontfeatures[\rmfamily,\sffamily]{} to disable TeX ligatures transforming << and >> as escaping working with pdflatex/xelatex failed with lualatex.

在 2.0 版本发生变更: Detection of LGR, T2A, X2 to trigger support of occasional Greek or Cyrillic letters ('pdflatex').

在 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) despite smartquotes being set to False.

'fontsubstitution'

Ignored if 'fontenc' was not configured to use LGR or X2 (or T2A). In case 'fontpkg' key is configured for usage with some TeX fonts known to be available in the LGR or X2 encodings, set this one to be the empty string. Else leave to its default.

Ignored with latex_engine other than 'pdflatex'.

Added in version 4.0.0.

'文本希腊语'

For the support of occasional Greek letters.

It is ignored with 'platex', 'xelatex' or 'lualatex' as latex_engine and defaults to either the empty string or to '\\usepackage{textalpha}' for 'pdflatex' depending on whether the 'fontenc' key was used with LGR 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 in math context. For example :math:`α` (U+03B1) will render as \(\alpha\).

Default: '\\usepackage{textalpha}' or '' if fontenc does not include the LGR option.

Added in version 2.0.

'geometry'

“几何体”包包含,默认定义为:

'\\usepackage{geometry}'

为日文文档增加了一个“[dvipdfm]”。Sphinx LaTeX样式文件将执行:

\PassOptionsToPackage{hmargin=1in,vmargin=1in,marginpar=0.5in}{geometry}

可以通过相应的:ref:`’sphinxsetup’选项1进行定制。

Default: '\\usepackage{geometry}' (or '\\usepackage[dvipdfm]{geometry}' for Japanese documents)

Added in version 1.5.

在 1.5.2 版本发生变更: dvipdfm 选项 如果 latex_engine'platex'.

Added in version 1.5.3: 边距1的:ref:`’sphinxsetup’键。

在 1.5.3 版本发生变更: LaTeX文件中的位置已移动到“usepackage{sphinx}`”和“sphinxsetup{..}”之后,因此也是在插入“fontpkg”键之后。这是为了以特殊的方式处理日语文档的纸张布局选项:文本宽度将设置为*zenkaku*宽度的整数倍,文本高度设置为基线的整数倍。有关详细信息,请参阅:ref:`hmargin`文档。

'hyperref'

“hyperref”包包含;还加载包“hypcap”并发出“urlstyle{same}`”。此操作在以下时间完成:文件:`sphinx.sty`文件已加载,并且在执行``preamble’``密钥的内容之前。

注意

必须加载“hyperref”和“hypcap”包。

Added in version 1.5: 以前这是从内部完成的:文件:sphinx.sty.

'写标题'

“maketitle”呼叫。如果要生成不同样式的标题页,请重写。

提示

如果键值设置为“r”newcommandsphinxbackoftitlepage{}sphinxmakeTilepage````,那么````将在标题页的背面排版(仅限于docclass``manual’)。

默认值: '\\sphinxmaketitle'

在 1.8.3 版本发生变更: Original \maketitle from document class is not overwritten, hence is reusable as part of some custom setting for this key.

Added in version 1.8.3: ``sphinxbackoftitlepage``可选宏。它也可以在``前导’``键中定义,而不是这个键。

'释放名称'

在标题页上以“release”元素为前缀的值。至于*title*和*author*在:confval:`latex_documents`的元组中使用,它是作为latex标记插入的。

默认值: 'Release'

'目录'

“目录”调用。默认的“\sphinxtableofcontents”是未修改的“tableofcontents”的包装,它本身可以由用户加载的包自定义。如果要生成不同的目录或将内容放在标题页和目录之间,请重写。

默认值: '\\sphinxtableofcontents'

在 1.5 版本发生变更: 以前,`tableofcontents`本身的意思是由Sphinx修改的。这就造成了与修改它的专用包(如“tocloft”或“etoc”)的不兼容。

“过渡”

用于显示转换的命令。如果要以不同方式显示过渡,请重写。

默认值: '\n\n\\bigskip\\hrule\\bigskip\n\n'

Added in version 1.2.

在 1.6 版本发生变更: 删除“\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 install idxlayout LaTeX package.

默认:'\\makeindex'

'打印索引'

“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 the idxlayout approach described in the documentation of the 'makeindex' key).

默认: '\\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.

默认: '\\fvset{fontsize=auto}'

Added in version 1.8.

在 2.0 版本发生变更: For 'xelatex' and 'lualatex' defaults to '\\fvset{fontsize=\\small}' as this is adapted to the relative widths of the FreeFont family.

在 4.0.0 版本发生变更: Changed default for 'pdflatex'. Previously it was using '\\fvset{fontsize=\\small}'.

在 4.1.0 版本发生变更: Changed default for Chinese documents to '\\fvset{fontsize=\\small,formatcom=\\xeCJKVerbAddon}'

由其他选项设置且因此不应重写的键包括:

'docclass' 'classoptions' 'title' 'release' 'author'

“sphinxsetup”配置设置

Added in version 1.5.

ref:`latex_elements 1’的“sphinxsetup”键提供了一个latex类型的自定义接口:

latex_elements = {
    'sphinxsetup': 'key1=value1, key2=value2, ...',
}

默认为空。如果非空,它将作为参数传递给文档前导码中的“sphinxsetup”宏,如下所示:

\usepackage{sphinx}
\sphinxsetup{key1=value1, key2=value2,...}

上面使用的颜色由“xcolor”包的“svgnames”选项提供:

latex_elements = {
    'passoptionstopackages': r'\PassOptionsToPackage{svgnames}{xcolor}',
}

It is possible to insert uses of the \sphinxsetup LaTeX macro directly into the body of the document, via the raw directive. This chapter is styled in the PDF output using the following insertion at its start. This uses keys described later in Additional CSS-like 'sphinxsetup' keys.

.. raw:: latex

   \begingroup
   \sphinxsetup{%
      TitleColor={named}{DarkGoldenrod},
      % pre_border-width is 5.1.0 alias for verbatimborder
      pre_border-width=2pt,
      pre_border-right-width=8pt,
      % pre_padding is a 5.1.0 alias for verbatimsep
      pre_padding=5pt,
      % Rounded boxes are new at 5.1.0
      pre_border-radius=5pt,
      % TeXcolor reminds that syntax must be as for LaTeX \definecolor
      pre_background-TeXcolor={named}{OldLace},
      % ... and since 5.3.0 also xcolor \colorlet syntax is accepted and we
      %     can thus drop the {named}{...} thing if xcolor is available!
      pre_border-TeXcolor=Gold,
      % ... and even take more advantage of xcolor syntax:
      pre_border-TeXcolor=Gold!90,
      % add a shadow to code-blocks
      pre_box-shadow=6pt 6pt,
      pre_box-shadow-TeXcolor=gray!20,
      %
      % This 5.1.0 CSS-named option is alias for warningborder
      div.warning_border-width=3pt,
      % Prior to 5.1.0, padding for admonitions was not customizable
      div.warning_padding=6pt,
      div.warning_padding-right=18pt,
      div.warning_padding-bottom=18pt,
      % Assume xcolor has been loaded with its svgnames option
      div.warning_border-TeXcolor=DarkCyan,
      div.warning_background-TeXcolor=LightCyan,
      % This one is the only option with space separated input:
      div.warning_box-shadow=-12pt -12pt inset,
      div.warning_box-shadow-TeXcolor=Cyan,
      %
      % The 5.1.0 new name would be div.attention_border-width
      attentionborder=3pt,
      % The 5.1.0 name here would be div.attention_border-TeXcolor
      attentionBorderColor=Crimson,
      % The 5.1.0 name would be div.attention_background-TeXcolor
      attentionBgColor=FloralWhite,
      %
      % For note/hint/important/tip, the CSS syntax was added at 6.2.0
      % Legacy syntax still works
      noteborder=1pt,
      noteBorderColor=Olive,
      % But setting a background color via the new noteBgColor means that
      % it will be rendered using the same interface as warning type
      noteBgColor=Olive!10,
      % We can customize separately the four border-widths, and mimic
      % the legacy "light" rendering, but now with a background color:
      % div.note_border-left-width=0pt,
      % div.note_border-right-width=0pt,
      % Let's rather for variety use lateral borders:
      div.note_border-top-width=0pt,
      div.note_border-bottom-width=0pt,
      %
      % As long as only border width and border color are set, *and* using
      % for this the old interface, the rendering will be the "light" one
      hintBorderColor=LightCoral,
      % but if we had used div.hint_border-TeXcolor or *any* CSS-named
      % option we would have triggered the more complex "heavybox" code.
   }

And this is placed at the end of the chapter source to end the scope of the configuration:

.. 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 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 the hyperref LaTeX docs.

默认: 5

Added in version 4.0.0.

hmargin, vmargin

水平方向的尺寸(分别为。垂直)页边距,作为“hmargin”传递(resp。“geometry”包的vmargin)选项。例子::

'sphinxsetup': 'hmargin={2in,1.5in}, vmargin={1.5in,2in}, marginpar=1in',

日语文档目前只接受这些参数的一维格式。然后向“geometry”包传递适当的选项,使文本宽度设置为*zenkaku*宽度的精确倍数,文本高度设置为基准线的整数倍,并与边距最接近。

默认值: 1in (equivalent to {1in,1in})

提示

对于点大小为11pt或12pt的日文“manual”docclass,使用“nomag”额外的文档类选项(参见:confval:latex_elements)的“extraclassoptions”键或所谓的TeX“true”单位:

'sphinxsetup': 'hmargin=1.5truein, vmargin=1.5truein, marginpar=5zw',

Added in version 1.5.3.

marginpar

“marginparwidth”LaTeX维度。对于日语文档,该值被修改为*zenkaku*宽度的最接近整数倍。

默认值: 0.5in

Added in version 1.5.3.

verbatimwithframe

Boolean to specify if code-blocks and literal includes are framed. Setting it to false does not deactivate use of package “framed”, because it is still in use for the optional background color.

默认值: true.

verbatimwrapslines

布尔值指定是否包含长线:rst:方向:code block的内容被包装。

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.

默认值: true

verbatimforcewraps

Boolean to specify if long lines in code-block‘s contents should be forcefully wrapped to never overflow due to long strings.

备注

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 not utf8x is allowed.

默认: false

Added in version 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.

默认: 3

Added in version 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 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.

默认:100

Added in version 3.5.0.

verbatimhintsturnover

Boolean to specify if code-blocks display “continued on next page” and “continued from previous page” hints in case of page breaks.

默认值: true

Added in version 1.6.3.

在 1.7 版本发生变更: 默认值从“false”更改为“true”。

verbatimcontinuedalign, verbatimcontinuesalign

相对于框架内容的水平位置:“l”(左对齐)、“r”(右对齐)或“c”(居中)。

默认值: r

Added in version 1.7.

parsedliteralwraps

Boolean指定:dudir:parsed literal'内容中的长行是否应换行。

默认值: true

Added in version 1.5.2: set this option value to false to recover former behavior.

inlineliteralwraps

Boolean指定是否允许在内联文字中使用换行符:但当前仅在字符``之后插入额外的潜在断点(除了LaTeX允许的空格或连字号)。, ; ? ! /``和` `。由于TeX内部结构,行中的空白将被拉伸(或收缩)以适应linebreak。

默认值: true

Added in version 1.5: set this option value to false to recover former behavior.

在 2.3.0 版本发生变更: 在“``”字符处添加了潜在断点。

verbatimvisiblespace

当一个长代码行被拆分时,在换行符位置之前的源代码行中的最后一个空格字符将使用此字符进行排版。

默认值: \textcolor{red}{\textvisiblespace}

verbatimcontinued

在连续代码行开始处插入的LaTeX宏。它的(复杂的…)默认字体是一个指向右边的红色小钩子:

\makebox[2\fontcharwd\font`\x][r]{\textcolor{red}{\tiny$\hookrightarrow$}}

在 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).

备注

Values for color keys must either:

  • obey the syntax of the \definecolor LaTeX command, e.g. something such as VerbatimColor={rgb}{0.2,0.3,0.5} or {RGB}{37,23,255} or {gray}{0.75} or (only with package xcolor) {HTML}{808080} or …

  • or obey the syntax of the \colorlet command from package xcolor (which then must exist in the LaTeX installation), e.g. VerbatimColor=red!10 or red!50!green or -red!75 or MyPreviouslyDefinedColor or… Refer to xcolor documentation for this syntax.

在 5.3.0 版本发生变更: Formerly only the \definecolor syntax was accepted.

标题颜色

The color for titles (as configured via use of package “titlesec”.)

默认值: {rgb}{0.126,0.263,0.361}

内部链接颜色

A color passed to hyperref as value of linkcolor and citecolor.

默认值: {rgb}{0.208,0.374,0.486}.

外部链接颜色

A color passed to hyperref as value of filecolor, menucolor, and urlcolor.

默认值: {rgb}{0.216,0.439,0.388}

逐字颜色

The background color for code-blocks.

默认:{gray}{0.95}

在 6.0.0 版本发生变更: Formerly, it was {rgb}{1,1,1} (white).

逐字顺序颜色

框架颜色。

默认:{RGB}{32,32,32}

在 6.0.0 版本发生变更: Formerly it was {rgb}{0,0,0} (black).

逐字高亮颜色

亮显线条的颜色。

默认值: {rgb}{0.878,1,1}

Added in version 1.6.6.

TableRowColorHeader

Sets the background color for (all) the header rows of tables.

It will have an effect only if either the latex_table_style contains 'colorrows' or if the table is assigned the colorrows class. It is ignored for tables with nocolorrows class.

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{...}.

默认:{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.

TableRowColorOdd

Sets the background color for odd rows in tables (the row count starts at 1 at the first non-header row). Has an effect only if the latex_table_style contains 'colorrows' or for specific tables assigned the colorrows class.

默认:{gray}{0.92}

There is also TableMergeColorOdd.

Added in version 5.3.0.

TableRowColorEven

Sets the background color for even rows in tables.

默认:{gray}{0.98}

There is also TableMergeColorEven.

Added in version 5.3.0.

逐字

代码行和框架之间的分隔。

See Additional CSS-like 'sphinxsetup' keys for its alias pre_padding and additional keys.

默认值: \fboxsep

逐字顺序

The width of the frame around code-blocks. See also Additional CSS-like 'sphinxsetup' keys for pre_border-width.

默认值: \fboxrule

阴影分隔

The separation between contents and frame for contents and topic boxes.

See Additional CSS-like 'sphinxsetup' keys for the alias div.topic_padding.

默认值: 5pt

阴影大小

The width of the lateral “shadow” to the right and bottom.

See Additional CSS-like 'sphinxsetup' keys for div.topic_box-shadow which allows to configure separately the widths of the vertical and horizontal shadows.

默认值: 4pt

在 6.1.2 版本发生变更: Fixed a regression introduced at 5.1.0 which modified unintentionally the width of topic boxes and worse had made usage of this key break PDF builds.

阴影规则

The width of the frame around topic boxes. See also Additional CSS-like 'sphinxsetup' keys for div.topic_border-width.

默认值: \fboxrule

|注释B颜色|

The color for the two horizontal rules used by Sphinx in LaTeX for styling a note type admonition.

默认值: {rgb}{0,0,0} (black)

noteBgColor, hintBgColor, importantBgColor, tipBgColor

The optional color for the background. It is a priori set to white, but is not used, unless it has been set explicitly, and doing this triggers Sphinx into switching to the more complex LaTeX code which is employed also for warning type admonitions. There are then additional options which are described in Additional CSS-like 'sphinxsetup' keys.

默认值: {rgb}{1,1,1} (white)

Added in version 6.2.0.

noteTextColor, hintTextColor, importantTextColor, tipTextColor

The optional color for the contents.

Default: unset (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, tipTeXextras

Some extra LaTeX code (such as \bfseries or \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, tipborder

两条横线的宽度。

If the background color is set, or the alternative Additional CSS-like 'sphinxsetup' keys syntax is used (e.g. div.note_border-width=1pt in place of noteborder=1pt), or any option with a CSS-alike name is used, then the border is a full frame and this parameter sets its width also for left and right.

默认值: 0.5pt

|警告B颜色|

The color for the admonition frame.

默认值: {rgb}{0,0,0} (black)

|警告背景颜色|

The background colors for the respective admonitions.

默认值: {rgb}{1,1,1} (white)

|警告边界|

The width of the frame. See Additional CSS-like 'sphinxsetup' keys for keys allowing to configure separately each border width.

默认值: 1pt

起始脚注

LaTeX宏插入页面底部脚注文本的开头,脚注编号之后。

默认值: \mbox{ }

脚注之前

在脚注标记之前插入的乳胶宏。默认值会删除其前面可能的空格(否则,TeX可以在那里插入一个换行符)。

默认值: \leavevmode\unskip

Added in version 1.5.

头家

默认“sffamilybfseries”。设置标题使用的字体。

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, …).

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.

重要

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 \definecolor syntax or, if package xcolor is available (it is then automatically used) also the \colorlet syntax:

    ...<other options>
    div.warning_border-TeXcolor={rgb}{1,0,0},% (always works)
    div.error_background-TeXcolor=red!10,% (works only if xcolor is available)
    ...<other options>
    
  • A colon in place of the equal sign will break LaTeX.

  • ...border-width or ...padding expect a single dimension: they can not be used so far with space separated dimensions.

  • ...top-right-radius et al. values may be either a single or two space separated dimensions.

  • Dimension specifications must use TeX units such as pt or cm or in. The px unit is recognized by pdflatex and lualatex but not by xelatex or platex.

  • It is allowed for such specifications to be so-called “dimensional expressions”, e.g. \fboxsep+2pt or 0.5\baselineskip are 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 3pt will break LaTeX. Beware also that \fboxsep \fboxsep will not be seen as space separated in LaTeX. You must use something such as {\fboxsep} \fboxsep. Or use directly 3pt 3pt which 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

code-block

pre

sphinxVerbatim

topic

div.topic

sphinxShadowBox

contents

div.topic

sphinxShadowBox

note

div.note

sphinxnote using sphinxheavybox

warning

div.warning

sphinxwarning (uses sphinxheavybox)

admonition type

div.<type>

sphinx<type> (using sphinxheavybox)

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:

    • \fboxrule (i.e. a priori 0.4pt) for code-block,

    • \fboxrule for topic or contents directive,

    • 1pt for warning and other “strong” admonitions,

    • 0.5pt for note and other “light” admonitions. The framing style of the “lighbox” used for them in absence of usage of CSS-named options will be emulated by the richer “heavybox” if setting border-left-width and border-right-width both to 0pt.

  • <prefix>_box-decoration-break can be set to either clone or slice and configures the behavior at page breaks. It defaults to slice for code-block (i.e. for <prefix>=pre) since 6.0.0. For other directives the default is clone.

  • <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 default is that all those dimensions are equal. They are set to:

    • \fboxsep (i.e. a priori 3pt) for code-block,

    • 5pt for topic or contents directive,

    • a special value for warning and other “strong” admonitions, which ensures a backward compatible behavior.

      重要

      Prior to 5.1.0 there was no separate customizability of padding for warning-type boxes in PDF via LaTeX output. The sum of padding and border-width (as set for example for warning by warningborder, now also named div.warning_border-width) was kept to a certain constant value. This limited the border-width to small values else the border could overlap the text contents. This behavior is kept as default.

    • the same padding behavior is obeyed per default for note or other “light” admonitions when using sphinxheavybox.

  • <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 default is that all four corners are either circular or straight, with common radii:

    • \fboxsep (i.e. a priori 3pt) for code-block (since 6.0.0).

    • 0pt for all other directives; this means to use straight corners.

    See a remark above about traps with spaces in LaTeX.

  • <prefix>_box-shadow is special in so far as it may be:

    • the none keyword,

    • 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 is 4pt 4pt, i.e. the shadow has a width of 4pt and 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.

    The shadow color defaults in all cases to {rgb}{0,0,0} i.e. to black.

    Since 6.0.0 the border color and background color of code-block, i.e. pre prefix, default respectively to {RGB}{32,32,32} and {gray}{0.95}. They previously defaulted to black, respectively white.

    For all other types, the border color defaults to black and the background color to white.

    The <prefix>_TeXcolor stands for the CSS property “color”, i.e. it influences the text color of the contents. As for the three other options, the naming TeXcolor is to stress that the input syntax is the TeX one for colors not an HTML/CSS one. If package xcolor is available in the LaTeX installation, one can use directly named colors as key values. Consider passing options such as dvipsnames, svgnames or x11names to xcolor via 'passoptionstopackages' key of latex_elements.

    If <prefix>_TeXcolor is set, a \color command 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.

备注

  • All directives support box-decoration-break to be set to slice.

    在 6.2.0 版本发生变更: Formerly, only code-block did. The default remains clone for all other directives, but this will probably change at 7.0.0.

  • The corners of rounded boxes may be elliptical.

    在 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.

    在 6.2.0 版本发生变更: Formerly it was to the contrary the rounded corners which were ignored in case an inset shadow was specified.

  • <prefix>_TeXcolor and <prefix>_TeXextras are new with 6.2.0.

    Usefulness is doubtful in the case of code-block:

    • pre_TeXcolor will 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 the fancyvrb interface.

    • pre_TeXextras=\footnotesize for example may be replaced by usage of the latex_elements key 'fvset'. For 'lualatex' or 'xelatex' Sphinx includes in the preamble already \fvset{fontsize=\small} and this induces fancyvrb into overriding a \footnotesize coming from pre_TeXextras. One has to use pre_TeXextras=\fvset{fontsize=\footnotesize} syntax. Simpler to set directly the latex_elements key 'fvset'

    Consider these options experimental and that some implementation details may change. For example if the pre_TeXextras LaTeX 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.topic prefix: the Sphinx LaTeX mark-up uses for both directives the same sphinxShadowBox environment which has currently no additional branching, contrarily to the sphinxadmonition environment which branches according to the admonition directive name, e.g. either to sphinxnote or sphinxwarning etc…

LaTeX宏和环境

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.

提示

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.

在 4.0.0 版本发生变更: split of sphinx.sty into multiple smaller units, to facilitate customization of many aspects simultaneously.

  • 文本样式命令:

    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 source

    Added in version 1.4.5: 使用前缀为“sphinx”的宏名称来限制与LaTeX包冲突的可能性。

    Added in version 1.8: \sphinxguilabel

    Added in version 3.0: \sphinxkeyboard

    Added in version 6.2.0: \sphinxparam\sphinxsamedocref

    Added in version 7.1.0: \sphinxparamcomma which defaults to a comma followed by a space and \sphinxparamcommaoneperline which is used for one-parameter-per-line signatures (see maximum_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) or name<space>[type parameters]<space>(parameters) (see PEP 695) where the length of <space> is set to 0pt by default. This can be changed via \setlength{\sphinxsignaturelistskip}{1ex} for instance.

  • 更多文本样式:

    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}

    \sphinxstyleindexlettergroupDefault

    请看源码,太长写不下

    \sphinxstyletopictitle

    \textbf{#1}\par\medskip

    \sphinxstylesidebartitle

    \textbf{#1}\par\medskip

    \sphinxstyleothertitle

    \textbf{#1}

    \sphinxstylesidebarsubtitle

    ~\\\textbf{#1} \smallskip

    \sphinxstyletheadfamily

    \sffamily它没有参数

    \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

    \sphinxstrong{#1}<space>

    \sphinxstylehinttitle

    idem

    \sphinxstyleimportanttitle

    idem

    \sphinxstyletiptitle

    idem

    \sphinxstylewarningtitle

    idem

    \sphinxstylecautiontitle

    idem

    \sphinxstyleattentiontitle

    idem

    \sphinxstyledangertitle

    idem

    \sphinxstyleerrortitle

    idem

    \sphinxstyleseealsotitle

    \sphinxstrong{#1}\par\nopagebreak

    Added in version 1.5: 这些宏以前被硬编码为不可自定义的“texttt”、“emph”等。。。

    Added in version 1.6: ``sphinxstyletheadfamily``默认为`sFamily``并允许在表的标题单元格中有多个段落。

    Added in version 1.6.3: \sphinxstylecodecontinued\sphinxstylecodecontinues.

    Added in version 1.8: \sphinxstyleindexlettergroup\sphinxstyleindexlettergroupDefault

    Added in version 6.2.0: \sphinxstylenotetitle et al. The #1 is the localized name of the directive, with a final colon. Wrap it as \sphinxremovefinalcolon{#1} if this final colon is to be removed. Examples:

    \renewcommand\sphinxstylewarningtitle[1]{%
      \underline{\textbf{\sphinxremovefinalcolon{#1}}}\par
    }
    \renewcommand{\sphinxstylenotetitle}[1]{%
      \textit{\textbf{\sphinxremovefinalcolon{#1}}}\par\nobreak
      % LaTeX syntax is complex and we would be better off using \hrule.
      {\parskip0pt\noindent}%
      \raisebox{1ex}%
       {\makebox[\linewidth]{\textcolor{sphinxnoteBorderColor}{\dotfill}}}
      % It is complex to obtain nice vertical spacing for both a paragraph
      % or a list following up; this set-up is better for a paragraph next.
      \par\vskip-\parskip
    }
    
  • \sphinxtableofcontents:一个包装器(在:file:sphinxhowto..cls`在:文件:`sphinxmanual册.cls)标准的“目录表”`。宏“sphinxtableofcontentshook”在扩展过程中就在“tableofcontents”自身之前执行。

    在 1.5 版本发生变更: 以前,`tableofcontents``的意思是由Sphinx修改的。

    在 2.0 版本发生变更: 硬编码重新定义``l@截面``以及``l@分段``以前在“manual”加载期间完成的docclass现在通过“sphinxtableofcontentshook”执行。此宏也由“howto”docclass执行,但默认为空。

    提示

    If adding to preamble the loading of tocloft package, also add to preamble \renewcommand\sphinxtableofcontentshook{} else it will reset \l@section and \l@subsection cancelling tocloft customization.

  • \sphinxmaketile:用作`’maketitle```:confval:latex_elements`键的默认设置。在类文件:文件中定义:`sphinxmanual.cls`和:文件:`sphinxhowto.cls.

    在 1.8.3 版本发生变更: 以前,LaTeX文档类中的“maketitle”是由Sphinx修改的。

  • \sphinxbackoftitlepage`:对于`’manual``docclass,如果定义了它,它将在`sphinxmaketile````的末尾执行,在最后一个`clearpage``之前。使用confval:latex元素的“maketitle”键或“preamble”键添加自定义的“sphinxbackoftitlepage”定义。

    Added in version 1.8.3.

  • \sphinxcite:引用引用的标准`cite``的包装。

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 “sphinxsetup”配置设置. 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 addstrut which is a boolean key, i.e. to be used as addstrut=true, or addstrut alone where =true is omitted, or addstrut=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.

重要

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).

环境

  • A:dudir:figure’可能有一个可选的图例,其中包含任意的body元素:它们在“sphinxlegend”环境中呈现。默认定义发出small``,并以`par``结尾。

    Added in version 1.5.6: 以前,small``是在LaTeX writer中硬编码的,缺少结尾par```。

  • 与环境相关的警告:

    • sphinx批注,

    • sphinx提示,

    • sphinx重点,

    • sphinxt贴士,

    • sphinx警告,

    • sphinx小心,

    • sphinx注意,

    • sphinx危险,

    • sphinx错误.

    They may be \renewenvironment ‘d individually, and must then be defined with one argument (it is the heading of the notice, for example Warning: 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.

    在 1.5 版本发生变更: 使用公共环境名称,单独自定义参数,如“noteBorderColor”、“noteborder”、“warningBgColor”、“warningBorderColor”、“warningborder”。。。

  • Environment for the seealso directive: sphinxseealso. It takes one argument which will be the localized string See also followed with a colon.

    Added in version 6.1.0.

    在 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.

  • The contents directive (with :local: option) and the topic directive are implemented by environment sphinxShadowBox.

    Added in version 1.4.2: 以前的代码重构到允许分页符的环境中。

    在 1.5 版本发生变更: 选项“阴影”、“阴影大小”、“阴影规则”。

  • The literal blocks (via :: or code-block), are implemented using sphinxVerbatim environment which is a wrapper of Verbatim environment from package fancyvrb.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 is sphinxVerbatimintable (it does not draw a frame, but allows a caption).

    在 1.5 版本发生变更: ``逐字的意思与``fancyvrb.sty``(也在名称“OriginalVerbatim”下);“sphinxverbatimitable”在表中使用。

    Added in version 1.5: 选项``有框架的verbatim``, verbatim封装行verbatim分隔verbatim边界

    Added in version 1.6.6: 支持``:强调行:``选项

    Added in version 1.6.6: 通过向用户LaTeX宏(如“sphinxVerbatimHighlightLine”)公开,可以更轻松地自定义格式。

  • 书目使用“sphinxthe书目”,Python模块索引和通用索引都使用“sphinxtheindex”;这些环境是文档类(或包)提供的“The书目”和“theindex”环境的包装器。

    在 1.5 版本发生变更: 以前,原始环境是由sphinx修改的。

杂项

  • 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.

    Added in version 3.5.0.

  • 章节、小节… 标题是使用*titlesec*的`titleformat``命令设置的。

  • 对于“manual”docclass,可以使用*fncychap*的命令“ChNameVar``ChNumVar``ChTitleVar```自定义章节标题。文件:文件:`sphinx.sty``对于*fncychap*选项“`Bjarne”,具有自定义的重新定义。

    在 1.5 版本发生变更: 以前,将*fncychap*与“Bjarne”以外的其他样式一起使用是不起作用的。

  • Docutils container directives are supported in LaTeX output: to let a container class with name foo influence the final PDF via LaTeX, it is only needed to define in the preamble an environment sphinxclassfoo. 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.

提示

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: 目前所有的模板变量都不稳定且没有文档记录。

在 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)