]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
Fix selection of unmarked RtL text
[lyx.git] / src / LaTeXFeatures.cpp
index c28d7958f6908e64ef3818b6fe518a25decfe618..7256002d3068831e8e05509a555757801ebeb7dc 100644 (file)
@@ -65,6 +65,10 @@ namespace lyx {
 static docstring const lyx_def = from_ascii(
        "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
 
+static docstring const lyx_rtl_def = from_ascii(
+       "\\let\\@@LyX\\LyX\n"
+       "\\def\\LyX{\\@ensure@LTR{\\@@LyX}}");
+
 static docstring const lyx_hyperref_def = from_ascii(
        "\\providecommand{\\LyX}{\\texorpdfstring%\n"
        "  {L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}\n"
@@ -908,6 +912,17 @@ void LaTeXFeatures::getFontEncodings(vector<string> & encodings) const
                }
 }
 
+
+bool LaTeXFeatures::hasRTLLanguage() const
+{
+       if (params_.language->rightToLeft())
+               return true;
+       for (auto const & lang : UsedLanguages_)
+               if (lang->rightToLeft())
+                       return true;
+       return false;
+}
+
 namespace {
 
 char const * simplefeatures[] = {
@@ -949,7 +964,6 @@ char const * simplefeatures[] = {
        // "cancel",
        "ascii",
        "url",
-       "covington",
        "csquotes",
        "enumitem",
        "endnotes",
@@ -974,7 +988,7 @@ char const * simplefeatures[] = {
        "todonotes",
        "forest",
        "varwidth",
-       "footnote",
+       "tablefootnote",
 };
 
 char const * bibliofeatures[] = {
@@ -1097,6 +1111,22 @@ string const LaTeXFeatures::getPackages() const
        // The rest of these packages are somewhat more complicated
        // than those above.
 
+       if (mustProvide("footnote")) {
+               if (isRequired("hyperref"))
+                       packages << "\\usepackage{footnotehyper}\n";
+               else
+                       packages << "\\usepackage{footnote}\n";
+       }
+
+       // [pdf]lscape is used to rotate longtables
+       if (mustProvide("lscape")) {
+               if (runparams_.flavor == OutputParams::LATEX
+                   || runparams_.flavor == OutputParams::DVILUATEX)
+                       packages << "\\usepackage{lscape}\n";
+               else
+                       packages << "\\usepackage{pdflscape}\n";
+       }
+
        // The tipa package and its extensions (tipx, tone) must not
        // be loaded with non-TeX fonts, since fontspec includes the
        // respective macros
@@ -1231,7 +1261,11 @@ string const LaTeXFeatures::getPackages() const
        // Some classes load natbib themselves, but still allow (or even require)
        // plain numeric citations (ReVTeX is such a case, see bug 5182).
        // This special case is indicated by the "natbib-internal" key.
-       if (mustProvide("natbib") && !isProvided("natbib-internal")) {
+       if (mustProvide("natbib")
+           && !isProvided("natbib-internal")
+           && !isProvided("biblatex")
+           && !isProvided("biblatex-natbib")
+           && !isProvided("jurabib")) {
                packages << "\\usepackage[";
                if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
                        packages << "numbers";
@@ -1250,7 +1284,11 @@ string const LaTeXFeatures::getPackages() const
        }
 
        // jurabib -- we need version 0.6 at least.
-       if (mustProvide("jurabib")) {
+       if (mustProvide("jurabib")
+           && !isProvided("natbib-internal")
+           && !isProvided("natbib")
+           && !isProvided("biblatex")
+           && !isProvided("biblatex-natbib")) {
                packages << "\\usepackage";
                if (!params_.biblio_opts.empty())
                        packages << '[' << params_.biblio_opts << ']';
@@ -1317,6 +1355,9 @@ TexString LaTeXFeatures::getMacros() const
                macros << getPreambleSnippets();
        }
 
+       if (mustProvide("xetexdashbreakstate"))
+               macros << "\\XeTeXdashbreakstate 0" << '\n';
+
        if (mustProvide("papersize")) {
                if (runparams_.flavor == OutputParams::LATEX
                    || runparams_.flavor == OutputParams::DVILUATEX)
@@ -1332,6 +1373,8 @@ TexString LaTeXFeatures::getMacros() const
                        macros << lyx_hyperref_def << '\n';
                else
                        macros << lyx_def << '\n';
+               if (runparams_.use_polyglossia && hasRTLLanguage())
+                       macros << lyx_rtl_def << '\n';
        }
 
        if (mustProvide("noun"))