Using pandoc to convert Markdown to PDF

7 March 2019

Pandoc can be used to create a PDF from a markdown file like this

pandoc -o out.pdf && open out.pdf

If you use the defaults it make your doc look like an academic paper. The reason for this is that this is what latex does by default. To fix this, add some YAML to the top of your doc, like the below:

geometry: left=2.5cm,right=2.5cm,top=3cm,bottom=3cm
output: pdf_document
fontsize: 12pt
papersize: a4
documentclass: report
fontfamily: palatino
header-includes: |

To explain further what is going on here:

  • geometry is a commonly used latex package which allows you to specify your own margins
  • the header-includes part turns off the rather annoying prepending of ‘Figure x: ’ to any images you include

It is also worth noting that with pandoc on MacOS via brew comes BasicTex, which is a smaller latex distro. For the full enchilada you can get MacTex instead:

brew install --cask mactex

Note that MaxTex is > 1gb and BasicTex is < 100mb, so there is a size penalty. If space is at a premium it is possible to go the BasicTex route and then just add packages. See for more on this.

This may also be of interest on image sizing: