{multline} support (without labels on the left)

This commit is contained in:
Marcel Fabian Krüger 2021-06-23 11:05:45 +02:00
parent 4005fc172d
commit 3a8dcdebe8
3 changed files with 107 additions and 1 deletions

View File

@ -4,6 +4,7 @@ local save_result = require'luamml-tex'.save_result
local store_column = require'luamml-table'.store_column
local store_tag = require'luamml-table'.store_tag
local get_table = require'luamml-table'.get_table
local set_row_attribute = require'luamml-table'.set_row_attribute
local to_text = require'luamml-lr'
local properties = node.get_properties_table()
@ -36,6 +37,12 @@ lua.get_functions_table()[funcid] = function()
store_column(startmath)
end
local funcid = luatexbase.new_luafunction'__luamml_amsmath_set_row_columnalign:n'
token.set_lua('__luamml_amsmath_set_row_columnalign:n', funcid, 'protected')
lua.get_functions_table()[funcid] = function()
set_row_attribute('columnalign', token.scan_argument())
end
do
local saved
funcid = luatexbase.new_luafunction'__luamml_amsmath_save_inner_table:n'
@ -81,6 +88,7 @@ lua.get_functions_table()[funcid] = function()
mml_table.displaystyle = true
local columns = node.count(node.id'align_record', tex.lists.align_head)//2
mml_table.columnalign = kind == 'align' and string.rep('right left', columns, ' ') or nil
mml_table.width = kind == 'multline' and '100%' 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'

View File

@ -271,6 +271,83 @@
\ignorespacesafterend
}
% For a more interesting one, let's consider multline:
\cs_new_eq:NN \__luamml_amsmath_original_multline:n \multline@
\cs_set:Npn \multline@ #1 {
\__luamml_amsmath_original_multline:n {
\ifmeasuring@ \else
\__luamml_amsmath_set_row_columnalign:n {left}
\fi
#1
\ifmeasuring@ \else
\__luamml_amsmath_set_row_columnalign:n {right}
\fi
}
}
\cs_new_eq:NN \__luamml_amsmath_original_mmeasure:n \mmeasure@
\cs_set:Npn \mmeasure@ #1 {
\exp_last_unbraced:Nno
\use_ii_i:nn
{ \luamml_flag_ignore: }
{ \__luamml_amsmath_original_mmeasure:n {#1} }
}
% Luckily, {multline} uses \endmultline@math in exactly
% the spot where we have to set the flag.
% Less luckily, \endmultline@math sometimes get overwritten for the last line.
% But that isn't a problem since we want special behavior there anyway.
\cs_set:Npn \endmultline@math {
\luamml_flag_save:Nn \displaystyle {mtd}
$
\__luamml_amsmath_add_last_to_row:
}
\cs_set:Npn \rendmultline@ {
\iftag@
\luamml_flag_save:Nn \displaystyle {mtd}
$
\__luamml_amsmath_add_last_to_row:
\let \endmultline@math \relax
\ifshifttag@
\hskip \multlinegap
\llap {
\vtop {
\raise@tag
\normalbaselines
\setbox \@ne \null
\dp \@ne \lineht@
\box \@ne
\hbox {
\strut@
\make@display@tag
}
}
}
\else
\hskip \multlinetaggap
\make@display@tag
\fi
\__luamml_amsmath_set_tag:
\else
\hskip \multlinegap
\fi
\hfilneg
\math@cr
\__luamml_amsmath_finalize_table:n {multline}
\egroup
$$
}
\cs_set:Npn \lendmultline@ {
\hfilneg
\hskip\multlinegap
\math@cr
\__luamml_amsmath_finalize_table:n {multline}
\egroup
$$
}
\cs_set:Npn \bBigg@ #1 #2 {
{
\ensuremath {

View File

@ -4,8 +4,23 @@ local save_result = require'luamml-tex'.save_result
local properties = node.get_properties_table()
local glue_id = node.id'glue'
local tabskip_sub = 12
assert(node.subtypes'glue'[tabskip_sub] == 'tabskip')
local function store_get_row()
local row_temp = tex.nest[tex.nest.ptr-1].head
local row_temp
for i=tex.nest.ptr-1, 0, -1 do
local head = tex.nest[i].head
local glue = head.next
if glue and glue.id == glue_id and glue.subtype == tabskip_sub then
row_temp = head
break
end
end
if not row_temp then
error[[luamml_table's store function called outside of table]]
end
local props = properties[row_temp]
if not props then
props = {}
@ -48,6 +63,11 @@ local function store_tag(xml)
last_tag = nil
end
local function set_row_attribute(name, value)
local mml_row = store_get_row()
mml_row[name] = value
end
luatexbase.add_to_callback('hpack_filter', function(_, group)
if group ~= 'fin_row' then return true end
@ -85,5 +105,6 @@ return {
store_column = store_column,
store_column_xml = store_column_xml,
store_tag = store_tag,
set_row_attribute = set_row_attribute,
get_table = get_table,
}