summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua')
-rw-r--r--Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua25
1 files changed, 21 insertions, 4 deletions
diff --git a/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua b/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua
index 8fe47ecb80f..be342c12fe5 100644
--- a/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua
+++ b/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua
@@ -91,8 +91,11 @@ local function insert_numeric(head, state)
return head, new_state
end
--- \hbox with an explicit dir can lead to wrong results
--- <R \hbox dir TLT{<R>}> and <L \hbox dir TRT{<L>}>
+-- TODO - \hbox with an explicit dir can lead to wrong results
+-- <R \hbox dir TLT{<R>}> and <L \hbox dir TRT{<L>}>. A small attempt
+-- was s made to improve the situation, but the problem is the 3-dir
+-- model in babel/Unicode and the 2-dir model in LuaTeX don't fit
+-- well.
function Babel.bidi(head, ispar, hdir)
local d -- d is used mainly for computations in a loop
@@ -101,6 +104,7 @@ function Babel.bidi(head, ispar, hdir)
local nodes = {}
local outer_first = nil
+ local inmath = false
local glue_d = nil
local glue_i = nil
@@ -119,9 +123,14 @@ function Babel.bidi(head, ispar, hdir)
(temp == 2 and 'al')
elseif ispar then -- Or error? Shouldn't happen
save_outer = ('TRT' == tex.pardir) and 'r' or 'l'
- else
+ else -- Or error? Shouldn't happen
save_outer = ('TRT' == hdir) and 'r' or 'l'
end
+ -- when the callback is called, we are just _after_ the box,
+ -- and the textdir is that of the surrounding text
+ -- if not ispar and hdir ~= tex.textdir then
+ -- save_outer = ('TRT' == hdir) and 'r' or 'l'
+ -- end
local outer = save_outer
local last = outer
-- 'al' is only taken into account in the first, current loop
@@ -160,6 +169,7 @@ function Babel.bidi(head, ispar, hdir)
end
end
d = d or 'l'
+ if inmath then d = ('TRT' == tex.mathdir) and 'r' or 'l' end
d_font = d_font or d
d_font = (d_font == 'l' and 0) or
@@ -208,6 +218,9 @@ function Babel.bidi(head, ispar, hdir)
glue_i = item
d = nil
+ elseif item.id == node.id'math' then
+ inmath = (item.subtype == 0)
+
else
d = nil
end
@@ -371,7 +384,11 @@ function Babel.bidi(head, ispar, hdir)
end
else
if d == 'an' or d == 'l' then
- state.sim = state.sim or item
+ if nodes[q][3] then -- nil except after an explicit dir
+ state.sim = item -- so we move sim 'inside' the group
+ else
+ state.sim = state.sim or item
+ end
state.eim = item
elseif d == 'r' and state.sim then
head, state = insert_implicit(head, state, outer)