texlive[63226] Master: luamathalign (4may22)
commits+karl at tug.org
commits+karl at tug.org
Wed May 4 22:52:09 CEST 2022
Revision: 63226
http://tug.org/svn/texlive?view=revision&revision=63226
Author: karl
Date: 2022-05-04 22:52:09 +0200 (Wed, 04 May 2022)
Log Message:
-----------
luamathalign (4may22)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdf
trunk/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx
trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua
trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty
trunk/Master/tlpkg/libexec/ctan2tds
Added Paths:
-----------
trunk/Master/texmf-dist/doc/lualatex/luamathalign/build.lua
Removed Paths:
-------------
trunk/Master/texmf-dist/tex/lualatex/luamathalign/build.lua
trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua
Added: trunk/Master/texmf-dist/doc/lualatex/luamathalign/build.lua
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/luamathalign/build.lua (rev 0)
+++ trunk/Master/texmf-dist/doc/lualatex/luamathalign/build.lua 2022-05-04 20:52:09 UTC (rev 63226)
@@ -0,0 +1,21 @@
+module = "luamathalign"
+typesetexe = "lualatex"
+tdsroot = "lualatex"
+checkengines = {"luatex"}
+unpackfiles = {"*.dtx"}
+installfiles = {"*.sty", "*.lua"}
+sourcefiles = {"*.dtx", "*.lua"}
+
+uploadconfig = {
+ pkg = "luamathalign",
+ version = "v0.3",
+ 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 & is not possible, especially in nested macros or environments.",
+ topic = {'maths', 'luatex'},
+ -- update = true,
+}
Property changes on: trunk/Master/texmf-dist/doc/lualatex/luamathalign/build.lua
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/lualatex/luamathalign/luamathalign.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx 2022-05-04 20:50:11 UTC (rev 63225)
+++ trunk/Master/texmf-dist/source/lualatex/luamathalign/luamathalign.dtx 2022-05-04 20:52:09 UTC (rev 63226)
@@ -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 at 2krueger.de}{tex at 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 @@
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 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 @@
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 @@
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 @@
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 @@
end, "protected")
luacmd("LuaMathAlign at 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 at 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 at 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 @@
luacmd("LuaMathAlign at 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 @@
\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
Deleted: trunk/Master/texmf-dist/tex/lualatex/luamathalign/build.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luamathalign/build.lua 2022-05-04 20:50:11 UTC (rev 63225)
+++ trunk/Master/texmf-dist/tex/lualatex/luamathalign/build.lua 2022-05-04 20:52:09 UTC (rev 63226)
@@ -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 & is not possible, especially in nested macros or environments.",
- topic = {'maths', 'luatex'},
- -- update = true,
-}
Deleted: trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua 2022-05-04 20:50:11 UTC (rev 63225)
+++ trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign-luaprop.lua 2022-05-04 20:52:09 UTC (rev 63226)
@@ -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
Modified: trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua 2022-05-04 20:50:11 UTC (rev 63225)
+++ trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.lua 2022-05-04 20:52:09 UTC (rev 63226)
@@ -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 @@
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 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 @@
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 @@
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 @@
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 @@
end, "protected")
luacmd("LuaMathAlign at 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 at 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 at 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 @@
luacmd("LuaMathAlign at 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])
Modified: trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty 2022-05-04 20:50:11 UTC (rev 63225)
+++ trunk/Master/texmf-dist/tex/lualatex/luamathalign/luamathalign.sty 2022-05-04 20:52:09 UTC (rev 63226)
@@ -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
Modified: trunk/Master/tlpkg/libexec/ctan2tds
===================================================================
--- trunk/Master/tlpkg/libexec/ctan2tds 2022-05-04 20:50:11 UTC (rev 63225)
+++ trunk/Master/tlpkg/libexec/ctan2tds 2022-05-04 20:52:09 UTC (rev 63226)
@@ -2129,7 +2129,7 @@
'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 @@
'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',
More information about the tex-live-commits
mailing list.