latex3 / tagging-project

Issues related to the tagging project
https://latex3.github.io/tagging-project/
LaTeX Project Public License v1.3c
35 stars 14 forks source link

Warnings with minipage in an \hbox, workaround? #54

Open jfbu opened 9 months ago

jfbu commented 9 months ago

Surely not unexpected, but it appears one can not use minipage inside \hbox without some adaptations:

\DocumentMetadata{
 uncompress,
 pdfversion=1.7,
 lang=en-US,
 testphase=phase-III
}
\documentclass{book}
\begin{document}

\hbox{%
  \begin{minipage}{\linewidth}
    Hello\par
  \end{minipage}%
}

\end{document}

other_tagging_minipage_in_hbox.log

Package tagpdf Warning: Parent-Child 'StructTreeRoot/pdf' --> 'Div/pdf2'.
(tagpdf)                Relation is not allowed (struct 0, /StructTreeRoot -->
(tagpdf)                struct 4) on line 11

Package tagpdf Warning: Parent-Child 'StructTreeRoot/pdf' -->
(tagpdf)                'text-unit/user'.
(tagpdf)                Relation is not allowed (struct 4, /Div --> struct 5)
(tagpdf)                on line 12

Package tagpdf Warning: Parent-Child 'StructTreeRoot/pdf' --> 'text/user'.
(tagpdf)                Relation is not allowed (struct 5, /text-unit -->
(tagpdf)                struct 6) on line 12

Package tagpdf Warning: Parent-Child 'StructTreeRoot/pdf' --> 'text/user'.
(tagpdf)                Relation is not allowed (struct 0, /StructTreeRoot -->
(tagpdf)                struct 7) on line 13

The etoc package provides user an \etocframedstyle command to configure \tableofcontents to use a framed rendering of TOC. Legacy code (which is currently awfully badly indented in etoc.pdf due to some Emacs accident probably years ago) has an \vbox around an \hbox around a minipage around a multicols (or not if only 1 column) to support its (optional) "framed" style.

Wha should I do for the transition to tagging-compatible implementation?

This would be first step in handling jfbu/etoc#4.

u-fischer commented 9 months ago

Well lots of problems with boxes in boxes are not solved yet ;-(.

The easiest here would be to use \mbox instead of \hbox (or \leavevmode). Another option is to disable the locally the sockets (but depending on the content of the minipage one perhaps need to reenable them inside the minipage again):

\DocumentMetadata{
 uncompress,
 pdfversion=1.7,
 lang=en-US,
 testphase=phase-III
}
\documentclass{book}
\begin{document}

%\leavevmode
\hbox{%
\AssignSocketPlug{tagsupport/minipage/before}{noop}%
\AssignSocketPlug{tagsupport/minipage/after}{noop}%
  \begin{minipage}{\linewidth}
    Hello\par
  \end{minipage}%
}

\end{document}
jfbu commented 9 months ago

Thanks @u-fischer! I will no doubt hit other problems, but all warnings from the test file of jfbu/etoc#4 were gone after incorporating your code. I don't know what is policy here so not closing this issue from my own initiative as anyhow you may consider this is something to address in other ways, like docs etc... but feel free to close of course.

jfbu commented 9 months ago

To provide additional background the \hbox and \vbox nesting are used by etoc framed style to ... frame the contents. The \hbox and \vbox use \bgroup, \egroup to in effect work as in first and second argument of an environment. The minipage is inserted for some forgotten reason which may have to do with using multicols inside it.

jfbu commented 9 months ago

@u-fischer sorry to be back but I have now re-activated the minipage sockets inside the surrounding minipage. It is not tested but does it look like the way to do it if it were to stay?

In particular, the \end{minipage} is immediately followed by the \egroup, so I guess my socket reactivation right before \egroup can be dropped altogether? or do they do global things?

        \end{minipage}% started in the \hbox
\ifEtoc@tagactive
\AssignSocketPlug{tagsupport/minipage/before}{tag/dflt}%
\AssignSocketPlug{tagsupport/minipage/after}{tag/dflt}%
\fi
      \egroup %  end of \hbox wrapper around minipage (inside \vbox)
u-fischer commented 9 months ago

assignment to sockets are local (you get the documentation with texdoc ltsockets).

jfbu commented 9 months ago

Ok. This part of the sockets documentations looks outdated:

% In contrast to template code, there is no standard configuration
% method through parameters for hooks, i.e., the code added to a hook
% \enquote{is} the configuration. If it wants to provide for
% configuration through parameters it has to also provide its own
% method to set such parameters in some way. However, in that case it
% is likely that using a hook is not the right approach and the
% developer better calls a template instance instead which then offers
% configuration through a key/value interface.

https://github.com/latex3/latex2e/blob/1d4df17f07911bf1ca1fdd401694fc825eb24bbc/base/ltsockets.dtx#L166-L173

HMM, maybe I should have read further

% There are also hooks that take arguments (typically portions of
% document data) and in that case the hook code can access these
% arguments through \verb=#1=, \verb=#2=, etc.

but then I find it all quite confusing what is meant in the end.

jfbu commented 8 months ago

Update: exact same problem with \parbox with similar work-around.

DocumentMetadata{
 uncompress,
 pdfversion=1.7,
 lang=en-US,
 testphase=phase-III
}
\documentclass{article}

\begin{document}
\hbox{%
%\AssignSocketPlug{tagsupport/parbox/before}{noop}%  THIS IS A FIX
%\AssignSocketPlug{tagsupport/parbox/after}{noop}%   THIS IS A FIX
  \parbox{1cm}{foo}%
}
\end{document}
jfbu commented 8 months ago

So, \sbox0{\parbox{1cm}{foo}} is enough to trigger the problem. It does not have to be a box typeset on the page.