[LyX/master] use \LRE/\RLE instead of \L/\R with babel-hebrew

Udi Fogiel <[email protected]> Mon, 06 Jul 2026 00:26:58 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 3670666a46452d7ff355ef3a0ba26ceb25339d80
Author: Udi Fogiel <[email protected]>
Date:   Sun Jul 5 22:13:40 2026 +0300

    use \LRE/\RLE instead of \L/\R with babel-hebrew
    
    This avoids a conflict with hyperref.
---
 lib/chkconfig.ltx               | 21 +++++++++++++++++++++
 src/Font.cpp                    | 22 ++++++++++++++++++----
 src/Paragraph.cpp               |  7 ++++++-
 src/insets/InsetSpecialChar.cpp |  4 ++++
 src/output_latex.cpp            | 18 ++++++++++++++----
 5 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx
index 98b9f19a1a..38281ac227 100644
--- a/lib/chkconfig.ltx
+++ b/lib/chkconfig.ltx
@@ -128,6 +128,11 @@
 \let\chk@pr@videpackage\@pr@videpackage
 \def\@pr@videpackage[#1]{\chk@pr@videpackage[#1]\endinput}
 
+% Same idea, but for files that declare themselves via the kernel's
+% generic \ProvidesFile rather than \ProvidesPackage.
+\let\chk@providesfile\@providesfile
+\def\@providesfile#1[#2]{\chk@providesfile{#1}[#2]\endinput}
+
 % Tests whether an package is present and also adds the version to the package list
 \newcommand{\TestPackageAddVersion}[2][\default]{
    \def\default{#2}
@@ -143,6 +148,21 @@
    \TestItem[#1]{#2}{package}{sty}{\AddPackage[\package@version]{#2}}{}
 }
 
+% Same as \TestPackageAddVersion, but for a file that declares its
+% version via the kernel's \ProvidesFile rather than \ProvidesPackage
+% (see the \@providesfile redefinition above). #1 must be a full file
+% name including its extension.
+\newcommand{\TestFileAddVersion}[2][\default]{
+   \def\default{#2}
+   \def\package@version{}
+   \IfFileExists{#1}{%
+      \input{#1}%
+      \protected@edef\package@@version{\csname ver@#1\endcsname}%
+      \protected@edef\package@version{\expandafter\@parse@version\package@@version//00\@nil}%
+   }{}
+   \TestItem[#1]{#2}{package}{tex}{\AddPackage[\package@version]{#2}}{}
+}
+
 % Adapted from ltxcheck.tex
 \newcommand{\TestFont}[2][\default]{
   \def\default{#2}
@@ -314,6 +334,7 @@
 \TestPackage{astron}
 \TestPackage{authordate1-4}
 \TestPackageAddVersion{babel}
+\TestFileAddVersion[hebrew.ldf]{babel-hebrew}
 \TestPackage[german-de.ldf]{babel-german3}
 \TestPackage{beamerposter}
 \TestPackage{biblatex}
diff --git a/src/Font.cpp b/src/Font.cpp
index 73698dad79..107ce23462 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -305,11 +305,25 @@ int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
 				count += 9;
 			}
 			if (isRightToLeft()) {
-				os << "\\R{";
-				count += 3;
+				if (language()->lang() == "hebrew"
+				    && LaTeXFeatures::isAvailableAtLeastFrom("babel-hebrew", 2026, 2, 16)) {
+					// avoids a conflict with hyperref (#5927)
+					os << "\\RLE{";
+					count += 5;
+				} else {
+					os << "\\R{";
+					count += 3;
+				}
 			} else {
-				os << "\\L{";
-				count += 3;
+				if (base.language()->lang() == "hebrew"
+				    && LaTeXFeatures::isAvailableAtLeastFrom("babel-hebrew", 2026, 2, 16)) {
+					// avoids a conflict with hyperref (#5927)
+					os << "\\LRE{";
+					count += 5;
+				} else {
+					os << "\\L{";
+					count += 3;
+				}
 			}
 		} else if (!language()->babel().empty()) {
 			string const tmp =
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 2f9ba6b95d..b75d8ecaf6 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1129,7 +1129,12 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
 			close_brace = 1;
 		} else {
 			// babel classic
-			os << "\\L{";
+			if (running_font.language()->lang() == "hebrew"
+			    && LaTeXFeatures::isAvailableAtLeastFrom("babel-hebrew", 2026, 2, 16))
+				// avoids a conflict with hyperref (#5927)
+				os << "\\LRE{";
+			else
+				os << "\\L{";
 			if (disp_env)
 				os << safebreakln;
 			close_brace = 1;
diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp
index 95594c11bf..7956949c57 100644
--- a/src/insets/InsetSpecialChar.cpp
+++ b/src/insets/InsetSpecialChar.cpp
@@ -269,6 +269,10 @@ void InsetSpecialChar::latex(otexstream & os, OutputParams const & rp) const
 		if (getLocalOrDefaultLang(rp)->lang() == "arabic_arabi"
 		    || getLocalOrDefaultLang(rp)->lang() == "farsi")
 			lswitch = "\\textLR{";
+		else if (getLocalOrDefaultLang(rp)->lang() == "hebrew"
+			 && LaTeXFeatures::isAvailableAtLeastFrom("babel-hebrew", 2026, 2, 16))
+			// avoids a conflict with hyperref (#5927)
+			lswitch = "\\LRE{";
 	}
 
 	if (sc_.need_protect && rp.moving_arg)
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index b92bf036df..2e571df1ce 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -19,6 +19,7 @@
 #include "Font.h"
 #include "InsetList.h"
 #include "Language.h"
+#include "LaTeXFeatures.h"
 #include "LyXRC.h"
 #include "OutputParams.h"
 #include "Paragraph.h"
@@ -1123,10 +1124,19 @@ void TeXOnePar(Buffer const & buf,
 				else if (outer_language->lang() == "arabic_arabi")
 					os << "\\textLR{";
 				// remaining RTL languages currently is hebrew
-				else if (par_language->rightToLeft() && !runparams.isFullUnicode())
-					os << "\\R{";
-				else
-					os << "\\L{";
+				else if (par_language->rightToLeft() && !runparams.isFullUnicode()) {
+					if (LaTeXFeatures::isAvailableAtLeastFrom("babel-hebrew", 2026, 2, 16))
+						// avoids a conflict with hyperref (#5927)
+						os << "\\RLE{";
+					else
+						os << "\\R{";
+				} else {
+					if (LaTeXFeatures::isAvailableAtLeastFrom("babel-hebrew", 2026, 2, 16))
+						// avoids a conflict with hyperref (#5927)
+						os << "\\LRE{";
+					else
+						os << "\\L{";
+				}
 				++state->LR_switch_;
 			}
 			// With CJK, the CJK tag has to be closed first (see below)
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs