Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

latex

pandoc

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

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?

like image 244
tmaric Avatar asked Nov 18 '14 18:11

tmaric


People also ask

How do you change the font size in code blocks?

settings>editor>editor settings(press 'choose')>here u will get font/font style/size....and selecting your preferable size..> ok...

How do I change the font in pandoc?

Get the default tex template from pandoc by running pandoc -D latex and then add the font definitions you want to the document. save as my-font. latex . Then run pandoc with the switch --template=my-font .

How do I increase font size in markdown?

To change the font size, you don't need to know a lot of html for this. Open the html output with notepad ++. Control F search for "font-size". You should see a section with font sizes for the headers (h1, h2, h3,...).


2 Answers

You can simply add \small before the beginning of the code snippet and \normalsize after (to return to normal).

You can also add other similar commands. For instance, if your document is doublespaced, you can add \singlespace before the code snippet and \doublespacing after.

For this to work you need to add in the yaml at the beginning of your document the following:

---
header-includes:
    - \usepackage{setspace}
---
like image 190
Vlad Avatar answered Sep 19 '22 16:09

Vlad


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.

like image 20
Kurt Pfeifle Avatar answered Sep 18 '22 16:09

Kurt Pfeifle