[LyX/master] remove insline forceLTR decorations with polyglossia+LuaTeX

Udi Fogiel <[email protected]> Mon, 06 Jul 2026 00:26:58 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit e91c8b61ac0e1f933b8b8310da864130353c9023
Author: Udi Fogiel <[email protected]>
Date:   Sun Jul 5 21:12:55 2026 +0300

    remove insline forceLTR decorations with polyglossia+LuaTeX
    
    polyglossia now use unibidi-lua which handles these situations.
    display environments are still wraped with \begin{LTR}...\end{LTR}.
---
 src/Font.cpp      | 24 ++++++++++++++----------
 src/Paragraph.cpp | 18 +++++++++++-------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/Font.cpp b/src/Font.cpp
index a0c4820a05..73698dad79 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -428,9 +428,10 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
 	}
 	*/
 	// If the current language is Hebrew, Arabic, or Farsi
-	// the numbers are written Left-to-Right. ArabTeX package
-	// and bidi (polyglossia with XeTeX) reorder the number automatically
-	// but the packages used for Hebrew and Farsi (Arabi) do not.
+	// the numbers are written Left-to-Right. Unicode engines and ArabTeX
+	// reorder numbers automatically, but the packages used for Hebrew
+	// and Farsi (Arabi) in classic (pdf)latex do not. As of polyglossia
+	// 2.10, luabidi handles this automatically as well.
 	if (!bparams.useBidiPackage(runparams)
 	    && !runparams.pass_thru
 	    && bits_.number() == FONT_ON
@@ -438,8 +439,9 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
 	    && (language()->lang() == "hebrew"
 		|| language()->lang() == "farsi"
 		|| language()->lang() == "arabic_arabi")) {
-		if (runparams.use_polyglossia) {
-			// LuaTeX/luabidi
+		if (runparams.use_polyglossia
+		    && !LaTeXFeatures::isAvailableAtLeastFrom("polyglossia", 2026, 4, 18)) {
+			// LuaTeX/luabidi (polyglossia < 2.10)
 			// \LR needs extra grouping
 			// (possibly a LuaTeX bug)
 			os << "{\\LR{";
@@ -606,9 +608,10 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
 	}
 
 	// If the current language is Hebrew, Arabic, or Farsi
-	// the numbers are written Left-to-Right. ArabTeX package
-	// and bidi (polyglossia with XeTeX) reorder the number automatically
-	// but the packages used for Hebrew and Farsi (Arabi) do not.
+	// the numbers are written Left-to-Right. Unicode engines and ArabTeX
+	// reorder numbers automatically, but the packages used for Hebrew
+	// and Farsi (Arabi) in classic (pdf)latex do not. As of polyglossia
+	// 2.10, luabidi handles this automatically as well.
 	if (!bparams.useBidiPackage(runparams)
 	    && !runparams.pass_thru
 	    && bits_.number() == FONT_ON
@@ -616,8 +619,9 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
 	    && (language()->lang() == "hebrew"
 		|| language()->lang() == "farsi"
 		|| language()->lang() == "arabic_arabi")) {
-		if (runparams.use_polyglossia) {
-			// LuaTeX/luabidi
+		if (runparams.use_polyglossia
+		    && !LaTeXFeatures::isAvailableAtLeastFrom("polyglossia", 2026, 4, 18)) {
+			// LuaTeX/luabidi (polyglossia < 2.10)
 			// luabidi's \LR needs extra grouping
 			// (possibly a LuaTeX bug)
 			os << "}}";
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 044bdb3ea5..2f9ba6b95d 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1109,16 +1109,20 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
 			if (disp_env) {
 				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;
-				}
+			} else if (bparams.useBidiPackage(runparams)) {
+				// XeTeX/bidi: wrap inline insets
+				os << "\\LRE{";
+				close_brace = 1;
+			} else if (!LaTeXFeatures::isAvailableAtLeastFrom("polyglossia", 2026, 4, 18)) {
+				// LuaTeX/luabidi (polyglossia < 2.10)
+				// \LRE needs extra grouping
+				// (possibly a LuaTeX bug)
+				os << '{';
+				close_brace = 1;
 				os << "\\LRE{";
 				close_brace += 1;
 			}
+			// luabidi (polyglossia >= 2.10): inline insets are not wrapped
 		} else if (running_font.language()->lang() == "farsi"
 			 || running_font.language()->lang() == "arabic_arabi") {
 			os << "\\textLR{" << termcmd;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs