summarylogtreecommitdiffstats
path: root/0001-biber-nocite-star.patch
blob: dac941b63cee19dc1a88b073cacc864caf0087fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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: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:
@@ -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})