From 7a3d98a55c04c4bb9f1a51c0da988235ae9962b5 Mon Sep 17 00:00:00 2001 From: Ferdinand Bachmann Date: Tue, 10 Oct 2023 12:49:18 +0200 Subject: [PATCH] make biber task work with \nocite{*} by parsing bcf file for cites Fixes #57 --- latexrun | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/latexrun b/latexrun index b669d9f..65d604d 100755 --- a/latexrun +++ b/latexrun @@ -1507,13 +1507,27 @@ class BibTeX(Task): # affecting system state. Hence, this task is trivially # stable. return True - if not self.__find_bib_cmds(os.path.dirname(jobname), jobname + '.aux'): + if not self.__find_bib_cmds(os.path.dirname(jobname), jobname + '.aux') and \ + not self.__find_bcf_entries(os.path.dirname(jobname), jobname + '.bcf'): # The tex file doesn't refer to any bibliographic data, so # don't run bibtex. return True return super().stable() + def __find_bcf_entries(self, basedir, bcfname): + debug('scanning for citations in {}'.format(bcfname)) + try: + bcf_data = open(bcfname, errors='surrogateescape').read() + except FileNotFoundError: + # The bcf file may not exist if latex aborted + return False + + if re.search(']*>', bcf_data, flags=re.M): + return True + + return False + def __find_bib_cmds(self, basedir, auxname, stack=()): debug('scanning for bib commands in {}'.format(auxname)) if auxname in stack: @@ -1629,7 +1643,7 @@ class BibTeX(Task): if self.__is_biber(): outbase = os.path.join(cwd, outbase) - outputs = [outbase + '.bbl', outbase + '.blg'] + outputs = [outbase + ext for ext in ('.bbl', '.blg', '.bcf')] return RunResult(outputs, {'outbase': outbase, 'status': status, 'inputs': inputs})