Skip to content

Instantly share code, notes, and snippets.

@habi
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save habi/9fafd8d4725862f172e7 to your computer and use it in GitHub Desktop.
Save habi/9fafd8d4725862f172e7 to your computer and use it in GitHub Desktop.
Document preparation from Markdown to PDF/DOC/HTML with bibliography

% Title Subtitle % Author % 26.11.2014

Introduction

This is the indtroduction to the document

Materials and Methods

Here you describe your methods, most probably with citations, in the form of [@SomeBibTeX-key].

Usage

To convert the document to PDF/DOC/HTML, you

  • have to install pandoc
  • add the document to a git repository
  • use the makefile above (change the path to your BibTeX file)

Then just

make pdf

make doc

or

make html

to get a PDF, Word or HTML file, respectively. The file name will be appended with the current git hash, so it's perfect to sending around to collaborators.

Watch out, all PDF, Word and HTML files in the current folder will be deleted during the process. But since the underlying Markdown file is safe, we can always regenerate them (and we have everything in a git repository anyways...).

## Makefile based on http://git.io/GIs6og
## Define standard Markdown extension
MEXT = md
## All markdown files in the working directory
SRC = $(wildcard *.$(MEXT))
## Bibliography
BIB = /path/to/your/bibliography.bib
## Get last commit hash
ID := $(shell git log --oneline --no-color | cut -c -6 | head -n 1)
## File names
PDFS=$(SRC:.md=.pdf)
HTML=$(SRC:.md=.html)
TEX=$(SRC:.md=.tex)
DOC=$(SRC:.md=.docx)
## Targets
all: $(PDFS) $(HTML) $(TEX) $(DOC)
pdf: clean $(PDFS)
html: clean $(HTML)
tex: clean $(TEX)
doc: clean $(DOC)
%.html: %.md
pandoc -w html5 -s -S --bibliography=$(BIB) -o $@ $<
rename.ul .html _$(ID).html *.html
%.tex: %.md
pandoc -w latex -s -S --bibliography=$(BIB) -o $@ $<
rename.ul .tex _$(ID).tex *.tex
%.pdf: %.md
pandoc -s -S --bibliography=$(BIB) -o $@ $<
rename.ul .pdf _$(ID).pdf *.pdf
%.docx: %.md
pandoc -s -S --bibliography=$(BIB) -o $@ $<
rename.ul .docx _$(ID).docx *.docx
clean:
rm -f *.html *.pdf *.tex *.docx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment