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

View File

@ -63,9 +63,39 @@
\ams@return@opt@arg \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 { \cs_set:Npn \endaligned {
\crcr \crcr
\__luamml_amsmath_save_inner_table: \__luamml_amsmath_save_inner_table:n \@currenvir
\egroup \egroup
\restorecolumn@ \restorecolumn@
\egroup \egroup
@ -104,8 +134,12 @@
\strut@ \strut@
{##} {##}
} }
\dim_compare:nNnF {0pt} = {
\box_wd:N \c_zero_int
} {
\__luamml_amsmath_set_tag:
}
\place@tag@gather \place@tag@gather
\__luamml_amsmath_set_tag:
\tabskip \iftagsleft@ \tabskip \iftagsleft@
\gdisplaywidth@ \gdisplaywidth@
\else \else
@ -114,6 +148,7 @@
\crcr \crcr
#1 #1
} }
\cs_new_eq:NN \__luamml_amsmath_original_gmeasure:n \gmeasure@ \cs_new_eq:NN \__luamml_amsmath_original_gmeasure:n \gmeasure@
\cs_set:Npn \gmeasure@ #1 { \cs_set:Npn \gmeasure@ #1 {
\exp_last_unbraced:Nno \exp_last_unbraced:Nno
@ -125,7 +160,7 @@
\cs_set:Npn \endgather { \cs_set:Npn \endgather {
\math@cr \math@cr
\black@ \totwidth@ \black@ \totwidth@
\__luamml_amsmath_finalize_table: \__luamml_amsmath_finalize_table:n {gather}
\egroup \egroup
$$ $$
\ignorespacesafterend \ignorespacesafterend
@ -223,7 +258,7 @@
\cs_set:Npn \endalign { \cs_set:Npn \endalign {
\math@cr \math@cr
\black@ \totwidth@ \black@ \totwidth@
\__luamml_amsmath_finalize_table: \__luamml_amsmath_finalize_table:n {align}
\egroup \egroup
\ifingather@ \ifingather@
\restorealignstate@ \restorealignstate@