Pandoc and Hanging Indents

Writing academic papers with Markdown and Pandoc is rather straightforward, and Pandoc does a rather bang-up job in its export - with one exception. It doesn’t create a hanging indent for references. Some citation styles require a hanging indent.

Its possible to go ahead and export the Markdown to .docx, open that output in Word, and reformat the reference section. I could, but I won’t. For one reason, I don’t have Office on my Linux machines (my OS of choice). The main reason though, is that I’m lazy. If I can automate a thing, I’d rather do that so that I can get on with other work at hand - like writing.

There is a way to get the hanging indents. I wish I could take the credit for this, but I won’t. At the same time, I can’t, for the life of me, find the source. I have it noted somewhere, but I just can’t find it. So, if you want to thank someone, and you find it on a search (I think I found this solution on a Stack Overflow post, but I’m not certain), thank them, not me.

A very basic academic paper, written with Markdown, might have a format that looks like this:

---
title: A Short Paper Example
author:
- Bill Dyer
- Joe Smuckatelli
date: July 29, 2018
bibliography: /home/bdyer/Documents/library.bib 
abstract: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
---

# Introduction

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua [@Rohr2015]. Notice that citation there [@Coski2015]. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

# Theory

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua [@Frederiksen2015]. Ut enimad minim veniam, quis nostrud...

# References

The main sections are:

Your requirements for a paper may be different, as far as headings go, but I’m willing to bet that you’ll need to state your references, so that section (call it References, Works Cited, or what have you) will be a part of the paper. Just make sure you put the References heading last since Pandoc always puts the list of sources at the bottom of the document (where they should be anyway).

Inside the sample text, you’ll see a few citekeys that look like this.

[@Rohr2015], [@Coski2015], and [@Frederiksen2015]

How these are used is beyond the scope of this post, but they’re the means by which Pandoc creates the references from the library.bib file. These samples are from a Civil War Paper; they are used here only to serve as example citekeys in this post. Whatever your citekeys, Pandoc will pull the right reference from your .bib file. It will put them in the right order too, it just seems to have trouble with hanging indents.

To get hanginging indents, place the following code underneath the References heading:

# References

\noindent  

\vspace{-1em}  
\setlength{\parindent}{-0.2in}  
\setlength{\leftskip}{0.2in}  
\setlength{\parskip}{8pt}

The code will not appear in your paper. Instead, it will be read by Pandoc and references, with hanging indents, will appear.

At first glace, the top line: \noindent looks out of place. The first line of a reference isn’t indented - only the subsequent wrapped lines are. The rest of the code ensures the hanging indent of those wrpapped lines.