]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Treat math style a bit more like other font features
[lyx.git] / src / BufferParams.cpp
index 3819e6d92b3834414ee9479dcc58a0e1e5e70bd3..fc4ac4a2c8d8a46b1de66773f2581ae5123b9d90 100644 (file)
@@ -1697,7 +1697,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 +1745,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 +1779,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 +2258,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")
@@ -2303,6 +2319,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
@@ -2328,19 +2348,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 = ",";
@@ -2372,7 +2398,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";
        }
 
 
@@ -2385,6 +2414,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);
@@ -2444,7 +2478,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();
@@ -2460,7 +2494,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"
@@ -3231,17 +3265,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
@@ -3256,24 +3288,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";
+       }
 }
 
 
@@ -3511,4 +3532,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