]> git.lyx.org Git - features.git/blobdiff - src/output_latex.cpp
Really fix bug #11616
[features.git] / src / output_latex.cpp
index a516c0d295a9e371d6fc7c1cc83986c47d992291..891e74cf17e56cbedb179b940a73257689d8338d 100644 (file)
@@ -64,7 +64,7 @@ enum OpenEncoding {
 struct OutputState
 {
        OutputState() : open_encoding_(none), cjk_inherited_(0),
-       prev_env_language_(nullptr), nest_level_(0)
+               prev_env_language_(nullptr), nest_level_(0)
        {
        }
        OpenEncoding open_encoding_;
@@ -821,7 +821,7 @@ void TeXOnePar(Buffer const & buf,
        // inside of was opened
        Language const * const outer_language =
                (runparams.local_font != nullptr) ?
-               runparams.local_font->language() : doc_language;
+                       runparams.local_font->language() : doc_language;
 
        Paragraph const * priorpar = (pit == 0) ? nullptr : &paragraphs.at(pit - 1);
 
@@ -1183,7 +1183,7 @@ void TeXOnePar(Buffer const & buf,
                && (par_language->lang() != "arabic_arabtex"
                    && outer_language->lang() != "arabic_arabtex")
                // have we opened an \L or \R environment?
-       && runparams.local_font != nullptr
+               && runparams.local_font != nullptr
                && runparams.local_font->isRightToLeft() != par_language->rightToLeft()
                // are we about to close the language?
                &&((nextpar && par_lang != nextpar_lang)
@@ -1402,20 +1402,20 @@ void TeXOnePar(Buffer const & buf,
                             && !text.inset().getLayout().parbreakIgnored()
                             && style.latextype != LATEX_ITEM_ENVIRONMENT
                             && style.latextype != LATEX_LIST_ENVIRONMENT
-                            && style.align == par.getAlign()
+                            && style.align == par.getAlign(bparams)
                             && nextpar->getDepth() == par.getDepth()
-                            && nextpar->getAlign() == par.getAlign())
+                            && nextpar->getAlign(bparams) == par.getAlign(bparams))
                            || (!next_layout.isEnvironment()
                                && nextpar->getDepth() > par.getDepth()
-                               && nextpar->getAlign() == next_layout.align)
+                               && nextpar->getAlign(bparams) == next_layout.align)
                            || (!style.isEnvironment()
                                && next_layout.latextype == LATEX_ENVIRONMENT
                                && nextpar->getDepth() < par.getDepth())
                            || (style.isCommand()
                                && !next_layout.isEnvironment()
-                               && style.align == par.getAlign()
-                               && next_layout.align == nextpar->getAlign())
-                           || (style.align != par.getAlign()
+                               && style.align == par.getAlign(bparams)
+                               && next_layout.align == nextpar->getAlign(bparams))
+                           || (style.align != par.getAlign(bparams)
                                && tclass.isDefaultLayout(next_layout))) {
                                os << '\n';
                        }
@@ -1466,7 +1466,8 @@ void latexParagraphs(Buffer const & buf,
                                && runparams.use_CJK))
           ) {
                docstring const cjkenc = bparams.encoding().iconvName() == "UTF-8"
-                                                                ? from_ascii("UTF8") : from_ascii(bparams.encoding().latexName());
+                                                                ? from_ascii("UTF8")
+                                                                : from_ascii(bparams.encoding().latexName());
                os << "\\begin{CJK}{" << cjkenc
                   << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
                state->open_encoding_ = CJK;
@@ -1604,8 +1605,10 @@ void latexParagraphs(Buffer const & buf,
 
        // if "auto end" is switched off, explicitly close the language at the end
        // but only if the last par is in a babel or polyglossia language
+       Language const * const lastpar_language =
+                       paragraphs.at(lastpit).getParLanguage(bparams);
        if (maintext && !lyxrc.language_auto_end && !mainlang.empty() &&
-               paragraphs.at(lastpit).getParLanguage(bparams)->encoding()->package() != Encoding::CJK) {
+               lastpar_language->encoding()->package() != Encoding::CJK) {
                os << from_utf8(subst(lang_end_command,
                                        "$$lang",
                                        mainlang))
@@ -1621,12 +1624,14 @@ void latexParagraphs(Buffer const & buf,
                state->open_encoding_ = none;
        }
        // Likewise for polyglossia or when using begin/end commands
-       // or after an active branch inset with a language switch
+       // or at the very end of an active branch inset with a language switch
        Language const * const outer_language = (runparams.local_font != nullptr)
                        ? runparams.local_font->language() : bparams.language;
        string const & prev_lang = runparams.use_polyglossia
                        ? getPolyglossiaEnvName(outer_language)
                        : outer_language->babel();
+       string const lastpar_lang = runparams.use_polyglossia ?
+               getPolyglossiaEnvName(lastpar_language): lastpar_language->babel();
        string const & cur_lang = openLanguageName(state);
        if (((runparams.inbranch && langOpenedAtThisLevel(state) && prev_lang != cur_lang)
             || (maintext && !is_child)) && !cur_lang.empty()) {
@@ -1636,7 +1641,11 @@ void latexParagraphs(Buffer const & buf,
                   << '\n';
                if (using_begin_end)
                        popLanguageName();
-       } else if (runparams.inbranch && !using_begin_end && prev_lang != cur_lang) {
+       } else if (runparams.inbranch && !using_begin_end
+                  && prev_lang != lastpar_lang && !lastpar_lang.empty()) {
+               // with !using_begin_end, cur_lang is empty, so we need to
+               // compare against the paragraph language (and we are in the
+               // last paragraph at this point)
                os << subst(lang_begin_command, "$$lang", prev_lang) << '\n';
        }
 
@@ -1658,14 +1667,10 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                   OutputParams const & runparams, Encoding const & newEnc,
                   bool force, bool noswitchmacro)
 {
-       // Never switch encoding with non-TeX fonts (always "utf8plain"),
-       // with LuaTeX and TeX fonts (only one encoding accepted by luainputenc),
+       // Never switch encoding with XeTeX/LuaTeX
        // or if we're in a moving argument or inherit the outer encoding.
-       if (bparams.useNonTeXFonts
-               || runparams.flavor == OutputParams::LUATEX
-               || runparams.flavor == OutputParams::DVILUATEX
-               || newEnc.name() == "inherit")
-         return make_pair(false, 0);
+       if (runparams.isFullUnicode() || newEnc.name() == "inherit")
+               return make_pair(false, 0);     
 
        // Only switch for auto-selected legacy encodings (inputenc setting
        // "auto-legacy" or "auto-legacy-plain").