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?
settings>editor>editor settings(press 'choose')>here u will get font/font style/size....and selecting your preferable size..> ok...
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 .
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,...).
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}
---
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With