Skip to content

Instantly share code, notes, and snippets.

@ihincks
Created September 10, 2014 16:48
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 ihincks/9e5bb2ec0dd49a2c574b to your computer and use it in GitHub Desktop.
Save ihincks/9e5bb2ec0dd49a2c574b to your computer and use it in GitHub Desktop.
Call bibtex on all .aux files in directory with given base.
#!/usr/bin/python
'''
A call to this script
multi-bibtex [options] texfile[.aux]
will result in the commands
bibtex [options] file.aux
being called for every file in the folder of texfile which
starts with "texfile".
This is useful, for example, when you want to use bibtex
(as opposed to biber which does what we want automatically)
with the tex package biblatex's environment refsection,
which creates multiple .aux files, one for each refsection.
'''
import sys
import os
import subprocess
if __name__ == "__main__":
filename = sys.argv[-1]
args = sys.argv[1:-2]
suffix = '.aux'
bibtex = 'bibtex'
folder = os.path.dirname(os.path.abspath(filename))
texfile = os.path.basename(filename)
if suffix in texfile:
texfile = texfile[:-4]
for f in os.listdir(folder):
if texfile in f and suffix in f:
cmd = [bibtex] + args + [f]
print ">>> Calling: {}".format(" ".join(cmd))
subprocess.call(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment