latex3 / tagpdf

Tagging support code for LaTeX
59 stars 7 forks source link

Suppressing tagging after resuming results in error #104

Open T-F-S opened 1 month ago

T-F-S commented 1 month ago

Testing your supposed tagging suppression in https://github.com/T-F-S/tcolorbox/issues/283#issuecomment-2202487503 I encountered a compilation error, if one suppressed code part is followed by another one.

The following code gives a MWE without tcolorbox and without tikzpicture, but with the same errors:

\DocumentMetadata{
  lang        = de,
  pdfversion  = 2.0,
  pdfstandard = ua-2,
  pdfstandard = a-4f,
  testphase   =
  {
    phase-III,
  },
  uncompress,
}

%\tagpdfsetup{tabsorder=structure}

\documentclass[]{article}

\ExplSyntaxOn
\makeatletter

\NewSocket{tagsupport/tcb/drawing/begin}{0}
\NewSocket{tagsupport/tcb/drawing/end}{0}
\NewSocketPlug{tagsupport/tcb/drawing/begin}{suspend}
 {\tag_mc_end_push:\tag_mc_begin:n{artifact}}
\NewSocketPlug{tagsupport/tcb/drawing/end}{resume}
 {\tag_mc_end:\tag_mc_begin_pop:n{}}
\AssignSocketPlug{tagsupport/tcb/drawing/begin}{suspend}
\AssignSocketPlug{tagsupport/tcb/drawing/end}{resume}

\NewDocumentCommand \dummy {}
  {
    \UseTaggingSocket{tcb/drawing/begin}
    \SuspendTagging{tcb/drawing}
    Dummy
    \ResumeTagging{tcb/drawing}
    \UseTaggingSocket{tcb/drawing/end}
  }

\makeatother
\ExplSyntaxOff

\begin{document}

abc

\dummy
\dummy
\dummy

efg

\end{document}

Package tagpdf Warning: there is no mc to end at 4

! Package tagpdf Error: there is no open structure on the stack

u-fischer commented 1 month ago

You need to correctly "balance" the para/begin and para/end code when you stop tagging (and generally too). In your example you are suspending tagging before you start the paragraph, in vmode, but you then resume it inside the paragraph.

It compiles fine if you add a \leavevmode:

\NewDocumentCommand \dummy {}
  {
    \leavevmode 
    \UseTaggingSocket{tcb/drawing/begin}
    \SuspendTagging{tcb/drawing}
    Dummy
    \ResumeTagging{tcb/drawing}
    \UseTaggingSocket{tcb/drawing/end}
  }

Or a \par:

\NewDocumentCommand \dummy {}
  {
    \UseTaggingSocket{tcb/drawing/begin}
    \SuspendTagging{tcb/drawing}
    Dummy\par
    \ResumeTagging{tcb/drawing}
    \UseTaggingSocket{tcb/drawing/end}
  }
T-F-S commented 1 month ago

I see. This seems to be true even for \clearpage. The following code also needs \leavevmode to work:

\NewDocumentCommand \dummy {}
  {
    \clearpage
    \leavevmode%  deletion gives an error
    \UseTaggingSocket{tcb/drawing/begin}
    \SuspendTagging{tcb/drawing}
    Dummy
    \ResumeTagging{tcb/drawing}
    \UseTaggingSocket{tcb/drawing/end}
  }