]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
Move bind file format tag to LyXAction.cpp, and rename it.
[lyx.git] / src / LaTeXFeatures.cpp
index ddadf1a0cb5a2cbed4bfe3e804605d9af89b6f9d..090a1d84d70328e58d753c86305f3c4cb6da23e0 100644 (file)
@@ -60,6 +60,11 @@ namespace lyx {
 static docstring const lyx_def = from_ascii(
        "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
 
+static docstring const lyx_hyperref_def = from_ascii(
+       "\\providecommand{\\LyX}{\\texorpdfstring%\n"
+       "  {L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}\n"
+        "  {LyX}}");
+
 static docstring const noun_def = from_ascii(
        "\\newcommand{\\noun}[1]{\\textsc{#1}}");
 
@@ -299,6 +304,7 @@ bool LaTeXFeatures::usePolyglossia() const
        return (lyxrc.language_package_selection == LyXRC::LP_AUTO)
                && isRequired("polyglossia")
                && isAvailable("polyglossia")
+               && !params_.documentClass().provides("babel")
                && this->hasPolyglossiaLanguages();
 }
 
@@ -575,7 +581,6 @@ char const * simplefeatures[] = {
        "framed",
        "soul",
        "textcomp",
-       "fixltx2e",
        "pmboxdraw",
        "bbding",
        "ifsym",
@@ -588,8 +593,8 @@ char const * simplefeatures[] = {
        "csquotes",
        "enumitem",
        "endnotes",
+       "hhline",
        "ifthen",
-       "amsthm",
        // listings is handled in BufferParams.cpp
        "bm",
        "pdfpages",
@@ -690,21 +695,17 @@ string const LaTeXFeatures::getPackages() const
        // than those above.
        //
 
-       // esint is preferred for esintoramsmath
-       if ((mustProvide("amsmath")
-            && params_.use_amsmath != BufferParams::package_off)
-           || (mustProvide("esintoramsmath")
-               && params_.use_esint == BufferParams::package_off
-               && params_.use_amsmath != BufferParams::package_off)) {
-               packages << "\\usepackage{amsmath}\n";
-       } else {
-               // amsbsy and amstext are already provided by amsmath
-               if (mustProvide("amsbsy"))
-                       packages << "\\usepackage{amsbsy}\n";
-               if (mustProvide("amstext"))
-                       packages << "\\usepackage{amstext}\n";
-       }
-       
+       // if fontspec is used, AMS packages have to be loaded before
+       // fontspec (in BufferParams)
+       if (!params_.useNonTeXFonts && !loadAMSPackages().empty())
+               packages << loadAMSPackages();
+
+       // fixltx2e must be loaded after amsthm, since amsthm produces an error with
+       // the redefined \[ command (bug 7233). Load is as early as possible, since
+       // other packages might profit from it.
+       if (mustProvide("fixltx2e"))
+               packages << "\\usepackage{fixltx2e}\n";
+
        // wasysym is a simple feature, but it must be after amsmath if both
        // are used
        // wasysym redefines some integrals (e.g. iint) from amsmath. That
@@ -759,11 +760,6 @@ string const LaTeXFeatures::getPackages() const
        if (mustProvide("setspace") && !tclass.provides("SetSpace"))
                packages << "\\usepackage{setspace}\n";
 
-       // amssymb.sty
-       if (mustProvide("amssymb")
-           || params_.use_amsmath == BufferParams::package_on)
-               packages << "\\usepackage{amssymb}\n";
-
        // esint must be after amsmath and wasysym, since it will redeclare
        // inconsistent integral symbols
        if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
@@ -858,8 +854,12 @@ docstring const LaTeXFeatures::getMacros() const
                        macros << papersizepdf_def << '\n';
        }
 
-       if (mustProvide("LyX"))
-               macros << lyx_def << '\n';
+       if (mustProvide("LyX")) {
+               if (isRequired("hyperref"))
+                       macros << lyx_hyperref_def << '\n';
+               else
+                       macros << lyx_def << '\n';
+       }
 
        if (mustProvide("noun"))
                macros << noun_def << '\n';
@@ -1039,6 +1039,35 @@ bool LaTeXFeatures::needBabelLangOptions() const
 }
 
 
+string const LaTeXFeatures::loadAMSPackages() const
+{
+       ostringstream tmp;
+       if (mustProvide("amsthm"))
+               tmp << "\\usepackage{amsthm}\n";
+
+       // esint is preferred for esintoramsmath
+       if ((mustProvide("amsmath")
+            && params_.use_amsmath != BufferParams::package_off)
+           || (mustProvide("esintoramsmath")
+               && params_.use_esint == BufferParams::package_off
+               && params_.use_amsmath != BufferParams::package_off)) {
+               tmp << "\\usepackage{amsmath}\n";
+       } else {
+               // amsbsy and amstext are already provided by amsmath
+               if (mustProvide("amsbsy"))
+                       tmp << "\\usepackage{amsbsy}\n";
+               if (mustProvide("amstext"))
+                       tmp << "\\usepackage{amstext}\n";
+       }
+       
+       if (mustProvide("amssymb")
+           || params_.use_amsmath == BufferParams::package_on)
+               tmp << "\\usepackage{amssymb}\n";
+
+       return tmp.str();
+}
+
+
 docstring const LaTeXFeatures::getTClassPreamble() const
 {
        // the text class specific preamble