]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Beamer: autonest column in columns
[lyx.git] / src / output_latex.cpp
index 25ec597387efb1e9e97f12358f46d4b54f8bd15a..1e99675cee5009c90a9f7f3354185eaff1d34b6a 100644 (file)
@@ -290,6 +290,14 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
                                  << "}\n";
                } else
                        os << from_ascii(style.latexparam()) << '\n';
+               if (style.latextype == LATEX_BIB_ENVIRONMENT
+                   || style.latextype == LATEX_ITEM_ENVIRONMENT
+                   || style.latextype ==  LATEX_LIST_ENVIRONMENT) {
+                       OutputParams rp = runparams;
+                       rp.local_font = &pit->getFirstFontSettings(bparams);
+                       latexArgInsets(paragraphs, pit, os, rp, style.listpreamble(),
+                                      "listpreamble:");
+               }
        }
        data.style = &style;
 
@@ -459,15 +467,21 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
                                                latexargs.find(ins->name());
                                if (lait != latexargs.end()) {
                                        Layout::latexarg arg = (*lait).second;
-                                       docstring ldelim = arg.mandatory ?
+                                       docstring ldelim;
+                                       docstring rdelim;
+                                       if (!arg.nodelims) {
+                                               ldelim = arg.mandatory ?
                                                        from_ascii("{") : from_ascii("[");
-                                       docstring rdelim = arg.mandatory ?
+                                               rdelim = arg.mandatory ?
                                                        from_ascii("}") : from_ascii("]");
+                                       }
                                        if (!arg.ldelim.empty())
                                                ldelim = arg.ldelim;
                                        if (!arg.rdelim.empty())
                                                rdelim = arg.rdelim;
                                        ins->latexArgument(os, runparams, ldelim, rdelim, arg.presetarg);
+                                       if (prefix == "listpreamble:")
+                                               os << breakln;
                                        inserted = true;
                                }
                        }
@@ -654,7 +668,7 @@ void parStartCommand(Paragraph const & par, otexstream & os,
 {
        switch (style.latextype) {
        case LATEX_COMMAND:
-               if (par.needsCProtection())
+               if (par.needsCProtection(runparams.moving_arg))
                        os << "\\cprotect";
                os << '\\' << from_ascii(style.latexname());
 
@@ -665,11 +679,16 @@ void parStartCommand(Paragraph const & par, otexstream & os,
                break;
        case LATEX_ITEM_ENVIRONMENT:
        case LATEX_LIST_ENVIRONMENT:
-               os << "\\" + style.itemcommand();
-               // Item arguments
-               if (!style.itemargs().empty())
-                       latexArgInsets(par, os, runparams, style.itemargs(), "item:");
-               os << " ";
+               if (runparams.for_search) {
+                       os << "\\" + style.itemcommand() << "{" << style.latexname() << "}";
+               }
+               else {
+                       os << "\\" + style.itemcommand();
+                       // Item arguments
+                       if (!style.itemargs().empty())
+                               latexArgInsets(par, os, runparams, style.itemargs(), "item:");
+                       os << " ";
+               }
                break;
        case LATEX_BIB_ENVIRONMENT:
                // ignore this, the inset will write itself
@@ -800,10 +819,12 @@ void TeXOnePar(Buffer const & buf,
                            || (priorpar->getDepth() == par.getDepth()
                                    && priorpar->layout() != par.layout()));
        Language const * const prev_language =
-               (priorpar && !priorpar->isPassThru())
-               ? (use_prev_env_language ? state->prev_env_language_
-                                        : priorpar->getParLanguage(bparams))
-               : outer_language;
+               runparams_in.for_search ?
+                       languages.getLanguage("ignore")
+               :(priorpar && !priorpar->isPassThru())
+                       ? (use_prev_env_language ? state->prev_env_language_
+                                               : priorpar->getParLanguage(bparams))
+                       : outer_language;
 
        bool const use_polyglossia = runparams.use_polyglossia;
        string const par_lang = use_polyglossia ?
@@ -831,9 +852,19 @@ void TeXOnePar(Buffer const & buf,
                os << '{';
        }
 
-       // In some insets (such as Arguments), we cannot use \selectlanguage
-       bool const localswitch = text.inset().forceLocalFontSwitch()
-                       || (using_begin_end && text.inset().forcePlainLayout());
+       // In some insets (such as Arguments), we cannot use \selectlanguage.
+       // Also, if an RTL language is set via environment in polyglossia,
+       // only a nested \\text<lang> command will reset the direction for LTR
+       // languages (see # 10111).
+       bool const in_polyglossia_rtl_env =
+               use_polyglossia
+               && runparams.local_font != 0
+               && outer_language->rightToLeft()
+               && !par_language->rightToLeft();
+       bool const localswitch = runparams_in.for_search
+                       || text.inset().forceLocalFontSwitch()
+                       || (using_begin_end && text.inset().forcePlainLayout())
+                       || in_polyglossia_rtl_env;
        if (localswitch) {
                lang_begin_command = use_polyglossia ?
                            "\\text$$lang$$opts{" : lyxrc.language_command_local;
@@ -844,12 +875,12 @@ void TeXOnePar(Buffer const & buf,
        bool const localswitch_needed = localswitch && par_lang != outer_lang;
 
        // localswitches need to be closed and reopened at each par
-       if ((par_lang != prev_lang || localswitch_needed)
+       if (runparams_in.for_search || ((par_lang != prev_lang || localswitch_needed)
             // check if we already put language command in TeXEnvironment()
             && !(style.isEnvironment()
                  && (pit == 0 || (priorpar->layout() != par.layout()
                                   && priorpar->getDepth() <= par.getDepth())
-                     || priorpar->getDepth() < par.getDepth()))) {
+                     || priorpar->getDepth() < par.getDepth())))) {
                if (!localswitch
                    && (!using_begin_end || langOpenedAtThisLevel(state))
                    && !lang_end_command.empty()
@@ -880,8 +911,8 @@ void TeXOnePar(Buffer const & buf,
                        // This behavior is not correct for ArabTeX, though.
                        if (!using_begin_end
                            // not for ArabTeX
-                               && par_language->lang() != "arabic_arabtex"
-                               && outer_language->lang() != "arabic_arabtex"
+                           && par_language->lang() != "arabic_arabtex"
+                           && outer_language->lang() != "arabic_arabtex"
                            // are we in an inset?
                            && runparams.local_font != 0
                            // is the inset within an \L or \R?
@@ -910,7 +941,7 @@ void TeXOnePar(Buffer const & buf,
                                        os << "\\L{";
                        }
                        // With CJK, the CJK tag has to be closed first (see below)
-                       if (runparams.encoding->package() != Encoding::CJK
+                       if ((runparams.encoding->package() != Encoding::CJK || runparams.for_search)
                            && (par_lang != openLanguageName(state) || localswitch)
                            && !par_lang.empty()) {
                                string bc = use_polyglossia ?
@@ -1134,7 +1165,7 @@ void TeXOnePar(Buffer const & buf,
                        os << '\n';
 
                // when the paragraph uses CJK, the language has to be closed earlier
-               if (font.language()->encoding()->package() != Encoding::CJK) {
+               if ((font.language()->encoding()->package() != Encoding::CJK) || runparams_in.for_search) {
                        if (lang_end_command.empty()) {
                                // If this is a child, we should restore the
                                // master language after the last paragraph.
@@ -1174,7 +1205,8 @@ void TeXOnePar(Buffer const & buf,
                                                && style != nextpar->layout())))
                                    || (atSameLastLangSwitchDepth(state)
                                        && state->lang_switch_depth_.size()
-                                       && cur_lang != par_lang))
+                                       && cur_lang != par_lang)
+                                   || in_polyglossia_rtl_env)
                                {
                                        if (using_begin_end && !localswitch)
                                                os << breakln;
@@ -1543,7 +1575,7 @@ void latexParagraphs(Buffer const & buf,
 
 pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                   OutputParams const & runparams, Encoding const & newEnc,
-                  bool force)
+                  bool force, bool noswitchmacro)
 {
        // XeTeX/LuaTeX use only one encoding per document:
        // * with useNonTeXFonts: "utf8plain",
@@ -1612,7 +1644,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                                state->open_encoding_ = inputenc;
                        }
                        // with the japanese option, inputenc is omitted.
-                       if (runparams.use_japanese)
+                       if (runparams.use_japanese || noswitchmacro)
                                return make_pair(true, count);
                        os << "\\inputencoding{" << inputenc_arg << '}';
                        return make_pair(true, count + 16);