On Sat, May 2, 2015 at 8:02 PM, Enrico Forestieri <for...@lyx.org> wrote:
> On Sat, May 02, 2015 at 07:03:53PM -0400, Scott Kostyshak wrote:
>>
>> An alternative would be to add a parameter to LaTeX::LaTeX() that says
>> whether to do a fresh compile.
>
> This alternative seems the most logical one to me. Add a bool parameter
> (clean_start or similar) which is false by default to tell the
> constructor to start afresh by removing previous leftovers.

OK, attached is an updated patch.

Scott
From d6671f9ea7f3497d55dab032fd32459fba898b48 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Sun, 3 May 2015 01:22:03 -0400
Subject: [PATCH] Do a fresh compile for preview after error (#9061)

As Enrico said, the user might have installed a package that was
missing (in which case the .tex file would not have changed).

Another reason is that changing some document settings did not
automatically lead to a fresh compile after an error (#9061).
---
 src/Buffer.cpp    | 17 +++++++++++++++--
 src/Buffer.h      |  3 +++
 src/Converter.cpp |  2 +-
 src/LaTeX.cpp     |  6 +++---
 src/LaTeX.h       |  9 +++++++--
 5 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 7022139..e2ef1e1 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -285,10 +285,15 @@ public:
 	/// we ran updateBuffer(), i.e., whether citation labels may need
 	/// to be updated.
 	mutable bool cite_labels_valid_;
-	/// these hold the file name and format, written to by Buffer::preview
-	/// and read from by LFUN_BUFFER_VIEW_CACHE.
+
+	/// These two hold the file name and format, written to by
+	/// Buffer::preview and read from by LFUN_BUFFER_VIEW_CACHE.
 	FileName preview_file_;
 	string preview_format_;
+	/// If there was an error when previewing, on the next preview we do
+	/// a fresh compile (e.g. in case the user installed a package that
+	/// was missing).
+	bool preview_error_;
 
 	mutable RefCache ref_cache_;
 
@@ -426,6 +431,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
 	internal_buffer = cloned_buffer_->d->internal_buffer;
 	preview_file_ = cloned_buffer_->d->preview_file_;
 	preview_format_ = cloned_buffer_->d->preview_format_;
+	preview_error_ = cloned_buffer_->d->preview_error_;
 }
 
 
@@ -1161,6 +1167,12 @@ void Buffer::setFullyLoaded(bool value)
 }
 
 
+bool Buffer::lastPreviewError() const
+{
+	return d->preview_error_;
+}
+
+
 PreviewLoader * Buffer::loader() const
 {
 	if (!isExporting() && lyxrc.preview == LyXRC::PREVIEW_OFF)
@@ -4232,6 +4244,7 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
 	LATTEST (isClone());
 	d->cloned_buffer_->d->preview_file_ = previewFile;
 	d->cloned_buffer_->d->preview_format_ = format;
+	d->cloned_buffer_->d->preview_error_ = (status != ExportSuccess);
 
 	if (status != ExportSuccess)
 		return status;
diff --git a/src/Buffer.h b/src/Buffer.h
index 05cf8aa..9c5c27e 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -648,6 +648,9 @@ public:
 	/// Export buffer to format \p format and open the result in a suitable viewer.
 	/// Note: This has nothing to do with preview of graphics or math formulas.
 	ExportStatus preview(std::string const & format) const;
+	/// true if there was a previous preview this session of this buffer and
+	/// there was an error on the previous preview of this buffer.
+	bool lastPreviewError() const;
 
 private:
 	///
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 3d3181a..0e0251e 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -644,7 +644,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
 	// do the LaTeX run(s)
 	string const name = buffer.latexName();
 	LaTeX latex(command, runparams, FileName(makeAbsPath(name)),
-		    buffer.filePath());
+		    buffer.filePath(), buffer.lastPreviewError());
 	TeXErrors terr;
 	ShowMessage show(buffer);
 	latex.message.connect(show);
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index 38a457d..119340e 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -92,7 +92,7 @@ bool operator!=(AuxInfo const & a, AuxInfo const & o)
  */
 
 LaTeX::LaTeX(string const & latex, OutputParams const & rp,
-	     FileName const & f, string const & p)
+	     FileName const & f, string const & p, bool const clean_start)
 	: cmd(latex), file(f), path(p), runparams(rp), biber(false)
 {
 	num_errors = 0;
@@ -105,6 +105,8 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
 		output_file =
 			FileName(changeExtension(file.absFileName(), ".dvi"));
 	}
+	if (clean_start)
+		deleteFilesOnError();
 }
 
 
@@ -169,8 +171,6 @@ int LaTeX::run(TeXErrors & terr)
 	theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFileName(),
 		runparams);
 
-	// Never write the depfile if an error was encountered.
-
 	// 0
 	// first check if the file dependencies exist:
 	//     ->If it does exist
diff --git a/src/LaTeX.h b/src/LaTeX.h
index 6b71f0f..48e8040 100644
--- a/src/LaTeX.h
+++ b/src/LaTeX.h
@@ -151,11 +151,16 @@ public:
 
 	/**
 	   cmd = the latex command, file = name of the (temporary) latex file,
-	   path = name of the files original path.
+	   path = name of the files original path,
+	   clean_start = This forces a fresh run by deleting the files in the temp
+			 dir. We set this e.g. if there was an error on previous
+			 preview, which is good if the user installed a package
+			 or changed certain document settings (#9061).
 	*/
 	LaTeX(std::string const & cmd, OutputParams const &,
 	      support::FileName const & file,
-	      std::string const & path = empty_string());
+	      std::string const & path = empty_string(),
+	      bool const clean_start = false);
 
 	/// runs LaTeX several times
 	int run(TeXErrors &);
-- 
2.1.0

Reply via email to