Last week I was asked to write up a fee schedule for our statistical consulting, so I thought it was as good as time as always to try out Pandoc. I’d been seeing it mentioned whenever I looked up an issue with Markdown, but this excellent post from R-Bloggers aptly-titled R and My Divorce From Word convinced me with a paltry amount of effort to give it a shot.
Install Haskell
One line in the terminal. Ready?
1
|
|
Install Pandoc through the Package Manager
Now, you could do this line next: sudo apt-get install pandoc
Although it is more straightforward this way, you will get a very outdated version of pandoc. Version 1.9, specifically. The most current version is 1.12, which supports reveal.js directly (we’ll get to that soon!)
Install Latest Pandoc via Haskell
Instead, use the Haskell platform you just downloaded to get the most recent, stable version of pandoc.
1 2 |
|
Make sure to update first before you enter the command cabal install pandoc
! Otherwise you will get an error message about the package not existing.
Set the path for your Pandoc: .bashrc and .zshrc
Problem is, your OS won’t be able to find it unless you put it in your path. If you go to your home directory (type ~
in the terminal to get there), followed by the command ls -a
then you will see a new hidden file called .cabal
Awesome. You’ve got Pandoc installed, now tell the OS which folder its in.
For .bashrc (if you don’t have Zsh installed) use the following:
1
|
|
Add this line to the top of your .bashrc file (accessed with the command emacs .bashrc
). Afterwards, don’t forget to source it: source .bashrc
Check if you have the correct version identified with the command pandoc --version
, where the first line of output should be “pandoc 1.12.1”
If you have Zsh installed, go to your .zshrc file with the command emacs .zshrc
Scroll down to the bottom untill you see the comment #Customize to your needs… You will see a whole slew of paths installed. Where to install yours?
1
|
|
It looks like the .bashrc command only its a wee bit different. Look for the colon (:) to deliniate where your command should be entered. Here is an example snippet of my path in Zsh: export PATH=$PATH:/home/becca/.cabal/bin:/home/becca/.rvm/gems/ruby-1.9.3-p448/bin:/home/becca/.rvm/gems/ruby-1.9.3-p448@global/bin:
Don’t forget to source your Zsh file with source .zshrc
, then as usual check if you have the correct version installed with pandoc --version
What’s that? You don’t have Zsh? You’re missing out! Here’s my post on how to install, configure, and use it: Zsh: Oh Myyyyyy
Write markdown documents in Emacs
As mentioned in an earlier post, you can set up a “markdown-mode” in emacs, using a package created by Jason Blevin (See: All Together Now: Markdown Mode). I installed this mode with the primary purpose for Octopress and am delighted the find that this syntax is supported in many other places.
Compile your Documents
After you’ve written your markdown file and want it to be generated in a LaTeX style PDF. This is done with one line: pandoc yourfile.md -o yourfile.pdf
Your PDF will be generated in the same file your current working directory/markdown file is. Brilliant!
Those crazy stupidly huge margins
Ah, but there’s a catch. The margins are quite wide. The solution offered on the website and confirmed by John Farlane is to use the geometry package format: pandoc -V geometry:margin=1in "consultfee.markdown" -o "consultfee.pdf"
Except this generated no difference in margin size for me.
A lengthy, elegant use of Pandoc was offered by Scott Granneman of Chainsaw on a Tire Swing. The part I used to solve my margin problem was the latex formatting section:
Create a .tex file with the command emacs filename.tex
Use the following two lines of code to change your margins.
1 2 |
|
So the final command to fix the large margins by calling in your .tex and .markdown files into one happy PDF looks like this:
1
|
|
And TA-DA! A normal looking PDF. Want to convert to a word file? No problem! pandoc -H consultfee.tex "consultfee.markdown" -o "consultfee.docx"
and like magic, you’ve got yourself a proper Microsoft word document.
To be honest, this solution made me just over the moon about pandoc. Its been about 2 weeks of pandoc use and I have zero need for doing writeups with Libereoffice. That alone should be enough reason to learn how to use it!