Press "Enter" to skip to content

Markdown to PDF in MacOSX

I tend to use markdown almost unconsciously when taking notes or expressing thoughts or ideas in a text editor. But on several occasions I’ve had the need to share what I’ve written with a non technical person and handing off markdown to them seems a bit so-so. So after a few of these incidences I settled the matter and decided to investigate if there was an easy way to just generate a pdf file from markdown from the command-line in MacOSX. A quick tour on google and you’ll find this excellent gist that describes more or less how to get it working. The problem was that everything didn’t quite work for me (I later found out that a fix was written in the comment but I didn’t know at the time). These are the two things that I had to do differently:

  1. When it says that you should do brew tap phinze/cask I simply ignored this step and went directly to brew cask install mactex
  2. When it’s time to create a symlink the gist instructs us to do sudo ln -s /usr/texbin/pdflatex /usr/local/bin/ but instead I had to do ln -s /Library/TeX/Root/bin/x86_64-darwin/pdflatex /usr/local/bin/pdflatex

Here are the instructions in its entirety:

Now you should be able to run pandoc from the command-line and generate pdfs like this:

Great! But I’m not using pandoc regularly so in order to make it a little easier to remember I wrote a small bash script that I’ve named md2pdf:

After some chmod +x md2pdf and having copied it to /usr/local/bin this allows me to simply write:

and it’ll generate a file called some.pdf. It’s also possible to specify another directory or filename if you like:

That’s it!

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *