Skip to content

Commit

Permalink
add support for Lbl in math aligments
Browse files Browse the repository at this point in the history
  • Loading branch information
u-fischer committed Feb 6, 2025
1 parent 18e85d0 commit 5c8d998
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
14 changes: 10 additions & 4 deletions luamml-structelemwriter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions luamml.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@
%</luatex>
% \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 }
Expand All @@ -738,6 +739,55 @@

%</luatex>
% \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}
%</luatex>
% \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.
Expand Down

0 comments on commit 5c8d998

Please sign in to comment.