def run(self): """Process .bib files, set file dependencies, and create a node that is to be transformed to the entries of the bibliography. """ env = self.state.document.settings.env cache = env.bibtex_cache.bibliographies # create id and cache for this node # this id will be stored with the node # and is used to look up additional data in env.bibtex_cache # (implementation note: new_serialno only guarantees unique # ids within a single document, but we need the id to be # unique across all documents, so we also include the docname # in the id) id_ = 'bibtex-bibliography-%s-%s' % (env.docname, env.new_serialno('bibtex')) info = BibliographyCache( docname=env.docname, cite=("all" if "all" in self.options else ("notcited" if "notcited" in self.options else ("cited"))), list_=self.options.get("list", "citation"), enumtype=self.options.get("enumtype", "arabic"), start=self.options.get("start", 1), style=self.options.get("style", "plain"), encoding=self.options.get( 'encoding', 'latex+' + self.state.document.settings.input_encoding), curly_bracket_strip=('disable-curly-bracket-strip' not in self.options), labelprefix=self.options.get("labelprefix", ""), ) if (info.list_ not in set(["bullet", "enumerated", "citation"])): env.app.warn("unknown bibliography list type '{0}'.".format( info.list_)) for bibfile in self.arguments[0].split(): # convert to normalized absolute path to ensure that the same file # only occurs once in the cache bibfile = os.path.normpath(env.relfn2path(bibfile.strip())[1]) self.process_bibfile(bibfile, info.encoding) env.note_dependency(bibfile) info.bibfiles.append(bibfile) cache[id_] = info return [bibliography('', ids=[id_])]
def run(self): """Process .bib files, set file dependencies, and create a node that is to be transformed to the entries of the bibliography. """ env = self.state.document.settings.env # create id and cache for this node # this id will be stored with the node # and is used to look up additional data in env.bibtex_cache # (implementation note: new_serialno only guarantees unique # ids within a single document, but we need the id to be # unique across all documents, so we also include the docname # in the id) id_ = 'bibtex-bibliography-%s-%s' % ( env.docname, env.new_serialno('bibtex')) if "filter" in self.options: if "all" in self.options: env.app.warn(standout(":filter: overrides :all:")) if "notcited" in self.options: env.app.warn(standout(":filter: overrides :notcited:")) if "cited" in self.options: env.app.warn(standout(":filter: overrides :cited:")) try: filter_ = ast.parse(self.options["filter"]) except SyntaxError: env.app.warn( standout("syntax error in :filter: expression") + " (" + self.options["filter"] + "); " "the option will be ignored" ) filter_ = ast.parse("cited") elif "all" in self.options: filter_ = ast.parse("True") elif "notcited" in self.options: filter_ = ast.parse("not cited") else: # the default filter: include only cited entries filter_ = ast.parse("cited") bibcache = BibliographyCache( list_=self.options.get("list", "citation"), enumtype=self.options.get("enumtype", "arabic"), start=self.options.get("start", 1), style=self.options.get("style", "alpha"), filter_=filter_, encoding=self.options.get( 'encoding', 'latex+' + self.state.document.settings.input_encoding), curly_bracket_strip=( 'disable-curly-bracket-strip' not in self.options), labelprefix=self.options.get("labelprefix", ""), labels={}, bibfiles=[], ) if (bibcache.list_ not in set(["bullet", "enumerated", "citation"])): env.app.warn( "unknown bibliography list type '{0}'.".format(bibcache.list_)) for bibfile in self.arguments[0].split(): # convert to normalized absolute path to ensure that the same file # only occurs once in the cache bibfile = os.path.normpath(env.relfn2path(bibfile.strip())[1]) self.process_bibfile(bibfile, bibcache.encoding) env.note_dependency(bibfile) bibcache.bibfiles.append(bibfile) env.bibtex_cache.set_bibliography_cache(env.docname, id_, bibcache) return [bibliography('', ids=[id_])]