# Changing font size in all fancyvrb from Jupyter Notebook (nbconvert)

I generated latex file from Jupyter Notebook using nbconvert. I need to change the font size in all Verbatim (fancyvrb) enviroments. I tried but nothing I know of works.

Here is all the settings from tex file http://pastebin.com/ThaeQEgc. I don't know where to put the fontsize=\scriptsize.

Thanks.

If you're using nbconvert, the easiest way to configure the tex output is to convert your .ipynb file to a .tex file and edit it directly before conversion to pdf.

However, that's a lot of manual work and not easily reproducible. And no one likes that.

A slightly more complicated solution is to use a custom template file and use that for the export (by using the --template=my_template_file.tplx flag).

Edit: Quickest approach I can think of has 6 steps:

1. copy document_contents.tplx to a new file and change the invocations of \begin{Verbatim} to include whichever options you want. Save as a separate file (e.g., my_document_contents.tplx).
2. copy base.tplx to a new file and have it extend my_document_contents.tplx instead of document_contents.tplx. Save as a separate file (e.g., my_base.tplx)
3. copy style_ipython.tplx to a new file. Change the file it extends to my_base.tplx, change invocations of \begin{Verbatim} to include whichever options you want. Save as a separate file (e.g., my_style_ipython.tplx).
4. copy article.tplx to a new file and have it extend my_style_ipython.tplx. save as a separate file (e.g., my_article.tplx).
5. Make sure all of these templates are on your template path…(which is a more complicated topic… the easiest solution is to have them in the same directory that you are using to invoking the jupyter nbconvert command).
6. invoke nbconvert with the --template my_article.tplx.

# Notes on the current template dependency/extension structure:

nbconvert relies on Jinja based templates and template inheritance. This has some drawbacks when it comes to LaTeX templates (and is largely why it's not more directly configurable…working on that :)).

As a first pass, look at base.tplx to see where the current preamble is being created.

You probably will need to include something like the document_contents.tplx in order to make sure that your outputs display properly. base.tplx extends this, so you may not need to change anything after all… just be aware that it may be necessary for your particular use case.

Cells will be formatted by the choice of cell style (the default is style_ipython.tplx), which directly extend the base.tplx template.

Finally, not much happens in it, but if you are using the defaults from the LatexExporter (which I'm gathering that you are if you are using direct to pdf conversion) you are using the article class via the article.tplx. The most useful part about this is that it gives an example of how you can dynamically determine which other templates to inherit from.

If you want to edit a single generated .tex file you can add in the preample

\DefineVerbatimEnvironment{Verbatim}{Verbatim}{fontsize=\footnotesize}


to change the font size globally for all Verbatim environments.