Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix \nocite{*} not triggering biber task by parsing bcf file for citations #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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