def preExecute(self): set_strict_mode( False) # allow incorrectly formatted author/editor names # If this is invoked during a live serve, we need to recompile the list of '.bib' files and # read them again, otherwise there's no way to distinguish existing entries from duplicates self.__bib_files = [] for node in self.translator.findPages( lambda p: p.source.endswith('.bib')): self.__bib_files.append(node.source) self.__database = BibliographyData() for bfile in self.__bib_files: try: db = parse_file(bfile) self.__bib_file_database[bfile] = db except UndefinedMacro as e: msg = "The BibTeX file %s has an undefined macro:\n%s" LOG.warning(msg, bfile, e) #TODO: https://bitbucket.org/pybtex-devs/pybtex/issues/93/ # databaseadd_entries-method-not-considering for key in db.entries: if key in self.__database.entries: if self.get('duplicate_warning') and ( key not in self.get('duplicates')): msg = "The BibTeX entry '%s' defined in %s already exists." LOG.warning(msg, key, bfile) else: self.__database.add_entry(key, db.entries[key])
def preExecute(self): duplicates = self.get('duplicates', list()) set_strict_mode(False) self.__database = BibliographyData() self.__bib_files = [] for node in self.translator.getPages(): if node.source.endswith('.bib'): self.__bib_files.append(node.source) for bfile in self.__bib_files: try: db = parse_file(bfile) self.__bib_file_database[bfile] = db except UndefinedMacro as e: msg = "The BibTeX file %s has an undefined macro:\n%s" LOG.warning(msg, bfile, e) #TODO: https://bitbucket.org/pybtex-devs/pybtex/issues/93/ # databaseadd_entries-method-not-considering warn = self.get('duplicate_warning') for key in db.entries: duplicate_key = key in self.__database.entries duplicate_key_allowed = key in duplicates if duplicate_key and (not duplicate_key_allowed): if warn: msg = "The BibTeX entry '%s' defined in %s already exists." LOG.warning(msg, key, bfile) elif not duplicate_key: self.__database.add_entry(key, db.entries[key])
def handleNewBib(fileName): """ Handle a BibTeX file that has just appeared in the drop folder. :param fileName: The name of the new BibTeX file. """ clipboard = "" pybtexErrors.set_strict_mode(False) # do not exit on an exception bib_data = readBib(fileName) mode = Modes.REGULAR index = -1 count = len(bib_data.entries) # Doing it in two separate loops, # so all entries would get the same time stamp. newEntries = {} for key in bib_data.entries: index += 1 entry = bib_data.entries[key] newKey = keygen(entry) # '' -- no author, i.e. the venue itself if newKey == '' or newKey == 'BadKey': continue (newKey, mode) = duplicateCheck(newKey, mode, index < count - 1) if newKey == 'BadKey': continue # the user decided to not create duplicate entry # delete the crossref field; using a hack (access to _dict and order) try: entry.fields._dict.pop('crossref') entry.fields.order.remove('crossref') except: pass newEntries[newKey] = entry for newKey in newEntries: entry = newEntries[newKey] paperDir = config.PAPERS_DIR + newKey bibFileName = paperDir + "/paper.bib" orgFileName = paperDir + "/paper.org" try: #pdb.set_trace() os.system("mkdir -p " + paperDir) # create the paper directory saveEntry(newKey, entry, bibFileName) os.system("touch " + orgFileName) # create the org file clipboard += newKey + ',' #pyperclip.copy(clipboard[:-1]) os.system("echo -n {s} | xsel -bi".format(s=clipboard[:-1])) except: tkMessageBox.showerror( 'LiteRef Error', 'Could not create the files for the key: ' + newKey + '\nAbandoning the key.') config.root.update() os.system("mv {fileName} {archive}".format(fileName=fileName, archive=config.DROP_DIR + ".last.bib"))
def main(self): errors.set_strict_mode(False) argv = self.recognize_legacy_optons(sys.argv[1:]) options, args = self.opt_parser.parse_args(argv) if len(args) != self.num_args: self.opt_parser.print_help() sys.exit(1) kwargs = self._extract_kwargs(options) self.run(*args, **kwargs) sys.exit(errors.error_code)
def main(path, strict=False): set_strict_mode(strict) loop = asyncio.get_event_loop() newbib = loop.run_until_complete(fix_bibtex(path)) basename, ext = os.path.splitext(path) newbib_path = '{}.new{}'.format(basename, ext) newbib.to_file(newbib_path) oldbib_path = '{}.old{}'.format(basename, ext) parse_bibfile(path).to_file(oldbib_path) print('\nPatched file:', newbib_path) print('Original file:', oldbib_path) print('Use a diff tool to see changes:') print(' ', _difftool(), oldbib_path, newbib_path)
def is_valid_bibtex(reference): """ Use pybtex to validate that a reference is in proper BibTeX format Args: reference: A String reference in BibTeX format. Returns: Boolean indicating if reference is valid bibtex. """ # str is necessary since pybtex seems to have an issue with unicode. The # filter expression removes all non-ASCII characters. sio = StringIO(remove_non_ascii(reference)) parser = bibtex.Parser() errors.set_strict_mode(False) bib_data = parser.parse_stream(sio) return len(bib_data.entries) > 0
def backwards_search(file): set_strict_mode(False) bibfile = parse_file(file) entries = bibfile.entries.values() #entries = entries[0:7] pool = Pool(processes=8) rows = [] for result in pool.imap(get_references_for_entry, entries): if result: entry, refs = result entry_name = get_entry_name(entry) for ref in refs: ref_name = clean_raw_ref(ref["raw_ref"][0]) rows.append((entry.key, entry_name, ref_name)) df = DataFrame(rows, columns=['paper_key', 'paper_name', 'ref_name']) return df
def make_standard_option(*args, **kwargs): option = make_option(*args, **kwargs) PybtexOption.STANDARD_OPTIONS[option.dest] = option return option def standard_option(name): return PybtexOption.STANDARD_OPTIONS[name] make_standard_option( '--strict', dest='strict', help='turn warnings into errors', action='callback', callback=lambda option, opt, value, parser: errors.set_strict_mode(True)) make_standard_option( '-f', '--bibliography-format', dest='bib_format', help='bibliograpy format (%plugin_choices)', type='load_plugin', plugin_group='pybtex.database.input', metavar='FORMAT', ) make_standard_option( '-b', '--output-backend', dest='output_backend',
#Synthesize LaTeX author compilation from .bib and processed .aux #Brygg Ullmer, Clemson University #Begun 2021-02-27 #https://stackoverflow.com/questions/30768745/is-there-a-reliable-python-library-for-taking-a-bibtex-entry-and-outputting-it-i from pybtex.database.input import bibtex from pybtex import errors import pandas as pd import sys errors.set_strict_mode(False) parser = bibtex.Parser() bib_data = parser.parse_file('tangibles-common6.bib') citationsFn = 'citations4.txt' citationsF = open(citationsFn, 'r+t') lines = citationsF.readlines() citations = {} for line in lines: cleanline = line.rstrip() citations[cleanline] = True authors = {} for el in bib_data.entries: bibref = str(el) #if bibref in citations: # print('Y', bibref) #else: # print('N', bibref)
def make_standard_option(*args, **kwargs): option = make_option(*args, **kwargs) PybtexOption.STANDARD_OPTIONS[option.dest] = option return option def standard_option(name): return PybtexOption.STANDARD_OPTIONS[name] make_standard_option( '--strict', dest='strict', help='turn warnings into errors', action='callback', callback=lambda option, opt, value, parser: errors.set_strict_mode(True) ) make_standard_option( '-f', '--bibliography-format', dest='bib_format', help='bibliograpy format (%plugin_choices)', type='load_plugin', plugin_group='pybtex.database.input', metavar='FORMAT', ) make_standard_option( '-b', '--output-backend', dest='output_backend', help='output backend (%plugin_choices)', type='load_plugin', plugin_group='pybtex.backends',