tmaric tmaric - 1 year ago 392
LaTeX Question

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

this small example:

An example code snippet:

class A
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

Font sizes of the code snippet and the text are equal.

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 Source

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download