Created
March 18, 2016 11:46
-
-
Save ntim/1fda5e39ed78d4dc057f to your computer and use it in GitHub Desktop.
List unused entries in latex bibliographies by parsing the aux file generated by biber
This file contains hidden or 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
| #!/usr/bin/python | |
| #-*- coding: utf-8 | |
| import os | |
| import glob | |
| from pybtex.database.input import bibtex | |
| from pyparsing import Word, alphanums, Literal | |
| auxfile = glob.glob("*.aux")[0] | |
| bibfiles = [] | |
| parser = bibtex.Parser() | |
| # Parse aux file and read used bib entries. | |
| bib = Word(alphanums) | |
| bibdata = Literal('\\abx@aux@cite{') + bib.setResultsName('bib') + Literal('}') | |
| with open(auxfile, 'r') as file: | |
| tokens = bibdata.searchString(file.read()) | |
| used = [token.bib for token in tokens] | |
| print "Found ", len(used), " used entries in ", auxfile | |
| for fname in os.listdir("./"): | |
| if fname.endswith(".bib"): | |
| # Get list of defined keys | |
| entries = parser.parse_file(fname).entries.items() | |
| available = [entry[0] for entry in entries] | |
| # | |
| print "Found ", len(available), " available entries in ", fname | |
| unused = [entry for entry in available if not entry in used] | |
| print "Unused entries of ", fname, ": ", unused |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment