]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInclude.cpp
Fix wrongly copy-pasted entries in SpellcheckerUi.ui
[lyx.git] / src / insets / InsetInclude.cpp
index 4d164cf56b8bd8397b0b864e6df063614714371b..3029349d94263cb93bee606eddf7c6888a189383 100644 (file)
@@ -18,6 +18,7 @@
 #include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "Converter.h"
 #include "Cursor.h"
 #include "DispatchResult.h"
 #include "Encoding.h"
@@ -546,6 +547,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
        LYXERR(Debug::LATEX, "exportfile:" << exportfile);
        LYXERR(Debug::LATEX, "writefile:" << writefile);
 
+       string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
+                       "latex" : "pdflatex";
        if (runparams.inComment || runparams.dryrun) {
                //Don't try to load or copy the file if we're
                //in a comment or doing a dryrun
@@ -553,10 +556,16 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
                 isLyXFileName(included_file.absFileName())) {
                // if it's a LyX file and we're inputting or including,
                // try to load it so we can write the associated latex
-               
+
                Buffer * tmp = loadIfNeeded();
-               if (!tmp)
+               if (!tmp) {
+                       docstring text = bformat(_("Could not load included "
+                               "file\n`%1$s'\n"
+                               "Please, check whether it actually exists."),
+                               included_file.displayName());
+                       Alert::warning(_("Missing included file"), text);
                        return;
+               }
 
                if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
                        // FIXME UNICODE
@@ -591,6 +600,11 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
 
                tmp->markDepClean(masterBuffer->temppath());
 
+               // Don't assume the child's format is latex
+               string const inc_format = tmp->bufferFormat();
+               FileName const tmpwritefile(changeExtension(writefile.absFileName(),
+                       formats.extension(inc_format)));
+
                // FIXME: handle non existing files
                // FIXME: Second argument is irrelevant!
                // since only_body is true, makeLaTeXFile will not look at second
@@ -608,11 +622,42 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
                runparams.master_language = buffer().params().language;
                runparams.par_begin = 0;
                runparams.par_end = tmp->paragraphs().size();
-               tmp->makeLaTeXFile(writefile,
-                                  masterFileName(buffer()).onlyPath().absFileName(),
-                                  runparams, false);
+               if (!tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()).
+                               onlyPath().absFileName(), runparams, false)) {
+                       docstring msg = bformat(_("Included file `%1$s' "
+                                       "was not exported correctly.\nWarning: "
+                                       "LaTeX export is probably incomplete."),
+                                       included_file.displayName());
+                       ErrorList & el = tmp->errorList("Export");
+                       if (!el.empty())
+                               msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
+                                               msg, el.begin()->error,
+                                               el.begin()->description);
+                       Alert::warning(_("Export failure"), msg);
+               }
                runparams.encoding = oldEnc;
                runparams.master_language = oldLang;
+
+               // If needed, use converters to produce a latex file from the child
+               if (tmpwritefile != writefile) {
+                       ErrorList el;
+                       bool const success =
+                               theConverters().convert(tmp, tmpwritefile, writefile,
+                                                       included_file,
+                                                       inc_format, tex_format, el);
+
+                       if (!success) {
+                               docstring msg = bformat(_("Included file `%1$s' "
+                                               "was not exported correctly.\nWarning: "
+                                               "LaTeX export is probably incomplete."),
+                                               included_file.displayName());
+                               if (!el.empty())
+                                       msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
+                                                       msg, el.begin()->error,
+                                                       el.begin()->description);
+                               Alert::warning(_("Export failure"), msg);
+                       }
+               }
        } else {
                // In this case, it's not a LyX file, so we copy the file
                // to the temp dir, so that .aux files etc. are not created
@@ -633,8 +678,6 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
                }
        }
 
-       string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
-                       "latex" : "pdflatex";
        switch (type(params())) {
        case VERB:
        case VERBAST: {