summaryrefslogtreecommitdiff
path: root/Master
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
parentf09c55f24ebafbc8d9d1a7e053774a4ecb070ca5 (diff)
luamathalign (4may22)
git-svn-id: svn://tug.org/texlive/trunk@63226 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/lualatex/luamathalign/build.lua (renamed from Master/texmf-dist/tex/lualatex/luamathalign/build.lua)2
-rw-r--r--Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdfbin391838 -> 394249 bytes
-rw-r--r--Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx112
-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
-rwxr-xr-xMaster/tlpkg/libexec/ctan2tds4
7 files changed, 158 insertions, 107 deletions
diff --git a/Master/texmf-dist/tex/lualatex/luamathalign/build.lua b/Master/texmf-dist/doc/lualatex/luamathalign/build.lua
index 3ce83c670a6..023b2dfcca7 100644
--- a/Master/texmf-dist/tex/lualatex/luamathalign/build.lua
+++ b/Master/texmf-dist/doc/lualatex/luamathalign/build.lua
@@ -8,7 +8,7 @@ sourcefiles = {"*.dtx", "*.lua"}
uploadconfig = {
pkg = "luamathalign",
- version = "v0.1",
+ version = "v0.3",
author = "Marcel Krüger",
license = "lppl1.3c",
summary = "More flexible alignment in amsmath environments",
diff --git a/Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdf b/Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdf
index d946d148943..a20abc46120 100644
--- a/Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdf
+++ b/Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx b/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx
index 401c8ef7eaf..1a1ebc614eb 100644
--- a/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx
+++ b/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx
@@ -57,7 +57,7 @@
%
% \GetFileInfo{luamathalign.dtx}
% \title{The \pkg{luamathalign} package\thanks{This document
-% corresponds to \pkg{luamathalign}~v0.1, dated~2022-04-18.}}
+% corresponds to \pkg{luamathalign}~v0.3, dated~2022-05-04.}}
% \author{Marcel Kr\"uger \\ \href{mailto:tex@2krueger.de}{tex@2krueger.de}}
%
% \maketitle
@@ -206,16 +206,24 @@
%<*lua>
% \fi
% \begin{macrocode}
+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
@@ -349,8 +357,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)
@@ -397,8 +405,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)
@@ -449,8 +457,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)
@@ -463,25 +471,51 @@ 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')
+% \end{macrocode}
+% The glue node is referred to as a kern for historical reasons. A glue node is
+% used since this interacts better with lua-ul.
+% \begin{macrocode}
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)
@@ -494,10 +528,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
@@ -520,22 +555,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)
@@ -552,7 +599,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])
@@ -570,11 +617,12 @@ end, "protected")
\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]
% \fi
% The actual \LaTeX\ package just loads the Lua module and patches \pkg{amsmath}:
% \begin{macrocode}
-% \RequirePackage{scrlfile}
+\RequirePackage{iftex}
+\RequireLuaTeX
\directlua{require'luamathalign'}
\IfPackageLoadedTF{amsmath}{%
\@firstofone
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
diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds
index 7d1b365a09e..946b5d96a6e 100755
--- a/Master/tlpkg/libexec/ctan2tds
+++ b/Master/tlpkg/libexec/ctan2tds
@@ -2129,7 +2129,7 @@ $standardtex
'luaintro', 'NULL', # doc pkg
'luakeys', '\.lua|luakeys(-debug)?\.tex|' . $standardtex,
'lualatex-math', '\.sty', # not phst-doc.cls
- 'luamathalign','luam.*\.lua|' . $standardtex, # not build.lua
+ 'luamathalign','luam.*\.lua|\.sty', # not build.lua
'luamesh', '\.sty', # not lltxdoc.cls
'luapackageloader', '\.lua|' . $standardtex,
'luaprogtable','\.lua|' . $standardtex,
@@ -3091,7 +3091,7 @@ my $core_latex = "$Master/texmf-dist/tex/latex";
'lua-typo' => 'etex',
'lua-ul' => 'etex-answer-y', # https://github.com/latex3/latex2e/issues/558
'luaindex' => 'lualatex --shell-escape',
- 'luamathalign' => 'etex',
+ 'luamathalign' => 'etex-answer-y',
'luatexja' => 'lualatex',
'makelabels' => 'tex --8bit',
'mandi' => 'pdflatex-preserve-pdf',