]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Remove accidentally committed debug statement
[lyx.git] / src / BufferParams.cpp
index 867f04536ad7c9cb211de41a077349361ef5c0fe..862c3ede40cbe739d54ebdef7a36fcbf3662786e 100644 (file)
@@ -308,7 +308,7 @@ bool inSystemDir(FileName const & document_dir, string & system_dir)
 
        string dir = document_dir.absFileName();
 
-       for (int i = 0; i < 2; ++i) {
+       for (int i = 0; i < 3; ++i) {
                dir = addPath(dir, "..");
                if (!fileSearch(dir, "configure.py").empty() &&
                    !fileSearch(dir, "chkconfig.ltx").empty()) {
@@ -754,6 +754,15 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                                origin.replace(0, sysdirprefix.length() - 1,
                                        package().system_support().absFileName());
                }
+               string const builddirprefix = "/buildlyxdir/";
+               if (prefixIs(origin, builddirprefix)) {
+                       string docsys;
+                       if (inSystemDir(filepath, docsys))
+                               origin.replace(0, builddirprefix.length() - 1, docsys);
+                       else
+                               origin.replace(0, builddirprefix.length() - 1,
+                                       package().system_support().absFileName());
+               }
        } else if (token == "\\begin_preamble") {
                readPreamble(lex);
        } else if (token == "\\begin_local_layout") {
@@ -1142,7 +1151,10 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
        string const relpath =
                to_utf8(makeRelPath(from_utf8(filepath), from_utf8(sysdir)));
        if (!prefixIs(relpath, "../") && !FileName::isAbsolute(relpath))
-               filepath = addPath("/systemlyxdir", relpath);
+               filepath = (prefixIs(docsys, package().build_support().realPath())) ?
+                                       addPath("/buildlyxdir", relpath)
+                                     : addPath("/systemlyxdir", relpath);
+
        else if (!save_transient_properties || !lyxrc.save_origin)
                filepath = "unavailable";
        os << "\\origin " << quoteIfNeeded(filepath) << '\n';
@@ -1697,7 +1709,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        bool const use_babel = features.useBabel() && !features.isProvided("babel");
        bool const use_polyglossia = features.usePolyglossia();
        bool const global = lyxrc.language_global_options;
-       if (use_babel || (use_polyglossia && global)) {
+       if (features.useBabel() || (use_polyglossia && global)) {
                language_options << features.getBabelLanguages();
                if (!language->babel().empty()) {
                        if (!language_options.str().empty())
@@ -1745,6 +1757,16 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                        os << "\\usepackage{unicode-math}\n";
        }
 
+       // load CJK support package before font selection
+       // (see autotests/export/latex/CJK/micro-sign_utf8-cjk-libertine.lyx)
+       if (!useNonTeXFonts && encoding().package() != Encoding::none && inputenc != "utf8x"
+               && (encoding().package() == Encoding::CJK || features.mustProvide("CJK"))) {
+               if (inputenc == "utf8-cjk" || inputenc == "utf8")
+                       os << "\\usepackage{CJKutf8}\n";
+               else
+                       os << "\\usepackage[encapsulated]{CJK}\n";
+       }
+
        // font selection must be done before loading fontenc.sty
        string const fonts = loadFonts(features);
        if (!fonts.empty())
@@ -1769,6 +1791,12 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                }
        }
 
+       // Load textcomp and pmboxdraw before (lua)inputenc (#11454)
+       if (features.mustProvide("textcomp"))
+               os << "\\usepackage{textcomp}\n";
+       if (features.mustProvide("pmboxdraw"))
+               os << "\\usepackage{pmboxdraw}\n";
+
        // handle inputenc etc.
        writeEncodingPreamble(os, features);
 
@@ -2242,8 +2270,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                   << "\\makeatother\n\n";
 
        // We try to load babel late, in case it interferes with other packages.
-       // Jurabib, hyperref, varioref, bicaption and listings (bug 8995) have to be
-       // called after babel, though.
+       // Jurabib, hyperref, varioref, bicaption, menukeys and listings (bug 8995)
+       // have to be called after babel, though.
        if (use_babel && !features.isRequired("jurabib")
            && !features.isRequired("hyperref")
            && !features.isRequired("varioref")
@@ -2264,7 +2292,18 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                else
                        os << "\\usepackage{listings}\n";
        }
-       if (!listings_params.empty()) {
+       string lst_params = listings_params;
+       // If minted, do not output the language option (bug 11203)
+       if (use_minted && contains(lst_params, "language=")) {
+               vector<string> opts =
+                       getVectorFromString(lst_params, ",", false);
+               for (size_t i = 0; i < opts.size(); ++i) {
+                       if (prefixIs(opts[i], "language="))
+                               opts.erase(opts.begin() + i--);
+               }
+               lst_params = getStringFromVector(opts, ",");
+       }
+       if (!lst_params.empty()) {
                if (use_minted)
                        os << "\\setminted{";
                else
@@ -2272,7 +2311,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                // do not test validity because listings_params is
                // supposed to be valid
                string par =
-                       InsetListingsParams(listings_params).separatedParams(true);
+                       InsetListingsParams(lst_params).separatedParams(true);
                os << from_utf8(par);
                os << "}\n";
        }
@@ -2292,6 +2331,10 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                os << "\\usepackage{xunicode}\n";
        }
 
+       // covington must be loaded after beamerarticle
+       if (features.isRequired("covington"))
+           os << "\\usepackage{covington}\n";
+
        // Polyglossia must be loaded last ...
        if (use_polyglossia) {
                // call the package
@@ -2317,19 +2360,25 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        }
 
        // ... but before biblatex (see #7065)
-       if (features.mustProvide("biblatex")
+       if ((features.mustProvide("biblatex")
+            || features.isRequired("biblatex-chicago"))
+           && !features.isProvided("biblatex-chicago")
            && !features.isProvided("biblatex-natbib")
            && !features.isProvided("natbib-internal")
            && !features.isProvided("natbib")
            && !features.isProvided("jurabib")) {
+               // The biblatex-chicago package has a differing interface
+               // it uses a wrapper package and loads styles via fixed options
+               bool const chicago = features.isRequired("biblatex-chicago");
                string delim = "";
                string opts;
                os << "\\usepackage";
                if (!biblatex_bibstyle.empty()
-                   && (biblatex_bibstyle == biblatex_citestyle)) {
+                   && (biblatex_bibstyle == biblatex_citestyle)
+                   && !chicago) {
                        opts = "style=" + biblatex_bibstyle;
                        delim = ",";
-               } else {
+               } else if (!chicago) {
                        if (!biblatex_bibstyle.empty()) {
                                opts = "bibstyle=" + biblatex_bibstyle;
                                delim = ",";
@@ -2361,7 +2410,10 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                        opts += delim + biblio_opts;
                if (!opts.empty())
                        os << "[" << opts << "]";
-               os << "{biblatex}\n";
+               if (chicago)
+                       os << "{biblatex-chicago}\n";
+               else
+                       os << "{biblatex}\n";
        }
 
 
@@ -2374,6 +2426,11 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                os << '\n';
        }
 
+       // Since menukeys uses catoptions, which does some heavy changes on key-value options,
+       // it is recommended to load menukeys as the last package (even after hyperref)
+       if (features.isRequired("menukeys"))
+               os << "\\usepackage{menukeys}\n";
+
        docstring const i18npreamble =
                features.getTClassI18nPreamble(use_babel, use_polyglossia,
                                               use_minted);
@@ -2433,7 +2490,7 @@ void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
 }
 
 
-bool BufferParams::setBaseClass(string const & classname)
+bool BufferParams::setBaseClass(string const & classname, string const & path)
 {
        LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
        LayoutFileList & bcl = LayoutFileList::get();
@@ -2449,7 +2506,7 @@ bool BufferParams::setBaseClass(string const & classname)
                bcl.addEmptyClass(classname);
        }
 
-       bool const success = bcl[classname].load();
+       bool const success = bcl[classname].load(path);
        if (!success) {
                docstring s =
                        bformat(_("Due to some error in it, the layout file:\n"
@@ -3220,17 +3277,15 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        else
                                os << "]{inputenc}\n";
                }
-               if (package == Encoding::CJK || features.mustProvide("CJK")) {
-                       if (language->encoding()->name() == "utf8-cjk"
-                           && LaTeXFeatures::isAvailable("CJKutf8"))
-                               os << "\\usepackage{CJKutf8}\n";
-                       else
-                               os << "\\usepackage{CJK}\n";
-               }
        } else if (inputenc != "default") {
                switch (encoding().package()) {
                case Encoding::none:
+               case Encoding::CJK:
                case Encoding::japanese:
+                       if (encoding().iconvName() != "UTF-8")
+                         // don't default to [utf8]{inputenc} with TeXLive >= 18
+                         os << "\\ifdefined\\UseRawInputEncoding\n"
+                                << "  \\UseRawInputEncoding\\fi\n";
                        break;
                case Encoding::inputenc:
                        // do not load inputenc if japanese is used
@@ -3245,24 +3300,13 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        else
                                os << "]{inputenc}\n";
                        break;
-               case Encoding::CJK:
-                       if (encoding().name() == "utf8-cjk"
-                           && LaTeXFeatures::isAvailable("CJKutf8"))
-                               os << "\\usepackage{CJKutf8}\n";
-                       else
-                               os << "\\usepackage{CJK}\n";
-                       break;
-               }
-               // Load the CJK package if needed by a secondary language.
-               // If the main encoding is some variant of UTF8, use CJKutf8.
-               if (encoding().package() != Encoding::CJK && features.mustProvide("CJK")) {
-                       if (encoding().iconvName() == "UTF-8"
-                           && LaTeXFeatures::isAvailable("CJKutf8"))
-                               os << "\\usepackage{CJKutf8}\n";
-                       else
-                               os << "\\usepackage{CJK}\n";
                }
        }
+       if (inputenc == "default" || features.isRequired("japanese")) {
+               // don't default to [utf8]{inputenc} with TeXLive >= 18
+               os << "\\ifdefined\\UseRawInputEncoding\n";
+               os << "  \\UseRawInputEncoding\\fi\n";
+       }
 }
 
 
@@ -3500,4 +3544,16 @@ void BufferParams::invalidateConverterCache() const
        pimpl_->isViewCacheValid = false;
 }
 
+
+// We shouldn't need to reset the params here, since anything
+// we need will be recopied.
+void BufferParams::copyForAdvFR(const BufferParams & bp)
+{
+       string const & lang = bp.language->lang();
+       setLanguage(lang);
+       layout_modules_ = bp.layout_modules_;
+       string const & doc_class = bp.documentClass().name();
+       setBaseClass(doc_class);
+}
+
 } // namespace lyx