-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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