Convert Markdown to PDF in Sublime Text

Sublime Text is an awesome text editor that has a ton of useful extensions that can be installed through the Package Manager that make it even better. One of my favorite parts of emacs is org-mode, this allows you to organize your life, make awesome notes, and even perform spreadsheet calculations all from with in the emacs text editor. The best part about org-mode is that you can export your documents to HTML, PDF, and LaTex. In my opinion, sublime text is almost a modern successor to emacs because a lot of the extensions that have been developed for Sublime Text allow you to do fancy things like this as well.

I am a huge fan of Markdown, It makes writing structured documents super simple, and is especially useful when your documents contain code snippets. As a CS student, I am often writing papers that include code snippets and this is not handled very well in most word processors. Org-mode does a great job of creating documents with code snippets, and I was excited to find out that with a few extensions to Sublime text you can make beautiful documents including code with little to no hassle.

The following steps are being done with Sublime Text 3 running on Debian Testing, the steps may be a bit different for other Operating Systems. In order to make beautiful documents with code snippets in Sublime Text you will need to do the following.

  1. If you have not already install Package Control
  2. Install MarkdownEditing in Sublime Text
  3. Install Pandoc in Sublime Text
  4. Install Pandoc in Debian
  5. Install TexLive in Debian (this is to convert things to PDF)

sudo apt-get install pandoc texlive

We are going to be leveraging the awesome tools that are provided by pandoc in order to make really cool things happen with our text editor! This even supports syntax highlighting! Once you have installed all of those pre requisites you can save a text file as markdown using the .md extension and then convert it to HTML, PDF, or other formats using pandoc. Simply open the command launcher with Control+Shift+P type in pandoc and select your output format.

Now you can turn this:

Sample Python Code

Sample Python Code

Into this:

Sample Python Code Pdf

Sample Python Code Pdf

Awesome! Next steps are to level up your Sublime Text skills with Mastering Sublime Text.

If you made it this far, you should probably follow me on twitter. 🙂

This entry was posted in Hacking. Bookmark the permalink.

9 Responses to Convert Markdown to PDF in Sublime Text

  1. Pingback: Built in PDF Magic in Debian « levlaz

  2. Nahuel says:

    Hi there, how do I get the outcome as a pdf? thanks!

  3. levlaz says:

    Are you using Linux?

  4. Nahuel Sznajderhaus says:

    I normally use texshop and I can compile pdflatex no problem. However, in sublime I used pandoc pdflatex and it didn’t work, it says: “pandoc: /usr/texbin/pdflatex not found. /usr/texbin/pdflatex is needed for pdf output”

    do you know how I fix this or how to check what’s wrong?

    • levlaz says:

      Hey Nahuel,

      Which operating system are you doing this on?


      • Nahuel Sznajderhaus says:

        thanks, I use Mac

        • Nahuel Sznajderhaus says:

          I fixed this. I just had to change /usr/texbin/ by /Library/TeX/texbin/ in Sublime Text 2>Preferences>Package Settings>Pandoc>Settings-Default

          What’s next? How to use citations where the references are in an external .bib file?

  5. Pingback: Terminal Reader Mode with Pandoc and Less | levlaz

Leave a Reply

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