summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-05-04 20:52:09 +0000
committerKarl Berry <karl@freefriends.org>2022-05-04 20:52:09 +0000
commit1157390207721a2fbf4eaa28b0a0af6bf91ce252 (patch)
tree0e6528a80e6f3c0bab29c0ff610aa06bd0dc880e /Master/texmf-dist/tex/lualatex
parentf09c55f24ebafbc8d9d1a7e053774a4ecb070ca5 (diff)
luamathalign (4may22)
git-svn-id: svn://tug.org/texlive/trunk@63226 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/luamathalign/build.lua21
-rw-r--r--Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua42
-rw-r--r--Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua101
-rw-r--r--Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty4
4 files changed, 75 insertions, 93 deletions
diff --git a/Master/texmf-dist/tex/lualatex/luamathalign/build.lua b/Master/texmf-dist/tex/lualatex/luamathalign/build.lua
deleted file mode 100644
index 3ce83c670a6..00000000000
--- a/Master/texmf-dist/tex/lualatex/luamathalign/build.lua
+++ /dev/null
@@ -1,21 +0,0 @@
-module = "luamathalign"
-typesetexe = "lualatex"
-tdsroot = "lualatex"
-checkengines = {"luatex"}
-unpackfiles = {"*.dtx"}
-installfiles = {"*.sty", "*.lua"}
-sourcefiles = {"*.dtx", "*.lua"}
-
-uploadconfig = {
- pkg = "luamathalign",
- version = "v0.1",
- author = "Marcel Krüger",
- license = "lppl1.3c",
- summary = "More flexible alignment in amsmath environments",
- ctanPath = "/macros/luatex/latex/luamathalign/",
- -- repository = "https://github.com/zauguin/luamathalign/"
- description = "Allow aligning mathematical expressions on points where \z
- where direcly using &amp; is not possible, especially in nested macros or environments.",
- topic = {'maths', 'luatex'},
- -- update = true,
-}
diff --git a/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua b/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua
deleted file mode 100644
index 3e10f0fc454..00000000000
--- a/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua
+++ /dev/null
@@ -1,42 +0,0 @@
-----Copyright (C) 2019--2022 by Marcel Krueger
----
---- This file may be distributed and/or modified under the
---- conditions of the LaTeX Project Public License, either
---- version 1.3c of this license or (at your option) any later
---- version. The latest version of this license is in:
----
---- http://www.latex-project.org/lppl.txt
----
---- and version 1.3 or later is part of all distributions of
---- LaTeX version 2005/12/01 or later.
-return function(namespace)
- return {
- query = function(n)
- local p = node.getproperty(n)
- return p and p[namespace]
- end,
- get = function(n, ...)
- local p = node.getproperty(n)
- if not p then
- p = {}
- node.setproperty(n, p)
- end
- local n = p[namespace]
- if nil == p[namespace] then
- local d = select('#', ...) ~= 0 and ... or {}
- n, p[namespace] = d, d
- end
- return n
- end,
- set = function(n, v)
- local p = node.getproperty(n)
- if not p then
- p = {}
- node.setproperty(n, p)
- end
- local old = p[namespace]
- p[namespace] = v
- return old
- end,
- }
-end
diff --git a/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua b/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua
index aa8476b0553..03f75fa5f55 100644
--- a/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua
+++ b/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua
@@ -17,16 +17,24 @@
--
-- and version 1.3 or later is part of all distributions of
-- LaTeX version 2005/12/01 or later.
+local properties = node.get_properties_table()
local luacmd = require'luamathalign-luacmd'
-local luaprop = require'luamathalign-luaprop'('mathalign')
local hlist = node.id'hlist'
local vlist = node.id'vlist'
local whatsit = node.id'whatsit'
-local kern = node.id'kern'
+local glue = node.id'glue'
local user_defined = node.subtype'user_defined'
local whatsit_id = luatexbase.new_whatsit'mathalign'
local node_cmd = token.command_id'node'
local ampersand = token.new(38, 4)
+
+local mmode do
+ for k,v in next, tex.getmodevalues() do
+ if v == 'math' then mmode = k end
+ end
+ assert(mmode)
+end
+
-- We might want to add y later
local function is_marked(mark, list)
for n in node.traverse(list) do
@@ -160,8 +168,8 @@ local isolate do
x = x + w
list.head, last = node.remove(list.head, n)
if x ~= offset then
- local k = node.new(kern)
- k.kern, offset = x - offset, x
+ local k = node.new(glue)
+ k.width, offset = x - offset, x
newhead, newtail = node.insert_after(newhead, newtail, k)
end
newhead, newtail = node.insert_after(newhead, newtail, n)
@@ -208,8 +216,8 @@ local isolate do
local after
list.head, after = node.remove(list.head, n)
if 0 ~= offset then
- local k = node.new(kern)
- k.kern, offset = -offset, 0
+ local k = node.new(glue)
+ k.width, offset = -offset, 0
newhead, newtail = node.insert_after(newhead, newtail, k)
end
newhead, newtail = node.insert_after(newhead, newtail, n)
@@ -260,8 +268,8 @@ local isolate do
x = x + w
head, last = node.remove(head, n)
if x ~= offset then
- local k = node.new(kern)
- k.kern, offset = x - offset, x
+ local k = node.new(glue)
+ k.width, offset = x - offset, x
newhead, newtail = node.insert_after(newhead, newtail, k)
end
newhead, newtail = node.insert_after(newhead, newtail, n)
@@ -274,25 +282,47 @@ local isolate do
end
end
-local mark, afterkern
+local function find_mmode_boundary()
+ for i=tex.nest.ptr,0,-1 do
+ local nest = tex.nest[i]
+ if nest.mode ~= mmode and nest.mode ~= -mmode then
+ return nest, i
+ end
+ end
+end
+
luatexbase.add_to_callback('post_mlist_to_hlist_filter', function(n)
- if mark then
+ local nest = find_mmode_boundary()
+ local props = properties[nest.head]
+ local alignment = props and props.luamathalign_alignment
+ if alignment then
+ props.luamathalign_alignment = nil
local x
- n, x = measure(mark, n)
- local k = node.new'kern'
+ n, x = measure(alignment.mark, n)
+ local k = node.new'glue'
local off = x - n.width
- k.kern, afterkern.kern = off, -off
+ k.width, alignment.afterkern.width = off, -off
node.insert_after(n.head, nil, k)
n.width = x
- mark, afterkern = nil, nil
end
return n
end, 'luamathalign')
local function get_kerntoken(newmark)
- assert(not mark)
- mark, afterkern = newmark, node.new'kern'
- return token.new(node.direct.todirect(afterkern), node_cmd)
+ local nest = find_mmode_boundary()
+ local props = properties[nest.head]
+ if not props then
+ props = {}
+ properties[nest.head] = props
+ end
+ if props.luamathalign_alignment then
+ tex.error('Multiple alignment classes trying to control the same cell')
+ return token.new(0, 0)
+ else
+ local afterkern = node.new'glue'
+ props.luamathalign_alignment = {mark = newmark, afterkern = afterkern}
+ return token.new(node.direct.todirect(afterkern), node_cmd)
+ end
end
local function insert_whatsit(mark)
@@ -305,10 +335,11 @@ luacmd("SetAlignmentPoint", function()
if mark < 0 then
for i=tex.nest.ptr,0,-1 do
local t = tex.nest[i].head
- if luaprop.query(t) ~= nil then
+ local props = properties[t]
+ if props and props.luamathalign_context ~= nil then
mark = mark + 1
if mark == 0 then
- luaprop.set(t, true)
+ props.luamathalign_context = true
return insert_whatsit(-i)
end
end
@@ -331,22 +362,34 @@ luacmd("ExecuteAlignment", function()
end, "protected")
luacmd("LuaMathAlign@begin", function()
- local nest = tex.nest.top
- luaprop.set(nest.head, false)
+ local t = tex.nest.top.head
+ local props = properties[t]
+ if not props then
+ props = {}
+ properties[t] = props
+ end
+ props.luamathalign_context = false
end, "protected")
luacmd("LuaMathAlign@end@early", function()
local t = tex.nest.top.head
- if luaprop.set(t, nil) == true then
- handle_whatsit(-tex.nest.ptr)
+ local props = properties[t]
+ if props then
+ if props.luamathalign_context == true then
+ handle_whatsit(-tex.nest.ptr)
+ end
+ props.luamathalign_context = nil
end
end, "protected")
local delayed
luacmd("LuaMathAlign@end", function()
- local nest = tex.nest.top
- local t = nest.head
- if luaprop.set(t, nil) == true then
- assert(not delayed)
- delayed = {get_kerntoken(-tex.nest.ptr), ampersand}
+ local t = tex.nest.top.head
+ local props = properties[t]
+ if props then
+ if props.luamathalign_context == true then
+ assert(not delayed)
+ delayed = {get_kerntoken(-tex.nest.ptr), ampersand}
+ end
+ props.luamathalign_context = nil
end
end, "protected")
luatexbase.add_to_callback("hpack_filter", function(head, groupcode)
@@ -363,7 +406,7 @@ end, "luamathalign.delayed")
luacmd("LuaMathAlign@IsolateAlignmentPoints", function()
local main = token.scan_int()
if not token.scan_keyword 'into' then
- tex.error'Expected "into"'
+ tex.error'Expected "into"'
end
local marks = token.scan_int()
local head, newhead = isolate(tex.box[main])
diff --git a/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty b/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty
index 6a735b40120..a993aff35d8 100644
--- a/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty
+++ b/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty
@@ -20,7 +20,9 @@
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage
{luamathalign}
- [2022-04-18 v0.1 additional math alignment tricks using Lua]
+ [2022-05-04 v0.3 additional math alignment tricks using Lua]
+\RequirePackage{iftex}
+\RequireLuaTeX
\directlua{require'luamathalign'}
\IfPackageLoadedTF{amsmath}{%
\@firstofone