Debian Codegraph @

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

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