3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author Jürgen Spitzmüller
13 * Full author contact details are available in file CREDITS.
21 #include "BufferList.h"
22 #include "BufferParams.h"
29 #include "support/debug.h"
30 #include "support/docstring.h"
31 #include "support/convert.h"
32 #include "support/FileName.h"
33 #include "support/filetools.h"
34 #include "support/gettext.h"
35 #include "support/lstrings.h"
36 #include "support/Systemcall.h"
37 #include "support/os.h"
45 using namespace lyx::support;
49 namespace os = support::os;
51 // TODO: in no particular order
52 // - get rid of the call to
53 // BufferList::updateIncludedTeXfiles, this should either
54 // be done before calling LaTeX::funcs or in a completely
56 // - the makeindex style files should be taken care of with
57 // the dependency mechanism.
61 docstring runMessage(unsigned int count)
63 return bformat(_("Waiting for LaTeX run number %1$d"), count);
72 void TeXErrors::insertError(int line, docstring const & error_desc,
73 docstring const & error_text,
74 string const & child_name)
76 Error newerr(line, error_desc, error_text, child_name);
77 errors.push_back(newerr);
81 void TeXErrors::insertRef(int line, docstring const & error_desc,
82 docstring const & error_text,
83 string const & child_name)
85 Error newerr(line, error_desc, error_text, child_name);
86 undef_ref.push_back(newerr);
90 bool operator==(AuxInfo const & a, AuxInfo const & o)
92 return a.aux_file == o.aux_file
93 && a.citations == o.citations
94 && a.databases == o.databases
95 && a.styles == o.styles;
99 bool operator!=(AuxInfo const & a, AuxInfo const & o)
109 LaTeX::LaTeX(string const & latex, OutputParams const & rp,
110 FileName const & f, string const & p, string const & lp,
111 bool allow_cancellation, bool const clean_start)
112 : cmd(latex), file(f), path(p), lpath(lp), runparams(rp), biber(false),
113 allow_cancel(allow_cancellation)
116 // lualatex can still produce a DVI with --output-format=dvi. However,
117 // we do not use that internally (we use the "dvilualatex" command) so
118 // it would only happen from a custom converter. Thus, it is better to
119 // guess that lualatex produces a PDF than to guess a DVI.
120 // FIXME we should base the extension on the output format, which we should
121 // get in a robust way, e.g. from the converter.
122 if (prefixIs(cmd, "pdf") || prefixIs(cmd, "lualatex") || prefixIs(cmd, "xelatex")) {
123 depfile = FileName(file.absFileName() + ".dep-pdf");
125 FileName(changeExtension(file.absFileName(), ".pdf"));
127 depfile = FileName(file.absFileName() + ".dep");
129 FileName(changeExtension(file.absFileName(), ".dvi"));
132 removeAuxiliaryFiles();
136 void LaTeX::removeAuxiliaryFiles() const
138 LYXERR(Debug::OUTFILE, "Removing auxiliary files");
139 // Note that we do not always call this function when there is an error.
140 // For example, if there is an error but an output file is produced we
141 // still would like to output (export/view) the file.
143 // What files do we have to delete?
145 // This will at least make latex do all the runs
146 depfile.removeFile();
148 // but the reason for the error might be in a generated file...
151 FileName const bbl(changeExtension(file.absFileName(), ".bbl"));
155 FileName const bcf(changeExtension(file.absFileName(), ".bcf"));
159 FileName const ind(changeExtension(file.absFileName(), ".ind"));
163 FileName const nls(changeExtension(file.absFileName(), ".nls"));
166 // nomencl file (old version of the package)
167 FileName const gls(changeExtension(file.absFileName(), ".gls"));
171 FileName const ent(changeExtension(file.absFileName(), ".ent"));
174 // Also remove the aux file
175 FileName const aux(changeExtension(file.absFileName(), ".aux"));
178 // Also remove the .out file (e.g. hyperref bookmarks) (#9963)
179 FileName const out(changeExtension(file.absFileName(), ".out"));
182 // Remove the output file, which is often generated even if error
183 output_file.removeFile();
187 int LaTeX::run(TeXErrors & terr)
188 // We know that this function will only be run if the lyx buffer
189 // has been changed. We also know that a newly written .tex file
190 // is always different from the previous one because of the date
191 // in it. However it seems safe to run latex (at least) one time
192 // each time the .tex file changes.
194 int scanres = NO_ERRORS;
195 int bscanres = NO_ERRORS;
196 int iscanres = NO_ERRORS;
197 unsigned int count = 0; // number of times run
198 num_errors = 0; // just to make sure.
199 unsigned int const MAX_RUN = 6;
200 DepTable head; // empty head
201 bool rerun = false; // rerun requested
203 // The class LaTeX does not know the temp path.
204 theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFileName(),
208 // first check if the file dependencies exist:
209 // ->If it does exist
210 // check if any of the files mentioned in it have
211 // changed (done using a checksum).
213 // run latex once and
214 // remake the dependency file
215 // -> if not changed:
216 // just return there is nothing to do for us.
217 // ->if it doesn't exist
219 // run latex once (we need to run latex once anyway) and
220 // remake the dependency file.
223 bool had_depfile = depfile.exists();
224 bool run_bibtex = false;
225 FileName const aux_file(changeExtension(file.absFileName(), ".aux"));
228 LYXERR(Debug::DEPEND, "Dependency file exists");
229 // Read the dep file:
230 had_depfile = head.read(depfile);
234 if (runparams.includeall) {
235 // On an "includeall" call (whose purpose is to set up/maintain counters and references
236 // for includeonly), we remove the master from the dependency list since
237 // (1) it will be checked anyway on the subsequent includeonly run
238 // (2) the master is always changed (due to the \includeonly line), and this alone would
239 // trigger a complete, expensive run each time
240 head.remove_file(file);
241 // Also remove all children which are included
242 Buffer const * buf = theBufferList().getBufferFromTmp(file.absFileName());
243 if (buf && buf->params().maintain_unincluded_children == BufferParams::CM_Mostly) {
244 for (auto const & incfile : buf->params().getIncludedChildren()) {
246 DocFileName(changeExtension(makeAbsPath(incfile, path)
247 .absFileName(), ".tex")).mangledFileName();
248 FileName inc = makeAbsPath(incm, file.onlyPath().realPath());
249 head.remove_file(inc);
253 // Update the checksums
255 // Can't just check if anything has changed because it might
256 // have aborted on error last time... in which cas we need
257 // to re-run latex and collect the error messages
258 // (even if they are the same).
259 if (!output_file.exists()) {
260 LYXERR(Debug::DEPEND,
261 "re-running LaTeX because output file doesn't exist.");
262 } else if (!head.sumchange()) {
263 LYXERR(Debug::DEPEND, "return no_change");
266 LYXERR(Debug::DEPEND, "Dependency file has changed");
269 if (head.extchanged(".bib") || head.extchanged(".bst"))
272 LYXERR(Debug::DEPEND,
273 "Dependency file does not exist, or has wrong format");
275 /// We scan the aux file even when had_depfile = false,
276 /// because we can run pdflatex on the file after running latex on it,
277 /// in which case we will not need to run bibtex again.
278 vector<AuxInfo> bibtex_info_old;
280 bibtex_info_old = scanAuxFiles(aux_file, runparams.only_childbibs);
283 LYXERR(Debug::OUTFILE, "Run #" << count);
284 message(runMessage(count));
286 int exit_code = startscript();
287 if (exit_code == Systemcall::KILLED || exit_code == Systemcall::TIMEOUT)
290 scanres = scanLogFile(terr);
291 if (scanres & ERROR_RERUN) {
292 LYXERR(Debug::OUTFILE, "Rerunning LaTeX");
294 exit_code = startscript();
295 if (exit_code == Systemcall::KILLED || exit_code == Systemcall::TIMEOUT)
297 scanres = scanLogFile(terr);
300 vector<AuxInfo> const bibtex_info = scanAuxFiles(aux_file, runparams.only_childbibs);
301 if (!run_bibtex && bibtex_info_old != bibtex_info)
304 // update the dependencies.
305 deplog(head); // reads the latex log
309 // At this point we must run the bibliography processor if needed.
310 // First, check if we're using biber instead of bibtex --
311 // biber writes no info to the aux file, so we just check
312 // if a bcf file exists (and if it was updated).
313 FileName const bcffile(changeExtension(file.absFileName(), ".bcf"));
314 biber |= head.exist(bcffile);
316 // If (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
317 // We do not run bibtex/biber on an "includeall" call (whose purpose is
318 // to set up/maintain counters and references for includeonly) since
319 // (1) bibliographic references will be updated on the subsequent includeonly run
320 // (2) this would trigger a complete run each time (as references in non-included
321 // children are removed on subsequent includeonly runs)
322 if (!runparams.includeall && (scanres & UNDEF_CIT || run_bibtex)) {
323 // Here we must scan the .aux file and look for
324 // "\bibdata" and/or "\bibstyle". If one of those
325 // tags is found -> run bibtex and set rerun = true;
327 LYXERR(Debug::OUTFILE, "Running Bibliography Processor.");
328 message(_("Running Bibliography Processor."));
329 updateBibtexDependencies(head, bibtex_info);
331 rerun |= runBibTeX(bibtex_info, runparams, exit_code);
332 if (exit_code == Systemcall::KILLED || exit_code == Systemcall::TIMEOUT)
334 FileName const blgfile(changeExtension(file.absFileName(), ".blg"));
335 if (blgfile.exists())
336 bscanres = scanBlgFile(head, terr);
337 } else if (!had_depfile) {
338 /// If we run pdflatex on the file after running latex on it,
339 /// then we do not need to run bibtex, but we do need to
340 /// insert the .bib and .bst files into the .dep-pdf file.
341 updateBibtexDependencies(head, bibtex_info);
345 // We know on this point that latex has been run once (or we just
346 // returned) and the question now is to decide if we need to run
347 // it any more. This is done by asking if any of the files in the
348 // dependency file has changed. (remember that the checksum for
349 // a given file is reported to have changed if it just was created)
350 // -> if changed or rerun == true:
351 // run latex once more and
352 // update the dependency structure
353 // -> if not changed:
354 // we do nothing at this point
356 if (rerun || head.sumchange()) {
359 LYXERR(Debug::DEPEND, "Dep. file has changed or rerun requested");
360 LYXERR(Debug::OUTFILE, "Run #" << count);
361 message(runMessage(count));
362 int exit_code = startscript();
363 if (exit_code == Systemcall::KILLED || exit_code == Systemcall::TIMEOUT)
365 scanres = scanLogFile(terr);
367 // update the depedencies
368 deplog(head); // reads the latex log
371 LYXERR(Debug::DEPEND, "Dep. file has NOT changed");
375 // Rerun bibliography processor?
376 // Complex bibliography packages such as Biblatex require
377 // an additional bibtex cycle sometimes.
378 // We do not run bibtex/biber on an "includeall" call (whose purpose is
379 // to set up/maintain counters and references for includeonly) since
380 // (1) bibliographic references will be updated on the subsequent includeonly run
381 // (2) this would trigger a complete run each time (as references in non-included
382 // children are removed on subsequent includeonly runs)
383 if (!runparams.includeall && scanres & UNDEF_CIT) {
384 // Here we must scan the .aux file and look for
385 // "\bibdata" and/or "\bibstyle". If one of those
386 // tags is found -> run bibtex and set rerun = true;
388 LYXERR(Debug::OUTFILE, "Re-Running Bibliography Processor.");
389 message(_("Re-Running Bibliography Processor."));
390 updateBibtexDependencies(head, bibtex_info);
392 rerun |= runBibTeX(bibtex_info, runparams, exit_code);
393 if (exit_code == Systemcall::KILLED || exit_code == Systemcall::TIMEOUT)
395 FileName const blgfile(changeExtension(file.absFileName(), ".blg"));
396 if (blgfile.exists())
397 bscanres = scanBlgFile(head, terr);
401 // After the bibliography was processed, we need more passes of LaTeX
402 // in order to resolve the citations. We need to do this before the index
403 // is being generated (since we need the correct pagination, see #2696).
404 // Also, memoir (at least) writes an empty *idx file in the first place.
405 // A further latex run is needed in that case as well.
406 FileName const idxfile(changeExtension(file.absFileName(), ".idx"));
407 if (run_bibtex || (idxfile.exists() && idxfile.isFileEmpty())) {
408 while ((head.sumchange() || rerun || (scanres & RERUN))
409 && count < MAX_RUN) {
410 // Yes rerun until message goes away, or until
411 // MAX_RUNS are reached.
414 LYXERR(Debug::OUTFILE, "Run #" << count);
415 message(runMessage(count));
417 scanres = scanLogFile(terr);
425 // Now that we have final pagination, run the index and nomencl processors
426 if (idxfile.exists()) {
428 LYXERR(Debug::OUTFILE, "Running Index Processor.");
429 message(_("Running Index Processor."));
430 // onlyFileName() is needed for cygwin
432 runMakeIndex(onlyFileName(idxfile.absFileName()), runparams);
433 if (ret == Systemcall::KILLED || ret == Systemcall::TIMEOUT)
435 else if (ret != Systemcall::OK) {
436 iscanres |= INDEX_ERROR;
438 _("Index Processor Error"),
439 _("The index processor did not run successfully. "
440 "Please check the output of View > Messages Pane!"));
442 FileName const ilgfile(changeExtension(file.absFileName(), ".ilg"));
443 if (ilgfile.exists())
444 iscanres = scanIlgFile(terr);
447 FileName const nlofile(changeExtension(file.absFileName(), ".nlo"));
448 // If all nomencl entries are removed, nomencl writes an empty nlo file.
449 // DepTable::hasChanged() returns false in this case, since it does not
450 // distinguish empty files from non-existing files. This is why we need
451 // the extra checks here (to trigger a rerun). Cf. discussions in #8905.
452 // FIXME: Sort out the real problem in DepTable.
453 if (head.haschanged(nlofile) || (nlofile.exists() && nlofile.isFileEmpty())) {
454 int const ret = runMakeIndexNomencl(file, ".nlo", ".nls");
455 if (ret == Systemcall::KILLED || ret == Systemcall::TIMEOUT)
459 FileName const glofile(changeExtension(file.absFileName(), ".glo"));
460 if (head.haschanged(glofile)) {
461 int const ret = runMakeIndexNomencl(file, ".glo", ".gls");
468 // We will re-run latex if the log file asks for it,
469 // or if the sumchange() is true.
470 // -> rerun asked for:
472 // remake the dependency file
473 // goto 2 or return if max runs are reached.
474 // -> rerun not asked for:
475 // just return (fall out of bottom of func)
477 while ((head.sumchange() || rerun || (scanres & RERUN))
478 && count < MAX_RUN) {
479 // Yes rerun until message goes away, or until
480 // MAX_RUNS are reached.
483 LYXERR(Debug::OUTFILE, "Run #" << count);
484 message(runMessage(count));
486 scanres = scanLogFile(terr);
492 // Write the dependencies to file.
496 // add flag here, just before return, instead of when exit_code
497 // is defined because scanres is sometimes overwritten above
499 scanres |= NONZERO_ERROR;
502 LYXERR(Debug::OUTFILE, "Done.");
504 if (bscanres & ERRORS)
505 return bscanres; // return on error
507 if (iscanres & ERRORS)
508 return iscanres; // return on error
514 int LaTeX::startscript()
516 // onlyFileName() is needed for cygwin
517 string tmp = cmd + ' '
518 + quoteName(onlyFileName(file.toFilesystemEncoding()))
519 + " > " + os::nulldev();
521 Systemcall::Starttype const starttype =
522 allow_cancel ? Systemcall::WaitLoop : Systemcall::Wait;
523 return one.startscript(starttype, tmp, path, lpath, true);
527 int LaTeX::runMakeIndex(string const & f, OutputParams const & rp,
528 string const & params)
530 string tmp = rp.use_japanese ?
531 lyxrc.jindex_command : lyxrc.index_command;
533 if (!rp.index_command.empty())
534 tmp = rp.index_command;
536 Language const * doc_lang = languages.getLanguage(rp.document_language);
538 if (contains(tmp, "$$x")) {
539 // This adds appropriate [te]xindy options
540 // such as language and codepage (for the
541 // main document language/encoding) as well
542 // as input markup (latex or xelatex)
543 string xdyopts = doc_lang ? doc_lang->xindy() : string();
544 if (!xdyopts.empty())
545 xdyopts = "-L " + xdyopts;
546 if (rp.isFullUnicode() && rp.encoding->package() == Encoding::none) {
547 if (!xdyopts.empty())
549 // xelatex includes lualatex
550 xdyopts += "-I xelatex";
552 else if (rp.encoding->iconvName() == "UTF-8") {
553 if (!xdyopts.empty())
555 // -I not really needed for texindy, but for xindy
556 xdyopts += "-C utf8 -I latex";
559 if (!xdyopts.empty())
561 // not really needed for texindy, but for xindy
562 xdyopts += "-I latex";
564 tmp = subst(tmp, "$$x", xdyopts);
567 if (contains(tmp, "$$b")) {
568 // advise xindy to write a log file
569 tmp = subst(tmp, "$$b", removeExtension(f));
572 LYXERR(Debug::OUTFILE,
573 "idx file has been made, running index processor ("
574 << tmp << ") on file " << f);
577 tmp = subst(tmp, "$$lang", doc_lang->babel());
578 tmp = subst(tmp, "$$lcode", doc_lang->code());
580 if (rp.use_indices) {
581 tmp = lyxrc.splitindex_command + " -m " + quoteName(tmp);
582 LYXERR(Debug::OUTFILE,
583 "Multiple indices. Using splitindex command: " << tmp);
589 Systemcall::Starttype const starttype =
590 allow_cancel ? Systemcall::WaitLoop : Systemcall::Wait;
591 return one.startscript(starttype, tmp, path, lpath, true);
595 int LaTeX::runMakeIndexNomencl(FileName const & fname,
596 string const & nlo, string const & nls)
598 LYXERR(Debug::OUTFILE, "Running Nomenclature Processor.");
599 message(_("Running Nomenclature Processor."));
600 string tmp = lyxrc.nomencl_command + ' ';
601 // onlyFileName() is needed for cygwin
602 tmp += quoteName(onlyFileName(changeExtension(fname.absFileName(), nlo)));
604 + onlyFileName(changeExtension(fname.toFilesystemEncoding(), nls));
606 Systemcall::Starttype const starttype =
607 allow_cancel ? Systemcall::WaitLoop : Systemcall::Wait;
608 return one.startscript(starttype, tmp, path, lpath, true);
612 vector<AuxInfo> const
613 LaTeX::scanAuxFiles(FileName const & fname, bool const only_childbibs)
615 vector<AuxInfo> result;
617 // With chapterbib, we have to bibtex all children's aux files
618 // but _not_ the master's!
619 if (only_childbibs) {
620 for (string const &s: children) {
622 makeAbsPath(s, fname.onlyPath().realPath());
623 fn.changeExtension("aux");
625 result.push_back(scanAuxFile(fn));
630 result.push_back(scanAuxFile(fname));
632 // This is for bibtopic
633 string const basename = removeExtension(fname.absFileName());
634 for (int i = 1; i < 1000; ++i) {
635 FileName const file2(basename
636 + '.' + convert<string>(i)
640 result.push_back(scanAuxFile(file2));
646 AuxInfo const LaTeX::scanAuxFile(FileName const & fname)
649 result.aux_file = fname;
650 scanAuxFile(fname, result);
655 void LaTeX::scanAuxFile(FileName const & fname, AuxInfo & aux_info)
657 LYXERR(Debug::OUTFILE, "Scanning aux file: " << fname);
659 ifstream ifs(fname.toFilesystemEncoding().c_str());
661 static regex const reg1("\\\\citation\\{([^}]+)\\}");
662 static regex const reg2("\\\\bibdata\\{([^}]+)\\}");
663 static regex const reg3("\\\\bibstyle\\{([^}]+)\\}");
664 static regex const reg4("\\\\@input\\{([^}]+)\\}");
666 while (getline(ifs, token)) {
667 token = rtrim(token, "\r");
669 // FIXME UNICODE: We assume that citation keys and filenames
670 // in the aux file are in the file system encoding.
671 token = to_utf8(from_filesystem8bit(token));
672 if (regex_match(token, sub, reg1)) {
673 string data = sub.str(1);
674 while (!data.empty()) {
676 data = split(data, citation, ',');
677 LYXERR(Debug::OUTFILE, "Citation: " << citation);
678 aux_info.citations.insert(citation);
680 } else if (regex_match(token, sub, reg2)) {
681 string data = sub.str(1);
682 // data is now all the bib files separated by ','
683 // get them one by one and pass them to the helper
684 while (!data.empty()) {
686 data = split(data, database, ',');
687 database = changeExtension(database, "bib");
688 LYXERR(Debug::OUTFILE, "BibTeX database: `" << database << '\'');
689 aux_info.databases.insert(database);
691 } else if (regex_match(token, sub, reg3)) {
692 string style = sub.str(1);
693 // token is now the style file
694 // pass it to the helper
695 style = changeExtension(style, "bst");
696 LYXERR(Debug::OUTFILE, "BibTeX style: `" << style << '\'');
697 aux_info.styles.insert(style);
698 } else if (regex_match(token, sub, reg4)) {
699 string const file2 = sub.str(1);
700 scanAuxFile(makeAbsPath(file2), aux_info);
706 void LaTeX::updateBibtexDependencies(DepTable & dep,
707 vector<AuxInfo> const & bibtex_info)
709 // Since a run of Bibtex mandates more latex runs it is ok to
710 // remove all ".bib" and ".bst" files.
711 dep.remove_files_with_extension(".bib");
712 dep.remove_files_with_extension(".bst");
713 //string aux = OnlyFileName(ChangeExtension(file, ".aux"));
715 for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
716 it != bibtex_info.end(); ++it) {
717 for (set<string>::const_iterator it2 = it->databases.begin();
718 it2 != it->databases.end(); ++it2) {
719 FileName const file = findtexfile(*it2, "bib");
721 dep.insert(file, true);
724 for (set<string>::const_iterator it2 = it->styles.begin();
725 it2 != it->styles.end(); ++it2) {
726 FileName const file = findtexfile(*it2, "bst");
728 dep.insert(file, true);
732 // biber writes nothing into the aux file.
733 // Instead, we have to scan the blg file
736 scanBlgFile(dep, terr);
741 bool LaTeX::runBibTeX(vector<AuxInfo> const & bibtex_info,
742 OutputParams const & rp, int & exit_code)
746 for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
747 it != bibtex_info.end(); ++it) {
748 if (!biber && it->databases.empty())
752 string tmp = rp.bibtex_command;
754 // onlyFileName() is needed for cygwin
755 tmp += quoteName(onlyFileName(removeExtension(
756 it->aux_file.absFileName())));
758 Systemcall::Starttype const starttype =
759 allow_cancel ? Systemcall::WaitLoop : Systemcall::Wait;
760 exit_code = one.startscript(starttype, tmp, path, lpath, true);
765 // Return whether bibtex was run
770 //helper func for scanLogFile; gets line number X from strings "... on input line X ..."
771 //returns 0 if none is found
772 int getLineNumber(const string &token){
773 string l = support::token(token, ' ', tokenPos(token,' ',"line") + 1);
774 return l.empty() ? 0 : convert<int>(l);
778 int LaTeX::scanLogFile(TeXErrors & terr)
782 int retval = NO_ERRORS;
784 onlyFileName(changeExtension(file.absFileName(), ".log"));
785 LYXERR(Debug::OUTFILE, "Log file: " << tmp);
786 FileName const fn = makeAbsPath(tmp);
787 // FIXME we should use an ifdocstream here and a docstring for token
788 // below. The encoding of the log file depends on the _output_ (font)
789 // encoding of the TeX file (T1, TU etc.). See #10728.
790 ifstream ifs(fn.toFilesystemEncoding().c_str());
791 bool fle_style = false;
792 static regex const file_line_error(".+\\.\\D+:[0-9]+: (.+)");
793 static regex const child_file("[^0-9]*([0-9]+[A-Za-z]*_.+\\.tex).*");
794 static regex const undef_ref(".*Reference `(\\w+)\\' on page.*");
795 // Flag for 'File ended while scanning' message.
796 // We need to wait for subsequent processing.
797 string wait_for_error;
800 stack <pair<string, int> > child;
807 while (getline(ifs, token)) {
808 // MikTeX sometimes inserts \0 in the log file. They can't be
809 // removed directly with the existing string utility
810 // functions, so convert them first to \r, and remove all
811 // \r's afterwards, since we need to remove them anyway.
812 token = subst(token, '\0', '\r');
813 token = subst(token, "\r", "");
816 LYXERR(Debug::OUTFILE, "Log line: " << token);
821 if (!ml_token.empty())
824 // Track child documents
825 for (size_t i = 0; i < token.length(); ++i) {
826 if (token[i] == '(') {
828 size_t j = token.find('(', i + 1);
829 size_t len = j == string::npos
830 ? token.substr(i + 1).length()
832 string const substr = token.substr(i + 1, len);
833 if (regex_match(substr, sub, child_file)) {
834 string const name = sub.str(1);
835 // Sometimes also masters have a name that matches
836 // (if their name starts with a number and _)
837 if (name != file.onlyFileName()) {
838 child.push(make_pair(name, pnest));
839 children.push_back(name);
843 } else if (token[i] == ')') {
845 && child.top().second == pnest)
850 child_name = child.empty() ? empty_string() : child.top().first;
852 if (contains(token, "file:line:error style messages enabled"))
855 //Handles both "LaTeX Warning:" & "Package natbib Warning:"
856 //Various handlers for missing citations below won't catch the problem if citation
857 //key is long (>~25chars), because pdflatex splits output at line length 80.
858 //TODO: TL 2020 engines will contain new commandline switch --cnf-line which we
859 //can use to set max_print_line variable for appropriate length and detect all
861 if (!runparams.includeall && (contains(token, "There were undefined citations.") ||
862 prefixIs(token, "Package biblatex Warning: The following entry could not be found")))
865 if (prefixIs(token, "LaTeX Warning:")
866 || prefixIs(token, "! pdfTeX warning")
867 || prefixIs(ml_token, "LaTeX Warning:")
868 || prefixIs(ml_token, "! pdfTeX warning")) {
869 // Here shall we handle different
871 retval |= LATEX_WARNING;
872 LYXERR(Debug::OUTFILE, "LaTeX Warning.");
873 if (contains(token, "Rerun to get cross-references")) {
875 LYXERR(Debug::OUTFILE, "We should rerun.");
876 // package clefval needs 2 latex runs before bibtex
877 } else if (contains(token, "Value of")
878 && contains(token, "on page")
879 && contains(token, "undefined")) {
880 retval |= ERROR_RERUN;
881 LYXERR(Debug::OUTFILE, "Force rerun.");
883 } else if (contains(token, "Etaremune labels have changed")) {
884 retval |= ERROR_RERUN;
885 LYXERR(Debug::OUTFILE, "Force rerun.");
887 } else if (contains(token, "Endnotes may have changed. Rerun")) {
889 LYXERR(Debug::OUTFILE, "We should rerun.");
890 //"Citation `cit' on page X undefined on input line X."
891 } else if (!runparams.includeall && contains(token, "Citation")
892 //&& contains(token, "on input line") //often split to newline
893 && contains(token, "undefined")) {
895 terr.insertRef(getLineNumber(token), from_ascii("Citation undefined"),
896 from_utf8(token), child_name);
897 //"Reference `X' on page Y undefined on input line Z."
898 // This warning might be broken accross multiple lines with long labels.
899 // Thus we check that
900 } else if (contains(token, "Reference `") && !contains(token, "on input line")) {
901 // Rest of warning in next line(s)
904 } else if (!ml_token.empty() && contains(ml_token, "Reference `")
905 && !contains(ml_token, "on input line")) {
906 // not finished yet. Continue with next line.
908 } else if (!ml_token.empty() && contains(ml_token, "Reference `")
909 && contains(ml_token, "on input line")) {
910 // We have collected the whole warning now.
911 if (!contains(ml_token, "undefined")) {
912 // Not the warning we are looking for
916 if (regex_match(ml_token, sub, undef_ref)) {
917 string const ref = sub.str(1);
918 Buffer const * buf = theBufferList().getBufferFromTmp(file.absFileName());
919 if (!buf || !buf->masterBuffer()->activeLabel(from_utf8(ref))) {
920 terr.insertRef(getLineNumber(ml_token), from_ascii("Reference undefined"),
921 from_utf8(ml_token), child_name);
922 retval |= UNDEF_UNKNOWN_REF;
927 } else if (contains(token, "Reference `")
928 && contains(token, "on input line")
929 && contains(token, "undefined")) {
930 if (regex_match(token, sub, undef_ref)) {
931 string const ref = sub.str(1);
932 Buffer const * buf = theBufferList().getBufferFromTmp(file.absFileName());
933 if (!buf || !buf->masterBuffer()->activeLabel(from_utf8(ref))) {
934 terr.insertRef(getLineNumber(token), from_ascii("Reference undefined"),
935 from_utf8(token), child_name);
936 retval |= UNDEF_UNKNOWN_REF;
940 // In case the above checks fail we catch at least this generic statement
941 // occuring for both CIT & REF.
942 } else if (!runparams.includeall && contains(token, "There were undefined references.")) {
943 if (!(retval & UNDEF_CIT)) //if not handled already
947 } else if (prefixIs(token, "Package")) {
949 retval |= PACKAGE_WARNING;
950 if (contains(token, "natbib Warning:")) {
952 if (!runparams.includeall
953 && contains(token, "Citation")
954 && contains(token, "on page")
955 && contains(token, "undefined")) {
957 //Unf only keys up to ~6 chars will make it due to line splits
958 terr.insertRef(getLineNumber(token), from_ascii("Citation undefined"),
959 from_utf8(token), child_name);
961 } else if (!runparams.includeall && contains(token, "run BibTeX")) {
963 } else if (!runparams.includeall && contains(token, "run Biber")) {
966 } else if (contains(token, "Rerun LaTeX") ||
967 contains(token, "Please rerun LaTeX") ||
968 contains(token, "Rerun to get")) {
969 // at least longtable.sty and bibtopic.sty
971 LYXERR(Debug::OUTFILE, "We should rerun.");
974 } else if (prefixIs(token, "LETTRE WARNING:")) {
975 if (contains(token, "veuillez recompiler")) {
977 LYXERR(Debug::OUTFILE, "We should rerun.");
980 } else if (token[0] == '(') {
981 if (contains(token, "Rerun LaTeX") ||
982 contains(token, "Rerun to get")) {
984 LYXERR(Debug::OUTFILE, "We should rerun.");
987 } else if (prefixIs(token, "! ")
989 && regex_match(token, sub, file_line_error)
990 && !contains(token, "pdfTeX warning"))) {
991 // Ok, we have something that looks like a TeX Error
992 // but what do we really have.
994 // Just get the error description:
996 if (prefixIs(token, "! "))
997 desc = string(token, 2);
1000 if (contains(token, "LaTeX Error:"))
1001 retval |= LATEX_ERROR;
1003 if (prefixIs(token, "! File ended while scanning")) {
1004 if (prefixIs(token, "! File ended while scanning use of \\Hy@setref@link.")){
1005 // bug 7344. We must rerun LaTeX if hyperref has been toggled.
1006 retval |= ERROR_RERUN;
1007 LYXERR(Debug::OUTFILE, "Force rerun.");
1009 // bug 6445. At this point its not clear we finish with error.
1010 wait_for_error = desc;
1015 if (prefixIs(token, "! Incomplete \\if")) {
1016 // bug 10666. At this point its not clear we finish with error.
1017 wait_for_error = desc;
1021 if (prefixIs(token, "! Paragraph ended before \\Hy@setref@link was complete.")){
1022 // bug 7344. We must rerun LaTeX if hyperref has been toggled.
1023 retval |= ERROR_RERUN;
1024 LYXERR(Debug::OUTFILE, "Force rerun.");
1027 if (!wait_for_error.empty() && prefixIs(token, "! Emergency stop.")){
1028 retval |= LATEX_ERROR;
1031 errstr = wait_for_error;
1032 wait_for_error.clear();
1034 if (!getline(ifs, tmp))
1036 tmp = rtrim(tmp, "\r");
1037 errstr += "\n" + tmp;
1040 } while (!contains(tmp, "(job aborted"));
1043 from_ascii("Emergency stop"),
1044 from_local8bit(errstr),
1048 // get the next line
1050 // We also collect intermediate lines
1051 // This is needed for errors in preamble
1052 string intermediate;
1054 if (!getline(ifs, tmp))
1056 tmp = rtrim(tmp, "\r");
1057 if (!prefixIs(tmp, "l."))
1058 intermediate += tmp;
1059 // 15 is somewhat arbitrarily chosen, based on practice.
1060 // We used 10 for 14 years and increased it to 15 when we
1064 } while (!prefixIs(tmp, "l."));
1065 if (prefixIs(tmp, "l.")) {
1066 // we have a latex error
1067 retval |= TEX_ERROR;
1069 "Package babel Error: You haven't defined the language")
1071 "Package babel Error: You haven't loaded the option")
1073 "Package babel Error: Unknown language"))
1074 retval |= ERROR_RERUN;
1075 // get the line number:
1077 sscanf(tmp.c_str(), "l.%d", &line);
1078 // get the rest of the message:
1079 string errstr(tmp, tmp.find(' '));
1080 bool preamble_error = false;
1081 if (suffixIs(errstr, "\\begin{document}")) {
1082 // this is an error in preamble
1083 // the real error is in the
1084 // intermediate lines
1085 errstr = intermediate;
1087 preamble_error = true;
1091 tmp = rtrim(tmp, "\r");
1092 while (!contains(errstr, "l.")
1094 && !prefixIs(tmp, "! ")
1095 && !contains(tmp, "(job aborted")) {
1099 tmp = rtrim(tmp, "\r");
1102 // Add a note that the error is to be found in preamble
1103 errstr += "\n" + to_utf8(_("(NOTE: The erroneous command is in the preamble)"));
1104 LYXERR(Debug::OUTFILE, "line: " << line << '\n'
1105 << "Desc: " << desc << '\n' << "Text: " << errstr);
1106 if (line == last_line)
1112 if (line_count <= 5) {
1114 // We have no idea what the encoding of
1116 // It seems that the output from the
1117 // latex compiler itself is pure ASCII,
1118 // but it can include bits from the
1119 // document, so whatever encoding we
1120 // assume here it can be wrong.
1121 terr.insertError(line,
1122 from_local8bit(desc),
1123 from_local8bit(errstr),
1129 // information messages, TeX warnings and other
1130 // warnings we have not caught earlier.
1131 if (prefixIs(token, "Overfull ")) {
1132 retval |= TEX_WARNING;
1133 } else if (prefixIs(token, "Underfull ")) {
1134 retval |= TEX_WARNING;
1135 } else if (!runparams.includeall && contains(token, "Rerun to get citations")) {
1136 // Natbib seems to use this.
1137 retval |= UNDEF_CIT;
1138 } else if (contains(token, "No pages of output")
1139 || contains(token, "no pages of output")) {
1140 // No output file (e.g. the DVI or PDF) was created
1141 retval |= NO_OUTPUT;
1142 } else if (contains(token, "Error 256 (driver return code)")) {
1143 // This is a xdvipdfmx driver error reported by XeTeX.
1144 // We have to check whether an output PDF file was created.
1145 FileName pdffile = file;
1146 pdffile.changeExtension("pdf");
1147 if (!pdffile.exists())
1148 // No output PDF file was created (see #10076)
1149 retval |= NO_OUTPUT;
1150 } else if (contains(token, "That makes 100 errors")) {
1151 // More than 100 errors were reported
1152 retval |= TOO_MANY_ERRORS;
1153 } else if (prefixIs(token, "!pdfTeX error:")) {
1154 // otherwise we dont catch e.g.:
1155 // !pdfTeX error: pdflatex (file feyn10): Font feyn10 at 600 not found
1158 from_ascii("pdfTeX Error"),
1159 from_local8bit(token),
1161 } else if (!ignore_missing_glyphs
1162 && prefixIs(token, "Missing character: There is no ")
1163 && !contains(token, "nullfont")) {
1164 // Warning about missing glyph in selected font
1165 // may be dataloss (bug 9610)
1166 // but can be ignored for 'nullfont' (bug 10394).
1167 // as well as for ZERO WIDTH NON-JOINER (0x200C) which is
1168 // missing in many fonts and output for ligature break (bug 10727).
1169 // Since this error only occurs with utf8 output, we can safely assume
1170 // that the log file is utf8-encoded
1171 docstring const utoken = from_utf8(token);
1172 if (!contains(utoken, 0x200C)) {
1173 retval |= LATEX_ERROR;
1175 from_ascii("Missing glyphs!"),
1179 } else if (!wait_for_error.empty()) {
1180 // We collect information until we know we have an error.
1181 wait_for_error += token + '\n';
1185 LYXERR(Debug::OUTFILE, "Log line: " << token);
1192 bool insertIfExists(FileName const & absname, DepTable & head)
1194 if (absname.exists() && !absname.isDirectory()) {
1195 head.insert(absname, true);
1202 bool handleFoundFile(string const & ff, DepTable & head)
1204 // convert from native os path to unix path
1205 string foundfile = os::internal_path(trim(ff));
1207 LYXERR(Debug::DEPEND, "Found file: " << foundfile);
1209 // Ok now we found a file.
1210 // Now we should make sure that this is a file that we can
1211 // access through the normal paths.
1212 // We will not try any fancy search methods to
1215 // (1) foundfile is an
1216 // absolute path and should
1219 if (FileName::isAbsolute(foundfile)) {
1220 LYXERR(Debug::DEPEND, "AbsolutePath file: " << foundfile);
1221 // On initial insert we want to do the update at once
1222 // since this file cannot be a file generated by
1224 absname.set(foundfile);
1225 if (!insertIfExists(absname, head)) {
1227 string strippedfile = foundfile;
1228 while (contains(strippedfile, " ")) {
1229 // files with spaces are often enclosed in quotation
1230 // marks; those have to be removed
1231 string unquoted = subst(strippedfile, "\"", "");
1232 absname.set(unquoted);
1233 if (insertIfExists(absname, head))
1235 // strip off part after last space and try again
1236 string tmp = strippedfile;
1237 rsplit(tmp, strippedfile, ' ');
1238 absname.set(strippedfile);
1239 if (insertIfExists(absname, head))
1245 string onlyfile = onlyFileName(foundfile);
1246 absname = makeAbsPath(onlyfile);
1249 while (contains(foundfile, ' ')) {
1250 if (absname.exists())
1254 // files with spaces are often enclosed in quotation
1255 // marks; those have to be removed
1256 string unquoted = subst(foundfile, "\"", "");
1257 absname = makeAbsPath(unquoted);
1258 if (absname.exists())
1260 // strip off part after last space and try again
1261 string strippedfile;
1262 rsplit(foundfile, strippedfile, ' ');
1263 foundfile = strippedfile;
1264 onlyfile = onlyFileName(strippedfile);
1265 absname = makeAbsPath(onlyfile);
1269 // (2) foundfile is in the tmpdir
1270 // insert it into head
1271 if (absname.exists() && !absname.isDirectory()) {
1272 // FIXME: This regex contained glo, but glo is used by the old
1273 // version of nomencl.sty. Do we need to put it back?
1274 static regex const unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
1275 if (regex_match(onlyfile, unwanted)) {
1276 LYXERR(Debug::DEPEND, "We don't want " << onlyfile
1277 << " in the dep file");
1278 } else if (suffixIs(onlyfile, ".tex")) {
1279 // This is a tex file generated by LyX
1280 // and latex is not likely to change this
1282 LYXERR(Debug::DEPEND, "Tmpdir TeX file: " << onlyfile);
1283 head.insert(absname, true);
1285 LYXERR(Debug::DEPEND, "In tmpdir file:" << onlyfile);
1286 head.insert(absname);
1290 LYXERR(Debug::DEPEND, "Not a file or we are unable to find it.");
1296 bool completeFilename(string const & ff, DepTable & head)
1298 // If we do not find a dot, we suspect
1299 // a fragmental file name
1300 if (!contains(ff, '.'))
1303 // if we have a dot, we let handleFoundFile decide
1304 return handleFoundFile(ff, head);
1308 int iterateLine(string const & token, regex const & reg, string const & opening,
1309 string const & closing, int fragment_pos, DepTable & head)
1312 string::const_iterator first = token.begin();
1313 string::const_iterator end = token.end();
1314 bool fragment = false;
1317 while (regex_search(first, end, what, reg)) {
1318 // if we have a dot, try to handle as file
1319 if (contains(what.str(1), '.')) {
1320 first = what[0].second;
1321 if (what.str(2) == closing) {
1322 handleFoundFile(what.str(1), head);
1323 // since we had a closing bracket,
1324 // do not investigate further
1326 } else if (what.str(2) == opening) {
1327 // if we have another opening bracket,
1328 // we might have a nested file chain
1329 // as is (file.ext (subfile.ext))
1330 fragment = !handleFoundFile(rtrim(what.str(1)), head);
1331 // decrease first position by one in order to
1332 // consider the opening delimiter on next iteration
1333 if (first > token.begin())
1336 // if we have no closing bracket,
1337 // try to handle as file nevertheless
1338 fragment = !handleFoundFile(
1339 what.str(1) + what.str(2), head);
1341 // if we do not have a dot, check if the line has
1342 // a closing bracket (else, we suspect a line break)
1343 else if (what.str(2) != closing) {
1344 first = what[0].second;
1347 // we have a closing bracket, so the content
1348 // is not a file name.
1349 // no need to investigate further
1350 first = what[0].second;
1353 last_match = what.str(1);
1356 // We need to consider the result from previous line iterations:
1357 // We might not find a fragment here, but another one might follow
1358 // E.g.: (filename.ext) <filenam
1359 // Vice versa, we consider the search completed if a real match
1360 // follows a potential fragment from a previous iteration.
1361 // E.g. <some text we considered a fragment (filename.ext)
1362 // result = -1 means we did not find a fragment!
1364 int last_match_pos = -1;
1365 if (!last_match.empty() && token.find(last_match) != string::npos)
1366 last_match_pos = int(token.find(last_match));
1368 if (last_match_pos > fragment_pos)
1369 result = last_match_pos;
1371 result = fragment_pos;
1373 if (last_match_pos < fragment_pos)
1374 result = fragment_pos;
1382 void LaTeX::deplog(DepTable & head)
1384 // This function reads the LaTeX log file end extracts all the
1385 // external files used by the LaTeX run. The files are then
1386 // entered into the dependency file.
1388 string const logfile =
1389 onlyFileName(changeExtension(file.absFileName(), ".log"));
1391 static regex const reg1("File: (.+).*");
1392 static regex const reg2("No file (.+)(.).*");
1393 static regex const reg3a("\\\\openout[0-9]+.*=.*`(.+)(..).*");
1394 // LuaTeX has a slightly different output
1395 static regex const reg3b("\\\\openout[0-9]+.*=\\s*(.+)");
1396 // If an index should be created, MikTex does not write a line like
1397 // \openout# = 'sample.idx'.
1398 // but instead only a line like this into the log:
1399 // Writing index file sample.idx
1400 static regex const reg4("Writing index file (.+).*");
1401 static regex const regoldnomencl("Writing glossary file (.+).*");
1402 static regex const regnomencl(".*Writing nomenclature file (.+).*");
1403 // If a toc should be created, MikTex does not write a line like
1404 // \openout# = `sample.toc'.
1405 // but only a line like this into the log:
1407 // This line is also written by tetex.
1408 // This line is not present if no toc should be created.
1409 static regex const miktexTocReg("\\\\tf@toc=\\\\write.*");
1410 // file names can be enclosed in <...> (anywhere on the line)
1411 static regex const reg5(".*<[^>]+.*");
1412 // and also (...) anywhere on the line
1413 static regex const reg6(".*\\([^)]+.*");
1415 FileName const fn = makeAbsPath(logfile);
1416 ifstream ifs(fn.toFilesystemEncoding().c_str());
1419 // Ok, the scanning of files here is not sufficient.
1420 // Sometimes files are named by "File: xxx" only
1421 // Therefore we use some regexps to find files instead.
1422 // Note: all file names and paths might contains spaces.
1423 // Also, file names might be broken across lines. Therefore
1424 // we mark (potential) fragments and merge those lines.
1425 bool fragment = false;
1427 getline(ifs, token);
1428 // MikTeX sometimes inserts \0 in the log file. They can't be
1429 // removed directly with the existing string utility
1430 // functions, so convert them first to \r, and remove all
1431 // \r's afterwards, since we need to remove them anyway.
1432 token = subst(token, '\0', '\r');
1433 token = subst(token, "\r", "");
1434 if (token.empty() || token == ")") {
1435 lastline = string();
1439 // FIXME UNICODE: We assume that the file names in the log
1440 // file are in the file system encoding.
1441 token = to_utf8(from_filesystem8bit(token));
1443 // Sometimes, filenames are broken across lines.
1444 // We care for that and save suspicious lines.
1445 // Here we exclude some cases where we are sure
1446 // that there is no continued filename
1447 if (!lastline.empty()) {
1448 static regex const package_info("Package \\w+ Info: .*");
1449 static regex const package_warning("Package \\w+ Warning: .*");
1450 if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
1451 || prefixIs(token, "Package:")
1452 || prefixIs(token, "Language:")
1453 || prefixIs(token, "LaTeX Info:")
1454 || prefixIs(token, "LaTeX Font Info:")
1455 || prefixIs(token, "\\openout[")
1456 || prefixIs(token, "))")
1457 || regex_match(token, package_info)
1458 || regex_match(token, package_warning))
1459 lastline = string();
1462 if (!lastline.empty())
1463 // probably a continued filename from last line
1464 token = lastline + token;
1465 if (token.length() > 255) {
1466 // string too long. Cut off.
1467 token.erase(0, token.length() - 251);
1472 // (1) "File: file.ext"
1473 if (regex_match(token, sub, reg1)) {
1474 // is this a fragmental file name?
1475 fragment = !completeFilename(sub.str(1), head);
1477 if (suffixIs(token, ")"))
1478 // no fragment for sure
1480 // (2) "No file file.ext"
1481 } else if (regex_match(token, sub, reg2)) {
1482 // file names must contains a dot, line ends with dot
1483 if (contains(sub.str(1), '.') && sub.str(2) == ".")
1484 fragment = !handleFoundFile(sub.str(1), head);
1486 // we suspect a line break
1488 // (3)(a) "\openout<nr> = `file.ext'."
1489 } else if (regex_match(token, sub, reg3a)) {
1490 // search for closing '. at the end of the line
1491 if (sub.str(2) == "\'.")
1492 fragment = !handleFoundFile(sub.str(1), head);
1494 // potential fragment
1496 // (3)(b) "\openout<nr> = file.ext" (LuaTeX)
1497 } else if (regex_match(token, sub, reg3b)) {
1498 // file names must contains a dot
1499 if (contains(sub.str(1), '.'))
1500 fragment = !handleFoundFile(sub.str(1), head);
1502 // potential fragment
1504 // (4) "Writing index file file.ext"
1505 } else if (regex_match(token, sub, reg4))
1506 // fragmential file name?
1507 fragment = !completeFilename(sub.str(1), head);
1508 // (5) "Writing nomenclature file file.ext"
1509 else if (regex_match(token, sub, regnomencl) ||
1510 regex_match(token, sub, regoldnomencl))
1511 // fragmental file name?
1512 fragment= !completeFilename(sub.str(1), head);
1513 // (6) "\tf@toc=\write<nr>" (for MikTeX)
1514 else if (regex_match(token, sub, miktexTocReg))
1515 fragment = !handleFoundFile(onlyFileName(changeExtension(
1516 file.absFileName(), ".toc")), head);
1518 // not found, but we won't check further
1521 int fragment_pos = -1;
1523 // We can have several of these on one line
1524 // (and in addition to those above)
1525 if (regex_match(token, sub, reg5)) {
1526 // search for strings in <...>
1527 static regex const reg5_1("<([^>]+)(.)");
1528 fragment_pos = iterateLine(token, reg5_1, "<", ">",
1529 fragment_pos, head);
1530 fragment = (fragment_pos != -1);
1534 // We can have several of these on one line
1535 // this must be queried separated, because of
1536 // cases such as "File: file.ext (type eps)"
1537 // where "File: file.ext" would be skipped
1538 if (regex_match(token, sub, reg6)) {
1539 // search for strings in (...)
1540 static regex const reg6_1("\\(([^()]+)(.)");
1541 fragment_pos = iterateLine(token, reg6_1, "(", ")",
1542 fragment_pos, head);
1543 fragment = (fragment_pos != -1);
1547 // probable linebreak within file name:
1551 // no linebreak: reset
1552 lastline = string();
1555 // Make sure that the main .tex file is in the dependency file.
1556 head.insert(file, true);
1560 int LaTeX::scanBlgFile(DepTable & dep, TeXErrors & terr)
1562 FileName const blg_file(changeExtension(file.absFileName(), "blg"));
1563 LYXERR(Debug::OUTFILE, "Scanning blg file: " << blg_file);
1565 ifstream ifs(blg_file.toFilesystemEncoding().c_str());
1567 static regex const reg1(".*Found (bibtex|BibTeX) data (file|source) '([^']+).*");
1568 static regex const bibtexError("^(.*---line [0-9]+ of file).*$");
1569 static regex const bibtexError2("^(.*---while reading file).*$");
1570 static regex const bibtexError3("(A bad cross reference---).*");
1571 static regex const bibtexError4("(Sorry---you've exceeded BibTeX's).*");
1572 static regex const bibtexError5("\\*Please notify the BibTeX maintainer\\*");
1573 static regex const biberError("^.*> (FATAL|ERROR) - (.*)$");
1574 int retval = NO_ERRORS;
1577 while (getline(ifs, token)) {
1578 token = rtrim(token, "\r");
1580 // FIXME UNICODE: We assume that citation keys and filenames
1581 // in the aux file are in the file system encoding.
1582 token = to_utf8(from_filesystem8bit(token));
1583 if (regex_match(token, sub, reg1)) {
1584 string data = sub.str(3);
1585 if (!data.empty()) {
1586 LYXERR(Debug::OUTFILE, "Found bib file: " << data);
1587 handleFoundFile(data, dep);
1590 else if (regex_match(token, sub, bibtexError)
1591 || regex_match(token, sub, bibtexError2)
1592 || regex_match(token, sub, bibtexError4)
1593 || regex_match(token, sub, bibtexError5)) {
1594 retval |= BIBTEX_ERROR;
1595 string errstr = N_("BibTeX error: ") + token;
1597 if ((prefixIs(token, "while executing---line")
1598 || prefixIs(token, "---line ")
1599 || prefixIs(token, "*Please notify the BibTeX"))
1600 && !prevtoken.empty()) {
1601 errstr = N_("BibTeX error: ") + prevtoken;
1602 msg = prevtoken + '\n';
1606 from_local8bit(errstr),
1607 from_local8bit(msg));
1608 } else if (regex_match(prevtoken, sub, bibtexError3)) {
1609 retval |= BIBTEX_ERROR;
1610 string errstr = N_("BibTeX error: ") + prevtoken;
1611 string msg = prevtoken + '\n' + token;
1613 from_local8bit(errstr),
1614 from_local8bit(msg));
1615 } else if (regex_match(token, sub, biberError)) {
1616 retval |= BIBTEX_ERROR;
1617 string errstr = N_("Biber error: ") + sub.str(2);
1619 from_local8bit(errstr),
1620 from_local8bit(token));
1628 int LaTeX::scanIlgFile(TeXErrors & terr)
1630 FileName const ilg_file(changeExtension(file.absFileName(), "ilg"));
1631 LYXERR(Debug::OUTFILE, "Scanning ilg file: " << ilg_file);
1633 ifstream ifs(ilg_file.toFilesystemEncoding().c_str());
1635 int retval = NO_ERRORS;
1638 while (getline(ifs, token)) {
1639 token = rtrim(token, "\r");
1640 if (prefixIs(token, "!! "))
1642 else if (!prevtoken.empty()) {
1643 retval |= INDEX_ERROR;
1644 string errstr = N_("Makeindex error: ") + prevtoken;
1645 string msg = prevtoken + '\n';
1648 from_local8bit(errstr),
1649 from_local8bit(msg));
1651 } else if (prefixIs(token, "ERROR: ")) {
1652 retval |= BIBTEX_ERROR;
1653 string errstr = N_("Xindy error: ") + token.substr(6);
1655 from_local8bit(errstr),
1656 from_local8bit(token));