commit cd8be655f1895957fb169cdf361297d9ecc40ec9
Author: Scott Kostyshak <[email protected]>
Date: Wed Mar 18 16:51:12 2015 -0400
Export/view a PDF even if error
A PDF is often still produced after a LaTeX error.
If there was an error when exporting a PDF, we now give an error
and the PDF (if it exists), where before we gave the error and
not the PDF. The GUI and command line behaviors are consistent:
in the GUI an error is given and the PDF is viewed; on the
command line, a non-zero exit code is given and a PDF is created.
This also solves what was in my mind an inconsistency: if the user
"updated" a document and there was an error, the resulting
PDF would be shown; but if the user viewed a document and there
was an error, the document would not be shown.
Note that this applies to all output formats, not just PDF.
For discussion, see:
https://www.mail-archive.com/[email protected]/msg186454.html
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index f9da416..e045e01 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4119,12 +4119,10 @@ Buffer::ExportStatus Buffer::doExport(string const &
target, bool put_in_tempdir
d->cloned_buffer_->d->errorLists[error_type] =
d->errorLists[error_type];
}
- if (!success)
- return ExportConverterError;
if (put_in_tempdir) {
result_file = tmp_result_file.absFileName();
- return ExportSuccess;
+ return success ? ExportSuccess : ExportConverterError;
}
if (dest_filename.empty())
@@ -4189,7 +4187,7 @@ Buffer::ExportStatus Buffer::doExport(string const &
target, bool put_in_tempdir
formats.prettyName(format)));
}
- return ExportSuccess;
+ return success ? ExportSuccess : ExportConverterError;
}
@@ -4214,11 +4212,10 @@ Buffer::ExportStatus Buffer::preview(string const &
format, bool includeall) con
}
// (2) export with included children only
ExportStatus const status = doExport(format, true, false, result_file);
- if (status != ExportSuccess)
- return status;
- if (!formats.view(*this, FileName(result_file), format))
+ FileName const previewFile(result_file);
+ if (previewFile.exists() && !formats.view(*this, previewFile, format))
return PreviewError;
- return PreviewSuccess;
+ return (status == ExportSuccess) ? PreviewSuccess : status;
}
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index e4f8b4b..ed59181 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -110,6 +110,10 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
void LaTeX::deleteFilesOnError() const
{
+ // Note that we do not always call this function when there is an error.
+ // For example, if there is an error but an output file is produced we
+ // still would like to output (export/view) the file.
+
// What files do we have to delete?
// This will at least make latex do all the runs
@@ -236,7 +240,9 @@ int LaTeX::run(TeXErrors & terr)
}
if (scanres & ERRORS) {
- deleteFilesOnError();
+ // We no longer run deleteFilesOnError() here
+ // because we now show a resulting PDF even if
+ // there was an error.
return scanres; // return on error
}