]> git.lyx.org Git - features.git/commitdiff
Do not try to pop from an empty stack
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 4 Feb 2022 16:23:52 +0000 (17:23 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 4 Feb 2022 16:23:52 +0000 (17:23 +0100)
src/Font.cpp
src/Paragraph.cpp
src/output_latex.cpp
src/output_latex.h

index 26218eeeac280dde50a82bba5400b1f2f8cfd30e..3ba04eba4756f9a6f2fcdccce2cf766433181db2 100644 (file)
@@ -631,7 +631,7 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
                bool const using_begin_end =
                        runparams.use_polyglossia ||
                                !lyxrc.language_command_end.empty();
-               if (using_begin_end)
+               if (using_begin_end && !languageStackEmpty())
                        popLanguageName();
        }
 
index da97d12ccd86bbeb8b3efdd7670092aa50b7b007..a08f3ac0074ec613bac5e691a4f4c7fa2eb45753 100644 (file)
@@ -2805,7 +2805,8 @@ void Paragraph::latex(BufferParams const & bparams,
                        string end_tag = subst(lang_end_command, "$$lang", running_lang);
                        os << from_ascii(end_tag);
                        column += end_tag.length();
-                       popLanguageName();
+                       if (!languageStackEmpty())
+                               popLanguageName();
                }
 
                // Switch file encoding if necessary (and allowed)
index ac22116976d7cf8cbb08b0b7ed91802637dc1a78..f6c7375c90a7513df16591c209cadad590131d50 100644 (file)
@@ -607,6 +607,14 @@ void popLanguageName()
 }
 
 
+bool languageStackEmpty()
+{
+       OutputState * state = getOutputState();
+
+       return state->lang_switch_depth_.empty();
+}
+
+
 string const & openLanguageName()
 {
        OutputState * state = getOutputState();
@@ -1768,7 +1776,7 @@ void latexParagraphs(Buffer const & buf,
                        << '\n';
                // If we have language_auto_begin, the stack will
                // already be empty, nothing to pop()
-               if (using_begin_end && !lyxrc.language_auto_begin)
+               if (using_begin_end && langOpenedAtThisLevel(state))
                        popLanguageName();
        }
 
index af40a86489ebc0843768e0406e8bea8e482daf85..311b2e61b09a0aa18812b88fe93fb22478f4d23a 100644 (file)
@@ -37,6 +37,9 @@ void pushLanguageName(std::string const & lang, bool localswitch = false);
  */
 void popLanguageName();
 
+// Check if we have an empty language stack
+bool languageStackEmpty();
+
 /** Return a reference to the last active language opened with
     polyglossia or when using begin/end commands. If none or when
     using babel with only a begin command, return a reference to