Skip to content

Commit

Permalink
handle labels in alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
u-fischer committed Feb 6, 2025
1 parent c2de63c commit 1c423f7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
2 changes: 2 additions & 0 deletions base/lttagging.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@
% \NewSocket{tagsupport/math/display/end}{0}
% \NewSocket{tagsupport/math/display/formula/begin}{2} %
% \NewSocket{tagsupport/math/display/formula/end}{0}
% \NewSocket{tagsupport/math/display/tag/begin}{0} %
% \NewSocket{tagsupport/math/display/tag/end}{0}
% \end{macrocode}
%
% \subsubsection{Sockets specific for luamml}
Expand Down
19 changes: 14 additions & 5 deletions required/latex-lab/latex-lab-amsmath.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,31 @@
% The tag/label must be saved, so that it can be reinserted later.
% TODO: xml export looks ok, but tagging with structure elements
% is wrong and must be corrected.
% TODO: \cs{maketag@@@} is used in places where tagging/luamml handling
% is not wanted. This must be checked and handled.
% \begin{macrocode}
\@namedef{maketag@@@} #1
\def\maketag@@@#1
{%
\ifmeasuring@
\hbox{\m@th\normalfont#1}%
\else
\tagmcend \tagstructbegin{tag=Lbl}%
\tagmcbegin{tag=Lbl}%
\UseTaggingSocket{math/display/tag/begin}
\hbox{\m@th\normalfont#1
\UseTaggingSocket{math/luamml/mtable/tag/save}
}%
\tagmcend \tagstructend \tagmcbegin{}%
\UseTaggingSocket{math/display/tag/end}
\fi
}
% \end{macrocode}
%
% \cs{eqref} uses \cs{tagform@} and so \cs{maketag@@@} but we do not want this tagging
% there.
%
% \begin{macrocode}
\def\maketag@@@notag#1{\hbox{\m@th\normalfont#1}}
\DeclareRobustCommand{\eqref}[1]
{\textup{\let\maketag@@@\maketag@@@notag\tagform@{\ref{#1}}}}
% \end{macrocode}
%
% \subsubsection{align \& friends}
% The align preamble (used in \cs{align@}) needs code for luamml
% to save the cells.
Expand Down
40 changes: 40 additions & 0 deletions required/latex-lab/latex-lab-math.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,46 @@
% \end{macrocode}
% \end{plugdecl}
%
% \subsubsection{Sockets for tags (labels)}
% \begin{socketdecl}
% {
% tagsupport/math/display/tag/begin,
% tagsupport/math/display/tag/end,
% }
% These sockets are used in \cs{maketag@@@} to tag
% labels as Lbl. luamml changes the plug to move
% the Lbl into the math structure with an intent.
% \changes{v0.6l}{2025-02-06}{added sockets for tags/labels}
% \begin{macrocode}
\socket_new:nn {tagsupport/math/display/tag/begin}{0}
\socket_new:nn {tagsupport/math/display/tag/end}{0}
% \end{macrocode}
%\end{socketdecl}
%
% \begin{plugdecl}{default}
% \changes{v0.6j}{2024-11-19}{moved \cs{tagpdfparaOff} into the socket, tagging/765}
% \begin{macrocode}
\socket_new_plug:nnn
{tagsupport/math/display/tag/begin}
{default}
{
\tag_mc_end:
\tag_struct_begin:n {tag=Lbl}
\tag_mc_begin:n {}
}
\socket_new_plug:nnn
{tagsupport/math/display/tag/end}
{default}
{
\tag_mc_end:
\tag_struct_end:
\tag_mc_begin:n{}
}
\socket_assign_plug:nn {tagsupport/math/display/tag/begin}{default}
\socket_assign_plug:nn {tagsupport/math/display/tag/end}{default}
% \end{macrocode}
% \end{plugdecl}
%
% \subsubsection{Internal sockets}
%
% \begin{variable}{\l_@@_content_template_tl}
Expand Down
14 changes: 10 additions & 4 deletions texmf/tex/lualatex/luamml/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
29 changes: 29 additions & 0 deletions texmf/tex/lualatex/luamml/luamml.sty
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,35 @@
}
\AssignSocketPlug{tagsupport/math/luamml/mtable/tag/set}{luamml}

\clist_map_inline:nn
{
align,
alignat,
xalignat,
xxalignat,
flalign,
gather,
%multline, % NO
%equation, % NO
}
{\tl_const:cn { c__luamml_label_#1_tl}{}}
\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}
\str_if_exist:cF { l__socket_tagsupport/math/luamml/hbox_plug_str }
{
\NewSocket{tagsupport/math/luamml/hbox}{2}
Expand Down

0 comments on commit 1c423f7

Please sign in to comment.