[latex3-commits] [git/LaTeX3-latex3-babel] main: Revised tabular in ‘mixed’ l-r mode. New: layout=notabular (93a996f)

Javier email at dante.de
Sun Jan 29 09:52:04 CET 2023


Repository : https://github.com/latex3/babel
On branch  : main
Link       : https://github.com/latex3/babel/commit/93a996f1ebd3e5509667b4934242184bcfbb303e

>---------------------------------------------------------------

commit 93a996f1ebd3e5509667b4934242184bcfbb303e
Author: Javier <email at localhost>
Date:   Sun Jan 29 09:52:04 2023 +0100

    Revised tabular in ‘mixed’ l-r mode. New: layout=notabular


>---------------------------------------------------------------

93a996f1ebd3e5509667b4934242184bcfbb303e
 README.md              |   8 ++-
 babel.dtx              | 170 ++++++++++++++++++++++++++++++++-----------------
 babel.ins              |   2 +-
 babel.pdf              | Bin 917543 -> 920333 bytes
 bbcompat.dtx           |   2 +-
 samples/lua-arabic.pdf | Bin 115514 -> 115515 bytes
 6 files changed, 118 insertions(+), 64 deletions(-)

diff --git a/README.md b/README.md
index ccb3cdd..0c6ef62 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-## Babel 3.85
+## Babel 3.85.2997
 
-2023-01-23
+(Draft)
 
 This package manages culturally-determined typographical (and other)
 rules, and hyphenation patterns for a wide range of languages. Many
@@ -48,6 +48,10 @@ respective authors.
 
 ### Summary of latest changes
 ```
+3.86  (dev)
+      * Revised `tabular` with ‘mixed’ directions. New option
+        `layout=notabular`.
+
 3.85  2023-01-23
       * A high-level interface to enable and disable transforms (lua).
       * Font-dependent transforms (lua).
diff --git a/babel.dtx b/babel.dtx
index dc01255..0e72ad9 100644
--- a/babel.dtx
+++ b/babel.dtx
@@ -32,7 +32,7 @@
 %
 % \iffalse
 %<*filedriver>
-\ProvidesFile{babel.dtx}[2022/01/23 v3.85 The Babel package]
+\ProvidesFile{babel.dtx}[2023/01/29 v3.85.2997 The Babel package]
 \documentclass{ltxdoc}
 \GetFileInfo{babel.dtx}
 \usepackage{fontspec}
@@ -5286,8 +5286,8 @@ help from Bernd Raichle, for which I am grateful.
 % \section{Tools}
 %
 %    \begin{macrocode}
-%<<version=3.85>>
-%<<date=2022/01/23>>
+%<<version=3.85.2997>>
+%<<date=2023/01/29>>
 %    \end{macrocode}
 %
 % \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -12203,7 +12203,7 @@ help from Bernd Raichle, for which I am grateful.
 \def\bbl at setdirs#1{% TODO - math
   \ifcase\bbl at select@type % TODO - strictly, not the right test
     \bbl at bodydir{#1}%
-    \bbl at pardir{#1}%
+    \bbl at pardir{#1}% <- Must precede \bbl at textdir
   \fi
   \bbl at textdir{#1}}
 % TODO. Only if \bbl at bidimode > 0?:
@@ -14859,11 +14859,11 @@ end
 %
 % The basic setup. The output is modified at a very low level to set
 % the |\bodydir| to the |\pagedir|. Sadly, we have to deal with boxes
-% in math with basic, so the |\bbl at mathboxdir| hack is activated every
-% math with the package option bidi=.
+% in math with |basic|, so hacks must be activated always with the
+% package option |bidi=|.
 %
 %    \begin{macrocode}
-\ifnum\bbl at bidimode>100 \ifnum\bbl at bidimode<200
+\ifnum\bbl at bidimode>\@ne % Excludes default=1
   \let\bbl at beforeforeign\leavevmode
   \AtEndOfPackage{\EnableBabelHook{babel-bidi}}
   \RequirePackage{luatexbase}
@@ -14875,13 +14875,10 @@ end
     \or
       require('babel-bidi-basic-r.lua')
     \fi}
-  % TODO - to locale_props, not as separate attribute
   \newattribute\bbl at attr@dir
   \directlua{ Babel.attr_dir = luatexbase.registernumber'bbl at attr@dir' }
-  % TODO. I don't like it, hackish:
   \bbl at exp{\output{\bodydir\pagedir\the\output}}
-  \AtEndOfPackage{\EnableBabelHook{babel-bidi}}
-\fi\fi
+\fi
 \chardef\bbl at thetextdir\z@
 \chardef\bbl at thepardir\z@
 \def\bbl at getluadir#1{%
@@ -14901,59 +14898,71 @@ end
       #2 TRT\relax
     \fi
   \fi}
+% ..00PPTT, with masks 0xC (par dir) and 0x3 (text dir)
 \def\bbl at thedir{0}
 \def\bbl at textdir#1{%
   \bbl at setluadir{text}\textdir{#1}%
   \chardef\bbl at thetextdir#1\relax
-  % par/text 0..8 = l/l l/r l/al r/l r/r r/al al/l al/r al/al
-  \edef\bbl at thedir{\the\numexpr\bbl at thepardir*3+#1}%
-  \setattribute\bbl at attr@dir{\numexpr\bbl at thepardir*3+#1}}
-\def\bbl at pardir#1{%
+  \edef\bbl at thedir{\the\numexpr\bbl at thepardir*4+#1}%
+  \setattribute\bbl at attr@dir{\numexpr\bbl at thepardir*4+#1}}
+\def\bbl at pardir#1{%  Used twice
   \bbl at setluadir{par}\pardir{#1}%
   \chardef\bbl at thepardir#1\relax}
-\def\bbl at bodydir{\bbl at setluadir{body}\bodydir}
-\def\bbl at pagedir{\bbl at setluadir{page}\pagedir}
-\def\bbl at dirparastext{\pardir\the\textdir\relax}%   %%%%
-%
-\ifnum\bbl at bidimode>\z@
+\def\bbl at bodydir{\bbl at setluadir{body}\bodydir}%   Used once
+\def\bbl at pagedir{\bbl at setluadir{page}\pagedir}%   Unused
+\def\bbl at dirparastext{\pardir\the\textdir\relax}% Used once
+%    \end{macrocode}
+%
+% In some cases, direction in |\hbox|es are set at the `lua` level,
+% namely, in math mode and in |\halign|. The latter is particularly
+% difficult to deal with in a general way if the direction of columns
+% is diferent to the text one, because they both are governed by
+% |\textdir|. Since \babel{} stores the direction in a macro and at each
+% node, we can recover and apply it. (Note an explicit direction at the
+% beginning of |\halign| applies only to the first column.)
+% |Babel.hlist_dir| is executed before the bidi algorithm, so that
+% the inserted ‘dir’ nodes look much like an explicit |\textdir|.
+% 
+%    \begin{macrocode}
+\ifnum\bbl at bidimode>\z@ % Includes default=1
+  \let\bbl at parabefore\relax
+  \AddToHook{para/before}{\bbl at parabefore}%
+  \global\let\bbl at thenextmath\relax
   \def\bbl at insidemath{0}%
-  \def\bbl at mathboxdir{%
-    \ifcase\bbl at thetextdir\relax
-      \everyhbox{\bbl at mathboxdir@aux L}%
-    \else
-      \everyhbox{\bbl at mathboxdir@aux R}%
-     \fi}
-  \def\bbl at mathboxdir@aux#1{%
-    \@ifnextchar\egroup{}{\textdir T#1T\relax}}
-  \def\bbl at everymath{\bbl at mathboxdir}
-  \def\bbl at everydisplay{%
-    \bbl at mathboxdir
-    \def\bbl at everymath{\bbl at mathboxdir}}
+  \def\bbl at everymath{%
+    \def\bbl at insidemath{1}%
+    \bbl at thenextmath}
+  \def\bbl at everydisplay{\def\bbl at insidemath{2}}
   \frozen at everymath\expandafter{%
     \expandafter\bbl at everymath\the\frozen at everymath}
   \frozen at everydisplay\expandafter{%
     \expandafter\bbl at everydisplay\the\frozen at everydisplay}
   \AtBeginDocument{
     \directlua{
-      Babel.use_math_box_dir = true
-      function Babel.math_box_dir(head)
-        if Babel.use_math_box_dir then
-          if not (token.get_macro('bbl at insidemath') == '0') then
-            if Babel.hlist_has_bidi(head) then
+      function Babel.hlist_dir(head)
+        local hlistmode = token.get_macro('bbl at insidemath')
+        if hlistmode == '0' then
+          return head
+        elseif hlistmode == '1' or hlistmode == '2' then % 1=math, 2=display
+          if Babel.hlist_has_bidi(head) then
+            local d = node.new(node.id'dir')
+            d.dir = '+TRT'
+            head = node.insert_before(head, head, d)
+          end
+        else % \halign with lr columns. Ignore tabskip boxes.
+          if head and not (head.id==12 and head.subtype==12) then
+            if node.get_attribute(head, Babel.attr_dir) & 0x3
+                \string~= 0 then % ie, 1 2 4 5 7 8
               local d = node.new(node.id'dir')
               d.dir = '+TRT'
-              node.insert_before(head, node.has_glyph(head), d)
-              for item in node.traverse(head) do
-                node.set_attribute(item,
-                  Babel.attr_dir, token.get_macro('bbl at thedir'))
-              end
+              head = node.insert_before(head, head, d)
             end
           end
         end
         return head
       end
-      luatexbase.add_to_callback("hpack_filter", Babel.math_box_dir,
-        "Babel.math_box_dir", 0)
+      luatexbase.add_to_callback("hpack_filter", Babel.hlist_dir,
+        "Babel.hlist_dir", 0)
   }}%
 \fi
 %    \end{macrocode}
@@ -15022,7 +15031,6 @@ end
     \ifx\maketag@@@\@undefined % Normal equation, eqnarray
       \AddToHook{env/equation/begin}{%
         \ifnum\bbl at thetextdir>\z@
-          \def\bbl at mathboxdir{\def\bbl at insidemath{1}}%
           \let\@eqnnum\bbl at eqnum
           \edef\bbl at eqnodir{\noexpand\bbl at textdir{\the\bbl at thetextdir}}%
           \chardef\bbl at thetextdir\z@
@@ -15038,8 +15046,6 @@ end
       \fi
       \AddToHook{env/eqnarray/begin}{%
         \ifnum\bbl at thetextdir>\z@
-          \def\bbl at mathboxdir{\def\bbl at insidemath{1}}
-          \def\bbl at mathboxdir{\def\bbl at insidemath{1}}%
           \edef\bbl at eqnodir{\noexpand\bbl at textdir{\the\bbl at thetextdir}}%
           \chardef\bbl at thetextdir\z@
           \bbl at add\normalfont{\bbl at eqnodir}%
@@ -15174,8 +15180,55 @@ end
     \csname bbl at inidata@\languagename\endcsname
     \bbl at release@transforms\relax % \relax closes the last item.
   \fi}
+%    \end{macrocode}
+%
+% The following comes before the test for the existence of |layout|,
+% because the default behavior is modified, too. Note |notabular|
+% (below) modifies |\bbl at nextfake@lr|.
+%
+%    \begin{macrocode}
+\IfBabelLayout{tabular}
+  {\let\bbl at OL@@tabular\@tabular
+   \bbl at replace\@tabular{$}{\bbl at nextfake$}%
+   \let\bbl at NL@@tabular\@tabular
+   \AtBeginDocument{%
+     \ifx\bbl at NL@@tabular\@tabular\else
+       \bbl at replace\@tabular{$}{\bbl at nextfake$}%
+       \let\bbl at NL@@tabular\@tabular
+     \fi}}
+  {}
+\ifx\bbl at OL@@tabular\@undefined % Default
+  \ifx\@tabular\@undefined\else
+    \def\bbl at nextfake@lr#1{%
+      #1% 
+      \ifnum\bbl at thetextdir>\z@
+        \edef\bbl at insidemath{3}% 
+        \def\bbl at parabefore{\bodydir TRT \pardir TRT \textdir TRT}%
+      \else
+        \edef\bbl at insidemath{0}%
+        \let\bbl at parabefore\relax
+      \fi}%
+    \let\bbl at OL@@tabular\@tabular
+    \bbl at replace\@tabular{$}{\bbl at nextfake@lr$}%
+    \let\bbl at NL@@tabular\@tabular
+    \AtBeginDocument{%
+      \ifx\bbl at NL@@tabular\@tabular\else
+        \bbl at replace\@tabular{$}{\bbl at nextfake@lr$}%
+        \let\bbl at NL@@tabular\@tabular
+      \fi}
+  \fi
+\fi
 \ifx\bbl at opt@layout\@nnil\endinput\fi  % if no layout
+%    \end{macrocode}
+%
+% \textsc{Omega} provided a companion to |\mathdir| (|\nextfakemath|)
+% for those cases where we did not want it to be applied, so that the
+% writing direction of the main text was left unchanged. |\bbl at nextfake|
+% is an attempt to emulate it, because \luatex{} has removed it. Also,
+% |\parshape| does not honour |\parshape| by default, so we need to
+% redefine |\@hangfrom|.
 %    
+%    \begin{macrocode}
 \ifnum\bbl at bidimode>\z@
   \def\bbl at nextfake#1{%  non-local changes, use always inside a group!
     \bbl at exp{%
@@ -15204,16 +15257,13 @@ end
     \fi
     \noindent\box\@tempboxa}
 \fi
-\IfBabelLayout{tabular}
-  {\let\bbl at OL@@tabular\@tabular
-   \bbl at replace\@tabular{$}{\bbl at nextfake$}%
-   \let\bbl at NL@@tabular\@tabular
-   \AtBeginDocument{%
-     \ifx\bbl at NL@@tabular\@tabular\else
-       \bbl at replace\@tabular{$}{\bbl at nextfake$}%
-       \let\bbl at NL@@tabular\@tabular
+\IfBabelLayout{notabular}
+  {\def\bbl at nextfake@lr#1{%
+     #1% 
+     \ifnum\bbl at thetextdir>\z@
+       \edef\bbl at insidemath{0}%
      \fi}}
-   {}
+  {}
 \IfBabelLayout{lists}
   {\let\bbl at OL@list\list
    \bbl at sreplace\list{\parshape}{\bbl at listparshape}%
@@ -22113,7 +22163,7 @@ function Babel.bidi(head, ispar)
         attr_dir = 0
         for at in node.traverse(item.attr) do
           if at.number == Babel.attr_dir then
-            attr_dir = at.value % 3
+            attr_dir = at.value & 0x3
           end
         end
         if attr_dir == 1 then
@@ -22373,7 +22423,7 @@ function Babel.bidi(head, ispar, hdir)
   local save_outer
   local temp = node.get_attribute(head, ATDIR)
   if temp then
-    temp = temp % 3
+    temp = temp & 0x3
     save_outer = (temp == 0 and 'l') or
                  (temp == 1 and 'r') or
                  (temp == 2 and 'al')
@@ -22443,7 +22493,7 @@ function Babel.bidi(head, ispar, hdir)
           attr_d = 0
         else
           attr_d = node.get_attribute(item, ATDIR)
-          attr_d = attr_d % 3
+          attr_d = attr_d & 0x3
         end
         if attr_d == 1 then
           outer_first = 'r'
@@ -22471,7 +22521,7 @@ function Babel.bidi(head, ispar, hdir)
 
     elseif item.id == DIR then
       d = nil
-      -- new_d = true
+
       if head ~= item then new_d = true end
 
     elseif item.id == node.id'glue' and item.subtype == 13 then
diff --git a/babel.ins b/babel.ins
index fbea84e..a7c4f81 100644
--- a/babel.ins
+++ b/babel.ins
@@ -26,7 +26,7 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %%
-\def\filedate{2022/01/23}
+\def\filedate{2023/01/29}
 \def\batchfile{babel.ins}
 \input docstrip.tex
 
diff --git a/babel.pdf b/babel.pdf
index ce98f96..5754e90 100644
Binary files a/babel.pdf and b/babel.pdf differ
diff --git a/bbcompat.dtx b/bbcompat.dtx
index eb860ed..aa5ecdf 100644
--- a/bbcompat.dtx
+++ b/bbcompat.dtx
@@ -30,7 +30,7 @@
 %
 % \iffalse
 %<*dtx>
-\ProvidesFile{bbcompat.dtx}[2022/01/23 v3.85]
+\ProvidesFile{bbcompat.dtx}[2023/01/29 v3.85.2997]
 %</dtx>
 %
 %% File 'bbcompat.dtx'
diff --git a/samples/lua-arabic.pdf b/samples/lua-arabic.pdf
index 9222676..40d493e 100644
Binary files a/samples/lua-arabic.pdf and b/samples/lua-arabic.pdf differ





More information about the latex3-commits mailing list.