summaryrefslogtreecommitdiff
path: root/macros/latex/required/babel/base/babel.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/required/babel/base/babel.dtx')
-rw-r--r--macros/latex/required/babel/base/babel.dtx389
1 files changed, 205 insertions, 184 deletions
diff --git a/macros/latex/required/babel/base/babel.dtx b/macros/latex/required/babel/base/babel.dtx
index a9b4ad69f9..d5706cdaf1 100644
--- a/macros/latex/required/babel/base/babel.dtx
+++ b/macros/latex/required/babel/base/babel.dtx
@@ -32,7 +32,7 @@
%
% \iffalse
%<*filedriver>
-\ProvidesFile{babel.dtx}[2022/01/26 v3.70 The Babel package]
+\ProvidesFile{babel.dtx}[2022/02/13 v3.71 The Babel package]
\documentclass{ltxdoc}
\GetFileInfo{babel.dtx}
\usepackage{fontspec}
@@ -547,6 +547,7 @@ _\usepackage[vietnamese,danish]{babel}_
\end{note}
\subsection{Mostly monolingual documents}
+\label{mostlymono}
\New{3.39} Very often, multilingual documents consist of a main
language with small pieces of text in another languages (words, idioms,
@@ -1291,6 +1292,11 @@ can take the following values:
\New{3.16} Selects which layout elements are adapted in bidi
documents. See sec.~\ref{bidi}.
+\Describe{provide=}{\texttt{*}}
+\New{3.49} An alternative to |\babelprovide| for languages passed as
+options. See section~\ref{inifiles}, which describes also the variants
+|provide+=| and |provide*=|.
+
\subsection{The \texttt{base} option}
With this package option \babel{} just loads some basic macros (those
@@ -1327,12 +1333,12 @@ be the same as the option name as set in |\usepackage|!).
\end{verbatim}
\end{example}
-% \begin{note}
-% With a recent version of \LaTeX, an alternative method to execute
-% some code just after an |ldf| file is loaded is with |\AddToHook| and
-% the hook |file/after/<language>.ldf|. \Babel{} does not predeclare
-% it, and you have to do it yourself with |\NewHook| or |\ProvideHook|.
-% \end{note}
+\begin{note}
+ With a recent version of \LaTeX, an alternative method to execute
+ some code just after an |ldf| file is loaded is with |\AddToHook| and
+ the hook |file/<language>.ldf/after|. \Babel{} does not predeclare
+ it, and you have to do it yourself with |\ActivateGenericHook|.
+\end{note}
\begin{warning}
Currently this option is not compatible with languages loaded on the
@@ -1344,8 +1350,8 @@ be the same as the option name as set in |\usepackage|!).
An alternative approach to define a language (or, more precisely, a
\textit{locale}) is by means of an \texttt{ini} file. Currently
-\babel{} provides about 200 of these files containing the basic data
-required for a locale.
+\babel{} provides about 250 of these files containing the basic data
+required for a locale, plus basic templates for 500 about locales.
|ini| files are not meant only for \babel, and they has been devised as
a resource for other packages. To easy interoperability between \TeX{}
@@ -1435,11 +1441,12 @@ Or also:
\begin{description}
\itemsep=-\parskip
\item[Arabic] Monolingual documents mostly work in \luatex, but it must
- be fine tuned, particularly graphical elements like |picture|. In \xetex{}
- \babel{} resorts to the \textsf{bidi} package, which seems to work.
+ be fine tuned, particularly math and graphical elements like
+ |picture|. In \xetex{} \babel{} resorts to the \textsf{bidi} package,
+ which seems to work.
\item[Hebrew] Niqqud marks seem to work in both engines, but depending
on the font cantillation marks might be misplaced (\xetex{} or
- \luatex{} with Harfbuzz seems better, but still problematic).
+ \luatex{} with Harfbuzz seems better).
\item[Devanagari] In \luatex{} and the the default renderer many fonts
work, but some others do not, the main issue being the ‘ra’. You may
need to set explicitly the script to either |deva| or |dev2|, eg:
@@ -1451,8 +1458,8 @@ need to set explicitly the script to either |deva| or |dev2|, eg:
also work with \xetex{}, although unlike with \luatex{} fine tuning
the font behavior is not always possible.
\item[Southeast scripts] Thai works in both \luatex{} and \xetex{}, but
- line breaking differs (rules can be modified in \luatex; they are
- hard-coded in \xetex). Lao seems to work, too, but there are no
+ line breaking differs (rules are hard-coded in \xetex, but they can
+ be modified in \luatex). Lao seems to work, too, but there are no
patterns for the latter in \luatex{}. Khemer clusters are rendered
wrongly with the default renderer. The comment about Indic scripts
and \textsf{lualatex} also applies here. Some quick patterns can
@@ -1479,7 +1486,7 @@ need to set explicitly the script to either |deva| or |dev2|, eg:
\item[Latin, Greek, Cyrillic] Combining chars with the default
\luatex{} font renderer might be wrong; on then other hand, with the
Harfbuzz renderer diacritics are stacked correctly, but many
- hyphenations points are discarded (this bug seems related to kerning,
+ hyphenations points are discarded (this bug is related to kerning,
so it depends on the font). With \xetex{} both combining characters
and hyphenation work as expected (not quite, but in most cases it
works; the problem here are font clusters).
@@ -2129,6 +2136,7 @@ zulu
\textbf{Modifying and adding values to |ini| files}
+\nobreak
\New{3.39} There is a way to modify the values of |ini| files when they
get loaded with |\babelprovide| and |import|. To set, say,
|digits.native| in the |numbers| section, use something like
@@ -2573,6 +2581,9 @@ Remerber there is an alternative syntax for the latter:
\begin{verbatim}
\usepackage[italian, polytonicgreek, provide=*]{babel}
\end{verbatim}
+Finally, also remember you might not need to load |italian| at all if
+there are only a few word in this language (see~\ref{mostlymono}).
+
\end{example}
\Describe{script=}{\meta{script-name}}
@@ -2630,7 +2641,10 @@ CJK.
\Describe{intrapenalty=}{\meta{penalty}}
Sets the interword penalty for the writing system of this language.
Currently used only in Southeast Asian scrips, like Thai. Ignored if 0
-(which is the default value).
+(which is the default value).
+
+\Describe{transforms=}{\meta{transform-list}}
+See section~\ref{transforms}.
\Describe{justification=}{\texttt{kashida} $\string|$
\texttt{elongated} $\string|$ \texttt{unhyphenated}}
@@ -2676,10 +2690,10 @@ well dates do not rely on |\arabic|.)
For example:
\begin{verbatim}
-\babelprovide[import]{telugu} % Telugu better with XeTeX
+\babelprovide[import]{telugu}
% Or also, if you want:
% \babelprovide[import, maparabic]{telugu}
-\babelfont{rm}{Gautami}
+\babelfont{rm}{Gautami} % With luatex, better with Harfbuzz
\begin{document}
_\telugudigits{1234}_
_\telugucounter{section}_
@@ -2827,7 +2841,7 @@ with the following command.
{\marg{year}\m{month}\m{day}}}
By default the calendar is the Gregorian, but an |ini| file may define
-strings for other calendars (currently |ar|, |ar-|*, |he|, |fa|, |hi|.)
+strings for other calendars (currently |ar|, |ar-|*, |he|, |fa|, |hi|).
In the latter case, the three arguments are the year, the month, and
the day in those in the corresponding calendar. They are \textit{not}
the Gregorian data to be converted (which means, say, 13 is a valid
@@ -2853,7 +2867,7 @@ current language.
If more than one language is used, it might be necessary to know which
language is active at a specific time. This can be checked by a call
-to |\iflanguage|, but note here ``language'' is used in the \TeX
+to |\iflanguage|, but note here ``language'' is used in the \TeX{}
sense, as a set of hyphenation patterns, and \textit{not} as its
\textsf{babel} name. This macro takes three arguments. The first
argument is the name of a language; the second and third arguments are
@@ -2940,7 +2954,9 @@ identifier, which can be retrieved with |\localeid|.
typically the LGC group, South East Asian, like Thai, and CJK, but
support depends on the engine: \textsf{pdftex} only deals with the
former, \xetex{} also with the second one (although in a limited way),
-while \luatex{} provides basic rules for the latter, too.
+while \luatex{} provides basic rules for the latter, too. With \luatex{}
+there are also tools for non-standard hyphenation rules, explained in
+the next section.
\Describe{\babelhyphen}{%
\colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}\marg{type}}
@@ -3087,6 +3103,7 @@ of the previous char in \luatex, and the font size set by the last
|\selectfont| in \xetex).
\subsection{Transforms}
+\label{transforms}
Transforms (only \luatex) provide a way to process the text on the
typesetting level in several language-dependent ways, like non-standard
@@ -3193,6 +3210,9 @@ Gujarati, Hindi, Kannada, Malayalam, Marathi, Oriya, Tamil, Telugu.}
\trans{Latin}{letters.uv}{Replaces \textit{v}, \textit{U} with
\textit{u}, \textit{V}.}
+\trans{Sanskrit}{transliteration.iast}{The IAST system to
+romanize Devanagari.\footnote{Thanks to Maximilian Mehner}}
+
\trans{Serbian}{transliteration.gajica}{(Note |serbian| with |ini|
files refers to the Cyrillic script, which is here the target.) The
standard system devised by Ljudevit Gaj.}
@@ -3280,7 +3300,7 @@ This feature is activated with the first |\babelposthyphenation| or
\babelprovide[hyphenrules=+]{russian-latin} % Create locale
\babelprehyphenation{russian-latin}{([sz])h} % Create rule
{
- string = {1|sz|šž},
+ string = _{1|sz|šž}_,
remove
}
\end{verbatim}
@@ -3449,15 +3469,16 @@ differ in the way `weak' numeric characters are ordered (eg, Arabic
\begin{warning}
The current code for \textbf{text} in \luatex{} should be considered
- essentially stable, but, of course, it is not bug-free and there
- can be improvements in the future, because setting bidi text has
- many subtleties (see for example <https://www.w3.org/TR/html-bidi/>).
- A basic stable version for other engines must wait. This applies to
+ essentially stable, but, of course, it is not bug-free and there can
+ be improvements in the future, because setting bidi text has many
+ subtleties (see for example <https://www.w3.org/TR/html-bidi/>). A
+ basic stable version for other engines must wait. This applies to
text; there is a basic support for \textbf{graphical} elements,
including the |picture| environment (with \textsf{pict2e}) and
\textsf{pfg/tikz}. Also, indexes and the like are under study, as
- well as math (there is progress in the latter, too, but for
- example |cases| may fail).
+ well as math (there are progresses in the latter, including
+ \textsf{amsmath} and \textsf{mathtools} too, but for example
+ |gathered| may fail).
An effort is being made to avoid incompatibilities in the future
(this one of the reason currently bidi must be explicitly requested
@@ -4156,7 +4177,7 @@ for a small example (|xe-bidi|).
See the code section for |\foreignlanguage*| (a new starred
version of |\foreignlanguage|).
-For old an deprecated functions, see the wiki.
+For old an deprecated functions, see the \babel{} site.
\medskip
\textbf{Options for locales loaded on the fly}
@@ -4173,7 +4194,8 @@ extended numerals in Greek).
\New{3.48} There is some work in progress for \babel{} to deal with
labels, both with the relation to captions (chapters, part), and how
counters are used to define them. It is still somewhat tentative
-because it is far from trivial -- see the wiki for further details.
+because it is far from trivial -- see the \babel{} site for further
+details.
\section{Loading languages with \file{language.dat}}
@@ -4925,50 +4947,6 @@ is true with these two environment selectors.
Its natural place of use is in hooks or in |\extras|\m{language}.
-\section{Changes}
-
-\subsection{Changes in \babel\ version 3.9}
-
-Most of the changes in version 3.9 were related to bugs, either to fix
-them (there were lots), or to provide some alternatives. Even new
-features like |\babelhyphen| are intended to solve a certain problem
-(in this case, the lacking of a uniform syntax and behavior for
-shorthands across languages). These changes, as well as the subsequent
-ones ($\ge$3.10), are described in this manual in the corresponding
-place. A selective list of the changes in 3.9 follows:
-\begin{itemize}
-\item |\select@language| did not set |\languagename|. This meant the
- language in force when auxiliary files were loaded was the one used
- in, for example, shorthands -- if the language was |german|, a
- |\select@language{spanish}| had no effect.
-
-\item |\foreignlanguage| and |otherlanguage*| messed up
- |\extras<language>|. Scripts, encodings and many other things were
- not switched correctly.
-
-\item The |:ENC| mechanism for hyphenation patterns used the encoding
- of the \textit{previous} language, not that of the language being
- selected.
-
-\item |'| (with |activeacute|) had the original value when writing to an
- auxiliary file, and things like an infinite loop can happen. It
- worked incorrectly with |^| (if activated) and also if deactivated.
-
-\item Active chars where not reset at the end of language options, and
- that lead to incompatibilities between languages.
-
-\item |\textormath| raised an error with a conditional.
-
-\item |\aliasshorthand| didn't work (or only in a few and very specific
- cases).
-
-\item |\l@english| was defined incorrectly (using |\let| instead of
- |\chardef|).
-
-\item |ldf| files not bundled with babel were not recognized when
- called as global options.
-\end{itemize}
-
\DocInput{babel.dtx}
\section{Acknowledgements}
@@ -5122,8 +5100,8 @@ help from Bernd Raichle, for which I am grateful.
% \section{Tools}
%
% \begin{macrocode}
-%<<version=3.70>>
-%<<date=2022/01/26>>
+%<<version=3.71>>
+%<<date=2022/02/13>>
% \end{macrocode}
%
% \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -12172,39 +12150,38 @@ help from Bernd Raichle, for which I am grateful.
% the language exists. With class options, check if the option is a
% language by checking if the correspondin file exists.
%
-%
% \begin{macrocode}
\bbl@foreach\bbl@language@opts{%
\def\bbl@tempa{#1}%
\ifx\bbl@tempa\bbl@opt@main\else
- \bbl@ifunset{ds@#1}%
- {\ifnum\bbl@iniflag<\tw@ % 0 ø (other = ldf)
- \DeclareOption{#1}{\bbl@load@language{#1}}%
- \else % + * (other = ini)
- \DeclareOption{#1}{%
- \bbl@ldfinit
- \babelprovide[import]{#1}%
- \bbl@afterldf{}}%
- \fi}%
- {}%
+ \ifnum\bbl@iniflag<\tw@ % 0 ø (other = ldf)
+ \bbl@ifunset{ds@#1}%
+ {\DeclareOption{#1}{\bbl@load@language{#1}}}%
+ {}%
+ \else % + * (other = ini)
+ \DeclareOption{#1}{%
+ \bbl@ldfinit
+ \babelprovide[import]{#1}%
+ \bbl@afterldf{}}%
+ \fi
\fi}
\bbl@foreach\@classoptionslist{%
\def\bbl@tempa{#1}%
\ifx\bbl@tempa\bbl@opt@main\else
- \bbl@ifunset{ds@#1}%
- {\ifnum\bbl@iniflag<\tw@ % 0 ø (other = ldf)
- \IfFileExists{#1.ldf}%
- {\DeclareOption{#1}{\bbl@load@language{#1}}}%
- {}%
- \else % + * (other = ini)
- \IfFileExists{babel-#1.tex}%
- {\DeclareOption{#1}{%
- \bbl@ldfinit
- \babelprovide[import]{#1}%
- \bbl@afterldf{}}}%
- {}%
- \fi}%
- {}%
+ \ifnum\bbl@iniflag<\tw@ % 0 ø (other = ldf)
+ \bbl@ifunset{ds@#1}%
+ {\IfFileExists{#1.ldf}%
+ {\DeclareOption{#1}{\bbl@load@language{#1}}}%
+ {}}%
+ {}%
+ \else % + * (other = ini)
+ \IfFileExists{babel-#1.tex}%
+ {\DeclareOption{#1}{%
+ \bbl@ldfinit
+ \babelprovide[import]{#1}%
+ \bbl@afterldf{}}}%
+ {}%
+ \fi
\fi}
% \end{macrocode}
%
@@ -13484,6 +13461,30 @@ help from Bernd Raichle, for which I am grateful.
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
@@ -14462,9 +14463,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}%
@@ -14474,6 +14477,7 @@ end
\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}%
@@ -14482,15 +14486,35 @@ 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}
% \end{macrocode}
%
% \subsection{Layout}
@@ -14518,8 +14542,12 @@ end
%
% \begin{macrocode}
\bbl@trace{Redefinitions for bidi layout}
+\def\BabelNoAMSMath{\let\bbl@noamsmath\relax}
\ifnum\bbl@bidimode>\z@
\let\bbl@eqnodir\relax
+% \ifx\matheqdirmode\@undefined\else
+% \matheqdirmode\@ne
+% \fi
\AtBeginDocument{%
\ifx\maketag@@@\@undefined % Normal equation, eqnarray
\AddToHook{env/eqnarray/begin}{%
@@ -14538,71 +14566,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>%
@@ -14665,28 +14703,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