gathered support

This commit is contained in:
Marcel Fabian Krüger 2021-06-23 04:39:58 +02:00
parent 36b3c596a7
commit 4005fc172d
2 changed files with 49 additions and 12 deletions

View File

@ -38,20 +38,21 @@ end
do
local saved
funcid = luatexbase.new_luafunction'__luamml_amsmath_save_inner_table:'
token.set_lua('__luamml_amsmath_save_inner_table:', funcid)
funcid = luatexbase.new_luafunction'__luamml_amsmath_save_inner_table:n'
token.set_lua('__luamml_amsmath_save_inner_table:n', funcid)
lua.get_functions_table()[funcid] = function()
-- TODO: Error handling etc
local kind = token.scan_argument()
local mml_table = get_table()
if not mml_table then return end
mml_table.displaystyle = true
local columns = node.count(node.id'align_record', tex.lists.align_head)//2
mml_table.columnalign = string.rep('right left', columns, ' ')
mml_table.columnalign = kind == 'gathered' and 'center' or string.rep('right left', columns, ' ')
local spacing = {}
for n in node.traverse_id(node.id'glue', tex.lists.align_head) do
spacing[#spacing+1] = n.width == 0 and '0' or string.format('%.3f', n.width/65781.76)
end
mml_table.columnspacing = table.concat(spacing, ' ', 2, #spacing-2)
mml_table.columnspacing = #spacing > 3 and table.concat(spacing, ' ', 2, #spacing-2) or nil
saved = mml_table
end
@ -70,20 +71,21 @@ do
end
end
funcid = luatexbase.new_luafunction'__luamml_amsmath_finalize_table:'
token.set_lua('__luamml_amsmath_finalize_table:', funcid)
funcid = luatexbase.new_luafunction'__luamml_amsmath_finalize_table:n'
token.set_lua('__luamml_amsmath_finalize_table:n', funcid)
lua.get_functions_table()[funcid] = function()
-- TODO: Error handling etc
local kind = token.scan_argument()
local mml_table = get_table()
if not mml_table then return end
mml_table.displaystyle = true
local columns = node.count(node.id'align_record', tex.lists.align_head)//2
mml_table.columnalign = string.rep('right left', columns, ' ')
mml_table.columnalign = kind == 'align' and string.rep('right left', columns, ' ') or nil
local spacing = {}
for n in node.traverse_id(node.id'glue', tex.lists.align_head) do
spacing[#spacing+1] = n.width == 0 and '0' or '.8em'
end
mml_table.columnspacing = table.concat(spacing, ' ', 2, #spacing-2)
mml_table.columnspacing = #spacing > 3 and table.concat(spacing, ' ', 2, #spacing-2) or nil
save_result(mml_table, true)
end

View File

@ -63,9 +63,39 @@
\ams@return@opt@arg
}
\renewcommand \gathered [1] [c] {
\RIfM@
\else
\nonmatherr@ { \begin {gathered} }
\fi
\luamml_annotate:en {
nucleus = true, core = false
} {
\alignedspace@left
}
\ams@start@box {#1} \bgroup
\Let@
\chardef \dspbrk@context \@ne
\restore@math@cr
\spread@equation
\ialign \bgroup
\hfil
\strut@
$
\m@th
\displaystyle
##
\luamml_flag_save:Nn \displaystyle {mtd}
$
\__luamml_amsmath_add_last_to_row:
\hfil
\crcr
\ams@return@opt@arg
}
\cs_set:Npn \endaligned {
\crcr
\__luamml_amsmath_save_inner_table:
\__luamml_amsmath_save_inner_table:n \@currenvir
\egroup
\restorecolumn@
\egroup
@ -104,8 +134,12 @@
\strut@
{##}
}
\dim_compare:nNnF {0pt} = {
\box_wd:N \c_zero_int
} {
\__luamml_amsmath_set_tag:
}
\place@tag@gather
\__luamml_amsmath_set_tag:
\tabskip \iftagsleft@
\gdisplaywidth@
\else
@ -114,6 +148,7 @@
\crcr
#1
}
\cs_new_eq:NN \__luamml_amsmath_original_gmeasure:n \gmeasure@
\cs_set:Npn \gmeasure@ #1 {
\exp_last_unbraced:Nno
@ -125,7 +160,7 @@
\cs_set:Npn \endgather {
\math@cr
\black@ \totwidth@
\__luamml_amsmath_finalize_table:
\__luamml_amsmath_finalize_table:n {gather}
\egroup
$$
\ignorespacesafterend
@ -223,7 +258,7 @@
\cs_set:Npn \endalign {
\math@cr
\black@ \totwidth@
\__luamml_amsmath_finalize_table:
\__luamml_amsmath_finalize_table:n {align}
\egroup
\ifingather@
\restorealignstate@