如何使用sphinx更改LaTeX PDF输出中的代码示例字体大小?

Sha*_*obe 9 python documentation latex python-sphinx

我发现sphinx生成的PDF中的默认代码示例字体太大了.

我已经尝试在生成的.tex文件中插入\tiny代码块上方的字体大小命令,但它只是使代码块上方的行变得很小,而不是代码块本身.

我不知道还能做什么 - 我是LaTeX的绝对初学者.

Sha*_*obe 11

我把它解决了.Pygments使用一个\begin{Verbatim}块来表示使用该fancyvrb包的代码片段.我找到文档(警告:PDF)提到了formatcom逐字块的选项.

Pygments的乳胶编写器源代表一个实例变量,verboptions被装订到每个逐字块的末尾,而Sphinx的乳胶桥让你可以替换它LatexFormatter.

在我的conf.py文件顶部,我添加了以下内容:

from sphinx.highlighting import PygmentsBridge
from pygments.formatters.latex import LatexFormatter

class CustomLatexFormatter(LatexFormatter):
    def __init__(self, **options):
        super(CustomLatexFormatter, self).__init__(**options)
        self.verboptions = r"formatcom=\footnotesize"

PygmentsBridge.latex_formatter = CustomLatexFormatter
Run Code Online (Sandbox Code Playgroud)

\footnotesize是我的偏好,但这里有一个尺寸列表