Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/latex-lab-minipage.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-minipage.dtx
4 %%
5 % Copyright (C) 2023-2026 LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 %
15 % The latex-lab bundle is developed in the LaTeX2e GitHub.
16 % Issues may be reported at
17 %
18 % https://github.com/latex3/latex2e/issues
19 %
20 \def\ltlabminipagedate{2026-04-24}
21 \def\ltlabminipageversion{0.81k}
22 %<*driver>
23 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
24 \documentclass[kernel]{l3in2edoc}
25
26 \EnableCrossrefs
27 \CodelineIndex
28 \begin{document}
29 \DocInput{latex-lab-minipage.dtx}
30 \end{document}
31 %</driver>
32 %
33 % \fi
34 %
35 %
36 % \title{The \textsf{latex-lab-minipage} package\\
37 % Changes related to the tagging of minipage and parbox}
38 % \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
39 % \date{v\ltlabminipageversion\ \ltlabminipagedate}
40 %
41 % \maketitle
42 %
43 % \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
44 % \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
45 % \newcommand{\docclass}{document class \marginpar{\raggedright document class
46 % customizations}}
47 %
48 % \providecommand\hook[1]{\texttt{#1}}
49 %
50 % \begin{abstract}
51 % \end{abstract}
52 %
53 % \section{Introduction}
54 %
55 % How to best tag minipages and parboxes is still under discussion.
56 % But as they start and contain paragraphs it is clear that
57 % some sockets are needed to interrupt and restart the tagging.
58 %
59 % The tagging added is currently quite simple-minded. See the
60 % todo-testfiles and the code comments for some open points.
61 %
62 % One of the main problems is how to properly embed them in the
63 % surrounding. When used in normal text (in a paragraph) they
64 % typically should close the \texttt{text} structure and reopen one
65 % at the end. But when used inside low-level \cs{vbox} or \cs{hbox}
66 % this is often wrong. The code uses now there two tagging sockets
67 % \texttt{parbox/before} and
68 % \texttt{parbox/after} which can be set to noop, if
69 % necessary.
70 %
71 % \begin{macrocode}
72 %<*package>
73 % \end{macrocode}
74 %
75 % \section{Implementation}
76 % \begin{macrocode}
77 \ProvidesExplPackage {latex-lab-testphase-minipage}
78 {\ltlabminipagedate} {\ltlabminipageversion}
79 {Code related to the tagging of minipages and parboxes}
80 % \end{macrocode}
81 %
82 %
83 % \subsection{Provide the kernel hooks}
84 % [kernel?]
85 % We need to check/set the status before the
86 % initial \cs{leavevmode} to decide how to handle the structure.
87 % Perhaps the same command will work for both?
88 % \begin{macrocode}
89 \def\@kernel@init@minipage{}
90 \def\@kernel@init@parbox{}
91 % \end{macrocode}
92 % We use sockets for the tag support code, as there will be cases where we want
93 % to exchange the content or disable it.
94 % The socket declarations are in lttagging.dtx.
95 % \begin{macrocode}
96 % \NewTaggingSocket{minipage/before}{0}
97 % \NewTaggingSocket{minipage/after} {0}
98 % \NewTaggingSocket{parbox/before} {0}
99 % \NewTaggingSocket{parbox/after}{0}
100 % \end{macrocode}
101 %
102 % \subsection{Patch minipage}
103 % [kernel?]
104 % The begin hook is inserted in \cs{@iiiminipage}
105 % \begin{macrocode}
106 \def\@iiiminipage#1#2[#3]#4{%
107 % \end{macrocode}
108 % Before switching to hmode we insert a hook. It is currently unused
109 % but could for example check if we are in vmode and change the following
110 % paragraph tag.
111 % \begin{macrocode}
112 \@kernel@init@minipage
113 \leavevmode
114 \@pboxswfalse
115 \setlength\@tempdima{#4}%
116 \def\@mpargs{{#1}{#2}[#3]{#4}}%
117 % \end{macrocode}
118 % insert the socket
119 % \begin{macrocode}
120 \UseTaggingSocket{minipage/before}% new
121 \setbox\@tempboxa\vbox\bgroup
122 \color@begingroup
123 \hsize\@tempdima
124 \textwidth\hsize \columnwidth\hsize
125 \@parboxrestore
126 % \end{macrocode}
127 % minipages are perhaps used in environments where the tagging of paragraphs
128 % has been altered. So we try to restore this. TODO: this should
129 % perhaps be done in \cs{@parboxrestore} directly.
130 % \begin{macrocode}
131 \UseTaggingSocket{para/restore}
132 \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
133 \socket_assign_plug:nn{fntext/process}{mp}%
134 \let\@listdepth\@mplistdepth \@mplistdepth\z@
135 \@minipagerestore
136 \@setminipage}
137 % \end{macrocode}
138 % And a hook at the end
139 % \begin{macrocode}
140 \def\endminipage{%
141 \par
142 \unskip
143 \ifvoid\@mpfootins\else
144 \vskip\skip\@mpfootins
145 \normalcolor
146 \footnoterule
147 \unvbox\@mpfootins
148 \fi
149 \@minipagefalse %% added 24 May 89
150 \color@endgroup
151 \egroup
152 % \end{macrocode}
153 % As the parbox command is called, we must prevent that it adds its
154 % additional tagging commands:
155 % \begin{macrocode}
156 \tag_suspend:n{minipage}
157 \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}%
158 \tag_resume:n{minipage}
159 \UseTaggingSocket{minipage/after} %new end ...
160 }
161 % \end{macrocode}
162 %
163 % \changes{v0.81i}{2026-02-24}{Use text mode vertical centering}
164 % And similar for \cs{parbox}
165 % \begin{macrocode}
166 \long\def\@iiiparbox#1#2[#3]#4#5{%
167 \@kernel@init@parbox
168 \leavevmode
169 \setlength\@tempdima{#4}%
170 \UseTaggingSocket{parbox/before}
171 \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore
172 % \end{macrocode}
173 % parbox are perhaps used in environments where the tagging of paragraphs
174 % has been altered. So we try to restore this. TODO: this should
175 % perhaps be done in \cs{@parboxrestore} directly.
176 % \begin{macrocode}
177 \UseTaggingSocket{para/restore}
178 #5\@@par}%
179 \ifx\relax#2\else
180 \setlength\@tempdimb{#2}%
181 \edef\@parboxto{to\the\@tempdimb}%
182 \fi
183 \if#1b\vbox
184 \else\if #1t\vtop
185 \else\vcenter@text
186 \fi\fi
187 \@parboxto{\let\hss\vss\let\unhbox\unvbox
188 \csname bm@#3\endcsname}%
189 \@end@tempboxa%
190 \UseTaggingSocket{parbox/after}
191 }
192 % \end{macrocode}
193 %
194 % \subsection{Tagging commands}
195 %
196 % \begin{macrocode}
197 \NewTaggingSocketPlug{minipage/before}{kernel}
198 {
199 % \end{macrocode}
200 % As there was a \cs{leavevmode} before that is a P/text open that we have to close
201 % if para tagging is active:
202 % \begin{macrocode}
203 \tag_mc_end_push:
204 \bool_if:NT \l__tag_para_bool {\tag_struct_end:}
205 % \end{macrocode}
206 % TODO: the P can be further up, we need a proper method to test and handle this.
207 % \begin{macrocode}
208 \tag_struct_begin:n{tag=\UseStructureName{minipage}}
209 }
210 % \end{macrocode}
211 % similar for the other sockets:
212 % \begin{macrocode}
213 \NewTaggingSocketPlug{minipage/after}{kernel}
214 {
215 \tag_struct_end:
216 \bool_if:NT \l__tag_para_bool
217 {\tag_struct_begin:n{tag=\UseStructureName{para/textblock}}}
218 \tag_mc_begin_pop:n{}
219 }
220
221 \NewTaggingSocketPlug{parbox/before}{kernel}
222 {
223 \tag_mc_end_push:
224 \bool_if:NT \l__tag_para_bool {\tag_struct_end:}
225 \tag_struct_begin:n{tag=\UseStructureName{parbox}}
226 }
227
228 \NewTaggingSocketPlug{parbox/after}{kernel}
229 {
230 \tag_struct_end:
231 \bool_if:NT \l__tag_para_bool
232 {\tag_struct_begin:n{tag=\UseStructureName{para/textblock}}}
233 \tag_mc_begin_pop:n{}
234 }
235 % \end{macrocode}
236 %
237 % Copies of the plugs with the previous names for compatibility.
238 % After release 2026-06-01 they should be replaced by the new names and then removed.
239 % \begin{macrocode}
240 \NewTaggingSocketPlug{minipage/before}{tag/dflt}
241 {
242 \tag_mc_end_push:
243 \bool_if:NT \l__tag_para_bool {\tag_struct_end:}
244 \tag_struct_begin:n{tag=\UseStructureName{minipage}}
245 }
246 \NewTaggingSocketPlug{minipage/after}{tag/dflt}
247 {
248 \tag_struct_end:
249 \bool_if:NT \l__tag_para_bool
250 {\tag_struct_begin:n{tag=\UseStructureName{para/textblock}}}
251 \tag_mc_begin_pop:n{}
252 }
253 \NewTaggingSocketPlug{parbox/before}{tag/dflt}
254 {
255 \tag_mc_end_push:
256 \bool_if:NT \l__tag_para_bool {\tag_struct_end:}
257 \tag_struct_begin:n{tag=\UseStructureName{parbox}}
258 }
259 \NewTaggingSocketPlug{parbox/after}{tag/dflt}
260 {
261 \tag_struct_end:
262 \bool_if:NT \l__tag_para_bool
263 {\tag_struct_begin:n{tag=\UseStructureName{para/textblock}}}
264 \tag_mc_begin_pop:n{}
265 }
266 % \end{macrocode}
267 % Activate the default tagging plug
268 % \begin{macrocode}
269 \AssignTaggingSocketPlug{minipage/before}{kernel}
270 \AssignTaggingSocketPlug{minipage/after} {kernel}
271 \AssignTaggingSocketPlug{parbox/before} {kernel}
272 \AssignTaggingSocketPlug{parbox/after} {kernel}
273 % \end{macrocode}
274 % \begin{macrocode}
275 %</package>
276 % \end{macrocode}