commit 911e6412b8e654d4d5fa9f692a9ffabbfc37bf44
Author: Enrico Forestieri <[email protected]>
Date:   Tue Jun 25 21:57:00 2019 +0200

    Refined fix for #9633
    
    A branch inset modifies the layout of the internal structures in
    which the text is organized. When a branch is active, it is as if it
    was not there, but its only presence makes a paragraph which would not
    be the last one to actually be the last one, or the check for the
    language of the previous paragraph to fail because there is no
    previous paragraph before the first one in a branch inset.
    Oney way I found to tackle it, is tracking whether the typesetted
    paragraphs are actually part of an active branch inset and acting
    accordingly.
---
 src/OutputParams.cpp       |    5 +++--
 src/OutputParams.h         |    5 +++++
 src/insets/InsetBranch.cpp |    7 +++++--
 src/output_latex.cpp       |   13 +++++++++++--
 status.23x                 |    2 ++
 5 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp
index d10bad4..5fbbdc3 100644
--- a/src/OutputParams.cpp
+++ b/src/OutputParams.cpp
@@ -20,8 +20,9 @@ namespace lyx {
 
 OutputParams::OutputParams(Encoding const * enc)
        : flavor(LATEX), math_flavor(NotApplicable), nice(false), 
is_child(false),
-         moving_arg(false), intitle(false), inulemcmd(0), local_font(0), 
master_language(0),
-         encoding(enc), free_spacing(false), use_babel(false), 
use_polyglossia(false),
+         moving_arg(false), intitle(false), inbranch(false), inulemcmd(0),
+         local_font(0), master_language(0), encoding(enc), free_spacing(false),
+         use_babel(false), use_polyglossia(false),
          use_indices(false), use_japanese(false), linelen(0), depth(0),
          exportdata(new ExportData), inDisplayMath(false), 
wasDisplayMath(false),
          inComment(false), openbtUnit(false), only_childbibs(false),
diff --git a/src/OutputParams.h b/src/OutputParams.h
index ff94912..cbcca69 100644
--- a/src/OutputParams.h
+++ b/src/OutputParams.h
@@ -102,6 +102,11 @@ public:
        */
        bool intitle;
 
+       /** inbranch == true means that the environment being typeset
+           is inside an active branch inset.
+       */
+       bool inbranch;
+
        /** inulemcmd > 0 means that the environment in which the
            inset is typeset is part of a ulem command (\uline, \uuline,
            \uwave, \sout  or \xout). Insets that output latex commands relying
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index 28400bc..4330504 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -293,8 +293,11 @@ bool InsetBranch::producesOutput() const
 
 void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
 {
-       if (producesOutput())
-               InsetText::latex(os, runparams);
+       if (producesOutput()) {
+               OutputParams rp = runparams;
+               rp.inbranch = true;
+               InsetText::latex(os, rp);
+       }
 }
 
 
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 858717b..3aa219b 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -1142,7 +1142,7 @@ void TeXOnePar(Buffer const & buf,
        if (localswitch_needed
            || (intitle_command && using_begin_end)
            || closing_rtl_ltr_environment
-           || ((runparams.isLastPar || close_lang_switch)
+           || (((runparams.isLastPar && !runparams.inbranch) || 
close_lang_switch)
                && (par_lang != outer_lang || (using_begin_end
                                                && style.isEnvironment()
                                                && par_lang != nextpar_lang)))) 
{
@@ -1546,14 +1546,23 @@ 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
+       Language const * const outer_language = (runparams.local_font != 0)
+                       ? runparams.local_font->language() : bparams.language;
+       string const & prev_lang = runparams.use_polyglossia
+                       ? getPolyglossiaEnvName(outer_language)
+                       : outer_language->babel();
        string const & cur_lang = openLanguageName(state);
-       if (maintext && !is_child && !cur_lang.empty()) {
+       if (((runparams.inbranch && langOpenedAtThisLevel(state) && prev_lang 
!= cur_lang)
+            || (maintext && !is_child)) && !cur_lang.empty()) {
                os << from_utf8(subst(lang_end_command,
                                        "$$lang",
                                        cur_lang))
                   << '\n';
                if (using_begin_end)
                        popLanguageName();
+       } else if (runparams.inbranch && !using_begin_end && prev_lang != 
cur_lang) {
+               os << subst(lang_begin_command, "$$lang", prev_lang) << '\n';
        }
 
        // reset inherited encoding
diff --git a/status.23x b/status.23x
index d98f333..91ca6df 100644
--- a/status.23x
+++ b/status.23x
@@ -64,6 +64,8 @@ Avoid using text mode for unicode symbols representable in 
math mode (bug 9616).
 - Use the selection as the argument of a macro also when the macro has only
   optional arguments (bug 10498).
 
+- Correctly close a language opened in a branch inset (bug 9633).
+
 
 * INTERNALS
 

Reply via email to