From 4005fc172da021ab3a4ec32f898d52daf1bf387e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Wed, 23 Jun 2021 04:39:58 +0200 Subject: [PATCH] gathered support --- luamml-amsmath.lua | 18 +++++++++------- luamml-patches-amsmath.sty | 43 ++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/luamml-amsmath.lua b/luamml-amsmath.lua index c3bfd80..3ef4298 100644 --- a/luamml-amsmath.lua +++ b/luamml-amsmath.lua @@ -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 diff --git a/luamml-patches-amsmath.sty b/luamml-patches-amsmath.sty index f2c9205..93d6a42 100644 --- a/luamml-patches-amsmath.sty +++ b/luamml-patches-amsmath.sty @@ -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@