[LyX/2.5.x] Properly track switch of direction (#6373)

Juergen Spitzmueller <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit c4f04bef83c04d73c7894752bf8ea8a864db0247
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Mar 19 11:43:04 2026 +0100

    Properly track switch of direction (#6373)
    
    Otherwise we might end with unbalanced braces
    
    (cherry picked from commit 0a6dd54aab97014def7e38c846ebaadba6334d52)
---
 src/output_latex.cpp | 12 +++++++++---
 status.25x           |  2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index adaf16f782..0ee6bd133b 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -61,7 +61,7 @@ enum OpenEncoding {
 struct OutputState
 {
 	OutputState() : prev_env_language_(nullptr), open_encoding_(none),
-		cjk_inherited_(0), nest_level_(0)
+		cjk_inherited_(0), nest_level_(0), LR_switch_(0)
 	{
 	}
 	Language const * prev_env_language_;
@@ -70,6 +70,7 @@ struct OutputState
 	OpenEncoding open_encoding_;
 	int cjk_inherited_;
 	int nest_level_;
+	int LR_switch_;
 };
 
 
@@ -1117,6 +1118,7 @@ void TeXOnePar(Buffer const & buf,
 					os << "\\R{";
 				else
 					os << "\\L{";
+				++state->LR_switch_;
 			}
 			// With CJK, the CJK tag has to be closed first (see below)
 			if ((runparams.encoding->package() != Encoding::CJK
@@ -1343,7 +1345,9 @@ void TeXOnePar(Buffer const & buf,
 	// as well as for any InTitleCommand (since these set the language locally);
 	// it is also needed if we're within an \L or \R that we may have opened above
 	// (not necessarily in this paragraph) and are about to close.
-	bool closing_rtl_ltr_environment = !using_begin_end
+	bool closing_rtl_ltr_environment =
+		state->LR_switch_ > 0
+		&& !using_begin_end
 		// not for ArabTeX
 		&& (par_language->lang() != "arabic_arabtex"
 		    && outer_language->lang() != "arabic_arabtex")
@@ -1435,8 +1439,10 @@ void TeXOnePar(Buffer const & buf,
 			}
 		}
 	}
-	if (closing_rtl_ltr_environment)
+	if (closing_rtl_ltr_environment) {
 		os << "}";
+		--state->LR_switch_;
+	}
 
 	// InTitle commands need to be closed after the language has been closed.
 	if (intitle_command) {
diff --git a/status.25x b/status.25x
index e19f5ea018..ce5acb1618 100644
--- a/status.25x
+++ b/status.25x
@@ -55,6 +55,8 @@ What's new
 
 - Properly resolve font in insets that do not inherit font (bug 13278).
 
+- Fix switch of text direction with verbatim content (bug 6373).
+
 - Fix old docbook layouts.
 
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.