From 5c8d99818b1bbd837d3c7c955ff6745f797c4f6b Mon Sep 17 00:00:00 2001 From: Ulrike Fischer Date: Thu, 6 Feb 2025 16:58:09 +0100 Subject: [PATCH] add support for Lbl in math aligments --- luamml-structelemwriter.lua | 14 ++++++++--- luamml.dtx | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/luamml-structelemwriter.lua b/luamml-structelemwriter.lua index 35454af..372f548 100644 --- a/luamml-structelemwriter.lua +++ b/luamml-structelemwriter.lua @@ -8,6 +8,9 @@ local mc_end = token.create'tag_mc_end:' local catlatex = luatexbase.registernumber("catcodetable@latex") +ltx.__tag.struct.luamml = ltx.__tag.struct.luamml or {} +ltx.__tag.struct.luamml.labels = ltx.__tag.struct.luamml.labels or {} + local function escape_name(name) return name end @@ -117,10 +120,13 @@ local function write_elem(tree, stash) end for _, elem in ipairs(tree) do if type(elem) ~= 'string' and not elem['tex:ignore'] then - if elem['intent']==':equationlabel' and lastlblstructnum then - elem[1][#elem+1]={[':structnum']= lastlblstructnum} - lastlblstructnum=nil - end + if elem['intent']==':equationlabel' and ltx.__tag.struct.luamml.labels then + if #ltx.__tag.struct.luamml.labels > 0 then + -- print("CHECK LABEL STRUCTURE: ",table.serialize(elem), table.serialize(ltx.__tag.struct.luamml.labels)) + local num= table.remove(ltx.__tag.struct.luamml.labels,1) + elem[1][#elem+1]={[':structnum']= num} + end + end write_elem(elem) end end diff --git a/luamml.dtx b/luamml.dtx index 71f17d1..204b4ec 100644 --- a/luamml.dtx +++ b/luamml.dtx @@ -715,6 +715,7 @@ % % \end{macrocode} % +% \subsubsection{Tags and labels} % These sockets save and set tags and labels in alignments. % \begin{macrocode} \str_if_exist:cF { l__socket_tagsupport/math/luamml/mtable/tag/save_plug_str } @@ -738,6 +739,55 @@ % % \end{macrocode} +% +% If math structure elements are created the Lbl-structure of a tag +% must be moved inside the math structure, typically as an additional column in an +% \texttt{mtable} with an intent \texttt{:equationlabel}. +% +% The luamml-code handles this by stashing the Lbl-structure, storing the +% structure number in an array and reusing it once it creates the math structure elements. +% +% This should only be done for specific environments, we define +% a constant to test: +% \begin{macrocode} +%<*luatex> +\clist_map_inline:nn + { + align, + alignat, + xalignat, + xxalignat, + flalign, + gather, + %multline, % NO + %equation, % NO + } + {\tl_const:cn { c__luamml_label_#1_tl}{}} +% \end{macrocode} +% +% +% \begin{macrocode} +\NewSocketPlug{tagsupport/math/display/tag/begin}{luamml} + { + \tag_mc_end: + \bool_lazy_and:nnTF + { \tl_if_exist_p:c { c__luamml_label_ \@currenvir _tl } } + { \int_if_odd_p:n { \int_div_truncate:nn { \l__luamml_flag_int } { 8 } } } + { + \typeout{Stash~and~move~\@currenvir~Lbl} + \tag_struct_begin:n {tag=Lbl,stash} + \directlua{table.insert(ltx.__tag.struct.luamml.labels,\tag_get:n{struct_num})} + } + { + \tag_struct_begin:n {tag=Lbl} + } + \tag_mc_begin:n {} + } +\AssignSocketPlug{tagsupport/math/display/tag/begin}{luamml} +% +% \end{macrocode} +% +% % \subsubsection{Horizontal boxes} % This socket annotates an \cs{hbox} inside box commands used in math. % We test for the socket until the release 2025-06-01.