+ // The following code depends on non-empty filenames
+ if (params().filename.empty())
+ return string();
+
+ string const orig_file = params().filename.absFilename();
+ string const rel_file = params().filename.relFilename(buf.filePath());
+
+ // If the file is compressed and we have specified that it
+ // should not be uncompressed, then just return its name and
+ // let LaTeX do the rest!
+ bool const zipped = params().filename.isZipped();
+
+ // temp_file will contain the file for LaTeX to act on if, for example,
+ // we move it to a temp dir or uncompress it.
+ string temp_file = orig_file;
+
+ // The master buffer. This is useful when there are multiple levels
+ // of include files
+ Buffer const * m_buffer = buf.getMasterBuffer();
+
+ // Return the output name if the file does not exist.
+ // We are not going to change the extension or using the name of the
+ // temporary file, the code is already complicated enough.
+ if (!IsFileReadable(orig_file))
+ return params().filename.outputFilename(m_buffer->filePath());
+
+ // We place all temporary files in the master buffer's temp dir.
+ // This is possible because we use mangled file names.
+ // This is necessary for DVI export.
+ string const temp_path = m_buffer->temppath();
+
+ CopyStatus status;
+ boost::tie(status, temp_file) =
+ copyToDirIfNeeded(orig_file, temp_path, zipped);
+
+ if (status == FAILURE)
+ return orig_file;
+
+ // a relative filename should be relative to the master
+ // buffer.
+ // "nice" means that the buffer is exported to LaTeX format but not
+ // run through the LaTeX compiler.
+ string const output_file = os::external_path(runparams.nice ?
+ params().filename.outputFilename(m_buffer->filePath()) :
+ OnlyFilename(temp_file));
+ string const source_file = runparams.nice ? orig_file : temp_file;
+
+ if (zipped) {
+ if (params().noUnzip) {
+ // We don't know whether latex can actually handle
+ // this file, but we can't check, because that would
+ // mean to unzip the file and thereby making the
+ // noUnzip parameter meaningless.
+ lyxerr[Debug::GRAPHICS]
+ << "\tpass zipped file to LaTeX.\n";
+
+ string const bb_orig_file = ChangeExtension(orig_file, "bb");
+ if (runparams.nice) {
+ runparams.exportdata->addExternalFile("latex",
+ bb_orig_file,
+ ChangeExtension(output_file, "bb"));
+ } else {
+ // LaTeX needs the bounding box file in the
+ // tmp dir
+ string bb_file = ChangeExtension(temp_file, "bb");
+ boost::tie(status, bb_file) =
+ copyFileIfNeeded(bb_orig_file, bb_file);
+ if (status == FAILURE)
+ return orig_file;
+ runparams.exportdata->addExternalFile("latex",
+ bb_file);
+ }
+ runparams.exportdata->addExternalFile("latex",
+ source_file, output_file);
+ runparams.exportdata->addExternalFile("dvi",
+ source_file, output_file);
+ // We can't strip the extension, because we don't know
+ // the unzipped file format
+ return latex_path(output_file,
+ lyx::support::EXCLUDE_EXTENSION);
+ }
+
+ string const unzipped_temp_file = unzippedFileName(temp_file);
+ if (compare_timestamps(unzipped_temp_file, temp_file) > 0) {
+ // temp_file has been unzipped already and
+ // orig_file has not changed in the meantime.
+ temp_file = unzipped_temp_file;
+ lyxerr[Debug::GRAPHICS]
+ << "\twas already unzipped to " << temp_file
+ << endl;
+ } else {
+ // unzipped_temp_file does not exist or is too old
+ temp_file = unzipFile(temp_file);
+ lyxerr[Debug::GRAPHICS]
+ << "\tunzipped to " << temp_file << endl;
+ }
+ }
+
+ string const from = formats.getFormatFromFile(temp_file);
+ if (from.empty()) {
+ lyxerr[Debug::GRAPHICS]
+ << "\tCould not get file format." << endl;
+ return orig_file;