]> git.lyx.org Git - features.git/blob - src/LaTeX.cpp
b9f72129b467e32843adf66841cc170c2d055e6f
[features.git] / src / LaTeX.cpp
1 /**
2  * \file LaTeX.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author Dekel Tsur
11  * \author Jürgen Spitzmüller
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "BufferList.h"
19 #include "LaTeX.h"
20 #include "LyXRC.h"
21 #include "DepTable.h"
22
23 #include "support/debug.h"
24 #include "support/convert.h"
25 #include "support/FileName.h"
26 #include "support/filetools.h"
27 #include "support/gettext.h"
28 #include "support/lstrings.h"
29 #include "support/Systemcall.h"
30 #include "support/os.h"
31
32 #include "support/regex.h"
33
34 #include <fstream>
35 #include <stack>
36
37
38 using namespace std;
39 using namespace lyx::support;
40
41 namespace lyx {
42
43 namespace os = support::os;
44
45 // TODO: in no particular order
46 // - get rid of the call to
47 //   BufferList::updateIncludedTeXfiles, this should either
48 //   be done before calling LaTeX::funcs or in a completely
49 //   different way.
50 // - the makeindex style files should be taken care of with
51 //   the dependency mechanism.
52
53 namespace {
54
55 docstring runMessage(unsigned int count)
56 {
57         return bformat(_("Waiting for LaTeX run number %1$d"), count);
58 }
59
60 } // anon namespace
61
62 /*
63  * CLASS TEXERRORS
64  */
65
66 void TeXErrors::insertError(int line, docstring const & error_desc,
67                             docstring const & error_text,
68                             string const & child_name)
69 {
70         Error newerr(line, error_desc, error_text, child_name);
71         errors.push_back(newerr);
72 }
73
74
75 bool operator==(AuxInfo const & a, AuxInfo const & o)
76 {
77         return a.aux_file == o.aux_file
78                 && a.citations == o.citations
79                 && a.databases == o.databases
80                 && a.styles == o.styles;
81 }
82
83
84 bool operator!=(AuxInfo const & a, AuxInfo const & o)
85 {
86         return !(a == o);
87 }
88
89
90 /*
91  * CLASS LaTeX
92  */
93
94 LaTeX::LaTeX(string const & latex, OutputParams const & rp,
95              FileName const & f, string const & p)
96         : cmd(latex), file(f), path(p), runparams(rp), biber(false)
97 {
98         num_errors = 0;
99         if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
100                 depfile = FileName(file.absFileName() + ".dep-pdf");
101                 output_file =
102                         FileName(changeExtension(file.absFileName(), ".pdf"));
103         } else {
104                 depfile = FileName(file.absFileName() + ".dep");
105                 output_file =
106                         FileName(changeExtension(file.absFileName(), ".dvi"));
107         }
108 }
109
110
111 void LaTeX::deleteFilesOnError() const
112 {
113         // currently just a dummy function.
114
115         // What files do we have to delete?
116
117         // This will at least make latex do all the runs
118         depfile.removeFile();
119
120         // but the reason for the error might be in a generated file...
121
122         // bibtex file
123         FileName const bbl(changeExtension(file.absFileName(), ".bbl"));
124         bbl.removeFile();
125
126         // biber file
127         FileName const bcf(changeExtension(file.absFileName(), ".bcf"));
128         bcf.removeFile();
129
130         // makeindex file
131         FileName const ind(changeExtension(file.absFileName(), ".ind"));
132         ind.removeFile();
133
134         // nomencl file
135         FileName const nls(changeExtension(file.absFileName(), ".nls"));
136         nls.removeFile();
137
138         // nomencl file (old version of the package)
139         FileName const gls(changeExtension(file.absFileName(), ".gls"));
140         gls.removeFile();
141
142         // Also remove the aux file
143         FileName const aux(changeExtension(file.absFileName(), ".aux"));
144         aux.removeFile();
145
146         // Remove the output file, which is often generated even if error
147         output_file.removeFile();
148 }
149
150
151 int LaTeX::run(TeXErrors & terr)
152         // We know that this function will only be run if the lyx buffer
153         // has been changed. We also know that a newly written .tex file
154         // is always different from the previous one because of the date
155         // in it. However it seems safe to run latex (at least) one time
156         // each time the .tex file changes.
157 {
158         int scanres = NO_ERRORS;
159         unsigned int count = 0; // number of times run
160         num_errors = 0; // just to make sure.
161         unsigned int const MAX_RUN = 6;
162         DepTable head; // empty head
163         bool rerun = false; // rerun requested
164
165         // The class LaTeX does not know the temp path.
166         theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFileName(),
167                 runparams);
168
169         // Never write the depfile if an error was encountered.
170
171         // 0
172         // first check if the file dependencies exist:
173         //     ->If it does exist
174         //             check if any of the files mentioned in it have
175         //             changed (done using a checksum).
176         //                 -> if changed:
177         //                        run latex once and
178         //                        remake the dependency file
179         //                 -> if not changed:
180         //                        just return there is nothing to do for us.
181         //     ->if it doesn't exist
182         //             make it and
183         //             run latex once (we need to run latex once anyway) and
184         //             remake the dependency file.
185         //
186
187         bool had_depfile = depfile.exists();
188         bool run_bibtex = false;
189         FileName const aux_file(changeExtension(file.absFileName(), ".aux"));
190
191         if (had_depfile) {
192                 LYXERR(Debug::DEPEND, "Dependency file exists");
193                 // Read the dep file:
194                 had_depfile = head.read(depfile);
195         }
196
197         if (had_depfile) {
198                 // Update the checksums
199                 head.update();
200                 // Can't just check if anything has changed because it might
201                 // have aborted on error last time... in which cas we need
202                 // to re-run latex and collect the error messages
203                 // (even if they are the same).
204                 if (!output_file.exists()) {
205                         LYXERR(Debug::DEPEND,
206                                 "re-running LaTeX because output file doesn't exist.");
207                 } else if (!head.sumchange()) {
208                         LYXERR(Debug::DEPEND, "return no_change");
209                         return NO_CHANGE;
210                 } else {
211                         LYXERR(Debug::DEPEND, "Dependency file has changed");
212                 }
213
214                 if (head.extchanged(".bib") || head.extchanged(".bst"))
215                         run_bibtex = true;
216         } else
217                 LYXERR(Debug::DEPEND,
218                         "Dependency file does not exist, or has wrong format");
219
220         /// We scan the aux file even when had_depfile = false,
221         /// because we can run pdflatex on the file after running latex on it,
222         /// in which case we will not need to run bibtex again.
223         vector<AuxInfo> bibtex_info_old;
224         if (!run_bibtex)
225                 bibtex_info_old = scanAuxFiles(aux_file);
226
227         ++count;
228         LYXERR(Debug::LATEX, "Run #" << count);
229         message(runMessage(count));
230
231         startscript();
232         scanres = scanLogFile(terr);
233         if (scanres & ERROR_RERUN) {
234                 LYXERR(Debug::LATEX, "Rerunning LaTeX");
235                 startscript();
236                 scanres = scanLogFile(terr);
237         }
238
239         if (scanres & ERRORS) {
240                 deleteFilesOnError();
241                 return scanres; // return on error
242         }
243
244         vector<AuxInfo> const bibtex_info = scanAuxFiles(aux_file);
245         if (!run_bibtex && bibtex_info_old != bibtex_info)
246                 run_bibtex = true;
247
248         // update the dependencies.
249         deplog(head); // reads the latex log
250         head.update();
251
252         // 1
253         // At this point we must run external programs if needed.
254         // makeindex will be run if a .idx file changed or was generated.
255         // And if there were undefined citations or changes in references
256         // the .aux file is checked for signs of bibtex. Bibtex is then run
257         // if needed.
258
259         // memoir (at least) writes an empty *idx file in the first place.
260         // A second latex run is needed.
261         FileName const idxfile(changeExtension(file.absFileName(), ".idx"));
262         rerun = idxfile.exists() && idxfile.isFileEmpty();
263
264         // run makeindex
265         if (head.haschanged(idxfile)) {
266                 // no checks for now
267                 LYXERR(Debug::LATEX, "Running MakeIndex.");
268                 message(_("Running Index Processor."));
269                 // onlyFileName() is needed for cygwin
270                 rerun |= runMakeIndex(onlyFileName(idxfile.absFileName()),
271                                 runparams);
272         }
273         FileName const nlofile(changeExtension(file.absFileName(), ".nlo"));
274         // If all nomencl entries are removed, nomencl writes an empty nlo file.
275         // DepTable::hasChanged() returns false in this case, since it does not
276         // distinguish empty files from non-existing files. This is why we need
277         // the extra checks here (to trigger a rerun). Cf. discussions in #8905.
278         // FIXME: Sort out the real problem in DepTable.
279         if (head.haschanged(nlofile) || (nlofile.exists() && nlofile.isFileEmpty()))
280                 rerun |= runMakeIndexNomencl(file, ".nlo", ".nls");
281         FileName const glofile(changeExtension(file.absFileName(), ".glo"));
282         if (head.haschanged(glofile))
283                 rerun |= runMakeIndexNomencl(file, ".glo", ".gls");
284
285         // check if we're using biber instead of bibtex
286         // biber writes no info to the aux file, so we just check
287         // if a bcf file exists (and if it was updated)
288         FileName const bcffile(changeExtension(file.absFileName(), ".bcf"));
289         biber |= head.exist(bcffile);
290
291         // run bibtex
292         // if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
293         if (scanres & UNDEF_CIT || run_bibtex) {
294                 // Here we must scan the .aux file and look for
295                 // "\bibdata" and/or "\bibstyle". If one of those
296                 // tags is found -> run bibtex and set rerun = true;
297                 // no checks for now
298                 LYXERR(Debug::LATEX, "Running BibTeX.");
299                 message(_("Running BibTeX."));
300                 updateBibtexDependencies(head, bibtex_info);
301                 rerun |= runBibTeX(bibtex_info, runparams);
302                 FileName const blgfile(changeExtension(file.absFileName(), ".blg"));
303                 if (blgfile.exists()) {
304                         int bscanres = scanBlgFile(head, terr);
305                         if (bscanres & ERRORS) {
306                                 deleteFilesOnError();
307                                 return bscanres; // return on error
308                         }
309                 }
310         } else if (!had_depfile) {
311                 /// If we run pdflatex on the file after running latex on it,
312                 /// then we do not need to run bibtex, but we do need to
313                 /// insert the .bib and .bst files into the .dep-pdf file.
314                 updateBibtexDependencies(head, bibtex_info);
315         }
316
317         // 2
318         // we know on this point that latex has been run once (or we just
319         // returned) and the question now is to decide if we need to run
320         // it any more. This is done by asking if any of the files in the
321         // dependency file has changed. (remember that the checksum for
322         // a given file is reported to have changed if it just was created)
323         //     -> if changed or rerun == true:
324         //             run latex once more and
325         //             update the dependency structure
326         //     -> if not changed:
327         //             we do nothing at this point
328         //
329         if (rerun || head.sumchange()) {
330                 rerun = false;
331                 ++count;
332                 LYXERR(Debug::DEPEND, "Dep. file has changed or rerun requested");
333                 LYXERR(Debug::LATEX, "Run #" << count);
334                 message(runMessage(count));
335                 startscript();
336                 scanres = scanLogFile(terr);
337                 if (scanres & ERRORS) {
338                         deleteFilesOnError();
339                         return scanres; // return on error
340                 }
341
342                 // update the depedencies
343                 deplog(head); // reads the latex log
344                 head.update();
345         } else {
346                 LYXERR(Debug::DEPEND, "Dep. file has NOT changed");
347         }
348         
349         // 3
350         // rerun bibtex?
351         // Complex bibliography packages such as Biblatex require
352         // an additional bibtex cycle sometimes.
353         if (scanres & UNDEF_CIT) {
354                 // Here we must scan the .aux file and look for
355                 // "\bibdata" and/or "\bibstyle". If one of those
356                 // tags is found -> run bibtex and set rerun = true;
357                 // no checks for now
358                 LYXERR(Debug::LATEX, "Running BibTeX.");
359                 message(_("Running BibTeX."));
360                 updateBibtexDependencies(head, bibtex_info);
361                 rerun |= runBibTeX(bibtex_info, runparams);
362                 FileName const blgfile(changeExtension(file.absFileName(), ".blg"));
363                 if (blgfile.exists()) {
364                         int bscanres = scanBlgFile(head, terr);
365                         if (bscanres & ERRORS) {
366                                 deleteFilesOnError();
367                                 return bscanres; // return on error
368                         }
369                 }
370         }
371
372         // 4
373         // The inclusion of files generated by external programs such as
374         // makeindex or bibtex might have done changes to pagenumbering,
375         // etc. And because of this we must run the external programs
376         // again to make sure everything is redone correctly.
377         // Also there should be no need to run the external programs any
378         // more after this.
379
380         // run makeindex if the <file>.idx has changed or was generated.
381         if (head.haschanged(idxfile)) {
382                 // no checks for now
383                 LYXERR(Debug::LATEX, "Running MakeIndex.");
384                 message(_("Running Index Processor."));
385                 // onlyFileName() is needed for cygwin
386                 rerun = runMakeIndex(onlyFileName(changeExtension(
387                                 file.absFileName(), ".idx")), runparams);
388         }
389
390         // I am not pretty sure if need this twice.
391         if (head.haschanged(nlofile))
392                 rerun |= runMakeIndexNomencl(file, ".nlo", ".nls");
393         if (head.haschanged(glofile))
394                 rerun |= runMakeIndexNomencl(file, ".glo", ".gls");
395
396         // 5
397         // we will only run latex more if the log file asks for it.
398         // or if the sumchange() is true.
399         //     -> rerun asked for:
400         //             run latex and
401         //             remake the dependency file
402         //             goto 2 or return if max runs are reached.
403         //     -> rerun not asked for:
404         //             just return (fall out of bottom of func)
405         //
406         while ((head.sumchange() || rerun || (scanres & RERUN))
407                && count < MAX_RUN) {
408                 // Yes rerun until message goes away, or until
409                 // MAX_RUNS are reached.
410                 rerun = false;
411                 ++count;
412                 LYXERR(Debug::LATEX, "Run #" << count);
413                 message(runMessage(count));
414                 startscript();
415                 scanres = scanLogFile(terr);
416                 if (scanres & ERRORS) {
417                         deleteFilesOnError();
418                         return scanres; // return on error
419                 }
420
421                 // keep this updated
422                 head.update();
423         }
424
425         // Write the dependencies to file.
426         head.write(depfile);
427         if (scanres & NO_OUTPUT) {
428                 // A previous run could have left a PDF and since
429                 // no PDF is created if NO_OUTPUT, we remove any
430                 // existing PDF and temporary files so that an
431                 // incorrect PDF is not displayed, which could otherwise
432                 // happen if View is run again because the checksum will
433                 // be the same so any lingering PDF will be viewed.
434                 deleteFilesOnError();
435         }
436         LYXERR(Debug::LATEX, "Done.");
437         return scanres;
438 }
439
440
441 int LaTeX::startscript()
442 {
443         // onlyFileName() is needed for cygwin
444         string tmp = cmd + ' '
445                      + quoteName(onlyFileName(file.toFilesystemEncoding()))
446                      + " > " + os::nulldev();
447         Systemcall one;
448         return one.startscript(Systemcall::Wait, tmp, path);
449 }
450
451
452 bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams,
453                          string const & params)
454 {
455         string tmp = runparams.use_japanese ?
456                 lyxrc.jindex_command : lyxrc.index_command;
457         
458         if (!runparams.index_command.empty())
459                 tmp = runparams.index_command;
460
461         LYXERR(Debug::LATEX,
462                 "idx file has been made, running index processor ("
463                 << tmp << ") on file " << f);
464
465         tmp = subst(tmp, "$$lang", runparams.document_language);
466         if (runparams.use_indices) {
467                 tmp = lyxrc.splitindex_command + " -m " + quoteName(tmp);
468                 LYXERR(Debug::LATEX,
469                 "Multiple indices. Using splitindex command: " << tmp);
470         }
471         tmp += ' ';
472         tmp += quoteName(f);
473         tmp += params;
474         Systemcall one;
475         one.startscript(Systemcall::Wait, tmp, path);
476         return true;
477 }
478
479
480 bool LaTeX::runMakeIndexNomencl(FileName const & file,
481                 string const & nlo, string const & nls)
482 {
483         LYXERR(Debug::LATEX, "Running MakeIndex for nomencl.");
484         message(_("Running MakeIndex for nomencl."));
485         string tmp = lyxrc.nomencl_command + ' ';
486         // onlyFileName() is needed for cygwin
487         tmp += quoteName(onlyFileName(changeExtension(file.absFileName(), nlo)));
488         tmp += " -o "
489                 + onlyFileName(changeExtension(file.toFilesystemEncoding(), nls));
490         Systemcall one;
491         one.startscript(Systemcall::Wait, tmp, path);
492         return true;
493 }
494
495
496 vector<AuxInfo> const
497 LaTeX::scanAuxFiles(FileName const & file)
498 {
499         vector<AuxInfo> result;
500
501         result.push_back(scanAuxFile(file));
502
503         string const basename = removeExtension(file.absFileName());
504         for (int i = 1; i < 1000; ++i) {
505                 FileName const file2(basename
506                         + '.' + convert<string>(i)
507                         + ".aux");
508                 if (!file2.exists())
509                         break;
510                 result.push_back(scanAuxFile(file2));
511         }
512         return result;
513 }
514
515
516 AuxInfo const LaTeX::scanAuxFile(FileName const & file)
517 {
518         AuxInfo result;
519         result.aux_file = file;
520         scanAuxFile(file, result);
521         return result;
522 }
523
524
525 void LaTeX::scanAuxFile(FileName const & file, AuxInfo & aux_info)
526 {
527         LYXERR(Debug::LATEX, "Scanning aux file: " << file);
528
529         ifstream ifs(file.toFilesystemEncoding().c_str());
530         string token;
531         static regex const reg1("\\\\citation\\{([^}]+)\\}");
532         static regex const reg2("\\\\bibdata\\{([^}]+)\\}");
533         static regex const reg3("\\\\bibstyle\\{([^}]+)\\}");
534         static regex const reg4("\\\\@input\\{([^}]+)\\}");
535
536         while (getline(ifs, token)) {
537                 token = rtrim(token, "\r");
538                 smatch sub;
539                 // FIXME UNICODE: We assume that citation keys and filenames
540                 // in the aux file are in the file system encoding.
541                 token = to_utf8(from_filesystem8bit(token));
542                 if (regex_match(token, sub, reg1)) {
543                         string data = sub.str(1);
544                         while (!data.empty()) {
545                                 string citation;
546                                 data = split(data, citation, ',');
547                                 LYXERR(Debug::LATEX, "Citation: " << citation);
548                                 aux_info.citations.insert(citation);
549                         }
550                 } else if (regex_match(token, sub, reg2)) {
551                         string data = sub.str(1);
552                         // data is now all the bib files separated by ','
553                         // get them one by one and pass them to the helper
554                         while (!data.empty()) {
555                                 string database;
556                                 data = split(data, database, ',');
557                                 database = changeExtension(database, "bib");
558                                 LYXERR(Debug::LATEX, "BibTeX database: `" << database << '\'');
559                                 aux_info.databases.insert(database);
560                         }
561                 } else if (regex_match(token, sub, reg3)) {
562                         string style = sub.str(1);
563                         // token is now the style file
564                         // pass it to the helper
565                         style = changeExtension(style, "bst");
566                         LYXERR(Debug::LATEX, "BibTeX style: `" << style << '\'');
567                         aux_info.styles.insert(style);
568                 } else if (regex_match(token, sub, reg4)) {
569                         string const file2 = sub.str(1);
570                         scanAuxFile(makeAbsPath(file2), aux_info);
571                 }
572         }
573 }
574
575
576 void LaTeX::updateBibtexDependencies(DepTable & dep,
577                                      vector<AuxInfo> const & bibtex_info)
578 {
579         // Since a run of Bibtex mandates more latex runs it is ok to
580         // remove all ".bib" and ".bst" files.
581         dep.remove_files_with_extension(".bib");
582         dep.remove_files_with_extension(".bst");
583         //string aux = OnlyFileName(ChangeExtension(file, ".aux"));
584
585         for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
586              it != bibtex_info.end(); ++it) {
587                 for (set<string>::const_iterator it2 = it->databases.begin();
588                      it2 != it->databases.end(); ++it2) {
589                         FileName const file = findtexfile(*it2, "bib");
590                         if (!file.empty())
591                                 dep.insert(file, true);
592                 }
593
594                 for (set<string>::const_iterator it2 = it->styles.begin();
595                      it2 != it->styles.end(); ++it2) {
596                         FileName const file = findtexfile(*it2, "bst");
597                         if (!file.empty())
598                                 dep.insert(file, true);
599                 }
600         }
601
602         // biber writes nothing into the aux file.
603         // Instead, we have to scan the blg file
604         if (biber) {
605                 TeXErrors terr;
606                 scanBlgFile(dep, terr);
607         }
608 }
609
610
611 bool LaTeX::runBibTeX(vector<AuxInfo> const & bibtex_info,
612                       OutputParams const & runparams)
613 {
614         bool result = false;
615         for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
616              it != bibtex_info.end(); ++it) {
617                 if (!biber && it->databases.empty())
618                         continue;
619                 result = true;
620
621                 string tmp = runparams.use_japanese ?
622                         lyxrc.jbibtex_command : lyxrc.bibtex_command;
623
624                 if (!runparams.bibtex_command.empty())
625                         tmp = runparams.bibtex_command;
626                 tmp += " ";
627                 // onlyFileName() is needed for cygwin
628                 tmp += quoteName(onlyFileName(removeExtension(
629                                 it->aux_file.absFileName())));
630                 Systemcall one;
631                 one.startscript(Systemcall::Wait, tmp, path);
632         }
633         // Return whether bibtex was run
634         return result;
635 }
636
637
638 int LaTeX::scanLogFile(TeXErrors & terr)
639 {
640         int last_line = -1;
641         int line_count = 1;
642         int retval = NO_ERRORS;
643         string tmp =
644                 onlyFileName(changeExtension(file.absFileName(), ".log"));
645         LYXERR(Debug::LATEX, "Log file: " << tmp);
646         FileName const fn = FileName(makeAbsPath(tmp));
647         ifstream ifs(fn.toFilesystemEncoding().c_str());
648         bool fle_style = false;
649         static regex const file_line_error(".+\\.\\D+:[0-9]+: (.+)");
650         static regex const child_file(".*([0-9]+[A-Za-z]*_.+\\.tex).*");
651         // Flag for 'File ended while scanning' message.
652         // We need to wait for subsequent processing.
653         string wait_for_error;
654         string child_name;
655         int pnest = 0;
656         stack <pair<string, int> > child;
657
658         string token;
659         while (getline(ifs, token)) {
660                 // MikTeX sometimes inserts \0 in the log file. They can't be
661                 // removed directly with the existing string utility
662                 // functions, so convert them first to \r, and remove all
663                 // \r's afterwards, since we need to remove them anyway.
664                 token = subst(token, '\0', '\r');
665                 token = subst(token, "\r", "");
666                 smatch sub;
667
668                 LYXERR(Debug::LATEX, "Log line: " << token);
669
670                 if (token.empty())
671                         continue;
672
673                 // Track child documents
674                 for (size_t i = 0; i < token.length(); ++i) {
675                         if (token[i] == '(') {
676                                 ++pnest;
677                                 size_t j = token.find('(', i + 1);
678                                 size_t len = j == string::npos
679                                                 ? token.substr(i + 1).length()
680                                                 : j - i - 1;
681                                 string const substr = token.substr(i + 1, len);
682                                 if (regex_match(substr, sub, child_file)) {
683                                         string const name = sub.str(1);
684                                         child.push(make_pair(name, pnest));
685                                         i += len;
686                                 }
687                         } else if (token[i] == ')') {
688                                 if (!child.empty()
689                                     && child.top().second == pnest)
690                                         child.pop();
691                                 --pnest;
692                         }
693                 }
694                 child_name = child.empty() ? empty_string() : child.top().first;
695
696                 if (contains(token, "file:line:error style messages enabled"))
697                         fle_style = true;
698
699                 if (prefixIs(token, "LaTeX Warning:") ||
700                     prefixIs(token, "! pdfTeX warning")) {
701                         // Here shall we handle different
702                         // types of warnings
703                         retval |= LATEX_WARNING;
704                         LYXERR(Debug::LATEX, "LaTeX Warning.");
705                         if (contains(token, "Rerun to get cross-references")) {
706                                 retval |= RERUN;
707                                 LYXERR(Debug::LATEX, "We should rerun.");
708                         // package clefval needs 2 latex runs before bibtex
709                         } else if (contains(token, "Value of")
710                                    && contains(token, "on page")
711                                    && contains(token, "undefined")) {
712                                 retval |= ERROR_RERUN;
713                                 LYXERR(Debug::LATEX, "Force rerun.");
714                         // package etaremune
715                         } else if (contains(token, "Etaremune labels have changed")) {
716                                 retval |= ERROR_RERUN;
717                                 LYXERR(Debug::LATEX, "Force rerun.");
718                         } else if (contains(token, "Citation")
719                                    && contains(token, "on page")
720                                    && contains(token, "undefined")) {
721                                 retval |= UNDEF_CIT;
722                         } else if (contains(token, "Citation")
723                                    && contains(token, "on input line")
724                                    && contains(token, "undefined")) {
725                                 retval |= UNDEF_CIT;
726                         }
727                 } else if (prefixIs(token, "Package")) {
728                         // Package warnings
729                         retval |= PACKAGE_WARNING;
730                         if (contains(token, "natbib Warning:")) {
731                                 // Natbib warnings
732                                 if (contains(token, "Citation")
733                                     && contains(token, "on page")
734                                     && contains(token, "undefined")) {
735                                         retval |= UNDEF_CIT;
736                                 }
737                         } else if (contains(token, "run BibTeX")) {
738                                 retval |= UNDEF_CIT;
739                         } else if (contains(token, "run Biber")) {
740                                 retval |= UNDEF_CIT;
741                                 biber = true;
742                         } else if (contains(token, "Rerun LaTeX") ||
743                                    contains(token, "Please rerun LaTeX") ||
744                                    contains(token, "Rerun to get")) {
745                                 // at least longtable.sty and bibtopic.sty
746                                 // might use this.
747                                 LYXERR(Debug::LATEX, "We should rerun.");
748                                 retval |= RERUN;
749                         }
750                 } else if (prefixIs(token, "LETTRE WARNING:")) {
751                         if (contains(token, "veuillez recompiler")) {
752                                 // lettre.cls
753                                 LYXERR(Debug::LATEX, "We should rerun.");
754                                 retval |= RERUN;
755                         }
756                 } else if (token[0] == '(') {
757                         if (contains(token, "Rerun LaTeX") ||
758                             contains(token, "Rerun to get")) {
759                                 // Used by natbib
760                                 LYXERR(Debug::LATEX, "We should rerun.");
761                                 retval |= RERUN;
762                         }
763                 } else if (prefixIs(token, "! ")
764                             || (fle_style
765                                 && regex_match(token, sub, file_line_error)
766                                 && !contains(token, "pdfTeX warning"))) {
767                            // Ok, we have something that looks like a TeX Error
768                            // but what do we really have.
769
770                         // Just get the error description:
771                         string desc;
772                         if (prefixIs(token, "! "))
773                                 desc = string(token, 2);
774                         else if (fle_style)
775                                 desc = sub.str();
776                         if (contains(token, "LaTeX Error:"))
777                                 retval |= LATEX_ERROR;
778
779                         if (prefixIs(token, "! File ended while scanning")){
780                                 if (prefixIs(token, "! File ended while scanning use of \\Hy@setref@link.")){
781                                         // bug 7344. We must rerun LaTeX if hyperref has been toggled.
782                                         retval |= ERROR_RERUN;
783                                         LYXERR(Debug::LATEX, "Force rerun.");
784                                 } else {
785                                         // bug 6445. At this point its not clear we finish with error.
786                                         wait_for_error = desc;
787                                         continue;
788                                 }
789                         }
790
791                         if (prefixIs(token, "! Paragraph ended before \\Hy@setref@link was complete.")){
792                                         // bug 7344. We must rerun LaTeX if hyperref has been toggled.
793                                         retval |= ERROR_RERUN;
794                                         LYXERR(Debug::LATEX, "Force rerun.");
795                         }
796
797                         if (!wait_for_error.empty() && prefixIs(token, "! Emergency stop.")){
798                                 retval |= LATEX_ERROR;
799                                 string errstr;
800                                 int count = 0;
801                                 errstr = wait_for_error;
802                                 do {
803                                         if (!getline(ifs, tmp))
804                                                 break;
805                                         tmp = rtrim(tmp, "\r");
806                                         errstr += "\n" + tmp;
807                                         if (++count > 5)
808                                                 break;
809                                 } while (!contains(tmp, "(job aborted"));
810
811                                 terr.insertError(0,
812                                                  from_local8bit("Emergency stop"),
813                                                  from_local8bit(errstr),
814                                                  child_name);
815                         }
816
817                         // get the next line
818                         string tmp;
819                         int count = 0;
820                         do {
821                                 if (!getline(ifs, tmp))
822                                         break;
823                                 tmp = rtrim(tmp, "\r");
824                                 if (++count > 10)
825                                         break;
826                         } while (!prefixIs(tmp, "l."));
827                         if (prefixIs(tmp, "l.")) {
828                                 // we have a latex error
829                                 retval |=  TEX_ERROR;
830                                 if (contains(desc,
831                                         "Package babel Error: You haven't defined the language")
832                                     || contains(desc,
833                                         "Package babel Error: You haven't loaded the option")
834                                     || contains(desc,
835                                         "Package babel Error: Unknown language"))
836                                         retval |= ERROR_RERUN;
837                                 // get the line number:
838                                 int line = 0;
839                                 sscanf(tmp.c_str(), "l.%d", &line);
840                                 // get the rest of the message:
841                                 string errstr(tmp, tmp.find(' '));
842                                 errstr += '\n';
843                                 getline(ifs, tmp);
844                                 tmp = rtrim(tmp, "\r");
845                                 while (!contains(errstr, "l.")
846                                        && !tmp.empty()
847                                        && !prefixIs(tmp, "! ")
848                                        && !contains(tmp, "(job aborted")) {
849                                         errstr += tmp;
850                                         errstr += "\n";
851                                         getline(ifs, tmp);
852                                         tmp = rtrim(tmp, "\r");
853                                 }
854                                 LYXERR(Debug::LATEX, "line: " << line << '\n'
855                                         << "Desc: " << desc << '\n' << "Text: " << errstr);
856                                 if (line == last_line)
857                                         ++line_count;
858                                 else {
859                                         line_count = 1;
860                                         last_line = line;
861                                 }
862                                 if (line_count <= 5) {
863                                         // FIXME UNICODE
864                                         // We have no idea what the encoding of
865                                         // the log file is.
866                                         // It seems that the output from the
867                                         // latex compiler itself is pure ASCII,
868                                         // but it can include bits from the
869                                         // document, so whatever encoding we
870                                         // assume here it can be wrong.
871                                         terr.insertError(line,
872                                                          from_local8bit(desc),
873                                                          from_local8bit(errstr),
874                                                          child_name);
875                                         ++num_errors;
876                                 }
877                         }
878                 } else {
879                         // information messages, TeX warnings and other
880                         // warnings we have not caught earlier.
881                         if (prefixIs(token, "Overfull ")) {
882                                 retval |= TEX_WARNING;
883                         } else if (prefixIs(token, "Underfull ")) {
884                                 retval |= TEX_WARNING;
885                         } else if (contains(token, "Rerun to get citations")) {
886                                 // Natbib seems to use this.
887                                 retval |= UNDEF_CIT;
888                         } else if (contains(token, "No pages of output")) {
889                                 // A dvi file was not created
890                                 retval |= NO_OUTPUT;
891                         } else if (contains(token, "That makes 100 errors")) {
892                                 // More than 100 errors were reprted
893                                 retval |= TOO_MANY_ERRORS;
894                         } else if (prefixIs(token, "!pdfTeX error:")){
895                                 // otherwise we dont catch e.g.:
896                                 // !pdfTeX error: pdflatex (file feyn10): Font feyn10 at 600 not found
897                                 retval |= ERRORS;
898                                         terr.insertError(0,
899                                                          from_local8bit("pdfTeX Error"),
900                                                          from_local8bit(token),
901                                                          child_name);
902                         }
903                 }
904         }
905         LYXERR(Debug::LATEX, "Log line: " << token);
906         return retval;
907 }
908
909
910 namespace {
911
912 bool insertIfExists(FileName const & absname, DepTable & head)
913 {
914         if (absname.exists() && !absname.isDirectory()) {
915                 head.insert(absname, true);
916                 return true;
917         }
918         return false;
919 }
920
921
922 bool handleFoundFile(string const & ff, DepTable & head)
923 {
924         // convert from native os path to unix path
925         string foundfile = os::internal_path(trim(ff));
926
927         LYXERR(Debug::DEPEND, "Found file: " << foundfile);
928
929         // Ok now we found a file.
930         // Now we should make sure that this is a file that we can
931         // access through the normal paths.
932         // We will not try any fancy search methods to
933         // find the file.
934
935         // (1) foundfile is an
936         //     absolute path and should
937         //     be inserted.
938         FileName absname;
939         if (FileName::isAbsolute(foundfile)) {
940                 LYXERR(Debug::DEPEND, "AbsolutePath file: " << foundfile);
941                 // On initial insert we want to do the update at once
942                 // since this file cannot be a file generated by
943                 // the latex run.
944                 absname.set(foundfile);
945                 if (!insertIfExists(absname, head)) {
946                         // check for spaces
947                         string strippedfile = foundfile;
948                         while (contains(strippedfile, " ")) {
949                                 // files with spaces are often enclosed in quotation
950                                 // marks; those have to be removed
951                                 string unquoted = subst(strippedfile, "\"", "");
952                                 absname.set(unquoted);
953                                 if (insertIfExists(absname, head))
954                                         return true;
955                                 // strip off part after last space and try again
956                                 string tmp = strippedfile;
957                                 string const stripoff =
958                                         rsplit(tmp, strippedfile, ' ');
959                                 absname.set(strippedfile);
960                                 if (insertIfExists(absname, head))
961                                         return true;
962                         }
963                 }
964         }
965
966         string onlyfile = onlyFileName(foundfile);
967         absname = makeAbsPath(onlyfile);
968
969         // check for spaces
970         while (contains(foundfile, ' ')) {
971                 if (absname.exists())
972                         // everything o.k.
973                         break;
974                 else {
975                         // files with spaces are often enclosed in quotation
976                         // marks; those have to be removed
977                         string unquoted = subst(foundfile, "\"", "");
978                         absname = makeAbsPath(unquoted);
979                         if (absname.exists())
980                                 break;
981                         // strip off part after last space and try again
982                         string strippedfile;
983                         string const stripoff =
984                                 rsplit(foundfile, strippedfile, ' ');
985                         foundfile = strippedfile;
986                         onlyfile = onlyFileName(strippedfile);
987                         absname = makeAbsPath(onlyfile);
988                 }
989         }
990
991         // (2) foundfile is in the tmpdir
992         //     insert it into head
993         if (absname.exists() && !absname.isDirectory()) {
994                 // FIXME: This regex contained glo, but glo is used by the old
995                 // version of nomencl.sty. Do we need to put it back?
996                 static regex const unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
997                 if (regex_match(onlyfile, unwanted)) {
998                         LYXERR(Debug::DEPEND, "We don't want " << onlyfile
999                                 << " in the dep file");
1000                 } else if (suffixIs(onlyfile, ".tex")) {
1001                         // This is a tex file generated by LyX
1002                         // and latex is not likely to change this
1003                         // during its runs.
1004                         LYXERR(Debug::DEPEND, "Tmpdir TeX file: " << onlyfile);
1005                         head.insert(absname, true);
1006                 } else {
1007                         LYXERR(Debug::DEPEND, "In tmpdir file:" << onlyfile);
1008                         head.insert(absname);
1009                 }
1010                 return true;
1011         } else {
1012                 LYXERR(Debug::DEPEND, "Not a file or we are unable to find it.");
1013                 return false;
1014         }
1015 }
1016
1017
1018 bool completeFilename(string const & ff, DepTable & head)
1019 {
1020         // If we do not find a dot, we suspect
1021         // a fragmental file name
1022         if (!contains(ff, '.'))
1023                 return false;
1024
1025         // if we have a dot, we let handleFoundFile decide
1026         return handleFoundFile(ff, head);
1027 }
1028
1029
1030 int iterateLine(string const & token, regex const & reg, string const & closing,
1031                 int fragment_pos, DepTable & head)
1032 {
1033         smatch what;
1034         string::const_iterator first = token.begin();
1035         string::const_iterator end = token.end();
1036         bool fragment = false;
1037         string last_match;
1038
1039         while (regex_search(first, end, what, reg)) {
1040                 // if we have a dot, try to handle as file
1041                 if (contains(what.str(1), '.')) {
1042                         first = what[0].second;
1043                         if (what.str(2) == closing) {
1044                                 handleFoundFile(what.str(1), head);
1045                                 // since we had a closing bracket,
1046                                 // do not investigate further
1047                                 fragment = false;
1048                         } else
1049                                 // if we have no closing bracket,
1050                                 // try to handle as file nevertheless
1051                                 fragment = !handleFoundFile(
1052                                         what.str(1) + what.str(2), head);
1053                 }
1054                 // if we do not have a dot, check if the line has
1055                 // a closing bracket (else, we suspect a line break)
1056                 else if (what.str(2) != closing) {
1057                         first = what[0].second;
1058                         fragment = true;
1059                 } else {
1060                         // we have a closing bracket, so the content
1061                         // is not a file name.
1062                         // no need to investigate further
1063                         first = what[0].second;
1064                         fragment = false;
1065                 }
1066                 last_match = what.str(1);
1067         }
1068
1069         // We need to consider the result from previous line iterations:
1070         // We might not find a fragment here, but another one might follow
1071         // E.g.: (filename.ext) <filenam
1072         // Vice versa, we consider the search completed if a real match
1073         // follows a potential fragment from a previous iteration.
1074         // E.g. <some text we considered a fragment (filename.ext)
1075         // result = -1 means we did not find a fragment!
1076         int result = -1;
1077         int last_match_pos = -1;
1078         if (!last_match.empty() && token.find(last_match) != string::npos)
1079                 last_match_pos = int(token.find(last_match));
1080         if (fragment) {
1081                 if (last_match_pos > fragment_pos)
1082                         result = last_match_pos;
1083                 else
1084                         result = fragment_pos;
1085         } else
1086                 if (last_match_pos < fragment_pos)
1087                         result = fragment_pos;
1088
1089         return result;
1090 }
1091
1092 } // anon namespace
1093
1094
1095 void LaTeX::deplog(DepTable & head)
1096 {
1097         // This function reads the LaTeX log file end extracts all the
1098         // external files used by the LaTeX run. The files are then
1099         // entered into the dependency file.
1100
1101         string const logfile =
1102                 onlyFileName(changeExtension(file.absFileName(), ".log"));
1103
1104         static regex const reg1("File: (.+).*");
1105         static regex const reg2("No file (.+)(.).*");
1106         static regex const reg3("\\\\openout[0-9]+.*=.*`(.+)(..).*");
1107         // If an index should be created, MikTex does not write a line like
1108         //    \openout# = 'sample.idx'.
1109         // but instead only a line like this into the log:
1110         //   Writing index file sample.idx
1111         static regex const reg4("Writing index file (.+).*");
1112         static regex const regoldnomencl("Writing glossary file (.+).*");
1113         static regex const regnomencl("Writing nomenclature file (.+).*");
1114         // If a toc should be created, MikTex does not write a line like
1115         //    \openout# = `sample.toc'.
1116         // but only a line like this into the log:
1117         //    \tf@toc=\write#
1118         // This line is also written by tetex.
1119         // This line is not present if no toc should be created.
1120         static regex const miktexTocReg("\\\\tf@toc=\\\\write.*");
1121         // file names can be enclosed in <...> (anywhere on the line)
1122         static regex const reg5(".*<[^>]+.*");
1123         // and also (...) anywhere on the line
1124         static regex const reg6(".*\\([^)]+.*");
1125
1126         FileName const fn = makeAbsPath(logfile);
1127         ifstream ifs(fn.toFilesystemEncoding().c_str());
1128         string lastline;
1129         while (ifs) {
1130                 // Ok, the scanning of files here is not sufficient.
1131                 // Sometimes files are named by "File: xxx" only
1132                 // Therefore we use some regexps to find files instead.
1133                 // Note: all file names and paths might contains spaces.
1134                 // Also, file names might be broken across lines. Therefore
1135                 // we mark (potential) fragments and merge those lines.
1136                 bool fragment = false;
1137                 string token;
1138                 getline(ifs, token);
1139                 // MikTeX sometimes inserts \0 in the log file. They can't be
1140                 // removed directly with the existing string utility
1141                 // functions, so convert them first to \r, and remove all
1142                 // \r's afterwards, since we need to remove them anyway.
1143                 token = subst(token, '\0', '\r');
1144                 token = subst(token, "\r", "");
1145                 if (token.empty() || token == ")") {
1146                         lastline = string();
1147                         continue;
1148                 }
1149
1150                 // FIXME UNICODE: We assume that the file names in the log
1151                 // file are in the file system encoding.
1152                 token = to_utf8(from_filesystem8bit(token));
1153
1154                 // Sometimes, filenames are broken across lines.
1155                 // We care for that and save suspicious lines.
1156                 // Here we exclude some cases where we are sure
1157                 // that there is no continued filename
1158                 if (!lastline.empty()) {
1159                         static regex const package_info("Package \\w+ Info: .*");
1160                         static regex const package_warning("Package \\w+ Warning: .*");
1161                         if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
1162                             || prefixIs(token, "Package:")
1163                             || prefixIs(token, "Language:")
1164                             || prefixIs(token, "LaTeX Info:")
1165                             || prefixIs(token, "LaTeX Font Info:")
1166                             || prefixIs(token, "\\openout[")
1167                             || prefixIs(token, "))")
1168                             || regex_match(token, package_info)
1169                             || regex_match(token, package_warning))
1170                                 lastline = string();
1171                 }
1172
1173                 if (!lastline.empty())
1174                         // probably a continued filename from last line
1175                         token = lastline + token;
1176                 if (token.length() > 255) {
1177                         // string too long. Cut off.
1178                         token.erase(0, token.length() - 251);
1179                 }
1180
1181                 smatch sub;
1182
1183                 // (1) "File: file.ext"
1184                 if (regex_match(token, sub, reg1)) {
1185                         // is this a fragmental file name?
1186                         fragment = !completeFilename(sub.str(1), head);
1187                         // However, ...
1188                         if (suffixIs(token, ")"))
1189                                 // no fragment for sure
1190                                 fragment = false;
1191                 // (2) "No file file.ext"
1192                 } else if (regex_match(token, sub, reg2)) {
1193                         // file names must contains a dot, line ends with dot
1194                         if (contains(sub.str(1), '.') && sub.str(2) == ".")
1195                                 fragment = !handleFoundFile(sub.str(1), head);
1196                         else
1197                                 // we suspect a line break
1198                                 fragment = true;
1199                 // (3) "\openout<nr> = `file.ext'."
1200                 } else if (regex_match(token, sub, reg3)) {
1201                         // search for closing '. at the end of the line
1202                         if (sub.str(2) == "\'.")
1203                                 fragment = !handleFoundFile(sub.str(1), head);
1204                         else
1205                                 // potential fragment
1206                                 fragment = true;
1207                 // (4) "Writing index file file.ext"
1208                 } else if (regex_match(token, sub, reg4))
1209                         // fragmential file name?
1210                         fragment = !completeFilename(sub.str(1), head);
1211                 // (5) "Writing nomenclature file file.ext"
1212                 else if (regex_match(token, sub, regnomencl) ||
1213                            regex_match(token, sub, regoldnomencl))
1214                         // fragmental file name?
1215                         fragment= !completeFilename(sub.str(1), head);
1216                 // (6) "\tf@toc=\write<nr>" (for MikTeX)
1217                 else if (regex_match(token, sub, miktexTocReg))
1218                         fragment = !handleFoundFile(onlyFileName(changeExtension(
1219                                                 file.absFileName(), ".toc")), head);
1220                 else
1221                         // not found, but we won't check further
1222                         fragment = false;
1223
1224                 int fragment_pos = -1;
1225                 // (7) "<file.ext>"
1226                 // We can have several of these on one line
1227                 // (and in addition to those above)
1228                 if (regex_match(token, sub, reg5)) {
1229                         // search for strings in <...>
1230                         static regex const reg5_1("<([^>]+)(.)");
1231                         fragment_pos = iterateLine(token, reg5_1, ">",
1232                                                    fragment_pos, head);
1233                         fragment = (fragment_pos != -1);
1234                 }
1235
1236                 // (8) "(file.ext)"
1237                 // We can have several of these on one line
1238                 // this must be queried separated, because of
1239                 // cases such as "File: file.ext (type eps)"
1240                 // where "File: file.ext" would be skipped
1241                 if (regex_match(token, sub, reg6)) {
1242                         // search for strings in (...)
1243                         static regex const reg6_1("\\(([^()]+)(.)");
1244                         fragment_pos = iterateLine(token, reg6_1, ")",
1245                                                    fragment_pos, head);
1246                         fragment = (fragment_pos != -1);
1247                 }
1248
1249                 if (fragment)
1250                         // probable linebreak within file name:
1251                         // save this line
1252                         lastline = token;
1253                 else
1254                         // no linebreak: reset
1255                         lastline = string();
1256         }
1257
1258         // Make sure that the main .tex file is in the dependency file.
1259         head.insert(file, true);
1260 }
1261
1262
1263 int LaTeX::scanBlgFile(DepTable & dep, TeXErrors & terr)
1264 {
1265         FileName const blg_file(changeExtension(file.absFileName(), "blg"));
1266         LYXERR(Debug::LATEX, "Scanning blg file: " << blg_file);
1267
1268         ifstream ifs(blg_file.toFilesystemEncoding().c_str());
1269         string token;
1270         static regex const reg1(".*Found (bibtex|BibTeX) data (file|source) '([^']+).*");
1271         static regex const bibtexError("^(.*---line [0-9]+ of file).*$");
1272         static regex const bibtexError2("^(.*---while reading file).*$");
1273         static regex const bibtexError3("(A bad cross reference---).*");
1274         static regex const bibtexError4("(Sorry---you've exceeded BibTeX's).*");
1275         static regex const bibtexError5("\\*Please notify the BibTeX maintainer\\*");
1276         static regex const biberError("^.*> (FATAL|ERROR) - (.*)$");
1277         int retval = NO_ERRORS;
1278
1279         string prevtoken;
1280         while (getline(ifs, token)) {
1281                 token = rtrim(token, "\r");
1282                 smatch sub;
1283                 // FIXME UNICODE: We assume that citation keys and filenames
1284                 // in the aux file are in the file system encoding.
1285                 token = to_utf8(from_filesystem8bit(token));
1286                 if (regex_match(token, sub, reg1)) {
1287                         string data = sub.str(3);
1288                         if (!data.empty()) {
1289                                 LYXERR(Debug::LATEX, "Found bib file: " << data);
1290                                 handleFoundFile(data, dep);
1291                         }
1292                 }
1293                 else if (regex_match(token, sub, bibtexError)
1294                          || regex_match(token, sub, bibtexError2)
1295                          || regex_match(token, sub, bibtexError4)
1296                          || regex_match(token, sub, bibtexError5)) {
1297                         retval |= BIBTEX_ERROR;
1298                         string errstr = N_("BibTeX error: ") + token;
1299                         string message;
1300                         if ((prefixIs(token, "while executing---line")
1301                              || prefixIs(token, "---line ")
1302                              || prefixIs(token, "*Please notify the BibTeX"))
1303                             && !prevtoken.empty()) {
1304                                 errstr = N_("BibTeX error: ") + prevtoken;
1305                                 message = prevtoken + '\n';
1306                         }
1307                         message += token;
1308                         terr.insertError(0,
1309                                          from_local8bit(errstr),
1310                                          from_local8bit(message));
1311                 } else if (regex_match(prevtoken, sub, bibtexError3)) {
1312                         retval |= BIBTEX_ERROR;
1313                         string errstr = N_("BibTeX error: ") + prevtoken;
1314                         string message = prevtoken + '\n' + token;
1315                         terr.insertError(0,
1316                                          from_local8bit(errstr),
1317                                          from_local8bit(message));
1318                 } else if (regex_match(token, sub, biberError)) {
1319                         retval |= BIBTEX_ERROR;
1320                         string errstr = N_("Biber error: ") + sub.str(2);
1321                         string message = token;
1322                         terr.insertError(0,
1323                                          from_local8bit(errstr),
1324                                          from_local8bit(message));
1325                 }
1326                 prevtoken = token;
1327         }
1328         return retval;
1329 }
1330
1331
1332 } // namespace lyx