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/lyx-devel@lists.lyx.org/msg186454.html
This commit is contained in:
Scott Kostyshak 2015-03-18 16:51:12 -04:00
parent 0a6120cb7f
commit cd8be655f1
2 changed files with 12 additions and 9 deletions

View File

@ -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]; d->cloned_buffer_->d->errorLists[error_type] = d->errorLists[error_type];
} }
if (!success)
return ExportConverterError;
if (put_in_tempdir) { if (put_in_tempdir) {
result_file = tmp_result_file.absFileName(); result_file = tmp_result_file.absFileName();
return ExportSuccess; return success ? ExportSuccess : ExportConverterError;
} }
if (dest_filename.empty()) if (dest_filename.empty())
@ -4189,7 +4187,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
formats.prettyName(format))); 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 // (2) export with included children only
ExportStatus const status = doExport(format, true, false, result_file); ExportStatus const status = doExport(format, true, false, result_file);
if (status != ExportSuccess) FileName const previewFile(result_file);
return status; if (previewFile.exists() && !formats.view(*this, previewFile, format))
if (!formats.view(*this, FileName(result_file), format))
return PreviewError; return PreviewError;
return PreviewSuccess; return (status == ExportSuccess) ? PreviewSuccess : status;
} }

View File

@ -110,6 +110,10 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
void LaTeX::deleteFilesOnError() const 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? // What files do we have to delete?
// This will at least make latex do all the runs // This will at least make latex do all the runs
@ -236,7 +240,9 @@ int LaTeX::run(TeXErrors & terr)
} }
if (scanres & ERRORS) { 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 return scanres; // return on error
} }