如何使用sphinx更改LaTeX PDF输出中的代码示例字体大小? [英] How do you change the code example font size in LaTeX PDF output with sphinx?
问题描述
我发现sphinx生成的PDF中的默认代码示例字体太大了。
I find the default code example font in the PDF generated by sphinx to be far too large.
我已经在生成的.tex中弄脏了我的手在代码块之上插入字体大小命令,如 \tiny
,但它只是使代码块上方的行微小,而不是代码块本身。
I've tried getting my hands dirty in the generated .tex file inserting font size commands like \tiny
above the code blocks, but it just makes the line above the code block tiny, not the code block itself.
我不知道还有什么要做 - 我是LaTeX的绝对初学者。
I'm not sure what else to do - I'm an absolute beginner with LaTeX.
推荐答案
我做了这个。 Pygments使用 \begin {Verbatim}
块来表示代码片段,它使用 fancyvrb
包。 我发现的文档(警告:PDF)提到一个 formatcom
选项。
I worked it out. Pygments uses a \begin{Verbatim}
block to denote code snippets, which uses the fancyvrb
package. The documentation I found (warning: PDF) mentions a formatcom
option for the verbatim block.
Pygments'乳胶作者源表示一个实例变量 verboptions
,被装订到每个逐字节块的末尾,Sphinx'乳胶桥可以替换 LatexFormatter
Pygments' latex writer source indicates an instance variable, verboptions
, is stapled to the end of each verbatim block and Sphinx' latex bridge lets you replace the LatexFormatter
.
在我的 conf.py
文件的顶部,我添加了以下内容:
At the top of my conf.py
file, I added the following:
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
\footnotesize
是我的偏好, 此处的大小列表可用
\footnotesize
was my preference, but a list of sizes is available here
这篇关于如何使用sphinx更改LaTeX PDF输出中的代码示例字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!