Writing in Markdown & Converting Markdown to PDF24 December 2012
I've discovered markdown a while back, when I've started using Symphony-CMS, I found markdown was clean simple to understand and allows me to do what I wanted without too much hassle, write. Indeed such was its simplicity, that I changed by Blog to allow me to write using markdown. No more formatting issues there; however I then required something more production of reports, thus I wanted my Markdown to be converted into PDF.
My First line of thought, and early use was to produce this onilne, Feed the Markdown to Symphony as usual and produce my standard HTML, then I would add on a pdf-generating extension which takes care of generating the pdf document for myself. I've tried this and it worked out nicely, the url2pdf extension provided a very good service as long as what I needed to do was going to be online and in single pages.
However I eventually wanted to start writing my own dissertation, previously I had been annoyed with using a Word Editor & inDesign, whilst they do their job its an overkill design wise and the documents just get too big to process. So I opted to start writing in Markdown, tracking all the changes using github, that way I could see and follow up my writing from anywhere. The only question-mark I had was how to eventually generate my Dissertation PDF without having to copy the finalized content over to something else.
That led me to start searching for ways of converting multi-page html documents to PDF, and then markdown to Latex since I knew latex was quite popular for document writing, except it was a new syntax for me so I'd prefer to use markdown. Then along that search I cam across Pandoc.
Markdown to PDF with Pandoc
First of all I have to say that Pandoc has been a life-saver, it allows content to be changed from/to various formats. Markdown, Latex and PDF are just 3 of them, it also has stuff like word processor and open office support.
Conversion from Markdown to PDF is fairly easy, pandoc comes up with a standard latex-template which you can modify, its great if you write a lot of reports and research papers which have to be submitted in various formats as you would just have to replace the template and your markdown content is straight away transformed into the pdf document with the right styling.
All you would need to do to convert your Markdown to PDF is the following:
- Install pandoc (you can use your package manager on linux)
- Make sure that you have latex2pdf and bibliography packages if required installed (some packages of pandoc don't have these as required)
- just run the pandoc command.
pandoc -o output.pdf input1.md input2.md
- Add optionals such as
--tocfor a Table of Contents
--bibliography mybibliography.bibfor a Bibliography
--csl bibliographytemplate.cslfor a particular Bibliography style
--template template.texto use your own particular template
- Then just wait a few seconds and you have your finalized PDF