]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeX.C
Updates from Bennett and myself.
[lyx.git] / src / LaTeX.C
index 0a4308e79d0e726c663a6e67d0535fc03cb5c36b..0557b7ab7d041ce68656269132e8cdc439424aa1 100644 (file)
 
 #include <config.h>
 
-#include "LaTeX.h"
 #include "bufferlist.h"
+#include "LaTeX.h"
 #include "gettext.h"
 #include "lyxrc.h"
 #include "debug.h"
 #include "DepTable.h"
+
 #include "support/filetools.h"
 #include "support/convert.h"
 #include "support/lstrings.h"
 
 #include <fstream>
 
-using lyx::support::absolutePath;
-using lyx::support::bformat;
-using lyx::support::changeExtension;
-using lyx::support::contains;
-using lyx::support::findtexfile;
-using lyx::support::getcwd;
-using lyx::support::onlyFilename;
-using lyx::support::prefixIs;
-using lyx::support::quoteName;
-using lyx::support::rtrim;
-using lyx::support::split;
-using lyx::support::subst;
-using lyx::support::suffixIs;
-using lyx::support::Systemcall;
-using lyx::support::unlink;
-using lyx::support::trim;
-
-namespace os = lyx::support::os;
+
+namespace lyx {
+
+using support::absolutePath;
+using support::bformat;
+using support::changeExtension;
+using support::contains;
+using support::FileName;
+using support::findtexfile;
+using support::getcwd;
+using support::makeAbsPath;
+using support::onlyFilename;
+using support::prefixIs;
+using support::quoteName;
+using support::rtrim;
+using support::split;
+using support::subst;
+using support::suffixIs;
+using support::Systemcall;
+using support::unlink;
+using support::trim;
+
+namespace os = support::os;
 namespace fs = boost::filesystem;
 
 using boost::regex;
@@ -68,7 +74,7 @@ using std::set;
 using std::vector;
 
 // TODO: in no particular order
-// - get rid of the extern BufferList and the call to
+// - get rid of the call to
 //   BufferList::updateIncludedTeXfiles, this should either
 //   be done before calling LaTeX::funcs or in a completely
 //   different way.
@@ -78,11 +84,9 @@ using std::vector;
 // - somewhere support viewing of bibtex and makeindex log files.
 // - we should perhaps also scan the bibtex log file
 
-extern BufferList bufferlist;
-
 namespace {
 
-string runMessage(unsigned int count)
+docstring runMessage(unsigned int count)
 {
        return bformat(_("Waiting for LaTeX run number %1$d"), count);
 }
@@ -93,8 +97,8 @@ string runMessage(unsigned int count)
  * CLASS TEXERRORS
  */
 
-void TeXErrors::insertError(int line, string const & error_desc,
-                           string const & error_text)
+void TeXErrors::insertError(int line, docstring const & error_desc,
+                           docstring const & error_text)
 {
        Error newerr(line, error_desc, error_text);
        errors.push_back(newerr);
@@ -125,11 +129,11 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
        : cmd(latex), file(f), path(p), runparams(rp)
 {
        num_errors = 0;
-       depfile = file + ".dep";
        if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
-               depfile += "-pdf";
+               depfile = FileName(makeAbsPath(file + ".dep-pdf"));
                output_file = changeExtension(file,".pdf");
        } else {
+               depfile = FileName(makeAbsPath(file + ".dep"));
                output_file = changeExtension(file,".dvi");
        }
 }
@@ -146,18 +150,20 @@ void LaTeX::deleteFilesOnError() const
 
        // but the reason for the error might be in a generated file...
 
-       string const ofname = onlyFilename(file);
-
        // bibtex file
-       string const bbl = changeExtension(ofname, ".bbl");
+       FileName const bbl(makeAbsPath(changeExtension(file, ".bbl")));
        unlink(bbl);
 
        // makeindex file
-       string const ind = changeExtension(ofname, ".ind");
+       FileName const ind(makeAbsPath(changeExtension(file, ".ind")));
        unlink(ind);
 
+       // nomencl file
+       FileName const nls(makeAbsPath(changeExtension(file, ".nls")));
+       unlink(nls);
+
        // Also remove the aux file
-       string const aux = changeExtension(ofname, ".aux");
+       FileName const aux(makeAbsPath(changeExtension(file, ".aux")));
        unlink(aux);
 }
 
@@ -177,7 +183,7 @@ int LaTeX::run(TeXErrors & terr)
        bool rerun = false; // rerun requested
 
        // The class LaTeX does not know the temp path.
-       bufferlist.updateIncludedTeXfiles(getcwd(), runparams);
+       theBufferList().updateIncludedTeXfiles(getcwd(), runparams);
 
        // Never write the depfile if an error was encountered.
 
@@ -197,7 +203,7 @@ int LaTeX::run(TeXErrors & terr)
        //             remake the dependency file.
        //
 
-       bool had_depfile = fs::exists(depfile);
+       bool had_depfile = fs::exists(depfile.toFilesystemEncoding());
        bool run_bibtex = false;
        string aux_file = onlyFilename(changeExtension(file, "aux"));
 
@@ -275,12 +281,18 @@ int LaTeX::run(TeXErrors & terr)
                && fs::is_empty(changeExtension(file, ".idx"));
 
        // run makeindex
-       if (head.haschanged(onlyFilename(changeExtension(file, ".idx")))) {
+       if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".idx")))))) {
                // no checks for now
                lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
                message(_("Running MakeIndex."));
                rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".idx")), runparams);
        }
+       if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".nlo")))))) {
+               lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
+               message(_("Running MakeIndex for nomencl."));
+               string const nomenclstr = " -s nomencl.ist -o " + changeExtension(file, ".nls");
+               rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".nlo")), runparams, nomenclstr);
+       }
 
        // run bibtex
        // if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
@@ -343,13 +355,21 @@ int LaTeX::run(TeXErrors & terr)
        // more after this.
 
        // run makeindex if the <file>.idx has changed or was generated.
-       if (head.haschanged(onlyFilename(changeExtension(file, ".idx")))) {
+       if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".idx")))))) {
                // no checks for now
                lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
                message(_("Running MakeIndex."));
                rerun = runMakeIndex(onlyFilename(changeExtension(file, ".idx")), runparams);
        }
 
+       // I am not pretty sure if need this twice. 
+       if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".nlo")))))) {
+               lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
+               message(_("Running MakeIndex for nomencl."));
+               string nomenclstr = " -s nomencl.ist -o " + changeExtension(file, ".nls");
+               rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".nlo")), runparams, nomenclstr);
+       }
+
        // 2
        // we will only run latex more if the log file asks for it.
        // or if the sumchange() is true.
@@ -394,14 +414,17 @@ int LaTeX::startscript()
 }
 
 
-bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams)
+bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams,
+                         string const & params)
 {
-       lyxerr[Debug::LATEX] << "idx file has been made,"
-               " running makeindex on file "
-                            <<  f << endl;
-       string tmp = lyxrc.index_command + " ";
+       lyxerr[Debug::LATEX]
+               << "idx file has been made, running makeindex on file "
+               << f << endl;
+       string tmp = lyxrc.index_command + ' ';
+       
        tmp = subst(tmp, "$$lang", runparams.document_language);
        tmp += quoteName(f);
+       tmp += params;
        Systemcall one;
        one.startscript(Systemcall::Wait, tmp);
        return true;
@@ -502,14 +525,14 @@ void LaTeX::updateBibtexDependencies(DepTable & dep,
                     it2 != it->databases.end(); ++it2) {
                        string file = findtexfile(*it2, "bib");
                        if (!file.empty())
-                               dep.insert(file, true);
+                               dep.insert(FileName(makeAbsPath(file)), true);
                }
 
                for (set<string>::const_iterator it2 = it->styles.begin();
                     it2 != it->styles.end(); ++it2) {
                        string file = findtexfile(*it2, "bst");
                        if (!file.empty())
-                               dep.insert(file, true);
+                               dep.insert(FileName(makeAbsPath(file)), true);
                }
        }
 }
@@ -648,7 +671,11 @@ int LaTeX::scanLogFile(TeXErrors & terr)
                                        last_line = line;
                                }
                                if (line_count <= 5) {
-                                       terr.insertError(line, desc, errstr);
+                                       // FIXME UNICODE
+                                       // We have no idea what the encoding of the log file is
+                                       // (probably pure ascii, but maybe some localized
+                                       // latex compilers or packages exist)
+                                       terr.insertError(line, from_utf8(desc), from_utf8(errstr));
                                        ++num_errors;
                                }
                        }
@@ -698,10 +725,10 @@ void handleFoundFile(string const & ff, DepTable & head)
                lyxerr[Debug::DEPEND] << "AbsolutePath file: "
                                      << foundfile << endl;
                // On initial insert we want to do the update at once
-               // since this file can not be a file generated by
+               // since this file cannot be a file generated by
                // the latex run.
                if (fs::exists(foundfile) && !fs::is_directory(foundfile))
-                       head.insert(foundfile, true);
+                       head.insert(FileName(makeAbsPath(foundfile)), true);
 
                return;
        }
@@ -726,13 +753,13 @@ void handleFoundFile(string const & ff, DepTable & head)
                                << "Tmpdir TeX file: "
                                << onlyfile
                                << endl;
-                       head.insert(onlyfile, true);
+                       head.insert(FileName(makeAbsPath(onlyfile)), true);
                } else {
                        lyxerr[Debug::DEPEND]
                                << "In tmpdir file:"
                                << onlyfile
                                << endl;
-                       head.insert(onlyfile);
+                       head.insert(FileName(makeAbsPath(onlyfile)));
                }
        } else
                lyxerr[Debug::DEPEND]
@@ -756,10 +783,18 @@ void LaTeX::deplog(DepTable & head)
        static regex reg3("No file ([^ ]+)\\..*");
        static regex reg4("\\\\openout[0-9]+.*=.*`([^ ]+)'\\..*");
        // If an index should be created, MikTex does not write a line like
-       //    \openout# = 'sample,idx'.
-       // but intstead only a line like this into the log:
+       //    \openout# = 'sample.idx'.
+       // but instead only a line like this into the log:
        //   Writing index file sample.idx
        static regex reg5("Writing index file ([^ ]+).*");
+       static regex regnomencl("Writing nomenclature file ([^ ]+).*");
+       // If a toc should be created, MikTex does not write a line like
+       //    \openout# = `sample.toc'.
+       // but only a line like this into the log:
+       //    \tf@toc=\write#
+       // This line is also written by tetex.
+       // This line is not present if no toc should be created.
+       static regex miktexTocReg("\\\\tf@toc=\\\\write.*");
 
        ifstream ifs(logfile.c_str());
        while (ifs) {
@@ -793,17 +828,23 @@ void LaTeX::deplog(DepTable & head)
                                first = what[0].second;
                                handleFoundFile(what.str(1), head);
                        }
-               } else if (regex_match(token, sub, reg2)) {
+               } else if (regex_match(token, sub, reg2))
                        handleFoundFile(sub.str(1), head);
-               } else if (regex_match(token, sub, reg3)) {
+               else if (regex_match(token, sub, reg3))
                        handleFoundFile(sub.str(1), head);
-               } else if (regex_match(token, sub, reg4)) {
+               else if (regex_match(token, sub, reg4))
                        handleFoundFile(sub.str(1), head);
-               } else if (regex_match(token, sub, reg5)) {
+               else if (regex_match(token, sub, reg5))
                        handleFoundFile(sub.str(1), head);
-               }
+               else if (regex_match(token, sub, regnomencl))
+                       handleFoundFile(sub.str(1), head);
+               else if (regex_match(token, sub, miktexTocReg))
+                       handleFoundFile(changeExtension(file, ".toc"), head);
        }
 
        // Make sure that the main .tex file is in the dependancy file.
-       head.insert(onlyFilename(file), true);
+       head.insert(FileName(makeAbsPath(onlyFilename(file))), true);
 }
+
+
+} // namespace lyx