commit cc4ed5e04b41e86e51f44d467680fc597fb94079
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Feb 4 17:23:52 2022 +0100

    Do not try to pop from an empty stack
---
 src/Font.cpp         |    2 +-
 src/Paragraph.cpp    |    3 ++-
 src/output_latex.cpp |   10 +++++++++-
 src/output_latex.h   |    3 +++
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/Font.cpp b/src/Font.cpp
index 26218ee..3ba04eb 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -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();
        }
 
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index da97d12..a08f3ac 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -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)
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index ac22116..f6c7375 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -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();
        }
 
diff --git a/src/output_latex.h b/src/output_latex.h
index af40a86..311b2e6 100644
--- a/src/output_latex.h
+++ b/src/output_latex.h
@@ -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
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to