Skip to content

Commit

Permalink
make biber task work with \nocite{*} by parsing bcf file for cites
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdi265 committed Oct 10, 2023
1 parent 38ff6ec commit 7a3d98a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions latexrun
Original file line number Diff line number Diff line change
Expand Up @@ -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:citekey [^>]*>', 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:
Expand Down Expand Up @@ -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})

Expand Down

0 comments on commit 7a3d98a

Please sign in to comment.