Skip to content

Instantly share code, notes, and snippets.

@yoavram
Created December 16, 2012 09:00
Show Gist options
  • Save yoavram/4305736 to your computer and use it in GitHub Desktop.
Save yoavram/4305736 to your computer and use it in GitHub Desktop.
How to create PDF, EPUB and mobile-PDF with Pandoc

% Creating PDFs with Pandoc % Yoav Ram % 2012-12-16 11:36:00 +2

Overview

This post will show how to convert a Markdown document to PDF, mobile-PDF and EPUB documents using Pandoc. The guide is not exhastive but rather a walkthrough of my own experiments. The mobile-PDF especially is lacking - it is based on somewhat advanced $LaTeX$, and I'm a novice user of that language.

The source Markdown file use for this post, creating-pdfs-with-pandoc.md, is available as a gist.

Simple PDF rendering

> pandoc creating-pdfs-with-pandoc.md -o creating-pdfs-with-pandoc.pdf

See result

With bibliography

> pandoc creating-pdfs-with-pandoc.md -o creating-pdfs-with-pandoc.pdf --bibliography=<path to bibtex file> [--csl=<path to csl file>] [--toc]

The CSL file is optional, if ommited Pandoc uses Chicago-style citations. You can find more information on citation styles at http://citationstyles.org/. If you add the --toc option Pandoc will add a table of contents.

See result

Creating EPUB

> pandoc creating-pdfs-with-pandoc.md -o creating-pdfs-with-pandoc.epub --bibliography=<path to bibtex file> [--csl=<path to csl file>] [--toc]

On Windows 7 you can open EPUB files with Calibre.

See result

Creating PDFs for mobile phones

This is following the discussion on tex.stackexchange, and using a Pandoc latex template which merges the default template with this one. Here is the template as a gist. Remember to put the template in Pandoc's template folder (on Windows 7, C:\Program Files (x86)\Pandoc\templates).

> pandoc creating-pdfs-with-pandoc.md -o creating-pdfs-with-pandoc.iphone.pdf -s --template=iphone-pandoc-template.latex --bibliography=<path to bibtex file> [--csl=<path to csl file>] [--toc]

This rendering is not so good - pages are split strangely and code segements are cropped. If anyone wants to play around with the template, I'll be happy to post the results.

See result

Sample text with math, code and citation

Here is a reference [@Kimura1966], and also a link to my blog Mutation-Selection Blog. Here's a footnote1 that you can see on the bottom.

One of my favorite mathematical expressions is the triangle ineuqality:

$$ \forall{x,y} ; |x + y| \leq |x| + |y| $$

And a piece of Python code:

for x in [p for p in posts if p['author'] == 'yoavram']:
	print x['date']
print 'done'

References

Footnotes

  1. Footnotes are great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment