diff options
author | Karl Berry <karl@freefriends.org> | 2022-02-13 21:27:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-02-13 21:27:08 +0000 |
commit | 24041c1e41a3999c280f7b0139c5ab5117d71330 (patch) | |
tree | 10ee1b5e78446349c3232d09e96fdca64723c1b0 /Master/texmf-dist/tex/generic/babel/luababel.def | |
parent | fd51a477ec609d23958713e57fbeffc026afdaaf (diff) |
babel (13feb22)
git-svn-id: svn://tug.org/texlive/trunk@62007 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/babel/luababel.def')
-rw-r--r-- | Master/texmf-dist/tex/generic/babel/luababel.def | 207 |
1 files changed, 124 insertions, 83 deletions
diff --git a/Master/texmf-dist/tex/generic/babel/luababel.def b/Master/texmf-dist/tex/generic/babel/luababel.def index 41137096197..1405e5710ba 100644 --- a/Master/texmf-dist/tex/generic/babel/luababel.def +++ b/Master/texmf-dist/tex/generic/babel/luababel.def @@ -248,6 +248,30 @@ end lang.patterns(lg, pats) end + function Babel.hlist_has_bidi(head) + local has_bidi = false + for item in node.traverse(head) do + if item.id == node.id'glyph' then + local itemchar = item.char + local chardata = Babel.characters[itemchar] + local dir = chardata and chardata.d or nil + if not dir then + for nn, et in ipairs(Babel.ranges) do + if itemchar < et[1] then + break + elseif itemchar <= et[2] then + dir = et[3] + break + end + end + end + if dir and (dir == 'al' or dir == 'r') then + has_bidi = true + end + end + end + return has_bidi + end } \endgroup \ifx\newattribute\@undefined\else @@ -1310,9 +1334,11 @@ end #2 TRT\relax \fi \fi} +\def\bbl@thedir{0} \def\bbl@textdir#1{% \bbl@setluadir{text}\textdir{#1}% \chardef\bbl@thetextdir#1\relax + \edef\bbl@thedir{\the\numexpr\bbl@thepardir*3+#1}% \setattribute\bbl@attr@dir{\numexpr\bbl@thepardir*3+#1}} \def\bbl@pardir#1{% \bbl@setluadir{par}\pardir{#1}% @@ -1321,6 +1347,7 @@ end \def\bbl@pagedir{\bbl@setluadir{page}\pagedir} \def\bbl@dirparastext{\pardir\the\textdir\relax}% %%%% \ifnum\bbl@bidimode>\z@ + \def\bbl@insidemath{0}% \def\bbl@mathboxdir{% \ifcase\bbl@thetextdir\relax \everyhbox{\bbl@mathboxdir@aux L}% @@ -1329,16 +1356,37 @@ end \fi} \def\bbl@mathboxdir@aux#1{% \@ifnextchar\egroup{}{\textdir T#1T\relax}} + \def\bbl@everymath{\def\bbl@insidemath{1}} + \def\bbl@everydisplay{% + \bbl@mathboxdir + \def\bbl@everymath{\bbl@mathboxdir}% + \def\bbl@insidemath{2}} \frozen@everymath\expandafter{% - \expandafter\bbl@mathboxdir\the\frozen@everymath} + \expandafter\bbl@everymath\the\frozen@everymath} \frozen@everydisplay\expandafter{% - \expandafter\bbl@mathboxdir\the\frozen@everydisplay} + \expandafter\bbl@everydisplay\the\frozen@everydisplay} + \AtBeginDocument{ + \directlua{ + function Babel.math_box_dir(head) + if not (token.get_macro('bbl@insidemath') == '0') then + if Babel.hlist_has_bidi(head) then + 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@thedir')) + end + end + end + return head + end + luatexbase.add_to_callback("hpack_filter", Babel.math_box_dir, + "Babel.math_box_dir", 0) + }}% \fi -\def\bbl@truellap{%s - \ifcase\bbl@attr@dir\expandafter\llap\else\expandafter\rlap\fi} -\def\bbl@truerlap{% - \ifcase\bbl@attr@dir\expandafter\rlap\else\expandafter\llap\fi} \bbl@trace{Redefinitions for bidi layout} +\def\BabelNoAMSMath{\let\bbl@noamsmath\relax} \ifnum\bbl@bidimode>\z@ \let\bbl@eqnodir\relax \AtBeginDocument{% @@ -1359,71 +1407,81 @@ end \bbl@xin@{,leqno,}{,\@classoptionslist,}% \ifin@ \def\@eqnnum{% - \setbox\z@\hbox{\normalfont\normalcolor(\theequation)}% - \hbox to0.01pt{\hss\hbox to\displaywidth{\box\z@\hss}}}% + \setbox\z@\hbox{\normalfont\normalcolor(\theequation)}% + \hbox to0.01pt{\hss\hbox to\displaywidth{\box\z@\hss}}}% \fi \else % amstex - \bbl@sreplace\intertext@{\normalbaselines}% - {\normalbaselines - \ifx\bbl@eqnodir\relax\else\bbl@pardir\@ne\bbl@textdir\@ne\fi} - \def\bbl@ams@tagbox#1#2{#1{\bbl@eqnodir#2}}% #1=\hbox|ams@lap - \def\bbl@ams@eqtagbox#1{% - \setbox\z@\hbox{\bbl@eqnodir#1}% - \hbox to\wd\z@{% - \ifx\bbl@ams@lap\hbox - \hss\hbox to\displaywidth{\box\z@\hss}% - \else - \hbox to\displaywidth{\hss\box\z@}\hss - \fi}} - \def\bbl@ams@preset#1{% - \ifnum\bbl@thetextdir>\z@ - \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}% - \chardef\bbl@thetextdir\z@ - \bbl@sreplace\textdef@{\hbox}{\bbl@ams@tagbox\hbox}% - \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@tagbox#1}% - \fi} - \@ifpackagewith{amsmath}{leqno}% - {\let\bbl@ams@lap\hbox}% = leqno - {\let\bbl@ams@lap\llap}% = default - % Not required?: split, alignat - \AddToHook{env/cases/begin}{\bbl@ams@preset\bbl@ams@lap}% - \AddToHook{env/multline/begin}{\bbl@ams@preset\hbox}% - \AddToHook{env/gather/begin}{\bbl@ams@preset\bbl@ams@lap}% - \AddToHook{env/gather*/begin}{\bbl@ams@preset\bbl@ams@lap}% - \AddToHook{env/align/begin}{\bbl@ams@preset\bbl@ams@lap}% - \AddToHook{env/align*/begin}{\bbl@ams@preset\bbl@ams@lap}% - % Hackish, for proper alignment-don’t ask me why it works! :-) - \bbl@exp{% - \\\AddToHook{env/align*/end}{\<iftag@>\<else>\\\tag*{}\<fi>}}% - \AddToHook{env/flalign/begin}{\bbl@ams@preset\hbox}% - \AddToHook{env/split/before}{% - \def\bbl@tempa{equation}% - \ifx\@currenvir\bbl@tempa - \def\bbl@ams@eqtagbox#1{% - \setbox\z@\hbox{\bbl@eqnodir#1}% - \hbox to\wd\z@{\box\z@}}% - \fi} - \AddToHook{env/equation/begin}{% - \bbl@add\ignorespacesafterend{\hrule\@height\z@}% - \ifnum\bbl@thetextdir>\z@ - \ifx\bbl@ams@lap\llap\hrule\@height\z@\fi - \def\bbl@eqnodir{\bbl@textdir\@ne}% - \bbl@textdir\z@ - \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@eqtagbox}% - \fi}% - \AddToHook{env/equation*/begin}{% - \bbl@add\ignorespacesafterend{\hrule\@height\z@}% - \ifnum\bbl@thetextdir>\z@ - \def\bbl@eqnodir{\bbl@textdir\@ne}% - \bbl@textdir\z@ - \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@eqtagbox}% - \fi}% + \ifx\bbl@noamsmath\@undefined + \edef\bbl@tempa{% + \catcode58=\the\catcode58\relax + \catcode95=\the\catcode95\relax}% + \catcode58=11 + \catcode95=11 + \bbl@sreplace\intertext@{\normalbaselines}% + {\normalbaselines + \ifx\bbl@eqnodir\relax\else\bbl@pardir\@ne\bbl@eqnodir\fi}% + \bbl@tempa + \def\bbl@ams@tagbox#1#2{#1{\bbl@eqnodir#2}}% #1=\hbox|ams@lap + \def\bbl@ams@eqtagbox#1{% + \setbox\z@\hbox{\bbl@eqnodir#1}% + \hbox to 0.01pt{% + \ifx\bbl@ams@lap\hbox + \hbox to\displaywidth{\hss\box\z@}\hss + \else + \hss\hbox to\displaywidth{\box\z@\hss}% + \fi}} + \def\bbl@ams@preset#1{% + \ifnum\bbl@thetextdir>\z@ + \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}% + \chardef\bbl@thetextdir\z@ + \bbl@sreplace\textdef@{\hbox}{\bbl@ams@tagbox\hbox}% + \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@tagbox#1}% + \fi} + \@ifpackagewith{amsmath}{leqno}% + {\let\bbl@ams@lap\hbox}% = leqno + {\let\bbl@ams@lap\llap}% = default + % + \AddToHook{env/cases/begin}{\bbl@ams@preset\bbl@ams@lap}% + \AddToHook{env/multline/begin}{\bbl@ams@preset\hbox}% + \AddToHook{env/gather/begin}{\bbl@ams@preset\bbl@ams@lap}% + \AddToHook{env/gather*/begin}{\bbl@ams@preset\bbl@ams@lap}% + \AddToHook{env/align/begin}{\bbl@ams@preset\bbl@ams@lap}% + \AddToHook{env/align*/begin}{\bbl@ams@preset\bbl@ams@lap}% + % Hackish, for proper alignment-don’t ask me why it works! :-) + \bbl@exp{% + \\\AddToHook{env/align*/end}{\<iftag@>\<else>\\\tag*{}\<fi>}}% + \AddToHook{env/flalign/begin}{\bbl@ams@preset\hbox}% + \AddToHook{env/split/before}{% + \ifnum\bbl@thetextdir>\z@ + \def\bbl@tempa{equation}% + \ifx\@currenvir\bbl@tempa + \def\bbl@ams@eqtagbox#1{% + \ifx\bbl@ams@lap\hbox + \hbox to0.01pt{\hss\bbl@eqnodir#1}% leqno + \else + \hbox to0.01pt{\bbl@eqnodir#1\hss}% eqno + \fi} + \fi + \fi} + \AddToHook{env/equation/begin}{% + \ifnum\bbl@thetextdir>\z@ + \ifx\bbl@ams@lap\llap\hrule\@height\z@\fi + \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}% + \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@eqtagbox}% + \fi}% + \AddToHook{env/equation*/begin}{% + \ifnum\bbl@thetextdir>\z@ + \edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}% + \bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@eqtagbox}% + \fi}% + \fi \fi} \fi \ifx\bbl@opt@layout\@nnil\endinput\fi % if no layout \ifnum\bbl@bidimode>\z@ \def\bbl@nextfake#1{% non-local changes, use always inside a group! \bbl@exp{% + \def\\\bbl@insidemath{0}% \mathdir\the\bodydir #1% Once entered in math, set boxes to restore values \<ifmmode>% @@ -1486,28 +1544,11 @@ end \directlua{ Babel.get_picture_dir = true Babel.picture_has_bidi = 0 + % function Babel.picture_dir (head) if not Babel.get_picture_dir then return head end - for item in node.traverse(head) do - if item.id == node.id'glyph' then - local itemchar = item.char - % TODO. Copypaste pattern from Babel.bidi (-r) - local chardata = Babel.characters[itemchar] - local dir = chardata and chardata.d or nil - if not dir then - for nn, et in ipairs(Babel.ranges) do - if itemchar < et[1] then - break - elseif itemchar <= et[2] then - dir = et[3] - break - end - end - end - if dir and (dir == 'al' or dir == 'r') then - Babel.picture_has_bidi = 1 - end - end + if Babel.hlist_has_bidi(head) then + Babel.picture_has_bidi = 1 end return head end |