Skip to content

Instantly share code, notes, and snippets.

@habi
Last active November 17, 2022 14:21
Show Gist options
  • Save habi/33ac11302444dd13cfe93c220ecf5cbd to your computer and use it in GitHub Desktop.
Save habi/33ac11302444dd13cfe93c220ecf5cbd to your computer and use it in GitHub Desktop.
My makefile, based on http://git.io/GIs6og
## 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 = /home/habi/P/Documents/library.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)
ODT=$(SRC:.md=.odt)
## Targets
all: $(PDFS) $(HTML) $(TEX) $(DOC) $(ODT)
pdf: $(PDFS)
html: $(HTML)
tex: $(TEX)
doc: $(DOC)
odt: $(ODT)
%.html: %.md
pandoc -w html5 -s --bibliography=$(BIB) -o $@ $<
rename.ul \. _$(ID)\. $@
%.tex: %.md
pandoc -w latex -s --bibliography=$(BIB) -o $@ $<
rename.ul \. _$(ID)\. $@
%.pdf: %.md
pandoc -s --output="/tmp/$@" --bibliography=$(BIB) $<
mv "/tmp/$@" $@
rename.ul \. _$(ID)\. $@
%.docx: %.md
pandoc -s --output="/tmp/$@" --bibliography=$(BIB) --csl=https://raw.githubusercontent.com/citation-style-language/styles/master/ieee-with-url.csl $<
mv "/tmp/$@" $@
rename.ul \. _$(ID)\. $@
clean:
rm *.html *.pdf *.tex *.docx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment