Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change the code example font size in LaTeX PDF output with Sphinx?

I find the default code example font in the PDF generated by Sphinx to be far too large.

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.

I'm not sure what else to do - I'm an absolute beginner with LaTeX.

like image 446
Shabbyrobe Avatar asked Mar 27 '12 23:03

Shabbyrobe


People also ask

How do I change font size in LaTeX code?

Change the font size of a piece of text using these commands, from the largest to the smallest: \Huge, \huge, \LARGE, \Large, \large, \normalsize, \small, \footnotesize, \scriptsize, and \tiny. Set the font size of the whole document by adding an option to the \documentclass command.

How do I change font in LaTeX?

Changing default font typeface The font can also be changed for a specific element in the document. The command \fontfamily{qcr}\selectfont will set the TeX gyre cursor font typeface, whose fontcode is qcr , for the text inside the braces.

How do you change the font size of the text from 11pt to 12pt in LaTeX?

You can change font size using \fontsize{10}{12}\selectfont (the first number is the pt size of the font, the second number the space in pts between lines: this becomes the value of \baselineskip ), but in general I think it's better to try using things like \tiny , \small , \scriptsize , \normalsize , \footnotesize , ...

What font does LaTeX output?

By default, in standard LaTeX classes the default style for text is usually a Roman (upright) serif font. To use other styles (families) such as sans serif, typewriter (monospace) etc. you need to use some specific LaTeX commands, as shown in the example below: In this example, a command and a switch are used.


1 Answers

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' 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.

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 was my preference, but a list of sizes is available here

like image 66
Shabbyrobe Avatar answered Oct 20 '22 00:10

Shabbyrobe