网页
综合
更新时间 2026-11-14 09:30:46
LaTeX customization — Sphinx documentation
自动蜘蛛
www.sphinx-doc.org
正文约 5759 字
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:
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.
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:
Paper size option of the document class ('a4paper' or 'letterpaper')
Default: 'letterpaper'
Point size option of the document class ('10pt', '11pt' or '12pt')
The value of the px when used in image attributes width and height. The default value is '0.75bp' which achieves 96px=1in (in TeX 1in = 72bp = 72.27pt.) To obtain for example 100px=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); for 72px=1in, simply use '1bp'; for 90px=1in, use '0.8bp' or '0.803pt'.
Added in version 1.5.
A string which will be positioned early in the preamble, designed to contain \PassOptionsToPackage{options}{foo} commands.
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” package inclusion, default r'\usepackage{babel}' (the suitable document language string is passed as class option, and english is 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 babel over 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.
Default: r'\usepackage{babel}' (for Japanese documents)
Changed in version 1.5: For latex_engine set 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 use babel, not polyglossia.
Changed in version 7.4.0: For French with 'lualatex' the default is to use babel.
Font package inclusion. The default with 'pdflatex' is:
For 'xelatex' and 'lualatex' on the other hand the \setmainfont, \setsansfont and \setmonofont commands of LaTeX package fontspec (included via 'fontenc') are used to set up the OpenType fonts GNU FreeSerif, FreeSans, and FreeMono (scaled with ratio 0.9) as document fonts.
Changed in version 1.2: Defaults to '' when the language uses 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. At 4.0.0 these commands were moved to the 'fontsubstitution' key.
Changed in version 4.0.0: The default font setting was changed. As shown above 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.
Changed in version 8.1.0: The monospace font FreeMono used with Unicode engines is loaded at scale 0.9. This replaces the former mechanism via 'fvset' which configured code-blocks to use \small. Inline literals now fit better in their surrounding text, and it is easier to set up custom fonts, as 'fvset' does not intervene anymore by default.
Inclusion of the “fncychap” package (which makes fancy chapter titles), default r'\usepackage[Bjarne]{fncychap}' for English documentation (this option is slightly customized by Sphinx), r'\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: r'\usepackage[Bjarne]{fncychap}' for English documents, r'\usepackage[Sonny]{fncychap}' for internationalized documents, and '' for Japanese documents.
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:
It is then needed to set appropriately latex_additional_files, for example:
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 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.
Additional document content (right before the indices).
Added in version 1.5.
Additional LaTeX packages. For example:
The specified LaTeX packages will be loaded before hyperref package and packages loaded from Sphinx extensions.
If you’d like to load additional LaTeX packages after hyperref, use 'preamble' key instead.
Added in version 2.3.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。