]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeX.C
Fix deleting of paragraphs after undo (fix #236).
[lyx.git] / src / LaTeX.C
index 03dcc49b9743cb93b0f95a8fcbf77e85e6470cca..054a7796a1f0303226765709a58e4dd6dc9a1c9a 100644 (file)
 #include <fstream>
 
 #include "LaTeX.h"
+#include "bufferlist.h"
+#include "gettext.h"
+#include "lyxfunc.h"
+#include "debug.h"
 #include "support/filetools.h"
-#include "support/os.h"
 #include "support/FileInfo.h"
-#include "debug.h"
-#include "support/lyxlib.h"
-#include "support/syscall.h"
-#include "support/syscontr.h"
-#include "support/path.h"
 #include "support/LRegex.h"
 #include "support/LSubstring.h"
 #include "support/lstrings.h"
-#include "bufferlist.h"
-#include "gettext.h"
-#include "lyx_gui_misc.h"
-#include "lyxfunc.h"
+#include "support/lyxlib.h"
+#include "support/systemcall.h"
+#include "support/os.h"
+#include "support/path.h"
+#include <cstdio>  // sscanf
 
 using std::ifstream;
 using std::getline;
@@ -76,8 +75,12 @@ LaTeX::LaTeX(string const & latex, string const & f, string const & p)
 {
        num_errors = 0;
        depfile = file + ".dep";
-       if (prefixIs(cmd, "pdf")) // Do we use pdflatex ?
+       if (prefixIs(cmd, "pdf")) // Do we use pdflatex ?
                depfile += "-pdf";
+               output_file = ChangeExtension(file,".pdf");
+       } else {
+               output_file = ChangeExtension(file,".dvi");
+       }
 }
 
 
@@ -154,12 +157,19 @@ int LaTeX::run(TeXErrors & terr, LyXFunc * lfun)
                head.read(depfile);
                // Update the checksums
                head.update();
-               if (!head.sumchange()) {
+               // Can't just check if anything has changed because it might have aborted
+               // on error last time... in which cas we need to re-run latex
+               // and collect the error messages (even if they are the same).
+               if (!FileInfo(output_file).exist()) {
+                       lyxerr[Debug::DEPEND]
+                               << "re-running LaTeX because output file doesn't exist." << endl;
+               } else if (!head.sumchange()) {
                        lyxerr[Debug::DEPEND] << "return no_change" << endl;
                        return NO_CHANGE;
+               } else {
+                       lyxerr[Debug::DEPEND]
+                               << "Dependency file has changed" << endl;
                }
-               lyxerr[Debug::DEPEND]
-                       << "Dependency file has changed" << endl;
 
                if (head.extchanged(".bib") || head.extchanged(".bst"))
                        run_bibtex = true;
@@ -348,8 +358,8 @@ int LaTeX::operator()()
 #else // cmd.exe (OS/2) causes SYS0003 error at "/dev/null"
        string tmp = cmd + ' ' + file + " > nul";
 #endif
-        Systemcalls one;
-       return one.startscript(Systemcalls::System, tmp);
+        Systemcall one;
+       return one.startscript(Systemcall::Wait, tmp);
 }
 
 
@@ -365,8 +375,8 @@ bool LaTeX::runMakeIndex(string const & f)
        // to come for a later time. (0.13 perhaps?)
        string tmp = "makeindex -c -q ";
        tmp += f;
-       Systemcalls one;
-       one.startscript(Systemcalls::System, tmp);
+       Systemcall one;
+       one.startscript(Systemcall::Wait, tmp);
        return true;
 }
 
@@ -496,8 +506,8 @@ bool LaTeX::runBibTeX(vector<Aux_Info> const & bibtex_info)
 
                string tmp = "bibtex ";
                tmp += OnlyFilename(ChangeExtension(it->aux_file, string()));
-               Systemcalls one;
-               one.startscript(Systemcalls::System, tmp);
+               Systemcall one;
+               one.startscript(Systemcall::Wait, tmp);
        }
        // Return whether bibtex was run
        return result;