]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeX.C
white-space changes, removed definitions.h several enum changes because of this,...
[lyx.git] / src / LaTeX.C
index 6b4bc7bd1d931fe1a7814d46d0f2b194c0f90a96..be5de47faf9e3421f134c7f5fe6d96ab68178fe1 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of
- * ======================================================
+ * ====================================================== 
  * 
  *           LyX, The Document Processor        
  *          Copyright 1995 Matthias Ettrich
@@ -8,31 +8,42 @@
  *           This file is Copyright 1996-1999
  *           Lars Gullik Bjønnes
  *
- * ======================================================
+ * ====================================================== 
  */
 
 #include <config.h>
 
-#include <cstdio>
-#include <cstdlib>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "support/filetools.h"
 #include "LaTeX.h"
-#include "lyxlex.h"
 #include "support/FileInfo.h"
-#include "error.h"
+#include "debug.h"
 #include "support/lyxlib.h"
 #include "support/syscall.h"
 #include "support/syscontr.h"
-#include "pathstack.h"
+#include "support/path.h"
 #include "bufferlist.h"
 #include "minibuffer.h"
 #include "gettext.h"
 
+using std::make_pair;
+
+// TODO: in no particular order
+// - get rid of the extern BufferList and the call to
+//   BufferList::updateIncludedTeXfiles, this should either
+//   be done before calling LaTeX::funcs or in a completely
+//   different way.
+// - the bibtex command options should be supported.
+// - the makeindex style files should be taken care of with
+//   the dependency mechanism.
+// - makeindex commandline options should be supported
+// - somewhere support viewing of bibtex and makeindex log files.
+// - we should perhaps also scan the bibtex log file
+// - we should perhaps also scan the bibtex log file
+
 extern BufferList bufferlist;
 
 struct texfile_struct {
@@ -57,177 +68,18 @@ const texfile_struct all_files[] = {
        { LaTeX::TEX, ".tex"}
 };
 
-// This should perhaps be placed in LyXLex
-static
-string readLine(FILE *file)
-{
-       if (feof(file))
-               return string();
-
-       int i = 0;
-       char s[512];
-
-       do {
-               s[i] = fgetc(file);
-               i++;
-       } while (!feof(file) && s[i-1] != '\n' && i<510);
-       s[i] = '\0';
-       string tmp;
-       if (i == 1 && feof(file))
-               ;
-       else
-               tmp = s;
-
-       return tmp;
-}
-
-
 
 /*
  * CLASS TEXERRORS
  */
 
-// I did not leave this inlined because DEC cxx does not like
-// variables declarations in inlined code (JMarc)
-TeXErrors::~TeXErrors()
-{
-       Error *tmp;
-       while (errors) {
-               tmp = errors->next_error;
-               delete errors;
-               errors = tmp;
-       }
-}
-
-
-void TeXErrors::scanError(LyXLex &lex)
-{
-       string token = lex.GetString();
-       // Sometimes the error string goes over more than one
-       // line, and we need to get them all.
-       string errstr;
-       string tmp = frontStrip(readLine(lex.getFile()));
-       if (tmp == "\n" || tmp.empty()) {
-               tmp = frontStrip(readLine(lex.getFile()));
-               if (contains(tmp, "See the LaTeX manual")) {
-                       do {
-                               tmp = readLine(lex.getFile());
-                       } while (!tmp.empty() && !contains(tmp, "..."));
-               }
-               tmp = frontStrip(readLine(lex.getFile()));
-       }
-
-       while ((tmp != "\n" || !contains(errstr, "l."))
-               && !prefixIs(tmp, "! ")
-               && !contains(tmp, "(job aborted")
-               && !tmp.empty()) {
-               errstr += tmp;
-               tmp = frontStrip(readLine(lex.getFile()));
-       }
-       lyxerr.debug("tmp: " + errstr);
-       int line = 0;
-       // unfortunately the error line is not always given
-       // by "l.###" in the beginning of the error string
-       // therefore we must search for "l.###" in the error
-       // msg.
-       if (contains(errstr, "l.")) {
-               // We make a const copy to make [] fast. (Asger)
-               string const es = errstr;
-               for (string::size_type i = 2; i < es.length(); ++i) {
-                       if (es[i-2] == 'l' && es[i-1] == '.' &&
-                           (es[i] >= '0' && es[i]<= '9')) {
-                               line = atoi(es.c_str() + i);
-                               break;
-                       }
-               }
-       }
-       insertError(line, token, errstr);
-
-       if (prefixIs(tmp, "! ")) {
-               scanError(lex);
-       }
-}
-
-
-bool TeXErrors::getFirstError(int *line, string *text)
-{
-        next_error = errors;
-        if (next_error) {
-                *line = next_error->error_in_line;
-                *text = next_error->error_desc + "\n" + next_error->error_text;
-                next_error = next_error->next_error;
-                return true;
-        }
-        return false;
-}
-
-
-bool TeXErrors::getNextError(int *line, string *text)
-{
-        if (next_error) {
-                *line = next_error->error_in_line;
-                *text = next_error->error_desc + "\n" + next_error->error_text;
-                next_error = next_error->next_error;
-                return true;
-        }
-        return false;
-}
-
-
-void TeXErrors::insertError(int line, string const &error_desc,
-                           string const &error_text)
-{
-        Error *newerr = new Error(line, error_desc, error_text);
-        if (errors) {
-                Error *tmperr = errors;
-                while (tmperr->next_error) tmperr = tmperr->next_error;
-                tmperr->next_error = newerr;
-        } else {
-                errors = newerr;
-        }
-}
-
-
-void TeXErrors::printErrors()
-{
-        lyxerr.print("Printing errors.");
-        if (errors) {
-                Error *tmperr = errors;
-                do {
-                        lyxerr.print(string("Error in line ")
-                                    + tostr(tmperr->error_in_line)
-                                    + ": " + tmperr->error_desc
-                                    + '\n' + tmperr->error_text);
-                       //%d: %s\n%s\n", tmperr->error_in_line,
-                       //     tmperr->error_desc.c_str(),
-                       //     tmperr->error_text.c_str());
-                        tmperr = tmperr->next_error;
-                } while (tmperr);
-        }
-}
-
-
-void TeXErrors::printWarnings()
-{
-}
-
-
-void TeXErrors::printStatus()
+void TeXErrors::insertError(int line, string const & error_desc,
+                           string const & error_text)
 {
-        lyxerr.print("Error struct:");
-        lyxerr.print(string("   status: ") + tostr(status));
-        lyxerr.print(string("   no err: ") + tostr(number_of_errors));
-        if (status == LaTeX::NO_ERRORS)  lyxerr.print("NO_ERRORS");
-        if (status & LaTeX::NO_LOGFILE)  lyxerr.print("NO_LOGFILE");
-        if (status & LaTeX::NO_OUTPUT)   lyxerr.print("NO_OUTPUT");
-        if (status & LaTeX::UNDEF_REF)   lyxerr. print("UNDEF_REF");
-        if (status & LaTeX::RERUN)       lyxerr. print("RERUN");
-        if (status & LaTeX::TEX_ERROR)   lyxerr.print("TEX_ERROR");
-        if (status & LaTeX::TEX_WARNING) lyxerr.print("TEX_WARNING");
-        if (status & LaTeX::NO_FILE)     lyxerr.print("NO_FILE");
+        Error newerr(line, error_desc, error_text);
+       errors.push_back(newerr);
 }
 
-
 /*
  * CLASS LaTeX
  */
@@ -242,7 +94,7 @@ LaTeX::LaTeX(string const & latex, string const & f, string const & p)
 }
 
 
-int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
+int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
        // We know that this function will only be run if the lyx buffer
        // has been changed. We also know that a newly written .tex file
        // is always different from the previous one because of the date
@@ -277,32 +129,34 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
        //             remake the dependency file.
        //
        FileInfo fi(depfile);
+       bool run_bibtex = false;
        if (fi.exist()) {
                // Read the dep file:
                head.read(depfile);
                // Update the checksums
                head.update();
                
-               lyxerr.debug("Dependency file exists", Error::LATEX);
+               lyxerr[Debug::LATEX] << "Dependency file exists" << endl;
                if (head.sumchange()) {
-                       lyxerr.debug("Dependency file has changed", 
-                                    Error::LATEX);
-                       lyxerr.debug(string(_("Run #")) + tostr(++count), 
-                                    Error::LATEX);
+                       ++count;
+                       if (head.extchanged(".bib")
+                           || head.extchanged(".bst")) run_bibtex = true;
+                       lyxerr[Debug::LATEX]
+                               << "Dependency file has changed\n"
+                               << "Run #" << count << endl; 
                        minib->Set(string(_("LaTeX run number ")) + tostr(count));
                        minib->Store();
                        this->operator()();
                        scanres = scanLogFile(terr);
                        if (scanres & LaTeX::ERRORS) return scanres; // return on error
                } else {
-                       lyxerr.debug("return no_change", Error::LATEX);
+                       lyxerr[Debug::LATEX] << "return no_change" << endl;
                        return LaTeX::NO_CHANGE;
                }
        } else {
-               lyxerr.debug("Dependency file does not exist",
-                            Error::LATEX);
-               lyxerr.debug(string(_("Run #")) + tostr(++count),
-                            Error::LATEX); 
+               ++count;
+               lyxerr[Debug::LATEX] << "Dependency file does not exist\n"
+                                    << "Run #" << count << endl;
                head.insert(file, true);
                minib->Set(string(_("LaTeX run number ")) + tostr(count));
                minib->Store();
@@ -326,20 +180,24 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
        // run makeindex
        if (head.haschanged(ChangeExtension(file, ".idx", true))) {
                // no checks for now
+               lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
                minib->Set(_("Running MakeIndex."));
                minib->Store();
-               rerun=runMakeIndex(ChangeExtension(file,".idx",true));
+               rerun = runMakeIndex(ChangeExtension(file, ".idx", true));
        }
 
        // run bibtex
-       if (scanres & LaTeX::UNDEF_CIT || scanres & LaTeX::RERUN) {
+       if (scanres & LaTeX::UNDEF_CIT
+           || scanres & LaTeX::RERUN
+           || run_bibtex) {
                // Here we must scan the .aux file and look for
                // "\bibdata" and/or "\bibstyle". If one of those
                // tags is found -> run bibtex and set rerun = true;
                // no checks for now
+               lyxerr[Debug::LATEX] << "Running BibTeX." << endl;
                minib->Set(_("Running BibTeX."));
                minib->Store();
-               rerun = runBibTeX(ChangeExtension(file, ".aux", true));
+               rerun = runBibTeX(ChangeExtension(file, ".aux", true), head);
        }
        
        // 1
@@ -356,10 +214,10 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
        //
        if (rerun || head.sumchange()) {
                rerun = false;
-               lyxerr.debug("Dep. file has changed or rerun requested", 
-                            Error::LATEX);
-               lyxerr.debug(string("Run #") + tostr(++count),
-                            Error::LATEX);
+               ++count;
+               lyxerr[Debug::LATEX]
+                       << "Dep. file has changed or rerun requested\n"
+                       << "Run #" << count << endl;
                minib->Set(string(_("LaTeX run number ")) + tostr(count));
                minib->Store();
                this->operator()();
@@ -369,7 +227,7 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
                deplog(head); // reads the latex log
                head.update();
        } else {
-               lyxerr.debug("Dep. file has NOT changed", Error::LATEX);
+               lyxerr[Debug::LATEX] << "Dep. file has NOT changed" << endl;
        }
 
        // 1.5
@@ -383,6 +241,7 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
        // run makeindex if the <file>.idx has changed or was generated.
        if (head.haschanged(ChangeExtension(file, ".idx", true))) {
                // no checks for now
+               lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
                minib->Set(_("Running MakeIndex."));
                minib->Store();
                rerun = runMakeIndex(ChangeExtension(file, ".idx", true));
@@ -403,7 +262,8 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
                // Yes rerun until message goes away, or until
                // MAX_RUNS are reached.
                rerun = false;
-               lyxerr.debug(string(_("Run #")) + tostr(++count), Error::LATEX);
+               ++count;
+               lyxerr[Debug::LATEX] << "Run #" << count << endl;
                minib->Set(string(_("LaTeX run number ")) + tostr(count));
                minib->Store();
                this->operator()();
@@ -415,7 +275,7 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib)
 
        // Write the dependencies to file.
        head.write(depfile);
-       lyxerr.debug("Done.", Error::LATEX);
+       lyxerr[Debug::LATEX] << "Done." << endl;
        return scanres;
 }
 
@@ -428,15 +288,15 @@ int LaTeX::operator()()
        string tmp = cmd + ' ' + file + " > nul";
 #endif
         Systemcalls one;
-       return one.Startscript(Systemcalls::System, tmp);
+       return one.startscript(Systemcalls::System, tmp);
 }
 
 
 bool LaTeX::runMakeIndex(string const &file)
 {
-       lyxerr.debug("idx file has been made,"
-                     " running makeindex on file "
-                     + file, Error::LATEX);
+       lyxerr[Debug::LATEX] << "idx file has been made,"
+               " running makeindex on file "
+                            <<  file << endl;
 
        // It should be possible to set the switches for makeindex
        // sorting style and such. It would also be very convenient
@@ -445,74 +305,138 @@ bool LaTeX::runMakeIndex(string const &file)
        string tmp = "makeindex -c -q ";
        tmp += file;
        Systemcalls one;
-       one.Startscript(Systemcalls::System, tmp);
+       one.startscript(Systemcalls::System, tmp);
        return true;
 }
 
 
-bool LaTeX::runBibTeX(string const &file)
+typedef pair<int, string> cmdret;
+static cmdret do_popen(string const & cmd)
 {
-       LyXLex lex(0, 0);
-       string token;
-       if (!lex.setFile(file)) {
-               // unable to open .aux file
-               // return at once
-               return false;
+       // One question is if we should use popen or
+       // create our own popen based on fork, exec, pipe
+       // of course the best would be to have a
+       // pstream (process stream), with the
+       // variants ipstream, opstream and
+       FILE * inf = popen(cmd.c_str(), "r");
+       string ret;
+       int c = fgetc(inf);
+       while (c != EOF) {
+               ret += static_cast<char>(c);
+               c = fgetc(inf);
        }
+       int pret = pclose(inf);
+       return make_pair(pret, ret);
+}
 
-       while (lex.IsOK()) {
-               if (lex.EatLine())
-                       token=lex.GetString();
-               else // blank line in the file being read
-                       continue;
 
+static string findtexfile(string const & fil, string const & format)
+{
+       // If fil is a file with absolute path we just return it
+       if (AbsolutePath(fil)) return fil;
+
+       // Check in the current dir.
+       if (FileInfo(OnlyFilename(fil)).exist())
+         return OnlyFilename(fil);
+       
+       // No we try to find it using kpsewhich.
+       string kpsecmd = "kpsewhich --format= " + format + " " + fil;
+       cmdret c = do_popen(kpsecmd);
+
+       lyxerr << "kpse status = " << c.first << "\n"
+              << "kpse result = `" << strip(c.second, '\n') << "'" << endl;
+       return c.first == 0 ? strip(c.second, '\n') : string();
+}
+
+
+bool LaTeX::runBibTeX(string const & file, DepTable & dep)
+{
+       ifstream ifs(file.c_str());
+       string token;
+       bool using_bibtex = false;
+       while (getline(ifs, token)) {
                if (contains(token, "\\bibdata{")) {
-                       // run bibtex and
-                       string tmp="bibtex ";
-                       tmp += ChangeExtension(file, string(), true);
-                       Systemcalls one;
-                       one.Startscript(Systemcalls::System, tmp);
-                       return true;
+                       using_bibtex = true;
+                       string::size_type a = token.find("\\bibdata{") + 9;
+                       string::size_type b = token.find_first_of("}", a);
+                       string data = token.substr(a, b - a);
+                       // data is now all the bib files separated by ','
+                       // get them one by one and pass them to the helper
+                       do {
+                               b = data.find_first_of(',', 0);
+                               string l;
+                               if (b == string::npos)
+                                       l = data;
+                               else {
+                                       l = data.substr(0, b - 0);
+                                       data.erase(0, b + 1);
+                               }
+                               string full_l = 
+                                       findtexfile(
+                                               ChangeExtension(l, "bib", false),
+                                               "bib");
+                               lyxerr << "data = `"
+                                      << full_l << "'" << endl;
+                               if (!full_l.empty()) {
+                                       // add full_l to the dep file.
+                                       dep.insert(full_l, true);
+                               }
+                       } while (b != string::npos);
+               } else if (contains(token, "\\bibstyle{")) {
+                       using_bibtex = true;
+                       string::size_type a = token.find("\\bibstyle{") + 10;
+                       string::size_type b = token.find_first_of("}", a);
+                       string style = token.substr(a, b - a);
+                       // token is now the style file
+                       // pass it to the helper
+                       string full_l = 
+                               findtexfile(
+                                       ChangeExtension(style, "bst", false),
+                                       "bst");
+                       lyxerr << "style = `"
+                              << full_l << "'" << endl;
+                       if (!full_l.empty()) {
+                               // add full_l to the dep file.
+                               dep.insert(full_l, true);
+                       }
                }
-               
+       }
+       if (using_bibtex) {
+               // run bibtex and
+               string tmp = "bibtex ";
+               tmp += ChangeExtension(file, string(), true);
+               Systemcalls one;
+               one.startscript(Systemcalls::System, tmp);
+               return true;
        }
        // bibtex was not run.
        return false;
 }
 
 
-int LaTeX::scanLogFile(TeXErrors &terr)
+int LaTeX::scanLogFile(TeXErrors & terr)
 {
-       string token;
        int retval = NO_ERRORS;
-       
-       LyXLex lex(0, 0);
-
        string tmp = ChangeExtension(file, ".log", true);
-       
-       if (!lex.setFile(tmp)) {
-               // unable to open file
-               // return at once
-               retval |= NO_LOGFILE;
-               return retval;
-       }
-       
-       while (lex.IsOK()) {
-               if (lex.EatLine())
-                       token = lex.GetString();
-               else // blank line in the file being read
-                       continue;
+       lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
+       ifstream ifs(tmp.c_str());
 
-               lyxerr.debug(token, Error::LATEX);
+       string token;
+       while (getline(ifs, token)) {
+               lyxerr[Debug::LATEX] << "Log line: " << token << endl;
                
+               if (token.empty())
+                       continue;
+
                if (prefixIs(token, "LaTeX Warning:")) {
                        // Here shall we handle different
                        // types of warnings
                        retval |= LATEX_WARNING;
-                       lyxerr.debug("LaTeX Warning.", Error::LATEX);
+                       lyxerr[Debug::LATEX] << "LaTeX Warning." << endl;
                        if (contains(token, "Rerun to get cross-references")) {
                                retval |= RERUN;
-                               lyxerr.debug("We should rerun.", Error::LATEX);
+                               lyxerr[Debug::LATEX]
+                                       << "We should rerun." << endl;
                        } else if (contains(token, "Citation")
                                   && contains(token, "on page")
                                   && contains(token, "undefined")) {
@@ -532,54 +456,41 @@ int LaTeX::scanLogFile(TeXErrors &terr)
                                // at least longtable.sty might use this.
                                retval |= RERUN;
                        }
-               } else if (prefixIs(token, "! LaTeX Error:")) {
-                       // Here shall we handle different
-                       // types of errors
-                       retval |= LATEX_ERROR;
-                       lyxerr.debug("LaTeX Error.", Error::LATEX);
-                       // this is not correct yet
-                       terr.scanError(lex);
-                       num_errors++;
                } else if (prefixIs(token, "! ")) {
                        // Ok, we have something that looks like a TeX Error
                        // but what do we really have.
 
                        // Just get the error description:
-                       string desc(token);
-                       desc.erase(0, 2);
-
-                       if (contains(desc, "Undefined control sequence")) {
-                               retval |= TEX_ERROR;
-                               lyxerr.debug("TeX Error.", Error::LATEX);
-                               terr.scanError(lex);
-                               num_errors++;
-                       } else {
-                               // get the next line
-                               lex.next();
-                               string tmp = lex.GetString();
-                               if (prefixIs(tmp, "l.")) {
+                       string desc(token, 2);
+                       if (contains(token, "LaTeX Error:"))
+                               retval |= LATEX_ERROR;
+                       // get the next line
+                       string tmp;
+                       getline(ifs, tmp);
+                       if (prefixIs(tmp, "l.")) {
                                // we have a latex error
-                                       retval |=  TEX_ERROR;
-                                       lyxerr.debug("TeX Error.", Error::LATEX);
+                               retval |=  TEX_ERROR;
                                // get the line number:
-                                       int line = 0;
-                                       sscanf(tmp.c_str(), "l.%d", &line);
+                               int line = 0;
+                               sscanf(tmp.c_str(), "l.%d", &line);
                                // get the rest of the message:
-                                       string errstr;
-                                       lex.EatLine();
-                                       tmp = lex.GetString();
-                                       while ((tmp != "\n" || !contains(errstr, "l."))
-                                              && !prefixIs(tmp, "! ")
-                                              && !contains(tmp, "(job aborted")
-                                              && !tmp.empty()) {
-                                               errstr += tmp;
-                                               errstr += "\n";
-                                               lex.EatLine();
-                                               tmp = lex.GetString();
-                                       }
-                                       terr.insertError(line, desc, errstr);
-                                       num_errors++;
+                               string errstr(tmp, tmp.find(' '));
+                               errstr += '\n';
+                               getline(ifs, tmp);
+                               while (!contains(errstr, "l.")
+                                      && !tmp.empty()
+                                      && !prefixIs(tmp, "! ")
+                                      && !contains(tmp, "(job aborted")) {
+                                       errstr += tmp;
+                                       errstr += "\n";
+                                       getline(ifs, tmp);
                                }
+                               lyxerr[Debug::LATEX]
+                                       << "line: " << line << '\n'
+                                       << "Desc: " << desc << '\n'
+                                       << "Text: " << errstr << endl;
+                               terr.insertError(line, desc, errstr);
+                               num_errors++;
                        }
                } else {
                        // information messages, TeX warnings and other
@@ -599,7 +510,8 @@ int LaTeX::scanLogFile(TeXErrors &terr)
                                retval |= TOO_MANY_ERRORS;
                        }
                }
-       }       
+       }
+       lyxerr[Debug::LATEX] << "Log line: " << token << endl;
        return retval;
 }
 
@@ -611,34 +523,28 @@ void LaTeX::deplog(DepTable & head)
        // dependency file.
 
        string logfile = ChangeExtension(file, ".log", true);
-       FilePtr in(logfile, FilePtr::read);
-       bool not_eof = true;
-       if (in()) while (not_eof) { // We were able to open the file
+       
+       ifstream ifs(logfile.c_str());
+       while (ifs) {
                // Now we read chars until we find a '('
-               int c;
-               do {
-                       c = fgetc(in());
-               } while (c != EOF && c != '(');
-               if (c == EOF) { 
-                       // Nothing more we can do
-                       not_eof = false; 
-                       continue;
-               } 
-
+               char c = 0;
+               while(ifs.get(c)) {
+                       if (c == '(') break;
+               };
+               if (!ifs) break;
+               
                // We now have c == '(', we now read the the sequence of
-               // chars until reaching EOL, or ' ' and put that into a string.
-
+               // chars until reaching EOL, ' ' or ')' and put that
+               // into a string.
                string foundfile;
-               c = fgetc(in());
-               while (c != '\n' && c != ' ' && c != ')') {
-                       foundfile += char(c);
-                       c = fgetc(in());
+               while (ifs.get(c)) {
+                       if (c == '\n' || c == ' ' || c == ')')
+                               break;
+                       foundfile += c;
                }
-               if (foundfile.empty()) continue;
-
-               lyxerr.debug("Found file: " 
-                            + foundfile,
-                            Error::LATEX);
+               lyxerr[Debug::LATEX] << "Found file: " 
+                                    << foundfile << endl;
+               
                // Ok now we found a file.
                // Now we should make sure that
                // this is a file that we can
@@ -648,9 +554,8 @@ void LaTeX::deplog(DepTable & head)
                //     absolute path and should
                //     be inserted.
                if (AbsolutePath(foundfile)) {
-                       lyxerr.debug("AbsolutePath file: " 
-                                    + foundfile,
-                                    Error::LATEX);
+                       lyxerr[Debug::LATEX] << "AbsolutePath file: " 
+                                            << foundfile << endl;
                        // On inital insert we want to do the update at once
                        // since this file can not be a file generated by
                        // the latex run.
@@ -662,64 +567,44 @@ void LaTeX::deplog(DepTable & head)
                //     insert it into head
                if (FileInfo(OnlyFilename(foundfile)).exist()) {
                        if (suffixIs(foundfile, ".aux")) {
-                               lyxerr.debug("We don't want "
-                                            + OnlyFilename(foundfile)
-                                            + " in the dep file",
-                                            Error::LATEX);
+                               lyxerr[Debug::LATEX] << "We don't want "
+                                                    << OnlyFilename(foundfile)
+                                                    << " in the dep file"
+                                                    << endl;
                        } else if (suffixIs(foundfile, ".tex")) {
                                // This is a tex file generated by LyX
                                // and latex is not likely to change this
                                // during its runs.
-                               lyxerr.debug("Tmpdir TeX file: "
-                                            + OnlyFilename(foundfile),
-                                            Error::LATEX);
+                               lyxerr[Debug::LATEX] << "Tmpdir TeX file: "
+                                                    << OnlyFilename(foundfile)
+                                                    << endl;
                                head.insert(foundfile, true);
                        } else {
-                               lyxerr.debug("In tmpdir file:"
-                                            + OnlyFilename(foundfile),
-                                            Error::LATEX);
+                               lyxerr[Debug::LATEX] << "In tmpdir file:"
+                                                    << OnlyFilename(foundfile)
+                                                    << endl;
                                head.insert(OnlyFilename(foundfile));
                        }
                        continue;
                }
-
-               // (3) the foundfile can be
-               //     found in the same dir
-               //     as the .lyx file and
-               //     should be inserted.
-               PathPush(path);
-               if (FileInfo(foundfile).exist()) {
-                       lyxerr.print("LyX Strange: this should actually never"
-                                    " happen anymore, this it should be"
-                                    " handled by the Absolute check.");
-                       lyxerr.debug("Same Directory file: " 
-                                    + foundfile,
-                                    Error::LATEX);
-                       head.insert(foundfile);
-                       PathPop();
-                       continue;
-               }
-               PathPop();
-               
-               lyxerr.debug("Not a file or we are unable to find it.",
-                            Error::LATEX);
-
-
+               lyxerr[Debug::LATEX]
+                       << "Not a file or we are unable to find it."
+                       << endl;
        }
 }
 
 
-void LaTeX::deptex(DepTable &head)
+void LaTeX::deptex(DepTable & head)
 {
        int except = AUX|LOG|DVI|BBL|IND|GLO; 
        string tmp;
        FileInfo fi;
-       for (int i = 0; i < file_count; i++) {
+       for (int i = 0; i < file_count; ++i) {
                if (!(all_files[i].file & except)) {
                        tmp = ChangeExtension(file,
                                              all_files[i].extension,
                                              true);
-                       lyxerr.debug("deptex: " + tmp, Error::LATEX);
+                       lyxerr[Debug::LATEX] << "deptex: " << tmp << endl;
                        if (fi.newFile(tmp).exist())
                                head.insert(tmp);
                }