Skip to content

Instantly share code, notes, and snippets.

@tskrynnyk
Forked from dsanson/extract_pandoc_bib.sh
Created November 9, 2011 08:55
Show Gist options
  • Save tskrynnyk/1350889 to your computer and use it in GitHub Desktop.
Save tskrynnyk/1350889 to your computer and use it in GitHub Desktop.
produce a bibtex file with only the pubs referred to by a pandoc file
#!/bin/sh
# Generate a bibtex file just containing those publications cited in
# a given pandoc document. To use
#
# extract_pandoc_bib.sh myfile.markdown
#
# this will generate `myfile.bib`.
bib="$HOME/.pandoc/default.bib"
inputfile="$1"
outputbib="${inputfile%.*}.bib"
olddir=$(pwd)
thisprocess=$(basename "$0")
tmpdir=$(mktemp -d -t ${thisprocess}_XXX)
tmptex="$tmpdir/file.tex"
tmpaux="$tmpdir/file.aux"
pandoc -t latex --bibliography="$bib" --natbib -s "$inputfile" -o "$tmptex" 2> /dev/null
cd "$tmpdir"
latex file.tex
bibtool -i "$bib" -x file.aux > file.bib
cd "$olddir"
mv "$tmpdir/file.bib" "$outputbib"
rm -rf "$tmpdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment