From 1721b8325c4b9e620f3156bee8c519c435c081b6 Mon Sep 17 00:00:00 2001
From: udifogiel <udifogiel@proton.me>
Date: Fri, 26 Jun 2026 07:14:39 +0300
Subject: [PATCH 1/6] update RTL tabular code

The LaTeX kernel don't use math in tabulars anymore,
so currently tabulars are typset with RTL columns in
RTL context, in all engines. There is also no need to wrap
the cell content with a direction command.
---
 src/insets/InsetTabular.cpp | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 51df839cde..66b1a57e70 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -3485,12 +3485,10 @@ void Tabular::TeXRow(otexstream & os, row_type row,
 	bool const row_colored = row_info[row].color != "default"
 			&& lcolor.isKnownLyXName(row_info[row].color);
 
-	// The bidi package (loaded by polyglossia with XeTeX) reverses RTL table columns
-	// Luabibdi (used by LuaTeX) behaves like classic
+	// RTL table columns are always reversed
 	bool const bidi_rtl =
 		runparams.local_font
-		&& runparams.local_font->isRightToLeft()
-		&& buffer().params().useBidiPackage(runparams);
+		&& runparams.local_font->isRightToLeft();
 	bool const ct = !buffer().params().output_changes;
 	idx_type lastcell =
 		bidi_rtl ? getFirstCellInRow(row, ct) : getLastCellInRow(row, ct);
@@ -3566,23 +3564,6 @@ void Tabular::TeXRow(otexstream & os, row_type row,
 
 		os.texrow().forceStart(par.id(), 0);
 
-		bool rtl = par.isRTL(buffer().params())
-			&& !par.empty()
-			&& getPWidth(cell).zero()
-			&& !runparams.isFullUnicode();
-
-		if (rtl) {
-			string const lang =
-				par.getParLanguage(buffer().params())->lang();
-			if (lang == "farsi")
-				os << "\\textFR{";
-			else if (lang == "arabic_arabi")
-				os << "\\textAR{";
-			// currently, remaining RTL languages are
-			// arabic_arabtex and hebrew
-			else
-				os << "\\R{";
-		}
 		// pass to the OutputParams that we are in a cell and
 		// which alignment we have set.
 		// InsetNewline needs this context information.
@@ -3639,8 +3620,6 @@ void Tabular::TeXRow(otexstream & os, row_type row,
 		}
 
 		runparams.encoding = newrp.encoding;
-		if (rtl)
-			os << '}';
 
 		if (color_last_multirow)
 			os << '}';
@@ -3712,12 +3691,10 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
 			os << "\\begin{turn}{" << convert<string>(rotate) << "}\n";
 	}
 
-	// The bidi package (loaded by polyglossia with XeTeX) swaps the column
-	// order for RTL (#9686). Thus we use this list.
+	// RTL table columns are always reversed. Thus we use this list.
 	bool const bidi_rtl =
 		runparams.local_font
-		&& runparams.local_font->isRightToLeft()
-		&& buffer().params().useBidiPackage(runparams);
+		&& runparams.local_font->isRightToLeft();
 	list<col_type> columns;
 	list<col_type> logical_columns;
 	for (col_type cl = 0; cl < ncols(); ++cl) {
-- 
2.43.0

