tmaric - 7 months ago 140
LaTeX Question

# How to set the font size for code blocks in pandoc markdown?

this small example:

An example code snippet:

~~~{.cpp}
class A
{
public:
static void f1 () {};

virtual void f2 () = override;
};
~~~


can be used to generate a PDF output with:

pandoc -o block-code.pdf block-code.txt


resulting in

The font sizes of both the code and the text that are equal. How can I change the font size of the code snippets for the pdf (LaTex) pandoc output?

Answer

I solved this problem for me by writing several LaTeX snippets into extra files I keep around:

 cat make-code-footnotesize.tex

\renewenvironment{Shaded} {\begin{snugshade}\footnotesize} {\end{snugshade}}


I have such snippets for all different sizes: huge, LARGE, Large, large, normalsize, small, footnotesize, scriptsize, tiny.

To apply them when running pandoc, just include the respective LaTeX snippet with the -H parameter:

 pandoc -o block-code.pdf block-code.txt \
-H make-code-scriptsize.tex --highlight-style=espresso


Result:

Note, this controls the font sizes for all code blocks in the PDF. It does not allow you to vary sizes from block to block. Of course, it also doesn't work for HTML, ODT, EPUB or other output -- only for LaTeX and PDF output.