]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
Re-fix #11146 with recent LaTeX
[lyx.git] / src / LaTeXFeatures.cpp
index d4b0018b73dbe936743f71bc5a52c7fd7a603dfd..7af795d54b43072f07f5c16a86c1415705e9a224 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"
@@ -200,6 +204,39 @@ static docstring const lyxgreyedout_def = from_ascii(
        "  {\\textcolor{note_fontcolor}\\bgroup\\ignorespaces}\n"
        "  {\\ignorespacesafterend\\egroup}\n");
 
+static docstring const lyxgreyedout_rtl_def = from_ascii(
+       "%% The greyedout annotation environment (with RTL support)\n"
+       "\\NewEnviron{lyxgreyedout}{%\n"
+       "\\if@rl%\n"
+       "\\everypar{\\textcolor{note_fontcolor}\\beginL\\ignorespaces}%\n"
+       "\\BODY\\everypar{\\ignorespacesafterend\\endL}\n"
+       "\\else%\n"
+       "\\textcolor{note_fontcolor}\\bgroup\\ignorespaces%\n"
+       "\\BODY\\ignorespacesafterend\\egroup\n"
+       "\\fi}\n");
+
+static docstring const lyxgreyedout_luartl_def = from_ascii(
+       "%% The greyedout annotation environment (with RTL support)\n"
+       "\\NewEnviron{lyxgreyedout}{%\n"
+       "\\if@RTL%\n"
+       "\\everypar{\\color{note_fontcolor}\\pardir TRT \\textdir TRT\\ignorespaces}%\n"
+       "\\BODY\\everypar{\\ignorespacesafterend}\n"
+       "\\else%\n"
+       "\\textcolor{note_fontcolor}\\bgroup\\ignorespaces%\n"
+       "\\BODY\\ignorespacesafterend\\egroup\n"
+       "\\fi}\n");
+
+static docstring const lyxgreyedout_luartl_babel_def = from_ascii(
+       "%% The greyedout annotation environment (with RTL support)\n"
+       "\\NewEnviron{lyxgreyedout}{%\n"
+       "\\if@rl%\n"
+       "\\everypar{\\color{note_fontcolor}\\pardir TRT \\textdir TRT\\ignorespaces}%\n"
+       "\\BODY\\everypar{\\ignorespacesafterend}\n"
+       "\\else%\n"
+       "\\textcolor{note_fontcolor}\\bgroup\\ignorespaces%\n"
+       "\\BODY\\ignorespacesafterend\\egroup\n"
+       "\\fi}\n");
+
 // We want to omit the file extension for includegraphics, but this does not
 // work when the filename contains other dots.
 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
@@ -908,6 +945,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[] = {
@@ -915,7 +963,6 @@ char const * simplefeatures[] = {
        "array",
        "verbatim",
        "longtable",
-       "rotating",
        "latexsym",
        "pifont",
        // subfig is handled in BufferParams.cpp
@@ -927,7 +974,6 @@ char const * simplefeatures[] = {
          the `float' package. See the caption package documentation
          for explanation.*/
        "float",
-       "rotfloat",
        "wrapfig",
        "booktabs",
        "dvipost",
@@ -937,6 +983,7 @@ char const * simplefeatures[] = {
        "framed",
        "soul",
        "textcomp",
+       "dingbat",
        "pmboxdraw",
        "bbding",
        "ifsym",
@@ -949,7 +996,6 @@ char const * simplefeatures[] = {
        // "cancel",
        "ascii",
        "url",
-       "covington",
        "csquotes",
        "enumitem",
        "endnotes",
@@ -974,8 +1020,8 @@ char const * simplefeatures[] = {
        "todonotes",
        "forest",
        "varwidth",
-       "footnote",
        "tablefootnote",
+       "environ"
 };
 
 char const * bibliofeatures[] = {
@@ -1098,6 +1144,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
@@ -1182,6 +1244,13 @@ string const LaTeXFeatures::getPackages() const
                                 << "]{graphicx}\n";
        }
 
+       // These must be loaded after graphicx, since they try
+       // to load graphicx without options
+       if (mustProvide("rotating"))
+               packages << "\\usepackage{rotating}\n";
+       if (mustProvide("rotfloat"))
+               packages << "\\usepackage{rotfloat}\n";
+
        // lyxskak.sty --- newer chess support based on skak.sty
        if (mustProvide("chess"))
                packages << "\\usepackage[ps,mover]{lyxskak}\n";
@@ -1232,7 +1301,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";
@@ -1251,7 +1324,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 << ']';
@@ -1336,6 +1413,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"))
@@ -1465,8 +1544,19 @@ TexString LaTeXFeatures::getMacros() const
        // greyed-out environment (note inset)
        // the color is specified in the routine
        // getColorOptions() to avoid LaTeX-package clashes
-       if (mustProvide("lyxgreyedout"))
-               macros << lyxgreyedout_def;
+       if (mustProvide("lyxgreyedout")) {
+               // We need different version for RTL (#8647)
+               if (hasRTLLanguage()) {
+                       if (runparams_.flavor == OutputParams::LUATEX)
+                               if (useBabel())
+                                       macros << lyxgreyedout_luartl_babel_def;
+                               else
+                                       macros << lyxgreyedout_luartl_def;
+                       else
+                               macros << lyxgreyedout_rtl_def;
+               } else
+                       macros << lyxgreyedout_def;
+       }
 
        if (mustProvide("lyxdot"))
                macros << lyxdot_def << '\n';