summaryrefslogtreecommitdiff
path: root/tex/context/base/math-dir.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/math-dir.lua')
-rw-r--r--tex/context/base/math-dir.lua48
1 files changed, 36 insertions, 12 deletions
diff --git a/tex/context/base/math-dir.lua b/tex/context/base/math-dir.lua
index 507a24e41..0f871beed 100644
--- a/tex/context/base/math-dir.lua
+++ b/tex/context/base/math-dir.lua
@@ -23,8 +23,19 @@ local trace_directions = false trackers.register("typesetters.directions.math
local report_directions = logs.reporter("typesetting","math directions")
-local insert_node_before = nodes.insert_before
-local insert_node_after = nodes.insert_after
+local nuts = nodes.nuts
+local tonut = nuts.tonut
+local tonode = nuts.tonode
+
+local getnext = nuts.getnext
+local getchar = nuts.getchar
+local getid = nuts.getid
+local getlist = nuts.getlist
+local setfield = nuts.setfield
+local getattr = nuts.getattr
+
+local insert_node_before = nuts.insert_before
+local insert_node_after = nuts.insert_after
local nodecodes = nodes.nodecodes
local tasks = nodes.tasks
@@ -33,7 +44,7 @@ local glyph_code = nodecodes.glyph
local hlist_code = nodecodes.hlist
local vlist_code = nodecodes.vlist
-local nodepool = nodes.pool
+local nodepool = nuts.pool
local new_textdir = nodepool.textdir
@@ -61,9 +72,9 @@ local function processmath(head)
stop = nil
end
while current do
- local id = current.id
+ local id = getid(current)
if id == glyph_code then
- local char = current.char
+ local char = getchar(current)
local cdir = chardirections[char]
if cdir == "en" or cdir == "an" then -- we could check for mathclass punctuation
if not start then
@@ -83,7 +94,7 @@ local function processmath(head)
if mirror then
local class = charclasses[char]
if class == "open" or class == "close" then
- current.char = mirror
+ setfield(current,"char",mirror)
if trace_directions then
report_directions("mirrored: %C to %C",char,mirror)
end
@@ -94,6 +105,13 @@ local function processmath(head)
end
elseif not start then
-- nothing
+if id == hlist_code or id == vlist_code then
+ local list, d = processmath(getlist(current))
+ setfield(current,"list",list)
+ if d then
+ done = true
+ end
+end
elseif start == stop then
start = nil
else
@@ -101,14 +119,14 @@ local function processmath(head)
-- math can pack things into hlists .. we need to make sure we don't process
-- too often: needs checking
if id == hlist_code or id == vlist_code then
- local list, d = processmath(current.list)
- current.list = list
+ local list, d = processmath(getlist(current))
+ setfield(current,"list",list)
if d then
done = true
end
end
end
- current = current.next
+ current = getnext(current)
end
if not start then
-- nothing
@@ -124,9 +142,11 @@ local enabled = false
function directions.processmath(head) -- style, penalties
if enabled then
- local a = head[a_mathbidi]
+ local h = tonut(head)
+ local a = getattr(h,a_mathbidi)
if a and a > 0 then
- return processmath(head)
+ local head, done = processmath(h)
+ return tonode(head), done
end
end
return head, false
@@ -142,4 +162,8 @@ function directions.setmath(n)
end
end
-commands.setmathdirection = directions.setmath
+interfaces.implement {
+ name = "setmathdirection",
+ actions = directions.setmath,
+ arguments = "integer"
+}