]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Remove unused declarations
[lyx.git] / src / BufferParams.cpp
index 7a641e01127bc20866cdf6ff6338f02d0ce0e6ff..537178e2fa5e446ca70ede4652d287eb99868b07 100644 (file)
@@ -983,6 +983,16 @@ string BufferParams::readToken(Lexer & lex, string const & token,
 }
 
 
+namespace {
+       // Quote argument if it contains spaces
+       string quoteIfNeeded(string const & str) {
+               if (contains(str, ' '))
+                       return "\"" + str + "\"";
+               return str;
+       }
+}
+
+
 void BufferParams::writeFile(ostream & os, Buffer const * buf) const
 {
        // The top of the file is written by the buffer.
@@ -995,11 +1005,12 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
                filepath.replace(0, sysdir.length(), "/systemlyxdir/");
        else if (!lyxrc.save_origin)
                filepath = "unavailable";
-       os << "\\origin " << filepath << '\n';
+       os << "\\origin " << quoteIfNeeded(filepath) << '\n';
 
        // the textclass
-       os << "\\textclass " << buf->includedFilePath(addName(buf->layoutPos(),
-                                               baseClass()->name()), "layout")
+       os << "\\textclass "
+          << quoteIfNeeded(buf->includedFilePath(addName(buf->layoutPos(),
+                                               baseClass()->name()), "layout"))
           << '\n';
 
        // then the preamble
@@ -2296,7 +2307,7 @@ string BufferParams::bufferFormat() const
        string format = documentClass().outputFormat();
        if (format == "latex") {
                if (useNonTeXFonts)
-                       return "xetex";
+                       return "xetex"; // FIXME: why not "luatex"?
                if (encoding().package() == Encoding::japanese)
                        return "platex";
        }
@@ -2916,20 +2927,16 @@ docstring BufferParams::getGraphicsDriver(string const & package) const
 void BufferParams::writeEncodingPreamble(otexstream & os,
                                         LaTeXFeatures & features) const
 {
-       // XeTeX does not need this
-       if (features.runparams().flavor == OutputParams::XETEX)
+       // "inputenc" package not required with non-TeX fonts.
+       if (useNonTeXFonts)
                return;
-       // LuaTeX neither, but with tex fonts, we need to load
-       // the luainputenc package.
-       if (features.runparams().flavor == OutputParams::LUATEX
-               || features.runparams().flavor == OutputParams::DVILUATEX) {
-               if (!useNonTeXFonts && inputenc != "default"
-                   && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
-                       || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
-                       os << "\\usepackage[utf8]{luainputenc}\n";
-               }
+       // "inputenc"  fails with XeTeX (even in 8-bit compatiblitly mode) and with TeX fonts,
+       // (this is a bug in the "inputenc" package see #9740).
+       if (features.runparams().flavor == OutputParams::XETEX)
                return;
-       }
+       // For LuaTeX with TeX fonts, we can load
+       // the "luainputenc" package with the specified encoding(s) (see below).
+
        if (inputenc == "auto") {
                string const doc_encoding =
                        language->encoding()->latexName();
@@ -2961,7 +2968,11 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                                        os << ',';
                                os << from_ascii(doc_encoding);
                        }
-                       os << "]{inputenc}\n";
+                       if (features.runparams().flavor == OutputParams::LUATEX
+                           || features.runparams().flavor == OutputParams::DVILUATEX)
+                               os << "]{luainputenc}\n";
+                       else
+                               os << "]{inputenc}\n";
                }
                if (package == Encoding::CJK || features.mustProvide("CJK")) {
                        if (language->encoding()->name() == "utf8-cjk"
@@ -2981,8 +2992,12 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        if (features.isRequired("japanese")
                            || features.isProvided("inputenc"))
                                break;
-                       os << "\\usepackage[" << from_ascii(encoding().latexName())
-                          << "]{inputenc}\n";
+                       os << "\\usepackage[" << from_ascii(encoding().latexName());
+                       if (features.runparams().flavor == OutputParams::LUATEX
+                           || features.runparams().flavor == OutputParams::DVILUATEX)
+                               os << "]{luainputenc}\n";
+                       else
+                               os << "]{inputenc}\n";
                        break;
                case Encoding::CJK:
                        if (encoding().name() == "utf8-cjk"
@@ -3112,10 +3127,10 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
 
 Encoding const & BufferParams::encoding() const
 {
-       // FIXME: actually, we should check for the flavor
-       // or runparams.isFullyUnicode() here:
-       // This check will not work with XeTeX/LuaTeX and tex fonts.
-       // Thus we have to reset the encoding in Buffer::makeLaTeXFile
+       // FIXME: additionally, we must check for runparams().flavor == XeTeX
+       // or runparams.isFullUnicode() to care for the combination
+       // of XeTeX and TeX-fonts (see #9740).
+       // Currently, we reset the encoding in Buffer::makeLaTeXFile
        // (for export) and Buffer::writeLaTeXSource (for preview).
        if (useNonTeXFonts)
                return *(encodings.fromLyXName("utf8-plain"));