X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetInclude.cpp;h=88153c6d2d35941ad375977036d292062b5f6756;hb=3d4076b598deb18660e50ec9c327efc3b15f15d0;hp=58d46ab09416bdde95cd6b8309c4fbff143685d4;hpb=eff76bd3ab5643340cc0216f5db7215893f3d2ac;p=lyx.git diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 58d46ab094..88153c6d2d 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -34,6 +34,7 @@ #include "LyXRC.h" #include "Lexer.h" #include "MetricsInfo.h" +#include "output_plaintext.h" #include "output_xhtml.h" #include "OutputParams.h" #include "TextClass.h" @@ -387,7 +388,8 @@ docstring InsetInclude::screenLabel() const temp = listings_label_; break; case NONE: - LASSERT(false, /**/); + LASSERT(false, temp = buffer().B_("Unknown")); + break; } temp += ": "; @@ -532,32 +534,92 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const mangledFileName(); } - FileName const writefile(makeAbsPath(mangled, masterBuffer->temppath())); - if (!runparams.nice) incfile = mangled; else if (!isValidLaTeXFileName(incfile)) { frontend::Alert::warning(_("Invalid filename"), _("The following filename will cause troubles " - "when running the exported file through LaTeX: ") + + "when running the exported file through LaTeX: ") + from_utf8(incfile)); - } - else if (!isValidDVIFileName(incfile)) { + } else if (!isValidDVIFileName(incfile)) { frontend::Alert::warning(_("Problematic filename for DVI"), _("The following filename can cause troubles " - "when running the exported file through LaTeX " - "and opening the resulting DVI: ") + + "when running the exported file through LaTeX " + "and opening the resulting DVI: ") + from_utf8(incfile), true); } + + FileName const writefile(makeAbsPath(mangled, masterBuffer->temppath())); + LYXERR(Debug::LATEX, "incfile:" << incfile); LYXERR(Debug::LATEX, "exportfile:" << exportfile); LYXERR(Debug::LATEX, "writefile:" << writefile); string const tex_format = flavor2format(runparams.flavor); - if (runparams.inComment || runparams.dryrun) { - //Don't try to load or copy the file if we're - //in a comment or doing a dryrun - } else if (isInputOrInclude(params()) && + + switch (type(params())) { + case VERB: + case VERBAST: { + incfile = latex_path(incfile); + // FIXME UNICODE + os << '\\' << from_ascii(params().getCmdName()) << '{' + << from_utf8(incfile) << '}'; + break; + } + case INPUT: { + runparams.exportdata->addExternalFile(tex_format, writefile, + exportfile); + + // \input wants file with extension (default is .tex) + if (!isLyXFileName(included_file.absFileName())) { + incfile = latex_path(incfile); + // FIXME UNICODE + os << '\\' << from_ascii(params().getCmdName()) + << '{' << from_utf8(incfile) << '}'; + } else { + incfile = changeExtension(incfile, ".tex"); + incfile = latex_path(incfile); + // FIXME UNICODE + os << '\\' << from_ascii(params().getCmdName()) + << '{' << from_utf8(incfile) << '}'; + } + break; + } + case LISTINGS: { + runparams.exportdata->addExternalFile(tex_format, writefile, + exportfile); + os << '\\' << from_ascii(params().getCmdName()); + string const opt = to_utf8(params()["lstparams"]); + // opt is set in QInclude dialog and should have passed validation. + InsetListingsParams params(opt); + if (!params.params().empty()) + os << "[" << from_utf8(params.params()) << "]"; + os << '{' << from_utf8(incfile) << '}'; + break; + } + case INCLUDE: { + runparams.exportdata->addExternalFile(tex_format, writefile, + exportfile); + + // \include don't want extension and demands that the + // file really have .tex + incfile = changeExtension(incfile, string()); + incfile = latex_path(incfile); + // FIXME UNICODE + os << '\\' << from_ascii(params().getCmdName()) << '{' + << from_utf8(incfile) << '}'; + break; + } + case NONE: + break; + } + + if (runparams.inComment || runparams.dryrun) + // Don't try to load or copy the file if we're + // in a comment or doing a dryrun + return; + + if (isInputOrInclude(params()) && 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 @@ -623,7 +685,9 @@ 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(); - if (!tmp->makeLaTeXFile(tmpwritefile, runparams, false)) { + runparams.is_child = true; + if (!tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()). + onlyPath().absFileName(), runparams, Buffer::OnlyBody)) { docstring msg = bformat(_("Included file `%1$s' " "was not exported correctly.\nWarning: " "LaTeX export is probably incomplete."), @@ -637,6 +701,7 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const } runparams.encoding = oldEnc; runparams.master_language = oldLang; + runparams.is_child = false; // If needed, use converters to produce a latex file from the child if (tmpwritefile != writefile) { @@ -662,8 +727,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const // 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 // in the original dir. Files included by this file will be - // found via the environment variable TEXINPUTS, which may be - // set in preferences and by default includes the original dir. + // found via either the environment variable TEXINPUTS, or + // input@path, see ../Buffer.cpp. unsigned long const checksum_in = included_file.checksum(); unsigned long const checksum_out = writefile.checksum(); @@ -672,69 +737,12 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const // FIXME UNICODE LYXERR(Debug::LATEX, to_utf8(bformat(_("Could not copy the file\n%1$s\n" - "into the temporary directory."), - from_utf8(included_file.absFileName())))); + "into the temporary directory."), + from_utf8(included_file.absFileName())))); return; } } } - - switch (type(params())) { - case VERB: - case VERBAST: { - incfile = latex_path(incfile); - // FIXME UNICODE - os << '\\' << from_ascii(params().getCmdName()) << '{' - << from_utf8(incfile) << '}'; - break; - } - case INPUT: { - runparams.exportdata->addExternalFile(tex_format, writefile, - exportfile); - - // \input wants file with extension (default is .tex) - if (!isLyXFileName(included_file.absFileName())) { - incfile = latex_path(incfile); - // FIXME UNICODE - os << '\\' << from_ascii(params().getCmdName()) - << '{' << from_utf8(incfile) << '}'; - } else { - incfile = changeExtension(incfile, ".tex"); - incfile = latex_path(incfile); - // FIXME UNICODE - os << '\\' << from_ascii(params().getCmdName()) - << '{' << from_utf8(incfile) << '}'; - } - break; - } - case LISTINGS: { - runparams.exportdata->addExternalFile(tex_format, writefile, - exportfile); - os << '\\' << from_ascii(params().getCmdName()); - string const opt = to_utf8(params()["lstparams"]); - // opt is set in QInclude dialog and should have passed validation. - InsetListingsParams params(opt); - if (!params.params().empty()) - os << "[" << from_utf8(params.params()) << "]"; - os << '{' << from_utf8(incfile) << '}'; - break; - } - case INCLUDE: { - runparams.exportdata->addExternalFile(tex_format, writefile, - exportfile); - - // \include don't want extension and demands that the - // file really have .tex - incfile = changeExtension(incfile, string()); - incfile = latex_path(incfile); - // FIXME UNICODE - os << '\\' << from_ascii(params().getCmdName()) << '{' - << from_utf8(incfile) << '}'; - break; - } - case NONE: - break; - } } @@ -792,7 +800,7 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const if (all_pars) { op.par_begin = 0; op.par_end = 0; - ibuf->writeLyXHTMLSource(xs.os(), op, true); + ibuf->writeLyXHTMLSource(xs.os(), op, Buffer::IncludedFile); } else xs << XHTMLStream::ESCAPE_NONE << "