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.
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.
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.
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 , ...
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With