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.
To change Latex Output options in sphinx, set the relevant
latex_elements
key in the build configuration file, documentation on this is located here.To change the font size for all fonts use
pointsize
.E.g.
To change other Latex settings that are listed in the documetntation use
preamble
or use a custom document class inlatex_documents
.E.g.
Reading the Sphinx sourcecode by default the code in LatexWriter sets code snippets to the
\code
latex primitive.So what you want to do is replace the
\code
with a suitable replacement.This is done by including a Latex command like
\newcommand{\code}[1]{\texttt{\tiny{#1}}}
either as part of the preamble or as part of a custom document class for sphinx that gets set inlatex_documents
as the documentclass key. An example sphinx document class is avaliable here.Other than just making it smaller with
\tiny
you can modify thelatex_documents
document class or thelatex_elements
preamble to use the Latex package listings for more fancy code formatting like in the StackOverflow question here.The package stuff from the linked post would go as a custom document class and the redefinition similar to
\newcommand{\code}[1]{\begin{lstlisting} #1 \end{lstlisting}}
would be part of the preamble.Alternatively you could write a sphinx extension that extends the default latex writer with a custom latex writer of your choosing though that is significantly more effort.
Other relevant StackOverflow questions include
You can add a modified Verbatim command into your PREAMBLE (Note in this case the font size is changed to tiny)
I worked it out. Pygments uses a
\begin{Verbatim}
block to denote code snippets, which uses thefancyvrb
package. The documentation I found (warning: PDF) mentions aformatcom
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 theLatexFormatter
.At the top of my
conf.py
file, I added the following:\footnotesize
was my preference, but a list of sizes is available here