]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeX.cpp
Squeeze warning.
[lyx.git] / src / LaTeX.cpp
index 47c2201a51bea2d172a5cabfb1911cb20d358d7c..3e8729adf13313888d9f0defdf7c85339f84e66d 100644 (file)
@@ -122,6 +122,10 @@ void LaTeX::deleteFilesOnError() const
        FileName const bbl(changeExtension(file.absFileName(), ".bbl"));
        bbl.removeFile();
 
+       // biber file
+       FileName const bcf(changeExtension(file.absFileName(), ".bcf"));
+       bcf.removeFile();
+
        // makeindex file
        FileName const ind(changeExtension(file.absFileName(), ".ind"));
        ind.removeFile();
@@ -269,6 +273,12 @@ int LaTeX::run(TeXErrors & terr)
        if (head.haschanged(glofile))
                rerun |= runMakeIndexNomencl(file, ".glo", ".gls");
 
+       // check if we're using biber instead of bibtex
+       // biber writes no info to the aux file, so we just check
+       // if a bcf file exists (and if it was updated)
+       FileName const bcffile(changeExtension(file.absFileName(), ".bcf"));
+       bool const biber = head.exist(bcffile);
+
        // run bibtex
        // if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
        if (scanres & UNDEF_CIT || run_bibtex) {
@@ -278,13 +288,21 @@ int LaTeX::run(TeXErrors & terr)
                // no checks for now
                LYXERR(Debug::LATEX, "Running BibTeX.");
                message(_("Running BibTeX."));
-               updateBibtexDependencies(head, bibtex_info);
-               rerun |= runBibTeX(bibtex_info, runparams);
+               updateBibtexDependencies(head, bibtex_info, biber);
+               rerun |= runBibTeX(bibtex_info, runparams, biber);
+               if (biber) {
+                       // since biber writes no info to the aux file, we have
+                       // to parse the blg file (which only exists after biber
+                       // was first issued)
+                       FileName const blgfile(changeExtension(file.absFileName(), ".blg"));
+                       if (blgfile.exists())
+                               scanBlgFile(head);
+               }
        } else if (!had_depfile) {
                /// If we run pdflatex on the file after running latex on it,
                /// then we do not need to run bibtex, but we do need to
                /// insert the .bib and .bst files into the .dep-pdf file.
-               updateBibtexDependencies(head, bibtex_info);
+               updateBibtexDependencies(head, bibtex_info, biber);
        }
 
        // 2
@@ -330,8 +348,8 @@ int LaTeX::run(TeXErrors & terr)
                // no checks for now
                LYXERR(Debug::LATEX, "Running BibTeX.");
                message(_("Running BibTeX."));
-               updateBibtexDependencies(head, bibtex_info);
-               rerun |= runBibTeX(bibtex_info, runparams);
+               updateBibtexDependencies(head, bibtex_info, biber);
+               rerun |= runBibTeX(bibtex_info, runparams, biber);
        }
 
        // 4
@@ -530,7 +548,8 @@ void LaTeX::scanAuxFile(FileName const & file, AuxInfo & aux_info)
 
 
 void LaTeX::updateBibtexDependencies(DepTable & dep,
-                                    vector<AuxInfo> const & bibtex_info)
+                                    vector<AuxInfo> const & bibtex_info,
+                                    bool biber)
 {
        // Since a run of Bibtex mandates more latex runs it is ok to
        // remove all ".bib" and ".bst" files.
@@ -554,16 +573,22 @@ void LaTeX::updateBibtexDependencies(DepTable & dep,
                                dep.insert(file, true);
                }
        }
+
+       // biber writes nothing into the aux file.
+       // Instead, we have to scan the blg file
+       if (biber) {
+               scanBlgFile(dep);
+       }
 }
 
 
 bool LaTeX::runBibTeX(vector<AuxInfo> const & bibtex_info,
-                     OutputParams const & runparams)
+                     OutputParams const & runparams, bool biber)
 {
        bool result = false;
        for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
             it != bibtex_info.end(); ++it) {
-               if (it->databases.empty())
+               if (!biber && it->databases.empty())
                        continue;
                result = true;
 
@@ -633,6 +658,10 @@ int LaTeX::scanLogFile(TeXErrors & terr)
                                   && contains(token, "undefined")) {
                                retval |= ERROR_RERUN;
                                LYXERR(Debug::LATEX, "Force rerun.");
+                       // package etaremune
+                       } else if (contains(token, "Etaremune labels have changed")) {
+                               retval |= ERROR_RERUN;
+                               LYXERR(Debug::LATEX, "Force rerun.");
                        } else if (contains(token, "Citation")
                                   && contains(token, "on page")
                                   && contains(token, "undefined")) {
@@ -1008,7 +1037,7 @@ void LaTeX::deplog(DepTable & head)
                        // However, ...
                        if (suffixIs(token, ")"))
                                // no line break for sure
-                               // pretend we've been succesfully searching
+                               // pretend we've been successfully searching
                                found_file = true;
                // (2) "No file file.ext"
                } else if (regex_match(token, sub, reg2)) {
@@ -1049,7 +1078,7 @@ void LaTeX::deplog(DepTable & head)
                                                file.absFileName(), ".toc")), head);
                else
                        // not found, but we won't check further
-                       // pretend we've been succesfully searching
+                       // pretend we've been successfully searching
                        found_file = true;
 
                // (8) "(file.ext"
@@ -1088,7 +1117,7 @@ void LaTeX::deplog(DepTable & head)
                                        // we have a closing bracket, so the content
                                        // is not a file name.
                                        // no need to investigate further
-                                       // pretend we've been succesfully searching
+                                       // pretend we've been successfully searching
                                        first = what[0].second;
                                        found_file = true;
                                }
@@ -1109,4 +1138,30 @@ void LaTeX::deplog(DepTable & head)
 }
 
 
+void LaTeX::scanBlgFile(DepTable & dep)
+{
+       FileName const blg_file(changeExtension(file.absFileName(), "blg"));
+       LYXERR(Debug::LATEX, "Scanning blg file: " << blg_file);
+
+       ifstream ifs(blg_file.toFilesystemEncoding().c_str());
+       string token;
+       static regex const reg1(".*Found bibtex data file '([^']+).*");
+
+       while (getline(ifs, token)) {
+               token = rtrim(token, "\r");
+               smatch sub;
+               // FIXME UNICODE: We assume that citation keys and filenames
+               // in the aux file are in the file system encoding.
+               token = to_utf8(from_filesystem8bit(token));
+               if (regex_match(token, sub, reg1)) {
+                       string data = sub.str(1);
+                       if (!data.empty()) {
+                               LYXERR(Debug::LATEX, "Found bib file: " << data);
+                               handleFoundFile(data, dep);
+                       }
+               }
+       } 
+}
+
+
 } // namespace lyx