Table 的 Sphinx LaTeX PDF 内容侧边栏

Table of contents sidebar in Sphinx LaTeX PDF

我正在从 Sphinx 生成 LaTeX 文档,并使用 pdflatex(来自 MikTeX)将其转换为 PDF。该文档在 PDF 查看器的边栏中缺少 table 内容。

如果我手动添加 \usepackage{hyperref} 到 tex 文件,它会起作用。但是如何在 conf.py 项目文件中告诉 Sphinx 这样做呢? Latex 输出选项中没有(明显的)相关选项。

谢谢!

Sphinx 文档的 2.5.3 自定义渲染 部分提到:

LaTeX preamble

Additional commands may be added as preamble in the generated LaTeX file. This is easily done by editing file conf.py:

f = open('latex-styling.tex', 'r+');
PREAMBLE = f.read();

latex_elements = {
  # The paper size ('letterpaper' or 'a4paper').
  #'papersize': 'a4paper',

  # The font size ('10pt', '11pt' or '12pt').
  #'pointsize': '10pt',

  # Additional stuff for the LaTeX preamble.
  'preamble': PREAMBLE
}

This will copy the contents of file latex-styling.tex (in same directory as conf.py) to the generated LaTeX document. For instance, if latex-styling.tex reads:

% My personal "bold" command
\newcommand{\mycommand}[1]{\textbf{#1}}

the generated LaTeX document becomes:

% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[a4paper,10pt,english]{sphinxmanual}
% snip (packages)
% My personal "bold" command
\newcommand{\mycommand}[1]{\textbf{#1}}
\title{My Extension Documentation}
\date{2013-06-30 22:25}
\release{1.0.0}
\author{Xavier Perseguers}

Other options

The configuration file conf.py lets you further tune the rendering with LaTeX. Please consult http://www.sphinx-doc.org/en/stable/config.html#options-for-latex-output for further instructions.

添加内容而不是将其插入单独的文件(例如,latex-styling.tex)的一种更直接的方法是逐字指定。文档中的下一小节针对特定包提到了这一点 typo3:

TYPO3 template

We want to stick as much as possible to default rendering, to avoid having to change the LaTeX code generation from Sphinx. As such, we choose to include a custom package typo3 (file typo3.sty) that will override some settings of package sphinx. To include it automatically, we simply use the preamble option of conf.py:

latex_elements = {
  # Additional stuff for the LaTeX preamble.
  'preamble': '\usepackage{typo3}'
}

最好将样式选项包含在单独的 latex-styling.tex 文件中,您可以通过 f.read() 使用 preamble 键来包含该文件。这样您就不必更新 conf.py。划分通常更好。