From f6a1b6bf26c4f91fecd67a0279fa2ea31f67c846 Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Sat, 1 Feb 2025 11:32:45 +0100
Subject: [PATCH] Fixed missing displacement when leqno is used in rtl
 paragraph (thanks to udifoglle@gmail.com) LuaTeX 1.20.6

---
 source/texk/web2c/luatexdir/ChangeLog         |  5 +++++
 source/texk/web2c/luatexdir/luatex.c          |  4 ++--
 .../texk/web2c/luatexdir/luatex_svnversion.h  |  2 +-
 source/texk/web2c/luatexdir/tex/texmath.c     | 22 ++++++++++---------
 4 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/source/texk/web2c/luatexdir/ChangeLog b/source/texk/web2c/luatexdir/ChangeLog
index e595e1681..7d8a77948 100644
--- a/source/texk/web2c/luatexdir/ChangeLog
+++ b/source/texk/web2c/luatexdir/ChangeLog
@@ -1,3 +1,8 @@
+2025-02-01 Luigi Scarso <luigi.scarso@gmail.com>
+	* Fixed missing displacement when leqno is used in rtl paragraph (thanks to udifoglle@gmail.com)
+	* LuaTeX 1.20.6
+
+
 2025-01-31 Luigi Scarso <luigi.scarso@gmail.com>
 	* In read_tfm_info avoid scaling fonts to >= 2048pt, which can cause overflow (TeXLive rev. 73614)
 	* \ignoreprimitiveerror as in pdftex
diff --git a/source/texk/web2c/luatexdir/luatex.c b/source/texk/web2c/luatexdir/luatex.c
index 1f5465784..02df6b5b2 100644
--- a/source/texk/web2c/luatexdir/luatex.c
+++ b/source/texk/web2c/luatexdir/luatex.c
@@ -33,8 +33,8 @@
 */
 
 int luatex_version = 120;
-int luatex_revision = '5';
-const char *luatex_version_string = "1.20.5";
+int luatex_revision = '6';
+const char *luatex_version_string = "1.20.6";
 const char *engine_name = my_name;
 
 #include <kpathsea/c-ctype.h>
diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h
index c7865db02..aefe3b91b 100644
--- a/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1,4 +1,4 @@
 #ifndef luatex_svn_revision_h
 #define luatex_svn_revision_h
-#define luatex_svn_revision 7647
+#define luatex_svn_revision 7648
 #endif
diff --git a/source/texk/web2c/luatexdir/tex/texmath.c b/source/texk/web2c/luatexdir/tex/texmath.c
index 8b6138e7c..e1f100c60 100644
--- a/source/texk/web2c/luatexdir/tex/texmath.c
+++ b/source/texk/web2c/luatexdir/tex/texmath.c
@@ -2564,23 +2564,20 @@ static void finish_displayed_math(boolean l, pointer eqno_box, pointer p)
             if (swap_dir) {
                 if (math_direction_par==dir_TLT) {
                     /*tex TRT + TLT + \eqno: (swap_dir=true,  math_direction_par=TLT, l=true) */
-                    s = new_kern(width(r) + eqno_w);
-                    try_couple_nodes(eqno_box,r);
-                    try_couple_nodes(r,eq_box);
-                    try_couple_nodes(eq_box,s);
                 } else {
                     /*tex TLT + TRT + \eqno: (swap_dir=true,  math_direction_par=TRT, l=true) */
-                    try_couple_nodes(eqno_box,r);
-                    try_couple_nodes(r,eq_box);
                 }
+                s = new_kern(width(r) + eqno_w);
+                try_couple_nodes(eqno_box,r);
+                try_couple_nodes(r,eq_box);
+                try_couple_nodes(eq_box,s);
             } else {
                 if (math_direction_par==dir_TLT) {
                     /*tex TLT + TLT + \leqno: (swap_dir=false, math_direction_par=TLT, l=true) */
-                    s = new_kern(width(r) + eqno_w);
                 } else {
                     /*tex TRT + TRT + \leqno: (swap_dir=false, math_direction_par=TRT, l=true) */
-                    s = new_kern(width(r));
                 }
+                s = new_kern(width(r) + eqno_w);
                 try_couple_nodes(eqno_box,r);
                 try_couple_nodes(r,eq_box);
                 try_couple_nodes(eq_box,s);
@@ -2590,11 +2587,16 @@ static void finish_displayed_math(boolean l, pointer eqno_box, pointer p)
             if (swap_dir) {
                 if (math_direction_par==dir_TLT) {
                     /*tex TRT + TLT + \leqno: (swap_dir=true,  math_direction_par=TLT, l=false) */
+                    s = new_kern(d);
+                    try_couple_nodes(s,eq_box);
+                    try_couple_nodes(eq_box,r);
+                    try_couple_nodes(r,eqno_box);
+                    eq_box = s;
                 } else {
                     /*tex TLT + TRT + \leqno: (swap_dir=true,  math_direction_par=TRT, l=false) */
+                    try_couple_nodes(eq_box,r);
+                    try_couple_nodes(r,eqno_box);
                 }
-                try_couple_nodes(eq_box,r);
-                try_couple_nodes(r,eqno_box);
             } else {
                 if (math_direction_par==dir_TLT) {
                     /*tex TLT + TLT + \eqno: (swap_dir=false, math_direction_par=TLT, l=false) */
-- 
GitLab