Open mbertucci47 opened 1 month ago
Yes, bracing environments is problematic with the tagging code. It hides the \@doendpe
which is important in various places. See also https://github.com/latex3/tagging-project/issues/48 and https://github.com/latex3/tagging-project/issues/18.
Needs some verification (and perhaps some further thoughts, but I think the following would resolve the problem generally:
\DocumentMetadata{testphase={phase-III,math}}
\documentclass{article}
\makeatletter
\def\@endpetrue {%
\global\let\if@endpe\iftrue
% if called inside a group propagate to the outside
\ifnum\currentgrouplevel>\z@
\aftergroup\propagate@doendpe
\fi
}
% if \if@endpe is still true run \@doendpe
% that in turn runs another \@endpetrue (besides other things), thus propagating further, if necessary
% However, if the endpe situation got resolved nothing further happens
\def\propagate@doendpe{%
\if@endpe
\typeout{=> run (another) @doendpe at group level \the\currentgrouplevel}%
\@doendpe
\else
\typeout{=> do not run (another) @doendpe}%
\fi
}
% with the above approach we do not need the propagation in \end... any longer
% (since this is now handled by \aftergroup\propagate@doendpe) so here a simple \endgroup is enough
\@namedef{end }#1{%
\romannumeral
\IfHookEmptyTF{env/#1/end}%
{\expandafter\z@}%
{\z@\UseHook{env/#1/end}}%
\csname end#1\endcsname\@checkend{#1}%
% \expandafter\endgroup\if@endpe\@doendpe\fi
\endgroup
\UseHook{env/#1/after}%
\if@ignore\@ignorefalse\ignorespaces\fi
}
\makeatother
\begin{document}
{\begin{equation}
A
\end{equation}}
Some text
{Braces set in different place
\begin{equation}
B
\end{equation}
Some text
}
\end{document}
I haven't had a chance to debug, but naively adding the changed code to the testmath-test file attached above produces errors, even without uncommenting the braced environments
It seems the changed code doesn't work with thebibliography
.
\DocumentMetadata{testphase={phase-III,math}}
\documentclass{article}
\makeatletter
\def\@endpetrue {%
\global\let\if@endpe\iftrue
% if called inside a group propagate to the outside
\ifnum\currentgrouplevel>\z@
\aftergroup\propagate@doendpe
\fi
}
% if \if@endpe is still true run \@doendpe
% that in turn runs another \@endpetrue (besides other things), thus propagating further, if necessary
% However, if the endpe situation got resolved nothing further happens
\def\propagate@doendpe{%
\if@endpe
\typeout{=> run (another) @doendpe at group level \the\currentgrouplevel}%
\@doendpe
\else
\typeout{=> do not run (another) @doendpe}%
\fi
}
% with the above approach we do not need the propagation in \end... any longer
% (since this is now handled by \aftergroup\propagate@doendpe) so here a simple \endgroup is enough
\@namedef{end }#1{%
\romannumeral
\IfHookEmptyTF{env/#1/end}%
{\expandafter\z@}%
{\z@\UseHook{env/#1/end}}%
\csname end#1\endcsname\@checkend{#1}%
% \expandafter\endgroup\if@endpe\@doendpe\fi
\endgroup
\UseHook{env/#1/after}%
\if@ignore\@ignorefalse\ignorespaces\fi
}
\makeatother
\begin{document}
\begin{equation}
\sum
\end{equation}
\begin{thebibliography}{9}
\bibitem{dihe:newdir}
W.~Diffie and E.~Hellman, \emph{New directions in cryptography}, IEEE
Transactions on Information Theory \textbf{22} (1976), no.~5, 644--654.
\end{thebibliography}
\end{document}
produces the error
! Package tagpdf Error: The number of automatic begin (3) and end (2)
(tagpdf) text-unit para hooks differ!
Getting rid of either the equation
or thebibliography
environment removes the error.
I missed out one necessary adjustments involving lists:
\ExplSyntaxOn
\socket_set_plug:nnn{tagsupport/block-endpe}{on}
{ \@endpetrue }
\socket_set_plug:nnn{tagsupport/block-endpe}{off}
{ \@endpefalse }
\ExplSyntaxOff
After that it should work.
If a math environment is placed in a braced group, it produces an error with the math tagging code. Compiling
with lualatex-dev produces
If the
Some text
after is removed, the error goes away.I noticed this because, out of curiosity, I wanted to see if
testmath.tex
worked with the tagging code. With a few modifications due to the lack of amsthm support, it does, except for two instances of math environments placed in a group. Modified version below with those environments commented out.testmath-test.txt
For reference, the commented lines are
and