[LyX/master] luabidi's \\LR[E] needs to be embraced (possibly a LuaTeX bug)

Juergen Spitzmueller spitz at lyx.org
Mon Apr 10 12:11:45 UTC 2023


commit 8917cb3cc880452dfbae9475b14ddb2ba58780ab
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Mon Apr 10 15:16:20 2023 +0200

    luabidi's \\LR[E] needs to be embraced (possibly a LuaTeX bug)
    
    without the grouping, trailing text disappears
---
 src/Font.cpp      |   12 ++++++++----
 src/Paragraph.cpp |   19 +++++++++++++------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/Font.cpp b/src/Font.cpp
index 0e4aa2b..e072bca 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -435,8 +435,10 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
 		|| language()->lang() == "arabic_arabi")) {
 		if (runparams.use_polyglossia) {
 			// LuaTeX/luabidi
-			os << "\\LR{";
-			count += 5;
+			// \LR needs extra grouping
+			// (possibly a LuaTeX bug)
+			os << "{\\LR{";
+			count += 6;
 		} else {
 			os << "{\\beginL ";
 			count += 9;
@@ -610,8 +612,10 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
 		|| language()->lang() == "arabic_arabi")) {
 		if (runparams.use_polyglossia) {
 			// LuaTeX/luabidi
-			os << "}";
-			count += 1;
+			// luabidi's \LR needs extra grouping
+			// (possibly a LuaTeX bug)
+			os << "}}";
+			count += 2;
 		} else {
 			os << "\\endL}";
 			count += 6;
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 3ec79d5..b8819fd 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1090,7 +1090,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
 		running_change = Change(Change::UNCHANGED);
 	}
 
-	bool close_brace = false;
+	unsigned int close_brace = 0;
 	bool const disp_env = (inset->isEnvironment() && inset->getLayout().isDisplay())
 			|| runparams.inDisplayMath;
 	string close_env;
@@ -1108,19 +1108,25 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
 				os << "\\begin{LTR}";
 				close_env = "LTR";
 			} else {
+				if (runparams.flavor == Flavor::LuaTeX) {
+					// luabidi's \LRE needs extra grouping
+					// (possibly a LuaTeX bug)
+					os << '{';
+					close_brace = 1;
+				}
 				os << "\\LRE{";
-				close_brace = true;
+				close_brace += 1;
 			}
 		} else if (running_font.language()->lang() == "farsi"
 			 || running_font.language()->lang() == "arabic_arabi") {
 			os << "\\textLR{" << termcmd;
-			close_brace = true;
+			close_brace = 1;
 		} else {
 			// babel classic
 			os << "\\L{";
 			if (disp_env)
 				os << safebreakln;
-			close_brace = true;
+			close_brace = 1;
 		}
 	}
 
@@ -1201,8 +1207,9 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
 	if (!close_env.empty())
 		os << "\\end{" << close_env << "}";
 
-	if (close_brace) {
-		os << '}';
+	if (close_brace > 0) {
+		for (unsigned i = 0; i < close_brace; ++i)
+			os << '}';
 		if (disp_env)
 			os << safebreakln;
 	}


More information about the lyx-cvs mailing list