简体   繁体   English

Sphinx LaTeX PDF中的目录侧栏

[英]Table of contents sidebar in Sphinx LaTeX PDF

I am generating a LaTeX document from Sphinx, and converting it to PDF using pdflatex (from MikTeX). 我正在从Sphinx生成LaTeX文档,并使用pdflatex(来自MikTeX)将其转换为PDF。 The document is missing a table of contents in the sidebar of the PDF viewer. 该文档在PDF查看器的侧边栏中缺少目录。

If I add manually \\usepackage{hyperref} to the tex file, it works. 如果我将\\usepackage{hyperref}手动添加到tex文件,则可以使用。 But how can I tell Sphinx to do it in the conf.py project file? 但是,如何在conf.py项目文件中告诉Sphinx呢? There is no (evident) related option in the latex output options. 乳胶输出选项中没有(明显的)相关选项。

Thanks! 谢谢!

Section 2.5.3 Customizing the rendering of the Sphinx document mentions: 2.5.3节“ 自定义 Sphinx文档的呈现 ”提到:

LaTeX preamble LaTeX序言

Additional commands may be added as preamble in the generated LaTeX file. 其他命令可以作为前导添加到生成的LaTeX文件中。 This is easily done by editing file conf.py : 这很容易通过编辑文件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. 这会将文件latex-styling.tex的内容(与latex-styling.tex位于同一目录中) conf.py到生成的LaTeX文档中。 For instance, if latex-styling.tex reads: 例如,如果latex-styling.tex读取:

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

the generated LaTeX document becomes: 生成的LaTeX文档变为:

 % 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. 配置文件conf.py允许您进一步使用LaTeX调整渲染。 Please consult http://www.sphinx-doc.org/en/stable/config.html#options-for-latex-output for further instructions. 请参阅http://www.sphinx-doc.org/en/stable/config.html#options-for-latex-output以获得更多说明。

A more direct way of adding content rather than inserting it in a separate file (say, latex-styling.tex ), is to specify if verbatim. 添加内容而不是将其插入单独的文件(例如latex-styling.tex )的一种更直接的方法是指定逐字记录。 The next subsection in the documentation mentions this for a specific package typo3 : 文档的下一个小节针对特定的软件包typo3提到了这typo3

TYPO3 template TYPO3模板

We want to stick as much as possible to default rendering, to avoid having to change the LaTeX code generation from Sphinx. 我们希望尽可能地坚持默认渲染,以避免不得不从Sphinx更改LaTeX代码生成。 As such, we choose to include a custom package typo3 (file typo3.sty ) that will override some settings of package sphinx . 因此,我们选择包括一个自定义程序包typo3 (文件typo3.sty ),它将覆盖程序包sphinx某些设置。 To include it automatically, we simply use the preamble option of conf.py : 要自动包含它,我们只需使用conf.pypreamble选项:

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

It's better to contain your styling options in a separate latex-styling.tex file that you can include using the preamble key via an f.read() . 最好将样式选项包含在单独的latex-styling.tex文件中,您可以通过f.read()使用preamble键将其包括在内。 That way you don't have to update conf.py . 这样,您不必更新conf.py Compartmentalization is usually better. 隔离通常更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM