* LaTeX.{cpp,h}:

- refine biber support: parse blg file to get the bib file into the dependency table with biber.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37581 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2011-02-10 10:09:59 +00:00
parent 4a8698c808
commit 14146a43fe
2 changed files with 54 additions and 9 deletions

View File

@ -207,8 +207,7 @@ int LaTeX::run(TeXErrors & terr)
LYXERR(Debug::DEPEND, "Dependency file has changed");
}
if (head.extchanged(".bib") || head.extchanged(".bst")
|| head.extchanged(".bcf"))
if (head.extchanged(".bib") || head.extchanged(".bst"))
run_bibtex = true;
} else
LYXERR(Debug::DEPEND,
@ -276,9 +275,9 @@ int LaTeX::run(TeXErrors & terr)
// 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, above, if it was updated)
// if a bcf file exists (and if it was updated)
FileName const bcffile(changeExtension(file.absFileName(), ".bcf"));
bool const biber = bcffile.exists();
bool const biber = head.exist(bcffile);
// run bibtex
// if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
@ -289,13 +288,21 @@ int LaTeX::run(TeXErrors & terr)
// no checks for now
LYXERR(Debug::LATEX, "Running BibTeX.");
message(_("Running BibTeX."));
updateBibtexDependencies(head, bibtex_info);
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
@ -341,7 +348,7 @@ int LaTeX::run(TeXErrors & terr)
// no checks for now
LYXERR(Debug::LATEX, "Running BibTeX.");
message(_("Running BibTeX."));
updateBibtexDependencies(head, bibtex_info);
updateBibtexDependencies(head, bibtex_info, biber);
rerun |= runBibTeX(bibtex_info, runparams, biber);
}
@ -541,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.
@ -565,6 +573,12 @@ 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);
}
}
@ -1124,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

View File

@ -185,7 +185,12 @@ private:
void scanAuxFile(support::FileName const &, AuxInfo &);
///
void updateBibtexDependencies(DepTable &, std::vector<AuxInfo> const &);
void updateBibtexDependencies(DepTable &,
std::vector<AuxInfo> const &,
bool biber);
///
void scanBlgFile(DepTable & head);
///
bool runBibTeX(std::vector<AuxInfo> const &,